public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/maskray/unnest] i386: Port elf_machine_{load_address, dynamic} from x86-64
@ 2021-09-24 20:12 Fangrui Song
  0 siblings, 0 replies; only message in thread
From: Fangrui Song @ 2021-09-24 20:12 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=91e92272caefad4b6156572fc41671dcbd93afe5

commit 91e92272caefad4b6156572fc41671dcbd93afe5
Author: Fangrui Song <maskray@google.com>
Date:   Fri Sep 24 09:36:32 2021 -0700

    i386: Port elf_machine_{load_address,dynamic} from x86-64
    
    This drops reliance on _GLOBAL_OFFSET_TABLE_[0] being the link-time
    address of _DYNAMIC.
    
    The code sequence length does not change.
    
    Reviewed-by: H.J. Lu <hjl.tools@gmail.com>

Diff:
---
 sysdeps/i386/dl-machine.h | 25 +++++++++----------------
 1 file changed, 9 insertions(+), 16 deletions(-)

diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h
index 590b41d8d7..0401888508 100644
--- a/sysdeps/i386/dl-machine.h
+++ b/sysdeps/i386/dl-machine.h
@@ -34,27 +34,20 @@ elf_machine_matches_host (const Elf32_Ehdr *ehdr)
 }
 
 
-/* Return the link-time address of _DYNAMIC.  Conveniently, this is the
-   first element of the GOT, a special entry that is never relocated.  */
-static inline Elf32_Addr __attribute__ ((unused, const))
-elf_machine_dynamic (void)
+/* Return the run-time load address of the shared object.  */
+static inline Elf32_Addr __attribute__ ((unused))
+elf_machine_load_address (void)
 {
-  /* This produces a GOTOFF reloc that resolves to zero at link time, so in
-     fact just loads from the GOT register directly.  By doing it without
-     an asm we can let the compiler choose any register.  */
-  extern const Elf32_Addr _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
-  return _GLOBAL_OFFSET_TABLE_[0];
+  extern const Elf32_Ehdr __ehdr_start attribute_hidden;
+  return (Elf32_Addr) &__ehdr_start;
 }
 
-/* Return the run-time load address of the shared object.  */
+/* Return the link-time address of _DYNAMIC.  */
 static inline Elf32_Addr __attribute__ ((unused))
-elf_machine_load_address (void)
+elf_machine_dynamic (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 ();
+  extern Elf32_Dyn _DYNAMIC[] attribute_hidden;
+  return (Elf32_Addr) _DYNAMIC - elf_machine_load_address ();
 }
 
 /* Set up the loaded object described by L so its unrelocated PLT


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-24 20:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-24 20:12 [glibc/maskray/unnest] i386: Port elf_machine_{load_address, dynamic} from x86-64 Fangrui Song

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).