Fix RELOC_HIDE miscompilation
PATCH 1/1 Fix RELOC_HIDE miscompilation
[resend due to mailer problems]
RELOC_HIDE got miscompiled on gcc3.1/x86-64 in the access to softirq.c's per cpu variables. This patch fixes the problem.
Clearly to hide the relocation the addition needs to be done after the value obfuscation, not before.
I don't know if it triggers on other architectures (x86-64 is especially stressf here because it has negative kernel addresses), but seems like the right thing to do.
Also does the arithmetic in unsigned long to avoid undue assumptions of the comp for pointers.
-Andi
include/linux/compiler.h renamed from include/linux/compiler.h-o +3 -3
@@ -16,7 +16,7 @@/* This macro obfuscates arithmetic on a variable address so that gcc shouldn't recognize the original var, and make assumptions about it */ #define RELOC_HIDE (ptr, off) \ - ({ __typeof__(ptr) __ptr; \ - __asm__ ("" : "=g"(__ptr) : "0"((void *)(ptr) + (off))); \ - __ptr; }) + ({ unsigned long __ptr; \ + __asm__ ("" : "=g"(__ptr) : "0"(ptr)); \ + (typeof(ptr)) (__ptr + (off)); })#endif /* __LINUX_COMPILER_H */
In message <[email protected]> you write:
Quoted 6 lines
[resend due to mailer problems]
RELOC_HIDEgot miscompiled on gcc3.1/x86-64 in the access to softirq.c's per cpu variables. This patch fixes the problem.
Quoted 6 lines
Clearly to hide the relocation the addition needs to be done after the value obfuscation, not before.
I don't know if it triggers on other architectures (x86-64 is especially stressf here because it has negative kernel addresses), but seems like the right thing to do.
Yes, agreed. Linus, please apply.
include/linux/compiler.h renamed from include/linux/compiler.h-o +3 -3
@@ -16,7 +16,7 @@/* This macro obfuscates arithmetic on a variable address so that gcc shouldn't recognize the original var, and make assumptions about it */ #define RELOC_HIDE (ptr, off) \ - ({ __typeof__(ptr) __ptr; \ - __asm__ ("" : "=g"(__ptr) : "0"((void *)(ptr) + (off))); \ - __ptr; }) + ({ unsigned long __ptr; \ + __asm__ ("" : "=g"(__ptr) : "0"(ptr)); \ + (typeof(ptr)) (__ptr + (off)); })#endif /* __LINUX_COMPILER_H */
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.