From: Szabolcs Nagy via Libc-alpha <libc-alpha@sourceware.org>
To: Fangrui Song <maskray@google.com>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH v2] aarch64: Make elf_machine_{load_address,dynamic} robust [BZ #28203]
Date: Wed, 11 Aug 2021 12:00:31 +0100 [thread overview]
Message-ID: <20210811110030.GK20410@arm.com> (raw)
In-Reply-To: <20210809172530.502327-1-maskray@google.com>
The 08/09/2021 10:25, Fangrui Song via Libc-alpha wrote:
> The AArch64 ABI is largely platform agnostic and does not specify
> _GLOBAL_OFFSET_TABLE_[0] ([1]). glibc ld.so turns out to be probably the
> only user of _GLOBAL_OFFSET_TABLE_[0] and GNU ld defines the value
> to the link-time address _DYNAMIC. [2]
>
> In 2012, __ehdr_start was implemented in GNU ld and gold in binutils
> 2.23. Using adrp+add / (-mcmodel=tiny) adr to access
> __ehdr_start/_DYNAMIC gives us a robust way to get the load address and
> the link-time address of _DYNAMIC.
>
> With https://sourceware.org/pipermail/libc-alpha/2021-August/129864.html,
> this patch, and disabling traditional TLSGD tests (neither Clang nor
> LLD's aarch64 port supports), LLD linked glibc has the same number of
> `make check` failures.
>
> [1]: From a psABI maintainer, https://bugs.llvm.org/show_bug.cgi?id=49672#c2
> [2]: LLD's aarch64 port does not set _GLOBAL_OFFSET_TABLE_[0] to the
> link-time address _DYNAMIC.
> LLD is widely used on aarch64 Android and ChromeOS devices. Software
> just works without the need for _GLOBAL_OFFSET_TABLE_[0].
This is OK to commit.
Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
>
> ---
> Changes from v1
> * Use C instead of asm. -mcmodel=tiny adr is possible.
> * Adjust commit message
> ---
> sysdeps/aarch64/dl-machine.h | 24 +++++++++---------------
> 1 file changed, 9 insertions(+), 15 deletions(-)
>
> diff --git a/sysdeps/aarch64/dl-machine.h b/sysdeps/aarch64/dl-machine.h
> index d29d827ab3..3e10cb462f 100644
> --- a/sysdeps/aarch64/dl-machine.h
> +++ b/sysdeps/aarch64/dl-machine.h
> @@ -37,28 +37,22 @@ elf_machine_matches_host (const ElfW(Ehdr) *ehdr)
> return ehdr->e_machine == EM_AARCH64;
> }
>
> -/* Return the link-time address of _DYNAMIC. Conveniently, this is the
> - first element of the GOT. */
> -static inline ElfW(Addr) __attribute__ ((unused))
> -elf_machine_dynamic (void)
> -{
> - extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
> - return _GLOBAL_OFFSET_TABLE_[0];
> -}
> -
> /* Return the run-time load address of the shared object. */
>
> static inline ElfW(Addr) __attribute__ ((unused))
> elf_machine_load_address (void)
> {
> - /* To figure out the load address we use the definition that for any symbol:
> - dynamic_addr(symbol) = static_addr(symbol) + load_addr
> + extern const ElfW(Ehdr) __ehdr_start attribute_hidden;
> + return (ElfW(Addr)) &__ehdr_start;
> +}
>
> - _DYNAMIC sysmbol is used here as its link-time address stored in
> - the special unrelocated first GOT entry. */
> +/* Return the link-time address of _DYNAMIC. */
>
> - extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
> - return (ElfW(Addr)) &_DYNAMIC - elf_machine_dynamic ();
> +static inline ElfW(Addr) __attribute__ ((unused))
> +elf_machine_dynamic (void)
> +{
> + extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
> + return (ElfW(Addr)) _DYNAMIC - elf_machine_load_address ();
> }
>
> /* Set up the loaded object described by L so its unrelocated PLT
> --
> 2.32.0.605.g8dce9f2422-goog
>
prev parent reply other threads:[~2021-08-11 11:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-09 17:25 [PATCH v2] aarch64: Make elf_machine_{load_address,dynamic} robust [BZ #28203] Fangrui Song via Libc-alpha
2021-08-11 11:00 ` Szabolcs Nagy via Libc-alpha [this message]
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
List information: https://www.gnu.org/software/libc/involved.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210811110030.GK20410@arm.com \
--to=libc-alpha@sourceware.org \
--cc=maskray@google.com \
--cc=szabolcs.nagy@arm.com \
/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: link
Be 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).