public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Fangrui Song <maskray@google.com>
Cc: GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [PATCH] i386: Port elf_machine_{load_address, dynamic} from x86-64
Date: Fri, 24 Sep 2021 09:05:17 -0700	[thread overview]
Message-ID: <CAMe9rOqBjRKiS0mSXL=W5wbEA_MvbVtZUXeC=aBHeiRPY4nioQ@mail.gmail.com> (raw)
In-Reply-To: <20210924042623.3899762-1-maskray@google.com>

On Thu, Sep 23, 2021 at 9:26 PM Fangrui Song <maskray@google.com> wrote:
>
> This drops reliance on _GLOBAL_OFFSET_TABLE_[0] being the link-time
> address of _DYNAMIC.
>
> The code sequence length does not change.
> ---
>  sysdeps/i386/dl-machine.h | 29 +++++++++++------------------
>  1 file changed, 11 insertions(+), 18 deletions(-)
>
> diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h
> index 590b41d8d7..9f0eeaf66e 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)
> -{
> -  /* 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];
> -}
> -
>  /* Return the run-time load address of the shared object.  */
> -static inline Elf32_Addr __attribute__ ((unused))
> +static inline ElfW(Addr) __attribute__ ((unused))
>  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 ();
> +  extern const ElfW(Ehdr) __ehdr_start attribute_hidden;
> +  return (ElfW(Addr)) &__ehdr_start;
> +}
> +
> +/* Return the link-time address of _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 ();
>  }

Please use Elf32 instead of ElfW.

>  /* Set up the loaded object described by L so its unrelocated PLT
> --
> 2.33.0.685.g46640cef36-goog
>


-- 
H.J.

      parent reply	other threads:[~2021-09-24 16:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-24  4:26 [PATCH] i386: Port elf_machine_{load_address,dynamic} " Fangrui Song
2021-09-24  6:20 ` [PATCH] i386: Port elf_machine_{load_address, dynamic} " H.J. Lu
2021-09-24  6:55   ` Fangrui Song
2021-09-24 16:05 ` H.J. Lu [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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMe9rOqBjRKiS0mSXL=W5wbEA_MvbVtZUXeC=aBHeiRPY4nioQ@mail.gmail.com' \
    --to=hjl.tools@gmail.com \
    --cc=libc-alpha@sourceware.org \
    --cc=maskray@google.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).