public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Fangrui Song <maskray@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc] x86_64: Simplify elf_machine_{load_address,dynamic} Date: Tue, 17 Aug 2021 17:49:26 +0000 (GMT) [thread overview] Message-ID: <20210817174926.21E2C395200F@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b37b75d269883a2c553bb7019a813094eb4e2dd1 commit b37b75d269883a2c553bb7019a813094eb4e2dd1 Author: Fangrui Song <maskray@google.com> Date: Tue Aug 17 10:45:57 2021 -0700 x86_64: Simplify elf_machine_{load_address,dynamic} and drop reliance on _GLOBAL_OFFSET_TABLE_[0] being the link-time address of _DYNAMIC. &__ehdr_start is a better way to get the load address. Reviewed-by: H.J. Lu <hjl.tools@gmail.com> Diff: --- sysdeps/x86_64/dl-machine.h | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h index a8596aa3fa..ceee50734e 100644 --- a/sysdeps/x86_64/dl-machine.h +++ b/sysdeps/x86_64/dl-machine.h @@ -35,27 +35,20 @@ elf_machine_matches_host (const ElfW(Ehdr) *ehdr) } -/* Return the link-time address of _DYNAMIC. Conveniently, this is the - first element of the GOT. This must be inlined in a function which - uses global data. */ +/* Return the run-time load address of the shared object. */ static inline ElfW(Addr) __attribute__ ((unused)) -elf_machine_dynamic (void) +elf_machine_load_address (void) { - /* This produces an IP-relative reloc which is resolved at link time. */ - extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden; - return _GLOBAL_OFFSET_TABLE_[0]; + extern const ElfW(Ehdr) __ehdr_start attribute_hidden; + return (ElfW(Addr)) &__ehdr_start; } - -/* Return the run-time load address of the shared object. */ +/* Return the link-time address of _DYNAMIC. */ static inline ElfW(Addr) __attribute__ ((unused)) -elf_machine_load_address (void) +elf_machine_dynamic (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 (); + return (ElfW(Addr)) _DYNAMIC - elf_machine_load_address (); } /* Set up the loaded object described by L so its unrelocated PLT
reply other threads:[~2021-08-17 17:49 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210817174926.21E2C395200F@sourceware.org \ --to=maskray@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).