aboutsummaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2017-09-28 15:28:00 -0700
committerH.J. Lu <hjl.tools@gmail.com>2017-09-28 15:28:12 -0700
commit4088d8dd29ce0629eeaa7cceca02414c85d98e05 (patch)
tree0b807276e1826b3c4522721d076aa81c23c5da8b /sysdeps
parent4d3693ec1cb7d247a217dc1eb7121c658f818dca (diff)
downloadglibc-4088d8dd29ce0629eeaa7cceca02414c85d98e05.zip
glibc-4088d8dd29ce0629eeaa7cceca02414c85d98e05.tar.gz
glibc-4088d8dd29ce0629eeaa7cceca02414c85d98e05.tar.bz2
x86: Allow undefined _DYNAMIC in static executable
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.
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/i386/dl-machine.h11
-rw-r--r--sysdeps/x86_64/dl-machine.h11
2 files changed, 18 insertions, 4 deletions
diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h
index 2e17eba..242c692 100644
--- a/sysdeps/i386/dl-machine.h
+++ b/sysdeps/i386/dl-machine.h
@@ -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
diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
index 6a04cbc..a79e5ca 100644
--- a/sysdeps/x86_64/dl-machine.h
+++ b/sysdeps/x86_64/dl-machine.h
@@ -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