diff mbox

[v2] Improve IFUNC check

Message ID 20200210191425.52xvvdot7kunt2gc@google.com
State New
Headers show

Commit Message

Fangrui Song Feb. 10, 2020, 7:14 p.m. UTC
On 2020-02-08, Aurelien Jarno wrote:
>On 2020-02-06 10:53, Fangrui Song wrote:
>> On 2020-02-06, Aurelien Jarno wrote:
>> > Hi,
>> >
>> > On 2020-02-04 22:09, Fangrui Song wrote:
>> > > GNU ld's RISCV port does not support IFUNC. ld -no-pie produces no
>> > > relocation and the test passed incorrectly. Be more rigid by testing
>> > > IRELATIVE explicitly.
>> >
>> > Thanks for your patch and sorry for the time to answer, I was testing it
>> > on many architectures. First of all I confirm it fixes the issue when
>> > building glibc with PIE on mips* and riscv64. I also confirm it
>> > introduces no regression on aarch64, armv5, armv7, hppa, m68k, powerpc,
>> > ppc64, ppc64le, s390x and x86_64.
>> >
>> > However it wrongly detects that IFUNC is not supported on sparc64 when
>> > PIE is not in use. Here is the output of of readelf for the non-PIE
>> > case:
>> >
>> > | Relocation section '.rela.dyn' at offset 0x110 contains 1 entry:
>> > |   Offset          Info           Type           Sym. Value    Sym. Name + Addend
>> > | 000000200280  0000000000f8 R_SPARC_JMP_IREL                     100128
>>
>> sparc64 -no-pie does not produce an R_SPARC_IRELATIVE. This looks weird.
>> All other archs emit an R_*_IRELATIVE.
>>
>> Can you dump the assembly (including .text and .[i]plt)?
>> Or can someone with sparc64 experience answer why sparc64 is different
>> here?
>
>Here is the dump of the .iplt section:
>Disassembly of section .iplt:
>
>0000000000200200 <.iplt>:
>        ...
>  200280:       03 00 00 80     sethi  %hi(0x20000), %g1
>  200284:       30 6f ff e7     b,a   %xcc, 200220 <__start+0x1000f8>
>  200288:       01 00 00 00     nop
>  20028c:       01 00 00 00     nop
>  200290:       01 00 00 00     nop
>  200294:       01 00 00 00     nop
>  200298:       01 00 00 00     nop
>  20029c:       01 00 00 00     nop
>
>There is no .text nor .plt section.
>
>-- 
>Aurelien Jarno                          GPG: 4096R/1DDD8C9B
>aurelien@aurel32.net                 http://www.aurel32.net

Attached PATCH v2.

sparc64 has a non-conventional R_SPARC_JMP_IREL, along with conventional
R_SPARC_IRELATIVE.

Comments

Aurelien Jarno Feb. 10, 2020, 10:19 p.m. UTC | #1
On 2020-02-10 11:14, Fangrui Song wrote:
> On 2020-02-08, Aurelien Jarno wrote:
> > On 2020-02-06 10:53, Fangrui Song wrote:
> > > On 2020-02-06, Aurelien Jarno wrote:
> > > > Hi,
> > > >
> > > > On 2020-02-04 22:09, Fangrui Song wrote:
> > > > > GNU ld's RISCV port does not support IFUNC. ld -no-pie produces no
> > > > > relocation and the test passed incorrectly. Be more rigid by testing
> > > > > IRELATIVE explicitly.
> > > >
> > > > Thanks for your patch and sorry for the time to answer, I was testing it
> > > > on many architectures. First of all I confirm it fixes the issue when
> > > > building glibc with PIE on mips* and riscv64. I also confirm it
> > > > introduces no regression on aarch64, armv5, armv7, hppa, m68k, powerpc,
> > > > ppc64, ppc64le, s390x and x86_64.
> > > >
> > > > However it wrongly detects that IFUNC is not supported on sparc64 when
> > > > PIE is not in use. Here is the output of of readelf for the non-PIE
> > > > case:
> > > >
> > > > | Relocation section '.rela.dyn' at offset 0x110 contains 1 entry:
> > > > |   Offset          Info           Type           Sym. Value    Sym. Name + Addend
> > > > | 000000200280  0000000000f8 R_SPARC_JMP_IREL                     100128
> > > 
> > > sparc64 -no-pie does not produce an R_SPARC_IRELATIVE. This looks weird.
> > > All other archs emit an R_*_IRELATIVE.
> > > 
> > > Can you dump the assembly (including .text and .[i]plt)?
> > > Or can someone with sparc64 experience answer why sparc64 is different
> > > here?
> > 
> > Here is the dump of the .iplt section:
> > Disassembly of section .iplt:
> > 
> > 0000000000200200 <.iplt>:
> >        ...
> >  200280:       03 00 00 80     sethi  %hi(0x20000), %g1
> >  200284:       30 6f ff e7     b,a   %xcc, 200220 <__start+0x1000f8>
> >  200288:       01 00 00 00     nop
> >  20028c:       01 00 00 00     nop
> >  200290:       01 00 00 00     nop
> >  200294:       01 00 00 00     nop
> >  200298:       01 00 00 00     nop
> >  20029c:       01 00 00 00     nop
> > 
> > There is no .text nor .plt section.
> > 
> > -- 
> > Aurelien Jarno                          GPG: 4096R/1DDD8C9B
> > aurelien@aurel32.net                 http://www.aurel32.net
> 
> Attached PATCH v2.
> 
> sparc64 has a non-conventional R_SPARC_JMP_IREL, along with conventional
> R_SPARC_IRELATIVE.

Thanks for the new version. I confirm it fixes the problem on sparc and
that it still works on other architectures.

Tested-by: Aurelien Jarno <aurelien@aurel32.net>
Aurelien Jarno March 4, 2020, 9:38 p.m. UTC | #2
Could someone please review the patch below so that it can get
committed? Thanks.

On 2020-02-10 11:14, Fangrui Song wrote:
> Attached PATCH v2.
> 
> sparc64 has a non-conventional R_SPARC_JMP_IREL, along with conventional
> R_SPARC_IRELATIVE.

> From 624b3a0c9e4f2f421227bb3f331723dfe807f157 Mon Sep 17 00:00:00 2001
> From: Fangrui Song <maskray@google.com>
> Date: Tue, 4 Feb 2020 21:55:44 -0800
> Subject: [PATCH] Improve IFUNC check [BZ #25506]
> 
> GNU ld does not support IFUNC but does not produces a relocation.
> The test passed incorrectly. Be more rigid by testing IRELATIVE
> explicitly.
> ---
>  configure    | 2 +-
>  configure.ac | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/configure b/configure
> index b959d2d988..3b98ec312f 100755
> --- a/configure
> +++ b/configure
> @@ -4035,7 +4035,7 @@ if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS \
>  	    -o conftest conftest.S 1>&5 2>&5; then
>    # Do a link to see if the backend supports IFUNC relocs.
>    $READELF -r conftest 1>&5
> -  LC_ALL=C $READELF -r conftest | grep 'no relocations' >/dev/null || {
> +  LC_ALL=C $READELF -Wr conftest | grep -q 'IRELATIVE\|R_SPARC_JMP_IREL' && {
>      libc_cv_ld_gnu_indirect_function=yes
>    }
>  fi
> diff --git a/configure.ac b/configure.ac
> index 49b900c1ed..e20034f301 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -649,7 +649,7 @@ if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS \
>  	    -o conftest conftest.S 1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
>    # Do a link to see if the backend supports IFUNC relocs.
>    $READELF -r conftest 1>&AS_MESSAGE_LOG_FD
> -  LC_ALL=C $READELF -r conftest | grep 'no relocations' >/dev/null || {
> +  LC_ALL=C $READELF -Wr conftest | grep -q 'IRELATIVE\|R_SPARC_JMP_IREL' && {
>      libc_cv_ld_gnu_indirect_function=yes
>    }
>  fi
> -- 
> 2.25.0.341.g760bfbb309-goog
>
Adhemerval Zanella March 5, 2020, 6:43 p.m. UTC | #3
On 10/02/2020 16:14, Fangrui Song wrote:
> On 2020-02-08, Aurelien Jarno wrote:
>> On 2020-02-06 10:53, Fangrui Song wrote:
>>> On 2020-02-06, Aurelien Jarno wrote:
>>> > Hi,
>>> >
>>> > On 2020-02-04 22:09, Fangrui Song wrote:
>>> > > GNU ld's RISCV port does not support IFUNC. ld -no-pie produces no
>>> > > relocation and the test passed incorrectly. Be more rigid by testing
>>> > > IRELATIVE explicitly.
>>> >
>>> > Thanks for your patch and sorry for the time to answer, I was testing it
>>> > on many architectures. First of all I confirm it fixes the issue when
>>> > building glibc with PIE on mips* and riscv64. I also confirm it
>>> > introduces no regression on aarch64, armv5, armv7, hppa, m68k, powerpc,
>>> > ppc64, ppc64le, s390x and x86_64.
>>> >
>>> > However it wrongly detects that IFUNC is not supported on sparc64 when
>>> > PIE is not in use. Here is the output of of readelf for the non-PIE
>>> > case:
>>> >
>>> > | Relocation section '.rela.dyn' at offset 0x110 contains 1 entry:
>>> > |   Offset          Info           Type           Sym. Value    Sym. Name + Addend
>>> > | 000000200280  0000000000f8 R_SPARC_JMP_IREL                     100128
>>>
>>> sparc64 -no-pie does not produce an R_SPARC_IRELATIVE. This looks weird.
>>> All other archs emit an R_*_IRELATIVE.
>>>
>>> Can you dump the assembly (including .text and .[i]plt)?
>>> Or can someone with sparc64 experience answer why sparc64 is different
>>> here?
>>
>> Here is the dump of the .iplt section:
>> Disassembly of section .iplt:
>>
>> 0000000000200200 <.iplt>:
>>        ...
>>  200280:       03 00 00 80     sethi  %hi(0x20000), %g1
>>  200284:       30 6f ff e7     b,a   %xcc, 200220 <__start+0x1000f8>
>>  200288:       01 00 00 00     nop
>>  20028c:       01 00 00 00     nop
>>  200290:       01 00 00 00     nop
>>  200294:       01 00 00 00     nop
>>  200298:       01 00 00 00     nop
>>  20029c:       01 00 00 00     nop
>>
>> There is no .text nor .plt section.
>>
>> -- 
>> Aurelien Jarno                          GPG: 4096R/1DDD8C9B
>> aurelien@aurel32.net                 http://www.aurel32.net
> 
> Attached PATCH v2.
> 
> sparc64 has a non-conventional R_SPARC_JMP_IREL, along with conventional
> R_SPARC_IRELATIVE.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Fangrui Song March 5, 2020, 7:47 p.m. UTC | #4
On 2020-03-05, Adhemerval Zanella wrote:
>
>
>On 10/02/2020 16:14, Fangrui Song wrote:
>> On 2020-02-08, Aurelien Jarno wrote:
>>> On 2020-02-06 10:53, Fangrui Song wrote:
>>>> On 2020-02-06, Aurelien Jarno wrote:
>>>> > Hi,
>>>> >
>>>> > On 2020-02-04 22:09, Fangrui Song wrote:
>>>> > > GNU ld's RISCV port does not support IFUNC. ld -no-pie produces no
>>>> > > relocation and the test passed incorrectly. Be more rigid by testing
>>>> > > IRELATIVE explicitly.
>>>> >
>>>> > Thanks for your patch and sorry for the time to answer, I was testing it
>>>> > on many architectures. First of all I confirm it fixes the issue when
>>>> > building glibc with PIE on mips* and riscv64. I also confirm it
>>>> > introduces no regression on aarch64, armv5, armv7, hppa, m68k, powerpc,
>>>> > ppc64, ppc64le, s390x and x86_64.
>>>> >
>>>> > However it wrongly detects that IFUNC is not supported on sparc64 when
>>>> > PIE is not in use. Here is the output of of readelf for the non-PIE
>>>> > case:
>>>> >
>>>> > | Relocation section '.rela.dyn'@offset 0x110 contains 1 entry:
>>>> > |�� Offset��������� Info���������� Type���������� Sym. Value��� Sym. Name + Addend
>>>> > | 000000200280� 0000000000f8 R_SPARC_JMP_IREL�������������������� 100128
>>>>
>>>> sparc64 -no-pie does not produce an R_SPARC_IRELATIVE. This looks weird.
>>>> All other archs emit an R_*_IRELATIVE.
>>>>
>>>> Can you dump the assembly (including .text and .[i]plt)?
>>>> Or can someone with sparc64 experience answer why sparc64 is different
>>>> here?
>>>
>>> Here is the dump of the .iplt section:
>>> Disassembly of section .iplt:
>>>
>>> 0000000000200200 <.iplt>:
>>> ������ ...
>>> �200280:������ 03 00 00 80���� sethi� %hi(0x20000), %g1
>>> �200284:������ 30 6f ff e7���� b,a�� %xcc, 200220 <__start+0x1000f8>
>>> �200288:������ 01 00 00 00���� nop
>>> �20028c:������ 01 00 00 00���� nop
>>> �200290:������ 01 00 00 00���� nop
>>> �200294:������ 01 00 00 00���� nop
>>> �200298:������ 01 00 00 00���� nop
>>> �20029c:������ 01 00 00 00���� nop
>>>
>>> There is no .text nor .plt section.
>>>
>>> --�
>>> Aurelien Jarno������������������������� GPG: 4096R/1DDD8C9B
>>> aurelien@aurel32.net���������������� http://www.aurel32.net
>>
>> Attached PATCH v2.
>>
>> sparc64 has a non-conventional R_SPARC_JMP_IREL, along with conventional
>> R_SPARC_IRELATIVE.
>
>LGTM, thanks.
>
>Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

Can someone kindly commit on my behalf? I don't have the permission.

Aurelien added a Tested-by: line https://sourceware.org/ml/libc-alpha/2020-02/msg00326.html
Adhemerval Zanella March 5, 2020, 8:06 p.m. UTC | #5
On 05/03/2020 16:47, Fangrui Song wrote:
> On 2020-03-05, Adhemerval Zanella wrote:
>>
>>
>> On 10/02/2020 16:14, Fangrui Song wrote:
>>> On 2020-02-08, Aurelien Jarno wrote:
>>>> On 2020-02-06 10:53, Fangrui Song wrote:
>>>>> On 2020-02-06, Aurelien Jarno wrote:
>>>>> > Hi,
>>>>> >
>>>>> > On 2020-02-04 22:09, Fangrui Song wrote:
>>>>> > > GNU ld's RISCV port does not support IFUNC. ld -no-pie produces no
>>>>> > > relocation and the test passed incorrectly. Be more rigid by testing
>>>>> > > IRELATIVE explicitly.
>>>>> >
>>>>> > Thanks for your patch and sorry for the time to answer, I was testing it
>>>>> > on many architectures. First of all I confirm it fixes the issue when
>>>>> > building glibc with PIE on mips* and riscv64. I also confirm it
>>>>> > introduces no regression on aarch64, armv5, armv7, hppa, m68k, powerpc,
>>>>> > ppc64, ppc64le, s390x and x86_64.
>>>>> >
>>>>> > However it wrongly detects that IFUNC is not supported on sparc64 when
>>>>> > PIE is not in use. Here is the output of of readelf for the non-PIE
>>>>> > case:
>>>>> >
>>>>> > | Relocation section '.rela.dyn'@offset 0x110 contains 1 entry:
>>>>> > |�� Offset��������� Info���������� Type���������� Sym. Value��� Sym. Name + Addend
>>>>> > | 000000200280� 0000000000f8 R_SPARC_JMP_IREL�������������������� 100128
>>>>>
>>>>> sparc64 -no-pie does not produce an R_SPARC_IRELATIVE. This looks weird.
>>>>> All other archs emit an R_*_IRELATIVE.
>>>>>
>>>>> Can you dump the assembly (including .text and .[i]plt)?
>>>>> Or can someone with sparc64 experience answer why sparc64 is different
>>>>> here?
>>>>
>>>> Here is the dump of the .iplt section:
>>>> Disassembly of section .iplt:
>>>>
>>>> 0000000000200200 <.iplt>:
>>>> ������ ...
>>>> �200280:������ 03 00 00 80���� sethi� %hi(0x20000), %g1
>>>> �200284:������ 30 6f ff e7���� b,a�� %xcc, 200220 <__start+0x1000f8>
>>>> �200288:������ 01 00 00 00���� nop
>>>> �20028c:������ 01 00 00 00���� nop
>>>> �200290:������ 01 00 00 00���� nop
>>>> �200294:������ 01 00 00 00���� nop
>>>> �200298:������ 01 00 00 00���� nop
>>>> �20029c:������ 01 00 00 00���� nop
>>>>
>>>> There is no .text nor .plt section.
>>>>
>>>> --�
>>>> Aurelien Jarno������������������������� GPG: 4096R/1DDD8C9B
>>>> aurelien@aurel32.net���������������� http://www.aurel32.net
>>>
>>> Attached PATCH v2.
>>>
>>> sparc64 has a non-conventional R_SPARC_JMP_IREL, along with conventional
>>> R_SPARC_IRELATIVE.
>>
>> LGTM, thanks.
>>
>> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> 
> Can someone kindly commit on my behalf? I don't have the permission.
> 
> Aurelien added a Tested-by: line https://sourceware.org/ml/libc-alpha/2020-02/msg00326.html

Done.
diff mbox

Patch

From 624b3a0c9e4f2f421227bb3f331723dfe807f157 Mon Sep 17 00:00:00 2001
From: Fangrui Song <maskray@google.com>
Date: Tue, 4 Feb 2020 21:55:44 -0800
Subject: [PATCH] Improve IFUNC check [BZ #25506]

GNU ld does not support IFUNC but does not produces a relocation.
The test passed incorrectly. Be more rigid by testing IRELATIVE
explicitly.
---
 configure    | 2 +-
 configure.ac | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index b959d2d988..3b98ec312f 100755
--- a/configure
+++ b/configure
@@ -4035,7 +4035,7 @@  if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS \
 	    -o conftest conftest.S 1>&5 2>&5; then
   # Do a link to see if the backend supports IFUNC relocs.
   $READELF -r conftest 1>&5
-  LC_ALL=C $READELF -r conftest | grep 'no relocations' >/dev/null || {
+  LC_ALL=C $READELF -Wr conftest | grep -q 'IRELATIVE\|R_SPARC_JMP_IREL' && {
     libc_cv_ld_gnu_indirect_function=yes
   }
 fi
diff --git a/configure.ac b/configure.ac
index 49b900c1ed..e20034f301 100644
--- a/configure.ac
+++ b/configure.ac
@@ -649,7 +649,7 @@  if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS \
 	    -o conftest conftest.S 1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
   # Do a link to see if the backend supports IFUNC relocs.
   $READELF -r conftest 1>&AS_MESSAGE_LOG_FD
-  LC_ALL=C $READELF -r conftest | grep 'no relocations' >/dev/null || {
+  LC_ALL=C $READELF -Wr conftest | grep -q 'IRELATIVE\|R_SPARC_JMP_IREL' && {
     libc_cv_ld_gnu_indirect_function=yes
   }
 fi
-- 
2.25.0.341.g760bfbb309-goog