This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Improve IFUNC check


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?

As my lld R_RISCV_IRELATIVE patch (https://reviews.llvm.org/D74022) shows

  # DIS64:      _start:
  # DIS64-NEXT:     1264: auipc a0, 0
  # DIS64-NEXT:           addi a0, a0, 12
  # DIS64:      Disassembly of section .iplt:
  # DIS64:      00001270 func:
  ## 64-bit: &.got.plt[func]-. = 0x3370-0x1270 = 4096*2+256
  # DIS64-NEXT:          auipc t3, 2
  # DIS64-NEXT:          ld t3, 256(t3)
  # DIS64-NEXT:          jalr t1, t3
  # DIS64-NEXT:          nop

The idea is to create an IPLT entry and bind absolute/PC-relative relocations to that address.
The IPLT entry needs a .got.plt slot, which is relocated by an R_*_IRELATIVE at runtime.
It is R_*_IRELATIVE because no symbol index is needed.


R_SPARC_JMP_IREL looks strange. I hope someone can explain.

And for the PIE case:

| Relocation section '.rela.dyn' at offset 0x290 contains 1 entry:
|   Offset          Info           Type           Sym. Value    Sym. Name + Addend
| 0000001021a0  0000000000f9 R_SPARC_IRELATIVE                    2c0
|
| Relocation section '.rela.plt' at offset 0x2a8 contains 1 entry:
|   Offset          Info           Type           Sym. Value    Sym. Name + Addend
| 000000102180  0000000000f8 R_SPARC_JMP_IREL                     2c0

Looks like you might want to slightly adjust the regex.

Also note that this is BZ#25506, to add to the commit message.

--
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                 http://www.aurel32.net


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]