[PATCH] Allow memset local PLT reference for RISC-V.

classic Classic list List threaded Threaded
35 messages Options
12
Reply | Threaded
Open this post in threaded view
|

[PATCH] Allow memset local PLT reference for RISC-V.

Sourceware - libc-alpha mailing list
This is similar to commit a26e2e9feab87d4f745c31411458b048742ac733
"Allow memset local PLT reference for powerpc soft-float.".

GCC 10.1 results in the localplt test failing for RISC-V.

From the original commit for power-pc:
    Since memset is documented as a function GCC may always implicitly
    generate calls to, it seems reasonable to allow that local PLT
    reference (just like those for libgcc functions that GCC implicitly
    generates calls to and that are also exported from libc.so), which
    this patch does.
---
 sysdeps/unix/sysv/linux/riscv/localplt.data | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sysdeps/unix/sysv/linux/riscv/localplt.data b/sysdeps/unix/sysv/linux/riscv/localplt.data
index 0ed8650b65..0a235592c3 100644
--- a/sysdeps/unix/sysv/linux/riscv/localplt.data
+++ b/sysdeps/unix/sysv/linux/riscv/localplt.data
@@ -5,6 +5,7 @@ libc.so: calloc
 libc.so: free
 libc.so: malloc
 libc.so: memalign
+libc.so: memset ?
 libc.so: realloc
 # The TLS-enabled version of these functions is interposed from libc.so.
 ld.so: _dl_signal_error
--
2.27.0

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Allow memset local PLT reference for RISC-V.

Andreas Schwab-2
On Jun 22 2020, Alistair Francis via Libc-alpha wrote:

> This is similar to commit a26e2e9feab87d4f745c31411458b048742ac733
> "Allow memset local PLT reference for powerpc soft-float.".
>
> GCC 10.1 results in the localplt test failing for RISC-V.

Why doesn't the redirect in sysdeps/generic/symbol-hacks.h work?

Andreas.

--
Andreas Schwab, [hidden email]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Allow memset local PLT reference for RISC-V.

Sourceware - libc-alpha mailing list
On Tue, Jun 23, 2020 at 12:19 AM Andreas Schwab <[hidden email]> wrote:
>
> On Jun 22 2020, Alistair Francis via Libc-alpha wrote:
>
> > This is similar to commit a26e2e9feab87d4f745c31411458b048742ac733
> > "Allow memset local PLT reference for powerpc soft-float.".
> >
> > GCC 10.1 results in the localplt test failing for RISC-V.
>
> Why doesn't the redirect in sysdeps/generic/symbol-hacks.h work?

I'm not sure.

I  suspect it's the same reason it didn't work in the commit this is
based off: a26e2e9feab87d4f745c31411458b048742ac733
"Allow memset local PLT reference for powerpc soft-float.".

The error is part of glibc's check scripts. I'm assuming memset is in
the binary which produces a check failure as we don't expect it to be.
I'm not sure where sysdeps/generic/symbol-hacks.h is involved in this
process though.

Alistair

>
> Andreas.
>
> --
> Andreas Schwab, [hidden email]
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Allow memset local PLT reference for RISC-V.

Sourceware - libc-alpha mailing list
In reply to this post by Andreas Schwab-2
On 6/23/20 12:19 AM, Andreas Schwab wrote:
> On Jun 22 2020, Alistair Francis via Libc-alpha wrote:
>
>> This is similar to commit a26e2e9feab87d4f745c31411458b048742ac733
>> "Allow memset local PLT reference for powerpc soft-float.".
>>
>> GCC 10.1 results in the localplt test failing for RISC-V.
>
> Why doesn't the redirect in sysdeps/generic/symbol-hacks.h work?

FWIW, for ARC port, Adhemerval suggested a similar workaround [1] but my stab at
it didn't work either [2]

[1] https://sourceware.org/pipermail/libc-alpha/2020-June/114838.html
[2] https://sourceware.org/pipermail/libc-alpha/2020-June/114911.html

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Allow memset local PLT reference for RISC-V.

Sourceware - libc-alpha mailing list
In reply to this post by Sourceware - libc-alpha mailing list
* Alistair Francis via Libc-alpha:

