[PATCH 48/74] x86, lto: Use inline assembler instead of global register variable to get sp

2012-08-18 Thread Andi Kleen
From: Andi Kleen 

LTO in gcc 4.6/47. has trouble with global register variables. They were used
to read the stack pointer. Use a simple inline assembler statement instead.

I verified this generates the same binary (on 64bit) as the original
register variable.

Signed-off-by: Andi Kleen 
---
 arch/x86/include/asm/thread_info.h |8 +---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/thread_info.h 
b/arch/x86/include/asm/thread_info.h
index 89f794f..d9fbfa1 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -167,9 +167,11 @@ struct thread_info {
  */
 #ifndef __ASSEMBLY__
 
-
-/* how to get the current stack pointer from C */
-register unsigned long current_stack_pointer asm("esp") __used;
+#define current_stack_pointer ({   \
+   unsigned long sp;   \
+   asm("mov %%esp,%0" : "=r" (sp));\
+   sp; \
+})
 
 /* how to get the thread information struct from C */
 static inline struct thread_info *current_thread_info(void)
-- 
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 48/74] x86, lto: Use inline assembler instead of global register variable to get sp

2012-08-19 Thread Jan Beulich
>>> Andi Kleen  08/19/12 4:59 AM >>>
>I verified this generates the same binary (on 64bit) as the original
>register variable.

This isn't very surprising given that the modified code is inside a
CONFIG_X86_32 conditional (as ought to be obvious from the code using
%%esp). Given that it's being used as operand to a binary &, the resulting
code - if the compiler handles this only half way sensibly - can hardly be
expected to be identical.

>-register unsigned long current_stack_pointer asm("esp") __used;
>+#define current_stack_pointer ({ \
>+unsigned long sp;\
>+asm("mov %%esp,%0" : "=r" (sp));\
>+sp;\
>+})
 
It would get closer to the original if you used "=g" (I noticed in a few
earlier patches already that you like to use "=r" in places where a register
is not strictly required, thus reducing the flexibility the compiler has).

Also, given that this is more a workaround for a compiler deficiency,
shouldn't this be conditional upon use of LTO?

Jan

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 48/74] x86, lto: Use inline assembler instead of global register variable to get sp

2012-08-19 Thread Andi Kleen
On Sun, Aug 19, 2012 at 09:37:27AM +0100, Jan Beulich wrote:
> >>> Andi Kleen  08/19/12 4:59 AM >>>
> >I verified this generates the same binary (on 64bit) as the original
> >register variable.
> 
> This isn't very surprising given that the modified code is inside a
> CONFIG_X86_32 conditional (as ought to be obvious from the code using
> %%esp). Given that it's being used as operand to a binary &, the resulting
> code - if the compiler handles this only half way sensibly - can hardly be
> expected to be identical.

Doh! Thanks. I'll double check.

You're right it'll likely change code. But it shouldn't be common.

> 
> >-register unsigned long current_stack_pointer asm("esp") __used;
> >+#define current_stack_pointer ({ \
> >+unsigned long sp;\
> >+asm("mov %%esp,%0" : "=r" (sp));\
> >+sp;\
> >+})
>  
> It would get closer to the original if you used "=g" (I noticed in a few
> earlier patches already that you like to use "=r" in places where a register
> is not strictly required, thus reducing the flexibility the compiler has).

My fingers have =r hardcoded. Will fix.

> 
> Also, given that this is more a workaround for a compiler deficiency,
> shouldn't this be conditional upon use of LTO?

I think it's cleaner than the global reg var, so unconditional should 
be fine. It wouldn't surprise me if global reg causes trouble even
without LTO, i probably just triggered some latent bug.

-Andi

-- 
a...@linux.intel.com -- Speaking for myself only.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/