This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Add x32 support to STACK_CHK_GUARD


On Fri, May 11, 2012 at 2:01 PM, Roland McGrath <roland@hack.frob.com> wrote:
> We already support sysdeps stackguard-macros.h files for ports and all
> those machine-specific cases ought to be moved out to new sysdeps files.
> It's not important that this cleanup be done right away. ?But for a new
> case, just add a new sysdeps file instead.
>
> While we're getting cleaner, it really would be better to use a %P0 with
> "i" (offsetof (tcbhead_t, stack_guard)) rather than the magic constant.
>
> In fact, AFAICT if you do that and make the insn just "mov", then a single
> x86_64 file would dtrt for both x86_64 and x32.
>

That is a good idea.  Here is a new patch.  I used %c1 the
same way as THREAD_SELF in nptl/sysdeps/x86_64/tls.h.
Tested on Linux/x32 and Linux/x86-64.  OK to install?

Thanks.


-- 
H.J.
--
	* elf/stackguard-macros.h (STACK_CHK_GUARD) [__x86_64__]: Use
	"%c1" with "i" (offsetof (tcbhead_t, stack_guard)).

diff --git a/elf/stackguard-macros.h b/elf/stackguard-macros.h
index a9889cf..0cad315 100644
--- a/elf/stackguard-macros.h
+++ b/elf/stackguard-macros.h
@@ -5,7 +5,9 @@
   ({ uintptr_t x; asm ("movl %%gs:0x14, %0" : "=r" (x)); x; })
 #elif defined __x86_64__
 # define STACK_CHK_GUARD \
-  ({ uintptr_t x; asm ("movq %%fs:0x28, %0" : "=r" (x)); x; })
+  ({ uintptr_t x;						\
+     asm ("mov %%fs:%c1, %0" : "=r" (x)				\
+	  : "i" (offsetof (tcbhead_t, stack_guard))); x; })
 #elif defined __powerpc64__
 # define STACK_CHK_GUARD \
   ({ uintptr_t x; asm ("ld %0,-28688(13)" : "=r" (x)); x; })


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]