> On Tue, Jun 23, 2020 at 12:19 AM Andreas Schwab <[hidden email]> wrote:
>>
>> On Jun 22 2020, Alistair Francis via Libc-alpha wrote:
>>
>> > This is similar to commit a26e2e9feab87d4f745c31411458b048742ac733
>> > "Allow memset local PLT reference for powerpc soft-float.".
>> >
>> > GCC 10.1 results in the localplt test failing for RISC-V.
>>
>> Why doesn't the redirect in sysdeps/generic/symbol-hacks.h work?
>
> I'm not sure.

Which function contains the memset PLT reference?  “objdump
--disassemble --reloc” should show it.  Does this function come from
libgcc, by chance?

Thanks,
Florian

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Allow memset local PLT reference for RISC-V.

Sourceware - libc-alpha mailing list
On 6/25/20 12:20 AM, Florian Weimer via Libc-alpha wrote:

> * Alistair Francis via Libc-alpha:
>
>> On Tue, Jun 23, 2020 at 12:19 AM Andreas Schwab <[hidden email]> wrote:
>>>
>>> On Jun 22 2020, Alistair Francis via Libc-alpha wrote:
>>>
>>>> This is similar to commit a26e2e9feab87d4f745c31411458b048742ac733
>>>> "Allow memset local PLT reference for powerpc soft-float.".
>>>>
>>>> GCC 10.1 results in the localplt test failing for RISC-V.
>>>
>>> Why doesn't the redirect in sysdeps/generic/symbol-hacks.h work?
>>
>> I'm not sure.
>
> Which function contains the memset PLT reference?  “objdump
> --disassemble --reloc” should show it.  Does this function come from
> libgcc, by chance?

yes this is libgcc. I saw this on ARC too (with gcc 10)

   1b2d0: ld r12,[pcl,0xe4d40] ;100010 <memset@@GLIBC_2.32+0x98c94>
   1b2d8: j.d [r12]
   1b2dc: mov r12,pcl

000366c8 <__mpn_mul>:

   36748: bl.d -111736 ;1b2d0 <.plt+0x40>
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Allow memset local PLT reference for RISC-V.

Sourceware - libc-alpha mailing list
* Vineet Gupta:

> On 6/25/20 12:20 AM, Florian Weimer via Libc-alpha wrote:
>> * Alistair Francis via Libc-alpha:
>>
>>> On Tue, Jun 23, 2020 at 12:19 AM Andreas Schwab <[hidden email]> wrote:
>>>>
>>>> On Jun 22 2020, Alistair Francis via Libc-alpha wrote:
>>>>
>>>>> This is similar to commit a26e2e9feab87d4f745c31411458b048742ac733
>>>>> "Allow memset local PLT reference for powerpc soft-float.".
>>>>>
>>>>> GCC 10.1 results in the localplt test failing for RISC-V.
>>>>
>>>> Why doesn't the redirect in sysdeps/generic/symbol-hacks.h work?
>>>
>>> I'm not sure.
>>
>> Which function contains the memset PLT reference?  “objdump
>> --disassemble --reloc” should show it.  Does this function come from
>> libgcc, by chance?
>
> yes this is libgcc. I saw this on ARC too (with gcc 10)
>
>    1b2d0: ld r12,[pcl,0xe4d40] ;100010 <memset@@GLIBC_2.32+0x98c94>
>    1b2d8: j.d [r12]
>    1b2dc: mov r12,pcl
>
> 000366c8 <__mpn_mul>:
> …
>    36748: bl.d -111736 ;1b2d0 <.plt+0x40>

Uhm, how does this end up in libgcc?

Thanks,
Florian

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Allow memset local PLT reference for RISC-V.

Palmer Dabbelt
In reply to this post by Sourceware - libc-alpha mailing list
On Mon, 22 Jun 2020 14:10:34 PDT (-0700), [hidden email] wrote:

> This is similar to commit a26e2e9feab87d4f745c31411458b048742ac733
> "Allow memset local PLT reference for powerpc soft-float.".
>
> GCC 10.1 results in the localplt test failing for RISC-V.
>
> From the original commit for power-pc:
>     Since memset is documented as a function GCC may always implicitly
>     generate calls to, it seems reasonable to allow that local PLT
>     reference (just like those for libgcc functions that GCC implicitly
>     generates calls to and that are also exported from libc.so), which
>     this patch does.
> ---
>  sysdeps/unix/sysv/linux/riscv/localplt.data | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/sysdeps/unix/sysv/linux/riscv/localplt.data b/sysdeps/unix/sysv/linux/riscv/localplt.data
> index 0ed8650b65..0a235592c3 100644
> --- a/sysdeps/unix/sysv/linux/riscv/localplt.data
> +++ b/sysdeps/unix/sysv/linux/riscv/localplt.data
> @@ -5,6 +5,7 @@ libc.so: calloc
>  libc.so: free
>  libc.so: malloc
>  libc.so: memalign
> +libc.so: memset ?
>  libc.so: realloc
>  # The TLS-enabled version of these functions is interposed from libc.so.
>  ld.so: _dl_signal_error

