public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] riscv: Drop reliance on _GLOBAL_OFFSET_TABLE_[0]
@ 2021-08-18  4:37 Fangrui Song
  2021-08-18 16:22 ` Palmer Dabbelt
  0 siblings, 1 reply; 4+ messages in thread
From: Fangrui Song @ 2021-08-18  4:37 UTC (permalink / raw)
  To: libc-alpha, Darius Rad, Palmer Dabbelt

&__ehdr_start is a better way to get the load address.

This is similar to commits b37b75d269883a2c553bb7019a813094eb4e2dd1
(x86-64) and 43d06ed218fc8be58987bdfd00e21e5720f0b862 (aarch64).
---
 sysdeps/riscv/dl-machine.h | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h
index aedf69fcdd..5b0746175c 100644
--- a/sysdeps/riscv/dl-machine.h
+++ b/sysdeps/riscv/dl-machine.h
@@ -76,27 +76,26 @@ elf_machine_matches_host (const ElfW(Ehdr) *ehdr)
   return 1;
 }
 
+/* Return the run-time load address of the shared object.  */
+static inline ElfW(Addr)
+elf_machine_load_address (void)
+{
+  extern const ElfW(Ehdr) __ehdr_start attribute_hidden;
+  return (ElfW(Addr)) &__ehdr_start;
+}
+
 /* Return the link-time address of _DYNAMIC.  */
 static inline ElfW(Addr)
 elf_machine_dynamic (void)
 {
-  extern ElfW(Addr) _GLOBAL_OFFSET_TABLE_ __attribute__ ((visibility ("hidden")));
-  return _GLOBAL_OFFSET_TABLE_;
+  extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
+  return (ElfW(Addr)) _DYNAMIC - elf_machine_load_address ();
 }
 
 #define STRINGXP(X) __STRING (X)
 #define STRINGXV(X) STRINGV_ (X)
 #define STRINGV_(...) # __VA_ARGS__
 
-/* Return the run-time load address of the shared object.  */
-static inline ElfW(Addr)
-elf_machine_load_address (void)
-{
-  ElfW(Addr) load_addr;
-  asm ("lla %0, _DYNAMIC" : "=r" (load_addr));
-  return load_addr - elf_machine_dynamic ();
-}
-
 /* Initial entry point code for the dynamic linker.
    The C function `_dl_start' is the real entry point;
    its return value is the user program's entry point.  */
-- 
2.33.0.rc2.250.ged5fa647cd-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] riscv: Drop reliance on _GLOBAL_OFFSET_TABLE_[0]
  2021-08-18  4:37 [PATCH] riscv: Drop reliance on _GLOBAL_OFFSET_TABLE_[0] Fangrui Song
@ 2021-08-18 16:22 ` Palmer Dabbelt
  2021-08-18 16:31   ` Fāng-ruì Sòng
  0 siblings, 1 reply; 4+ messages in thread
From: Palmer Dabbelt @ 2021-08-18 16:22 UTC (permalink / raw)
  To: maskray; +Cc: libc-alpha, Darius Rad, maskray

On Tue, 17 Aug 2021 21:37:44 PDT (-0700), maskray@google.com wrote:
> &__ehdr_start is a better way to get the load address.
>
> This is similar to commits b37b75d269883a2c553bb7019a813094eb4e2dd1
> (x86-64) and 43d06ed218fc8be58987bdfd00e21e5720f0b862 (aarch64).
> ---
>  sysdeps/riscv/dl-machine.h | 21 ++++++++++-----------
>  1 file changed, 10 insertions(+), 11 deletions(-)
>
> diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h
> index aedf69fcdd..5b0746175c 100644
> --- a/sysdeps/riscv/dl-machine.h
> +++ b/sysdeps/riscv/dl-machine.h
> @@ -76,27 +76,26 @@ elf_machine_matches_host (const ElfW(Ehdr) *ehdr)
>    return 1;
>  }
>
> +/* Return the run-time load address of the shared object.  */
> +static inline ElfW(Addr)
> +elf_machine_load_address (void)
> +{
> +  extern const ElfW(Ehdr) __ehdr_start attribute_hidden;
> +  return (ElfW(Addr)) &__ehdr_start;
> +}
> +
>  /* Return the link-time address of _DYNAMIC.  */
>  static inline ElfW(Addr)
>  elf_machine_dynamic (void)
>  {
> -  extern ElfW(Addr) _GLOBAL_OFFSET_TABLE_ __attribute__ ((visibility ("hidden")));
> -  return _GLOBAL_OFFSET_TABLE_;
> +  extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
> +  return (ElfW(Addr)) _DYNAMIC - elf_machine_load_address ();
>  }
>
>  #define STRINGXP(X) __STRING (X)
>  #define STRINGXV(X) STRINGV_ (X)
>  #define STRINGV_(...) # __VA_ARGS__
>
> -/* Return the run-time load address of the shared object.  */
> -static inline ElfW(Addr)
> -elf_machine_load_address (void)
> -{
> -  ElfW(Addr) load_addr;
> -  asm ("lla %0, _DYNAMIC" : "=r" (load_addr));
> -  return load_addr - elf_machine_dynamic ();
> -}
> -
>  /* Initial entry point code for the dynamic linker.
>     The C function `_dl_start' is the real entry point;
>     its return value is the user program's entry point.  */

