[PATCH v12 06/31] string: Improve generic strchr

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Mon Feb 6 13:07:55 GMT 2023



On 03/02/23 23:58, Richard Henderson wrote:
> On 2/2/23 08:11, Adhemerval Zanella wrote:
>> New algorithm now calls strchrnul.
>>
>> Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu,
>> and powerpc64-linux-gnu by removing the arch-specific assembly
>> implementation and disabling multi-arch (it covers both LE and BE
>> for 64 and 32 bits).
>>
>> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> 
> strchrnul needs libc_hidden_builtin_proto.  On riscv64:
> 
>    8:    00000097              auipc    ra,0x0
>             8: R_RISCV_CALL_PLT    __strchrnul
>             8: R_RISCV_RELAX    *ABS*
>    c:    000080e7              jalr    ra # 8 <__GI_strchr+0x8>

It is similar to x86_64 as well:

x86_64-linux-gnu$ objdump -dwr posix/execvpe.os
[...]
 234:   4c 89 ff                mov    %r15,%rdi
 237:   e8 00 00 00 00          call   23c <__execvpe_common+0x12c>     238: R_X86_64_PLT32     __strchrnul-0x4
[...]

But the static linker ends up generating a local call as expected:

$ riscv64-glibc-linux-gnu-objdump -dr libc.so
[...]
000000000008726e <strchr>:
   8726e:       7179                    addi    sp,sp,-48
   87270:       ec26                    sd      s1,24(sp)
   87272:       000e9497                auipc   s1,0xe9
   87276:       4264b483                ld      s1,1062(s1) # 170698 <__stack_chk_guard@GLIBC_2.27>
   8727a:       609c                    ld      a5,0(s1)
   8727c:       e43e                    sd      a5,8(sp)
   8727e:       4781                    li      a5,0
   87280:       f022                    sd      s0,32(sp)
   87282:       f406                    sd      ra,40(sp)
   87284:       842e                    mv      s0,a1
   87286:       02a000ef                jal     ra,872b0 <strchrnul>
[...]

The intra PLT should trigger a regression with make check local-plt test,
and I did a make check for all architecture to make sure I am not missing
anything.

I will send a patch to fix this internal inconsistencies.


More information about the Libc-alpha mailing list