Acked-by: Palmer Dabbelt <[hidden email]>

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Allow memset local PLT reference for RISC-V.

Sourceware - libc-alpha mailing list
In reply to this post by Sourceware - libc-alpha mailing list
On 6/25/20 11:41 AM, Florian Weimer via Libc-alpha wrote:

>>
>> 000366c8 <__mpn_mul>:
>> …
>>    36748: bl.d -111736 ;1b2d0 <.plt+0x40>
>
> Uhm, how does this end up in libgcc?

Never mind, I must not have been awoke when I wrote this. But I'm sure at some
point with gcc-10 I saw a memset PLT call, but now forget how it triggered.

-Vineet

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Allow memset local PLT reference for RISC-V.

Sourceware - libc-alpha mailing list
In reply to this post by Sourceware - libc-alpha mailing list
* Alistair Francis via Libc-alpha:

> On Tue, Jun 23, 2020 at 12:19 AM Andreas Schwab <[hidden email]> wrote:
>>
>> On Jun 22 2020, Alistair Francis via Libc-alpha wrote:
>>
>> > This is similar to commit a26e2e9feab87d4f745c31411458b048742ac733
>> > "Allow memset local PLT reference for powerpc soft-float.".
>> >
>> > GCC 10.1 results in the localplt test failing for RISC-V.
>>
>> Why doesn't the redirect in sysdeps/generic/symbol-hacks.h work?
>
> I'm not sure.
>
> I  suspect it's the same reason it didn't work in the commit this is
> based off: a26e2e9feab87d4f745c31411458b048742ac733
> "Allow memset local PLT reference for powerpc soft-float.".
>
> The error is part of glibc's check scripts. I'm assuming memset is in
> the binary which produces a check failure as we don't expect it to be.
> I'm not sure where sysdeps/generic/symbol-hacks.h is involved in this
> process though.

Please post disassembly showing the location of the PLT calls.  Which
functions have them?

Thanks,
Florian

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Allow memset local PLT reference for RISC-V.

Sourceware - libc-alpha mailing list
On Mon, Jun 29, 2020 at 2:11 AM Florian Weimer <[hidden email]> wrote:

>
> * Alistair Francis via Libc-alpha:
>
> > On Tue, Jun 23, 2020 at 12:19 AM Andreas Schwab <[hidden email]> wrote:
> >>
> >> On Jun 22 2020, Alistair Francis via Libc-alpha wrote:
> >>
> >> > This is similar to commit a26e2e9feab87d4f745c31411458b048742ac733
> >> > "Allow memset local PLT reference for powerpc soft-float.".
> >> >
> >> > GCC 10.1 results in the localplt test failing for RISC-V.
> >>
> >> Why doesn't the redirect in sysdeps/generic/symbol-hacks.h work?
> >
> > I'm not sure.
> >
> > I  suspect it's the same reason it didn't work in the commit this is
> > based off: a26e2e9feab87d4f745c31411458b048742ac733
> > "Allow memset local PLT reference for powerpc soft-float.".
> >
> > The error is part of glibc's check scripts. I'm assuming memset is in
> > the binary which produces a check failure as we don't expect it to be.
> > I'm not sure where sysdeps/generic/symbol-hacks.h is involved in this
> > process though.
>
> Please post disassembly showing the location of the PLT calls.  Which
> functions have them?

Sorry, I was waiting on my build to finish (I forgot to keep the
artifacts the first time).

I'm assuming you wanted the objdump of libc.a?

