[Gc] Patch for __libc_stack_end

Mike Hearn mike at navi.cx
Fri Jan 21 10:28:14 PST 2005


Hi,

This symbol has different versions in different glibc releases. It was
originally public, then it went private, then it went public again. I
talked to the glibc guys about this and they deemed this solution
kosher.

Is this patch OK Hans?

thanks -mike



Mike Hearn <mike at navi.cx>
Use dlsym to locate __libc_stack_end to bypass the symbol versioning
mechanism


-------------- next part --------------
--- os_dep.c	2005-01-21 18:25:26.964645200 +0000
+++ os_dep.c.mike	2005-01-21 18:25:13.092754048 +0000
@@ -859,9 +859,6 @@
 # define STAT_SKIP 27   /* Number of fields preceding startstack	*/
 			/* field in /proc/self/stat			*/
 
-# pragma weak __libc_stack_end
-  extern ptr_t __libc_stack_end;
-
 # ifdef IA64
     /* Try to read the backing store base from /proc/self/maps.	*/
     /* We look for the writable mapping with a 0 major device,  */
@@ -930,22 +927,24 @@
     char c;
     word result = 0;
     size_t i, buf_offset = 0;
+    ptr_t *__libc_stack_end = 0;
 
     /* First try the easy way.  This should work for glibc 2.2	*/
     /* This fails in a prelinked ("prelink" command) executable */
     /* since the correct value of __libc_stack_end never	*/
     /* becomes visible to us.  The second test works around 	*/
-    /* this.							*/  
-      if (0 != &__libc_stack_end && 0 != __libc_stack_end ) {
+    /* this.							*/
+    __libc_stack_end = dlsym(NULL, "__libc_stack_end");
+      if (0 != __libc_stack_end && 0 != *__libc_stack_end) {
 #       ifdef IA64
 	  /* Some versions of glibc set the address 16 bytes too	*/
 	  /* low while the initialization code is running.		*/
-	  if (((word)__libc_stack_end & 0xfff) + 0x10 < 0x1000) {
-	    return __libc_stack_end + 0x10;
+	  if (((word)*__libc_stack_end & 0xfff) + 0x10 < 0x1000) {
+	    return *__libc_stack_end + 0x10;
 	  } /* Otherwise it's not safe to add 16 bytes and we fall	*/
 	    /* back to using /proc.					*/
 #	else 
-	  return __libc_stack_end;
+	  return *__libc_stack_end;
 #	endif
       }
     f = open("/proc/self/stat", O_RDONLY);


More information about the Gc mailing list