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]

[PATCH,HURD] Fix value of __libc_stack_end


When using some libthread, we need to update the value of __libc_stack_end
to what the libthread allocated. This requires making __libc_stack_end
non-relro to be able to modify it.

Samuel

2011-08-24  Samuel Thibault  <samuel.thibault@ens-lyon.org>

* sysdeps/generic/ldsodefs.h [LIBC_STACK_END_NOT_RELRO] (__libc_stack_end): Do
not use attribute_relro.
* sysdeps/mach/hurd/dl-sysdep.h (LIBC_STACK_END_NOT_RELRO): Define.
* sysdeps/mach/hurd/i386/init-first.c (init): Update __libc_stack_end to
libthread-provided value.
* sysdeps/mach/hurd/dl-sysdep.c (__libc_stack_end): Do not use attribute_relro.

---
 generic/ldsodefs.h          |    6 +++++-
 mach/hurd/dl-sysdep.c       |    2 +-
 mach/hurd/dl-sysdep.h       |    3 ++-
 mach/hurd/i386/init-first.c |    2 ++
 4 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index d040590..cb24ca7 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -723,7 +723,11 @@ rtld_hidden_proto (_dl_make_stack_executable)
    might use the variable which results in copy relocations on some
    platforms.  But this does not matter, ld.so can always use the local
    copy.  */
-extern void *__libc_stack_end attribute_relro;
+extern void *__libc_stack_end
+#ifndef LIBC_STACK_END_NOT_RELRO
+     attribute_relro
+#endif
+     ;
 rtld_hidden_proto (__libc_stack_end)
 
 /* Parameters passed to the dynamic linker.  */
diff --git a/sysdeps/mach/hurd/dl-sysdep.h b/sysdeps/mach/hurd/dl-sysdep.h
index 4b21b77..8f1c728 100644
--- a/sysdeps/mach/hurd/dl-sysdep.h
+++ b/sysdeps/mach/hurd/dl-sysdep.h
@@ -25,7 +25,8 @@
 #define RTLD_PRIVATE_ERRNO 0
 
 #ifdef SHARED
-/* _dl_argv cannot be attribute_relro, because the stack-switching
+/* _dl_argv and __libc_stack_end cannot be attribute_relro, because the stack-switching
    libc initializer for using cthreads might write into it.  */
 # define DL_ARGV_NOT_RELRO 1
+# define LIBC_STACK_END_NOT_RELRO 1
 #endif
diff --git a/sysdeps/mach/hurd/i386/init-first.c b/sysdeps/mach/hurd/i386/init-first.c
index e79af1d..7b2ea12 100644
--- a/sysdeps/mach/hurd/i386/init-first.c
+++ b/sysdeps/mach/hurd/i386/init-first.c
@@ -227,6 +224,8 @@ init (int *_data)
 
       void switch_stacks (void);
 
+      __libc_stack_end = newsp;
+
       /* Copy per-thread variables from that temporary
 	 area onto the new cthread stack.  */
       memcpy (__hurd_threadvar_location_from_sp (0, newsp),
diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c
index a63151f..a5df5c1 100644
--- a/sysdeps/mach/hurd/dl-sysdep.c
+++ b/sysdeps/mach/hurd/dl-sysdep.c
@@ -55,7 +55,7 @@ INTVARDEF(__libc_enable_secure)
 int __libc_multiple_libcs = 0;	/* Defining this here avoids the inclusion
 				   of init-first.  */
 /* This variable containts the lowest stack address ever used.  */
-void *__libc_stack_end attribute_relro = NULL;
+void *__libc_stack_end = NULL;
 rtld_hidden_data_def(__libc_stack_end)
 void *_dl_random attribute_relro = NULL; /* TODO */
 


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