x86: Allow undefined _DYNAMIC in static executable
Commit Message
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.
Any comments?
H.J.
---
* 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.
---
sysdeps/i386/dl-machine.h | 17 +++++++++++++++--
sysdeps/x86_64/dl-machine.h | 13 +++++++++++++
2 files changed, 28 insertions(+), 2 deletions(-)
@@ -54,8 +54,21 @@ 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 ();
+#ifdef SHARED
+ extern Elf32_Dyn _DYNAMIC[] attribute_hidden;
+ return (Elf32_Addr) &_DYNAMIC - elf_machine_dynamic ();
+#else
+ extern Elf32_Dyn _DYNAMIC[] __attribute__((weak, visibility ("hidden")));
+ if (_DYNAMIC)
+ {
+ /* 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 ();
+ }
+ else
+ return 0;
+#endif
}
/* Set up the loaded object described by L so its unrelocated PLT
@@ -55,8 +55,21 @@ 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. */
+#ifdef SHARED
extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
return (ElfW(Addr)) &_DYNAMIC - elf_machine_dynamic ();
+#else
+ extern ElfW(Dyn) _DYNAMIC[] __attribute__((weak, visibility ("hidden")));
+ if (_DYNAMIC)
+ {
+ /* 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 ();
+ }
+ else
+ return 0;
+#endif
}
/* Set up the loaded object described by L so its unrelocated PLT