I see this (which I'm guessing is the PLT call) in libc.a

00000012 <.LVL4>:
    *ptr++ = 0ul;
  12:   00000097                auipc   ra,0x0
                        12: R_RISCV_CALL        memset
                        12: R_RISCV_RELAX       *ABS*
  16:   000080e7                jalr    ra # 12 <.LVL4>

Which is called from the __sigblock() function.

Alistair

>
> Thanks,
> Florian
>
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Allow memset local PLT reference for RISC-V.

Sourceware - libc-alpha mailing list
On Mon, Jun 29, 2020 at 8:58 AM Alistair Francis <[hidden email]> wrote:

>
> On Mon, Jun 29, 2020 at 2:11 AM Florian Weimer <[hidden email]> wrote:
> >
> > * Alistair Francis via Libc-alpha:
> >
> > > On Tue, Jun 23, 2020 at 12:19 AM Andreas Schwab <[hidden email]> wrote:
> > >>
> > >> On Jun 22 2020, Alistair Francis via Libc-alpha wrote:
> > >>
> > >> > This is similar to commit a26e2e9feab87d4f745c31411458b048742ac733
> > >> > "Allow memset local PLT reference for powerpc soft-float.".
> > >> >
> > >> > GCC 10.1 results in the localplt test failing for RISC-V.
> > >>
> > >> Why doesn't the redirect in sysdeps/generic/symbol-hacks.h work?
> > >
> > > I'm not sure.
> > >
> > > I  suspect it's the same reason it didn't work in the commit this is
> > > based off: a26e2e9feab87d4f745c31411458b048742ac733
> > > "Allow memset local PLT reference for powerpc soft-float.".
> > >
> > > The error is part of glibc's check scripts. I'm assuming memset is in
> > > the binary which produces a check failure as we don't expect it to be.
> > > I'm not sure where sysdeps/generic/symbol-hacks.h is involved in this
> > > process though.
> >
> > Please post disassembly showing the location of the PLT calls.  Which
> > functions have them?
>
> Sorry, I was waiting on my build to finish (I forgot to keep the
> artifacts the first time).
>
> I'm assuming you wanted the objdump of libc.a?
>
> I see this (which I'm guessing is the PLT call) in libc.a
>
> 00000012 <.LVL4>:
>     *ptr++ = 0ul;
>   12:   00000097                auipc   ra,0x0
>                         12: R_RISCV_CALL        memset
>                         12: R_RISCV_RELAX       *ABS*
>   16:   000080e7                jalr    ra # 12 <.LVL4>
>
> Which is called from the __sigblock() function.

Ah, I just checked libgcc, it has the memset PLT call:

0000020e <.L27>:
 20e:   0605                    addi    a2,a2,1
 210:   060a                    slli    a2,a2,0x2
 212:   4581                    li      a1,0
 214:   00000097                auipc   ra,0x0
                        214: R_RISCV_CALL_PLT   memset
                        214: R_RISCV_RELAX      *ABS*
 218:   000080e7                jalr    ra # 214 <.L27+0x6>

There are a few of them in libgcc.a as well.

Alistair

>
> Alistair
>
> >
> > Thanks,
> > Florian
> >
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Allow memset local PLT reference for RISC-V.

Sourceware - libc-alpha mailing list
In reply to this post by Sourceware - libc-alpha mailing list
* Alistair Francis:

> On Mon, Jun 29, 2020 at 2:11 AM Florian Weimer <[hidden email]> wrote:
>>
>> * Alistair Francis via Libc-alpha:
>>
>> > On Tue, Jun 23, 2020 at 12:19 AM Andreas Schwab <[hidden email]> wrote:
>> >>
>> >> On Jun 22 2020, Alistair Francis via Libc-alpha wrote:
>> >>
>> >> > This is similar to commit a26e2e9feab87d4f745c31411458b048742ac733
>> >> > "Allow memset local PLT reference for powerpc soft-float.".
>> >> >
>> >> > GCC 10.1 results in the localplt test failing for RISC-V.
>> >>
>> >> Why doesn't the redirect in sysdeps/generic/symbol-hacks.h work?
>> >
>> > I'm not sure.
>> >
>> > I  suspect it's the same reason it didn't work in the commit this is
>> > based off: a26e2e9feab87d4f745c31411458b048742ac733
>> > "Allow memset local PLT reference for powerpc soft-float.".
>> >
>> > The error is part of glibc's check scripts. I'm assuming memset is in
>> > the binary which produces a check failure as we don't expect it to be.
>> > I'm not sure where sysdeps/generic/symbol-hacks.h is involved in this
>> > process though.
>>
>> Please post disassembly showing the location of the PLT calls.  Which
>> functions have them?
>
> Sorry, I was waiting on my build to finish (I forgot to keep the
> artifacts the first time).
>
> I'm assuming you wanted the objdump of libc.a?

libc_pic.a.  libc.a is built for static linking and does not use the
symbol hacks.

If the PLT reference comes from libgcc.a, it won't show up in
libc_pic.a, though.  It will only be present in libc.so.

Thanks,
Florian

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Allow memset local PLT reference for RISC-V.

Sourceware - libc-alpha mailing list
On Mon, Jun 29, 2020 at 9:12 AM Florian Weimer <[hidden email]> wrote:

>
> * Alistair Francis:
>
> > On Mon, Jun 29, 2020 at 2:11 AM Florian Weimer <[hidden email]> wrote:
> >>
> >> * Alistair Francis via Libc-alpha:
> >>
> >> > On Tue, Jun 23, 2020 at 12:19 AM Andreas Schwab <[hidden email]> wrote:
> >> >>
> >> >> On Jun 22 2020, Alistair Francis via Libc-alpha wrote:
> >> >>
> >> >> > This is similar to commit a26e2e9feab87d4f745c31411458b048742ac733
> >> >> > "Allow memset local PLT reference for powerpc soft-float.".
> >> >> >
> >> >> > GCC 10.1 results in the localplt test failing for RISC-V.
> >> >>
> >> >> Why doesn't the redirect in sysdeps/generic/symbol-hacks.h work?
> >> >
> >> > I'm not sure.
> >> >
> >> > I  suspect it's the same reason it didn't work in the commit this is
> >> > based off: a26e2e9feab87d4f745c31411458b048742ac733
> >> > "Allow memset local PLT reference for powerpc soft-float.".
> >> >
> >> > The error is part of glibc's check scripts. I'm assuming memset is in
> >> > the binary which produces a check failure as we don't expect it to be.
> >> > I'm not sure where sysdeps/generic/symbol-hacks.h is involved in this
> >> > process though.
> >>
> >> Please post disassembly showing the location of the PLT calls.  Which
> >> functions have them?
> >
> > Sorry, I was waiting on my build to finish (I forgot to keep the
> > artifacts the first time).
> >
> > I'm assuming you wanted the objdump of libc.a?
>
> libc_pic.a.  libc.a is built for static linking and does not use the
> symbol hacks.
>
> If the PLT reference comes from libgcc.a, it won't show up in
> libc_pic.a, though.  It will only be present in libc.so.

Ah ok.

There is also a PLT memset in libc_pic.a

 1bc:   009aa023                sw      s1,0(s5)
          memset (result->__data, '\0',
 1c0:   865e                    mv      a2,s7
 1c2:   4581                    li      a1,0
 1c4:   008a8513                addi    a0,s5,8
 1c8:   00000097                auipc   ra,0x0
                        1c8: R_RISCV_CALL_PLT   __GI_memset
                        1c8: R_RISCV_RELAX      *ABS*
 1cc:   000080e7                jalr    ra # 1c8 <.LVL39+0x14>

Alistair

>
> Thanks,
> Florian
>
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Allow memset local PLT reference for RISC-V.

Sourceware - libc-alpha mailing list
In reply to this post by Sourceware - libc-alpha mailing list
* Alistair Francis:

> Ah, I just checked libgcc, it has the memset PLT call:
>
> 0000020e <.L27>:
>  20e:   0605                    addi    a2,a2,1
>  210:   060a                    slli    a2,a2,0x2
>  212:   4581                    li      a1,0
>  214:   00000097                auipc   ra,0x0
>                         214: R_RISCV_CALL_PLT   memset
>                         214: R_RISCV_RELAX      *ABS*
>  218:   000080e7                jalr    ra # 214 <.L27+0x6>
>
> There are a few of them in libgcc.a as well.

And that's linked into libc.so?

I would suggest to figure out the name of the function (not sure why
objdump doesn't print it in your case), and add that to the comment
localplt.data.

Thanks,
Florian

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Allow memset local PLT reference for RISC-V.

Sourceware - libc-alpha mailing list
In reply to this post by Sourceware - libc-alpha mailing list
* Alistair Francis:

> There is also a PLT memset in libc_pic.a
>
>  1bc:   009aa023                sw      s1,0(s5)
>           memset (result->__data, '\0',
>  1c0:   865e                    mv      a2,s7
>  1c2:   4581                    li      a1,0
>  1c4:   008a8513                addi    a0,s5,8
>  1c8:   00000097                auipc   ra,0x0
>                         1c8: R_RISCV_CALL_PLT   __GI_memset
>                         1c8: R_RISCV_RELAX      *ABS*
>  1cc:   000080e7                jalr    ra # 1c8 <.LVL39+0x14>

That's weird.  What does a direct call (to a hidden symbol) look like,
relocation-wise.

Thanks,
Florian

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Allow memset local PLT reference for RISC-V.

Sourceware - libc-alpha mailing list
On Mon, Jun 29, 2020 at 9:30 AM Florian Weimer <[hidden email]> wrote:

>
> * Alistair Francis:
>
> > There is also a PLT memset in libc_pic.a
> >
> >  1bc:   009aa023                sw      s1,0(s5)
> >           memset (result->__data, '\0',
> >  1c0:   865e                    mv      a2,s7
> >  1c2:   4581                    li      a1,0
> >  1c4:   008a8513                addi    a0,s5,8
> >  1c8:   00000097                auipc   ra,0x0
> >                         1c8: R_RISCV_CALL_PLT   __GI_memset
> >                         1c8: R_RISCV_RELAX      *ABS*
> >  1cc:   000080e7                jalr    ra # 1c8 <.LVL39+0x14>
>
> That's weird.  What does a direct call (to a hidden symbol) look like,
> relocation-wise.

I'm not sure. How can I figure out?

Alistair

>
> Thanks,
> Florian
>
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Allow memset local PLT reference for RISC-V.

Sourceware - libc-alpha mailing list
* Alistair Francis:

> On Mon, Jun 29, 2020 at 9:30 AM Florian Weimer <[hidden email]> wrote:
>>
>> * Alistair Francis:
>>
>> > There is also a PLT memset in libc_pic.a
>> >
>> >  1bc:   009aa023                sw      s1,0(s5)
>> >           memset (result->__data, '\0',
>> >  1c0:   865e                    mv      a2,s7
>> >  1c2:   4581                    li      a1,0
>> >  1c4:   008a8513                addi    a0,s5,8
>> >  1c8:   00000097                auipc   ra,0x0
>> >                         1c8: R_RISCV_CALL_PLT   __GI_memset
>> >                         1c8: R_RISCV_RELAX      *ABS*
>> >  1cc:   000080e7                jalr    ra # 1c8 <.LVL39+0x14>
>>
>> That's weird.  What does a direct call (to a hidden symbol) look like,
>> relocation-wise.
>
> I'm not sure. How can I figure out?

Look at different internal calls, e.g. __twalk_r and __libc_updwtmp (for
two variants, one with a hidden prototype and one without).

Thanks,
Florian

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Allow memset local PLT reference for RISC-V.

Sourceware - libc-alpha mailing list
On Mon, Jun 29, 2020 at 9:39 AM Florian Weimer <[hidden email]> wrote:

>
> * Alistair Francis:
>
> > On Mon, Jun 29, 2020 at 9:30 AM Florian Weimer <[hidden email]> wrote:
> >>
> >> * Alistair Francis:
> >>
> >> > There is also a PLT memset in libc_pic.a
> >> >
> >> >  1bc:   009aa023                sw      s1,0(s5)
> >> >           memset (result->__data, '\0',
> >> >  1c0:   865e                    mv      a2,s7
> >> >  1c2:   4581                    li      a1,0
> >> >  1c4:   008a8513                addi    a0,s5,8
> >> >  1c8:   00000097                auipc   ra,0x0
> >> >                         1c8: R_RISCV_CALL_PLT   __GI_memset
> >> >                         1c8: R_RISCV_RELAX      *ABS*
> >> >  1cc:   000080e7                jalr    ra # 1c8 <.LVL39+0x14>
> >>
> >> That's weird.  What does a direct call (to a hidden symbol) look like,
> >> relocation-wise.
> >
> > I'm not sure. How can I figure out?
>
> Look at different internal calls, e.g. __twalk_r and __libc_updwtmp (for
> two variants, one with a hidden prototype and one without).

Here is what I see from the libc_pic.a lib.

__twalk_r

00000000         *UND*  00000000 __GI___twalk_r
...
  __twalk_r (loaded, do_release_shlib, handle);
 1b2:   4088                    lw      a0,0(s1)
 1b4:   8622                    mv      a2,s0
 1b6:   00000597                auipc   a1,0x0
                        1b6: R_RISCV_PCREL_HI20 do_release_shlib
                        1b6: R_RISCV_RELAX      *ABS*
 1ba:   00058593                mv      a1,a1
                        1ba: R_RISCV_PCREL_LO12_I       .L0
                        1ba: R_RISCV_RELAX      *ABS*
 1be:   00000097                auipc   ra,0x0
                        1be: R_RISCV_CALL       __GI___twalk_r
                        1be: R_RISCV_RELAX      *ABS*
 1c2:   000080e7                jalr    ra # 1be <.L52+0xc>

__libc_updwtmp

000009c0 g     F .text  00000124 .hidden __libc_updwtmp
...
00000064 <.LVL8>:
  64:   0141                    addi    sp,sp,16
  __libc_updwtmp (file_name, utmp);
  66:   00000317                auipc   t1,0x0
                        66: R_RISCV_CALL        __libc_updwtmp
                        66: R_RISCV_RELAX       *ABS*
  6a:   00030067                jr      t1 # 66 <.LVL8+0x2>

Alistair

>
> Thanks,
> Florian
>
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Allow memset local PLT reference for RISC-V.

Sourceware - libc-alpha mailing list
* Alistair Francis:

> On Mon, Jun 29, 2020 at 9:39 AM Florian Weimer <[hidden email]> wrote:
>>
>> * Alistair Francis:
>>
>> > On Mon, Jun 29, 2020 at 9:30 AM Florian Weimer <[hidden email]> wrote:
>> >>
>> >> * Alistair Francis:
>> >>
>> >> > There is also a PLT memset in libc_pic.a
>> >> >
>> >> >  1bc:   009aa023                sw      s1,0(s5)
>> >> >           memset (result->__data, '\0',
>> >> >  1c0:   865e                    mv      a2,s7
>> >> >  1c2:   4581                    li      a1,0
>> >> >  1c4:   008a8513                addi    a0,s5,8
>> >> >  1c8:   00000097                auipc   ra,0x0
>> >> >                         1c8: R_RISCV_CALL_PLT   __GI_memset
>> >> >                         1c8: R_RISCV_RELAX      *ABS*
>> >> >  1cc:   000080e7                jalr    ra # 1c8 <.LVL39+0x14>
>> >>
>> >> That's weird.  What does a direct call (to a hidden symbol) look like,
>> >> relocation-wise.
>> >
>> > I'm not sure. How can I figure out?
>>
>> Look at different internal calls, e.g. __twalk_r and __libc_updwtmp (for
>> two variants, one with a hidden prototype and one without).
>
> Here is what I see from the libc_pic.a lib.
>
> __twalk_r
>
> 00000000         *UND*  00000000 __GI___twalk_r
> ...
>   __twalk_r (loaded, do_release_shlib, handle);
>  1b2:   4088                    lw      a0,0(s1)
>  1b4:   8622                    mv      a2,s0
>  1b6:   00000597                auipc   a1,0x0
>                         1b6: R_RISCV_PCREL_HI20 do_release_shlib
>                         1b6: R_RISCV_RELAX      *ABS*
>  1ba:   00058593                mv      a1,a1
>                         1ba: R_RISCV_PCREL_LO12_I       .L0
>                         1ba: R_RISCV_RELAX      *ABS*
>  1be:   00000097                auipc   ra,0x0
>                         1be: R_RISCV_CALL       __GI___twalk_r
>                         1be: R_RISCV_RELAX      *ABS*
>  1c2:   000080e7                jalr    ra # 1be <.L52+0xc>
>
> __libc_updwtmp
>
> 000009c0 g     F .text  00000124 .hidden __libc_updwtmp
> ...
> 00000064 <.LVL8>:
>   64:   0141                    addi    sp,sp,16
>   __libc_updwtmp (file_name, utmp);
>   66:   00000317                auipc   t1,0x0
>                         66: R_RISCV_CALL        __libc_updwtmp
>                         66: R_RISCV_RELAX       *ABS*
>   6a:   00030067                jr      t1 # 66 <.LVL8+0x2>

Okay, then the memcpy symbol hack does not work on RISC-V, and it's
worth fixing that.

It would be interesting to build iconv/gconv_open.c with --save-temps
and see what exactly ends up in the assembler file (and also what the
preprocessed sources look like).

Thanks,
Florian

12