[git commit ldso-future] use _dl_pagesize and _dl_stack_end from ldso in other libs

Peter S. Mazinger ps.m at gmx.net
Mon Apr 11 11:27:03 UTC 2011


commit: http://git.uclibc.org/uClibc/commit/?id=c360cf016f11484f85f21f9ef40979ab1f30ea34
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/ldso-future

Export __libc_stack_end only on ppc (see ldsodefs.h for details)

Signed-off-by: Peter S. Mazinger <ps.m at gmx.net>
---
 ldso/include/ldsodefs.h              |   12 ++++++------
 ldso/ldso/dl-startup.c               |    8 ++------
 ldso/ldso/ldso.c                     |    3 ++-
 libc/misc/internals/__uClibc_main.c  |   14 ++++++++++++--
 libpthread/linuxthreads/attr.c       |    4 ++--
 libpthread/nptl/init.c               |    2 +-
 libpthread/nptl/pthread_getattr_np.c |    4 ++--
 7 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/ldso/include/ldsodefs.h b/ldso/include/ldsodefs.h
index bf6f3b1..8afddc0 100644
--- a/ldso/include/ldsodefs.h
+++ b/ldso/include/ldsodefs.h
@@ -257,15 +257,15 @@ struct rtld_global
 struct rtld_global_ro
 {
 #endif
-#ifdef SHARED
 	/* Store the page size for later use */
-	size_t _dl_pagesize;
+	EXTERN size_t _dl_pagesize;
 	/* Variable pointing to the end of the stack (or close to it).  This value
 	   must be constant over the runtime of the application.  Some programs
 	   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.  */
-	void *_dl_stack_end;
+	EXTERN void *_dl_stack_end;
+#ifdef SHARED
 	/* We add a function table to _rtld_global_ro which is then used to
 	   call the function instead of going through the PLT.  The result
 	   is that we can avoid exporting the functions and we do not jump
@@ -373,10 +373,10 @@ extern void _dl_deallocate_tls (void *tcb, bool dealloc_tcb) internal_function a
    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.  */
-/* gcc uses it in rs6000/linux-unwind.c, could be patched to use
- * _dl_stack_end from the structure */
+/* gcc uses it in rs6000/linux-unwind.h, ckecked up to 4.5.2
+ * could be patched to use _dl_stack_end from the structure */
 /* gcc's boehm-gc has fallback if not found */
-#if 1 /*!defined SHARED || (defined IS_IN_rtld && defined __powerpc__)*/
+#if defined IS_IN_rtld && defined __powerpc__
 extern void *__libc_stack_end attribute_relro;
 #endif
 
diff --git a/ldso/ldso/dl-startup.c b/ldso/ldso/dl-startup.c
index 76826ed..78bed69 100644
--- a/ldso/ldso/dl-startup.c
+++ b/ldso/ldso/dl-startup.c
@@ -100,11 +100,6 @@ static __attribute_used__ unsigned long _dl_skip_args = 0;
 /* Static declarations */
 static int (*_dl_elf_main) (int, char **, char **);
 
-#if 1 /*def __powerpc__*/
-/* see ldsodefs.h why only for ppc */
-void * __libc_stack_end attribute_relro = NULL; /* Points to argc on stack, e.g. *((long *)__libc_stack_end) == argc */
-#endif
-
 /* When we enter this piece of code, the program stack looks like this:
 	argc            argument counter (integer)
 	argv[0]         program name (pointer)
@@ -325,7 +320,8 @@ DL_START(unsigned long args)
 	   since the dynamic resolver is not yet ready. */
 
 	GLRO(dl_stack_end) = (void *)(argv - 1);
-#if 1 /*def __powerpc__*/
+#ifdef __powerpc__
+	/* see ldsodefs.h why only for ppc */
 	__libc_stack_end = GLRO(dl_stack_end);
 #endif
 
diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c
index 49c14a1..142de79 100644
--- a/ldso/ldso/ldso.c
+++ b/ldso/ldso/ldso.c
@@ -54,7 +54,8 @@ struct rtld_global _rtld_global =
 
 struct rtld_global_ro _rtld_global_ro attribute_relro =
 {
-	._dl_pagesize = 0
+	._dl_pagesize = 0,
+	._dl_stack_end = NULL
 #ifdef SHARED
 ,	._dl_run_init_array = _dl_run_init_array,
 	._dl_run_fini_array = _dl_run_fini_array,
diff --git a/libc/misc/internals/__uClibc_main.c b/libc/misc/internals/__uClibc_main.c
index 0783c26..4bdc9ea 100644
--- a/libc/misc/internals/__uClibc_main.c
+++ b/libc/misc/internals/__uClibc_main.c
@@ -42,7 +42,7 @@
 #include <ldsodefs.h>
 
 #ifndef SHARED
-void *__libc_stack_end attribute_relro = NULL;
+void *_dl_stack_end attribute_relro = NULL;
 
 # ifdef __UCLIBC_HAS_SSP__
 #  include <dl-osinfo.h>
@@ -217,9 +217,13 @@ void __uClibc_init(void)
     if (__pagesize)
 	return;
 
+#ifdef SHARED
+    __pagesize = GLRO(dl_pagesize);
+#else
     /* Setup an initial value.  This may not be perfect, but is
      * better than  malloc using __pagesize=0 for atexit, ctors, etc.  */
     __pagesize = PAGE_SIZE;
+#endif
 
 #ifdef __UCLIBC_HAS_THREADS__
     /* Before we start initializing uClibc we have to call
@@ -318,7 +322,10 @@ void __uClibc_main(int (*main)(int, char **, char **), int argc,
 #endif
 
 #ifndef SHARED
-    __libc_stack_end = stack_end;
+    GLRO(dl_stack_end) = stack_end;
+# ifdef __powerpc__
+    __libc_stack_end = GLRO(dl_stack_end);
+# endif
 #endif
 
     __rtld_fini = rtld_fini;
@@ -363,7 +370,10 @@ void __uClibc_main(int (*main)(int, char **, char **), int argc,
 
 #ifndef __ARCH_HAS_NO_LDSO__
     /* Make certain getpagesize() gives the correct answer */
+# ifndef SHARED
+    /* for SHARED this was already set in __uClibc_init() */
     __pagesize = (auxvt[AT_PAGESZ].a_un.a_val)? auxvt[AT_PAGESZ].a_un.a_val : PAGE_SIZE;
+# endif
 
     /* Prevent starting SUID binaries where the stdin. stdout, and
      * stderr file descriptors are not already opened. */
diff --git a/libpthread/linuxthreads/attr.c b/libpthread/linuxthreads/attr.c
index 313d850..f142675 100644
--- a/libpthread/linuxthreads/attr.c
+++ b/libpthread/linuxthreads/attr.c
@@ -435,8 +435,8 @@ int pthread_getattr_np (pthread_t thread, pthread_attr_t *attr)
 	      uintptr_t to;
 	      if (sscanf (line, "%" SCNxPTR "-%" SCNxPTR, &from, &to) != 2)
 		continue;
-	      if (from <= (uintptr_t) __libc_stack_end
-		  && (uintptr_t) __libc_stack_end < to)
+	      if (from <= (uintptr_t) GLRO(dl_stack_end)
+		  && (uintptr_t) GLRO(dl_stack_end) < to)
 		{
 		  /* Found the entry.  Now we have the info we need.  */
 		  attr->__stacksize = rl.rlim_cur;
diff --git a/libpthread/nptl/init.c b/libpthread/nptl/init.c
index 379c4bb..6dbe975 100644
--- a/libpthread/nptl/init.c
+++ b/libpthread/nptl/init.c
@@ -342,7 +342,7 @@ __pthread_initialize_minimal_internal (void)
   /* Set initial thread's stack block from 0 up to __libc_stack_end.
      It will be bigger than it actually is, but for unwind.c/pt-longjmp.c
      purposes this is good enough.  */
-  THREAD_SETMEM (pd, stackblock_size, (size_t) __libc_stack_end);
+  THREAD_SETMEM (pd, stackblock_size, (size_t) GLRO(dl_stack_end));
 
   /* Initialize the list of all running threads with the main thread.  */
   INIT_LIST_HEAD (&__stack_user);
diff --git a/libpthread/nptl/pthread_getattr_np.c b/libpthread/nptl/pthread_getattr_np.c
index 86a4385..3635aef 100644
--- a/libpthread/nptl/pthread_getattr_np.c
+++ b/libpthread/nptl/pthread_getattr_np.c
@@ -105,8 +105,8 @@ pthread_getattr_np (
 		  uintptr_t to;
 		  if (sscanf (line, "%" SCNxPTR "-%" SCNxPTR, &from, &to) != 2)
 		    continue;
-		  if (from <= (uintptr_t) __libc_stack_end
-		      && (uintptr_t) __libc_stack_end < to)
+		  if (from <= (uintptr_t) GLRO(dl_stack_end)
+		      && (uintptr_t) GLRO(dl_stack_end) < to)
 		    {
 		      /* Found the entry.  Now we have the info we need.  */
 		      iattr->stacksize = rl.rlim_cur;
-- 
1.7.3.4



More information about the uClibc-cvs mailing list