Reviewed-by: Palmer Dabbelt <palmerdabbelt@google.com>
Acked-by: Palmer Dabbelt <palmerdabbelt@google.com>

LMK if you want me to commit this, but from the history it looks like 
you have commit access so feel free to yourself (assuming you've built 
it for all our targets).

Thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] riscv: Drop reliance on _GLOBAL_OFFSET_TABLE_[0]
  2021-08-18 16:22 ` Palmer Dabbelt
@ 2021-08-18 16:31   ` Fāng-ruì Sòng
  2021-08-18 21:09     ` Palmer Dabbelt
  0 siblings, 1 reply; 4+ messages in thread
From: Fāng-ruì Sòng @ 2021-08-18 16:31 UTC (permalink / raw)
  To: Palmer Dabbelt; +Cc: libc-alpha, Darius Rad

On Wed, Aug 18, 2021 at 9:22 AM Palmer Dabbelt <palmerdabbelt@google.com> wrote:
>
> On Tue, 17 Aug 2021 21:37:44 PDT (-0700), maskray@google.com wrote:
> > &__ehdr_start is a better way to get the load address.
> >
> > This is similar to commits b37b75d269883a2c553bb7019a813094eb4e2dd1
> > (x86-64) and 43d06ed218fc8be58987bdfd00e21e5720f0b862 (aarch64).
> > ---
> >  sysdeps/riscv/dl-machine.h | 21 ++++++++++-----------
> >  1 file changed, 10 insertions(+), 11 deletions(-)
> >
> > diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h
> > index aedf69fcdd..5b0746175c 100644
> > --- a/sysdeps/riscv/dl-machine.h
> > +++ b/sysdeps/riscv/dl-machine.h
> > @@ -76,27 +76,26 @@ elf_machine_matches_host (const ElfW(Ehdr) *ehdr)
> >    return 1;
> >  }
> >
> > +/* Return the run-time load address of the shared object.  */
> > +static inline ElfW(Addr)
> > +elf_machine_load_address (void)
> > +{
> > +  extern const ElfW(Ehdr) __ehdr_start attribute_hidden;
> > +  return (ElfW(Addr)) &__ehdr_start;
> > +}
> > +
> >  /* Return the link-time address of _DYNAMIC.  */
> >  static inline ElfW(Addr)
> >  elf_machine_dynamic (void)
> >  {
> > -  extern ElfW(Addr) _GLOBAL_OFFSET_TABLE_ __attribute__ ((visibility ("hidden")));
> > -  return _GLOBAL_OFFSET_TABLE_;
> > +  extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
> > +  return (ElfW(Addr)) _DYNAMIC - elf_machine_load_address ();
> >  }
> >
> >  #define STRINGXP(X) __STRING (X)
> >  #define STRINGXV(X) STRINGV_ (X)
> >  #define STRINGV_(...) # __VA_ARGS__
> >
> > -/* Return the run-time load address of the shared object.  */
> > -static inline ElfW(Addr)
> > -elf_machine_load_address (void)
> > -{
> > -  ElfW(Addr) load_addr;
> > -  asm ("lla %0, _DYNAMIC" : "=r" (load_addr));
> > -  return load_addr - elf_machine_dynamic ();
> > -}
> > -
> >  /* Initial entry point code for the dynamic linker.
> >     The C function `_dl_start' is the real entry point;
> >     its return value is the user program's entry point.  */
>
> Reviewed-by: Palmer Dabbelt <palmerdabbelt@google.com>
> Acked-by: Palmer Dabbelt <palmerdabbelt@google.com>
>
> LMK if you want me to commit this, but from the history it looks like
> you have commit access so feel free to yourself (assuming you've built
> it for all our targets).
>
> Thanks!

I have the commit access:)

Checked with  scripts/build-many-glibcs.py /tmp/glibc-many glibcs
riscv64-linux-gnu-rv64imafdc-lp64d --keep all
(and riscv32-linux-gnu-rv32imac-ilp32) and ran elf/ldconfig &
elf/ld.so with qemu-riscv64-static.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] riscv: Drop reliance on _GLOBAL_OFFSET_TABLE_[0]
  2021-08-18 16:31   ` Fāng-ruì Sòng
@ 2021-08-18 21:09     ` Palmer Dabbelt
  0 siblings, 0 replies; 4+ messages in thread
From: Palmer Dabbelt @ 2021-08-18 21:09 UTC (permalink / raw)
  To: maskray; +Cc: libc-alpha, Darius Rad

On Wed, 18 Aug 2021 09:31:39 PDT (-0700), maskray@google.com wrote:
> On Wed, Aug 18, 2021 at 9:22 AM Palmer Dabbelt <palmerdabbelt@google.com> wrote:
>>
>> On Tue, 17 Aug 2021 21:37:44 PDT (-0700), maskray@google.com wrote:
>> > &__ehdr_start is a better way to get the load address.
>> >
>> > This is similar to commits b37b75d269883a2c553bb7019a813094eb4e2dd1
>> > (x86-64) and 43d06ed218fc8be58987bdfd00e21e5720f0b862 (aarch64).
>> > ---
>> >  sysdeps/riscv/dl-machine.h | 21 ++++++++++-----------
>> >  1 file changed, 10 insertions(+), 11 deletions(-)
>> >
>> > diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h
>> > index aedf69fcdd..5b0746175c 100644
>> > --- a/sysdeps/riscv/dl-machine.h
>> > +++ b/sysdeps/riscv/dl-machine.h
>> > @@ -76,27 +76,26 @@ elf_machine_matches_host (const ElfW(Ehdr) *ehdr)
>> >    return 1;
>> >  }
>> >
>> > +/* Return the run-time load address of the shared object.  */
>> > +static inline ElfW(Addr)
>> > +elf_machine_load_address (void)
>> > +{
>> > +  extern const ElfW(Ehdr) __ehdr_start attribute_hidden;
>> > +  return (ElfW(Addr)) &__ehdr_start;
>> > +}
>> > +
>> >  /* Return the link-time address of _DYNAMIC.  */
>> >  static inline ElfW(Addr)
>> >  elf_machine_dynamic (void)
>> >  {
>> > -  extern ElfW(Addr) _GLOBAL_OFFSET_TABLE_ __attribute__ ((visibility ("hidden")));
>> > -  return _GLOBAL_OFFSET_TABLE_;
>> > +  extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
>> > +  return (ElfW(Addr)) _DYNAMIC - elf_machine_load_address ();
>> >  }
>> >
>> >  #define STRINGXP(X) __STRING (X)
>> >  #define STRINGXV(X) STRINGV_ (X)
>> >  #define STRINGV_(...) # __VA_ARGS__
>> >
>> > -/* Return the run-time load address of the shared object.  */
>> > -static inline ElfW(Addr)
>> > -elf_machine_load_address (void)
>> > -{
>> > -  ElfW(Addr) load_addr;
>> > -  asm ("lla %0, _DYNAMIC" : "=r" (load_addr));
>> > -  return load_addr - elf_machine_dynamic ();
>> > -}
>> > -
>> >  /* Initial entry point code for the dynamic linker.
>> >     The C function `_dl_start' is the real entry point;
>> >     its return value is the user program's entry point.  */
>>
>> Reviewed-by: Palmer Dabbelt <palmerdabbelt@google.com>
>> Acked-by: Palmer Dabbelt <palmerdabbelt@google.com>
>>
>> LMK if you want me to commit this, but from the history it looks like
>> you have commit access so feel free to yourself (assuming you've built
>> it for all our targets).
>>
>> Thanks!
>
> I have the commit access:)
>
> Checked with  scripts/build-many-glibcs.py /tmp/glibc-many glibcs
> riscv64-linux-gnu-rv64imafdc-lp64d --keep all
> (and riscv32-linux-gnu-rv32imac-ilp32) and ran elf/ldconfig &
> elf/ld.so with qemu-riscv64-static.

Works for me.  Thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-18 21:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-18  4:37 [PATCH] riscv: Drop reliance on _GLOBAL_OFFSET_TABLE_[0] Fangrui Song
2021-08-18 16:22 ` Palmer Dabbelt
2021-08-18 16:31   ` Fāng-ruì Sòng
2021-08-18 21:09     ` Palmer Dabbelt

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