]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
LoongArch: Fix bad reloc with mixed visibility ifunc symbols in shared libraries
authorXi Ruoyao <xry111@xry111.site>
Sun, 30 Jun 2024 07:18:22 +0000 (15:18 +0800)
committerliuzhensong <liuzhensong@loongson.cn>
Fri, 5 Jul 2024 04:11:11 +0000 (12:11 +0800)
commit41ef0bff2033bb7b30a2792417aa946503492ce0
tree9c18ea35d658259c1fe5315e98997207e2c9f831
parent1c31db21fe6555e1a9b2a33b95a0125250c517d8
LoongArch: Fix bad reloc with mixed visibility ifunc symbols in shared libraries

With a simple test case:

    .globl  ifunc
    .globl  ifunc_hidden
    .hidden ifunc_hidden
    .type   ifunc, %gnu_indirect_function
    .type   ifunc_hidden, %gnu_indirect_function

    .text
    .align  2
    ifunc:  ret
    ifunc_hidden: ret

    test:
      bl ifunc
      bl ifunc_hidden

"ld -shared" produces a shared object with one R_LARCH_NONE (instead of
R_LARCH_JUMP_SLOT as we expect) to relocate the GOT entry of "ifunc".
It's because the indices in .plt and .rela.plt mismatches for
STV_DEFAULT STT_IFUNC symbols when another PLT entry exists for a
STV_HIDDEN STT_IFUNC symbol, and such a mismatch breaks the logic of
loongarch_elf_finish_dynamic_symbol.  Fix the issue by reordering .plt
so the indices no longer mismatch.

Signed-off-by: Xi Ruoyao <xry111@xry111.site>
bfd/elfnn-loongarch.c
ld/testsuite/ld-loongarch-elf/ifunc-reloc.d [new file with mode: 0644]
ld/testsuite/ld-loongarch-elf/ifunc-reloc.s [new file with mode: 0644]
ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp