Commit 74708ced authored by Nicolas Pitre's avatar Nicolas Pitre Committed by Russell King

[ARM PATCH] 1824/1: guard against gcc not respecting local variable register assignment

Patch from Nicolas Pitre

The recent discovery of a problem with gcc not always respecting register
assignment for local variables to be used with inline assembly is worrisome.
If unnoticed, such problems can cover bugs that might prove hard to find
especially when the code is right but silently ignored.  This patch adds a
test where needed to have the assembler confirm our register selection and
fail the kernel build if the wrong registers are allocated.
parent 8a51beef
......@@ -42,6 +42,15 @@
#define CR_XP (1 << 23) /* Extended page tables */
#define CR_VE (1 << 24) /* Vectored interrupts */
/*
* This is used to ensure the compiler did actually allocate the register we
* asked it for some inline assembly sequences. Apparently we can't trust
* the compiler from one version to another so a bit of paranoia won't hurt.
* This string is meant to be concatenated with the inline asm string and
* will cause compilation to stop on mismatch.
*/
#define __asmeq(x, y) ".ifnc " x "," y " ; .err ; .endif\n\t"
#ifndef __ASSEMBLY__
#include <linux/kernel.h>
......
......@@ -15,6 +15,7 @@
#include <asm/errno.h>
#include <asm/arch/memory.h>
#include <asm/domain.h>
#include <asm/system.h>
#define VERIFY_READ 0
#define VERIFY_WRITE 1
......@@ -107,7 +108,9 @@ extern int __get_user_8(void *);
extern int __get_user_bad(void);
#define __get_user_x(__r1,__p,__e,__s,__i...) \
__asm__ __volatile__ ("bl __get_user_" #__s \
__asm__ __volatile__ ( \
__asmeq("%0", "r0") __asmeq("%1", "r1") \
"bl __get_user_" #__s \
: "=&r" (__e), "=r" (__r1) \
: "0" (__p) \
: __i, "cc")
......@@ -223,7 +226,9 @@ extern int __put_user_8(void *, unsigned long long);
extern int __put_user_bad(void);
#define __put_user_x(__r1,__p,__e,__s) \
__asm__ __volatile__ ("bl __put_user_" #__s \
__asm__ __volatile__ ( \
__asmeq("%0", "r0") __asmeq("%2", "r1") \
"bl __put_user_" #__s \
: "=&r" (__e) \
: "0" (__p), "r" (__r1) \
: "ip", "lr", "cc")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment