]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
x86: Allow undefined _DYNAMIC in static executable
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 28 Sep 2017 22:28:00 +0000 (15:28 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 28 Sep 2017 22:28:12 +0000 (15:28 -0700)
When --enable-static-pie is used to build static PIE, _DYNAMIC is used
to compute the load address of static PIE.  But _DYNAMIC is undefined
when creating static executable.  This patch makes _DYNAMIC weak in PIE
libc.a so that it can be undefined.

* sysdeps/i386/dl-machine.h (elf_machine_load_address): Allow
undefined _DYNAMIC in PIE libc.a.
* sysdeps/x86_64/dl-machine.h (elf_machine_load_address):
Likewse.

ChangeLog
sysdeps/i386/dl-machine.h
sysdeps/x86_64/dl-machine.h

index e4919f2f3813a2bc0a7f880fabd551ff6b515eb3..1171915738732003eb17e703f9fd1ee25a75d42f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2017-09-28  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * sysdeps/i386/dl-machine.h (elf_machine_load_address): Allow
+       undefined _DYNAMIC in PIE libc.a.
+       * sysdeps/x86_64/dl-machine.h (elf_machine_load_address):
+       Likewse.
+
 2017-09-28  Wilco Dijkstra  <wdijkstr@arm.com>
 
        * sysdeps/alpha/fpu/bits/mathinline.h: Delete file.
index 2e17eba5c08042ac5cad563afa6078fe70dc3222..242c692c17ac2b138a78b6d4f3b1140d48891f94 100644 (file)
@@ -54,8 +54,15 @@ elf_machine_load_address (void)
   /* Compute the difference between the runtime address of _DYNAMIC as seen
      by a GOTOFF reference, and the link-time address found in the special
      unrelocated first GOT entry.  */
-  extern Elf32_Dyn bygotoff[] asm ("_DYNAMIC") attribute_hidden;
-  return (Elf32_Addr) &bygotoff - elf_machine_dynamic ();
+#ifndef SHARED
+  extern Elf32_Dyn _DYNAMIC[] __attribute__((weak, visibility ("hidden")));
+  if (!_DYNAMIC)
+    return 0;
+#endif
+  /* The address of dynamic must be taken as non-weak to avoid dynamic
+     relocation.  */
+  extern Elf32_Dyn dynamic[] asm ("_DYNAMIC") attribute_hidden;
+  return (Elf32_Addr) &dynamic - elf_machine_dynamic ();
 }
 
 /* Set up the loaded object described by L so its unrelocated PLT
index 6a04cbcdc98da4363719892bde060b5e7adb97d4..a79e5ca2f9e1eb112bad1bb9511ff47e9296dba3 100644 (file)
@@ -55,8 +55,15 @@ elf_machine_load_address (void)
   /* Compute the difference between the runtime address of _DYNAMIC as seen
      by an IP-relative reference, and the link-time address found in the
      special unrelocated first GOT entry.  */
-  extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
-  return (ElfW(Addr)) &_DYNAMIC - elf_machine_dynamic ();
+#ifndef SHARED
+  extern ElfW(Dyn) _DYNAMIC[] __attribute__((weak, visibility ("hidden")));
+  if (!_DYNAMIC)
+    return 0;
+#endif
+  /* The address of dynamic must be taken as non-weak to avoid dynamic
+     relocation.  */
+  extern ElfW(Dyn) dynamic[] asm ("_DYNAMIC") attribute_hidden;
+  return (ElfW(Addr)) &dynamic - elf_machine_dynamic ();
 }
 
 /* Set up the loaded object described by L so its unrelocated PLT