* [PATCH] Revert x86: Allow undefined _DYNAMIC in static executable
@ 2017-10-03 22:50 H.J. Lu
0 siblings, 0 replies; only message in thread
From: H.J. Lu @ 2017-10-03 22:50 UTC (permalink / raw)
To: GNU C Library
This code is used in non-PIE static executable and static PIE. It checks
if _DYNAMIC is undefined before using it to compute load address. But
not all targets can convert access _DYNAMIC via GOT, which needs dynamic
relocation, to PC-relative at link-time.
I am checking it in.
H.J.
---
* sysdeps/i386/dl-machine.h (elf_machine_load_address): Don't
allow undefined _DYNAMIC in PIE libc.a.
* sysdeps/x86_64/dl-machine.h (elf_machine_load_address):
Likewse.
---
sysdeps/i386/dl-machine.h | 11 ++---------
sysdeps/x86_64/dl-machine.h | 11 ++---------
2 files changed, 4 insertions(+), 18 deletions(-)
diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h
index 242c692c17..2e17eba5c0 100644
--- a/sysdeps/i386/dl-machine.h
+++ b/sysdeps/i386/dl-machine.h
@@ -54,15 +54,8 @@ 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. */
-#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 ();
+ extern Elf32_Dyn bygotoff[] asm ("_DYNAMIC") attribute_hidden;
+ return (Elf32_Addr) &bygotoff - 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 a79e5ca2f9..6a04cbcdc9 100644
--- a/sysdeps/x86_64/dl-machine.h
+++ b/sysdeps/x86_64/dl-machine.h
@@ -55,15 +55,8 @@ 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. */
-#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 ();
+ extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
+ return (ElfW(Addr)) &_DYNAMIC - elf_machine_dynamic ();
}
/* Set up the loaded object described by L so its unrelocated PLT
--
2.13.6
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-10-03 22:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-03 22:50 [PATCH] Revert x86: Allow undefined _DYNAMIC in static executable H.J. Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).