diff options
author | Xi Ruoyao <xry111@xry111.site> | 2022-09-20 14:09:30 +0800 |
---|---|---|
committer | liuzhensong <liuzhensong@loongson.cn> | 2022-09-20 17:16:06 +0800 |
commit | ae2e4d4035f511543d12f74b3b7fdb1ba0daab16 (patch) | |
tree | e4974a4c0504bcbc069b32a90f7bf814ce428552 /ld/testsuite | |
parent | 6224a6c2ead26a04f0b2b8ccf4ff5b817afbb425 (diff) | |
download | gdb-ae2e4d4035f511543d12f74b3b7fdb1ba0daab16.zip gdb-ae2e4d4035f511543d12f74b3b7fdb1ba0daab16.tar.gz gdb-ae2e4d4035f511543d12f74b3b7fdb1ba0daab16.tar.bz2 |
LoongArch: Fix R_LARCH_IRELATIVE insertion after elf_link_sort_relocs
loongarch_elf_finish_dynamic_symbol is called after elf_link_sort_relocs
if -z combreloc. elf_link_sort_relocs redistributes the contents of
.rela.* sections those would be merged into .rela.dyn, so the slot for
R_LARCH_IRELATIVE may be out of relplt->contents now.
To make things worse, the boundary check
dyn < dyn + relplt->size / sizeof (*dyn)
is obviously wrong ("x + 10 < x"? :), causing the issue undetected
during the linking process and the resulted executable suddenly crashes
at runtime.
The issue was found during an attempt to add static-pie support to the
toolchain.
Fix it by iterating through the inputs of .rela.dyn to find the slot.
Diffstat (limited to 'ld/testsuite')
-rw-r--r-- | ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp | 1 | ||||
-rw-r--r-- | ld/testsuite/ld-loongarch-elf/local-ifunc-reloc.d | 10 | ||||
-rw-r--r-- | ld/testsuite/ld-loongarch-elf/local-ifunc-reloc.s | 28 |
3 files changed, 39 insertions, 0 deletions
diff --git a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp index dfa8ee1..726ee82 100644 --- a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp +++ b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp @@ -31,6 +31,7 @@ if [istarget "loongarch64-*-*"] { run_dump_test "macro_op" run_dump_test "syscall" run_dump_test "disas-jirl" + run_dump_test "local-ifunc-reloc" } if [istarget "loongarch32-*-*"] { diff --git a/ld/testsuite/ld-loongarch-elf/local-ifunc-reloc.d b/ld/testsuite/ld-loongarch-elf/local-ifunc-reloc.d new file mode 100644 index 0000000..29f2d3f --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/local-ifunc-reloc.d @@ -0,0 +1,10 @@ +#as: +#ld: -shared -z combreloc +#objdump: -R + +.*: +file format .* + +DYNAMIC RELOCATION RECORDS +OFFSET +TYPE +VALUE +[[:xdigit:]]+ R_LARCH_IRELATIVE +\*ABS\*\+0x[[:xdigit:]]+ +[[:xdigit:]]+ R_LARCH_64 +test diff --git a/ld/testsuite/ld-loongarch-elf/local-ifunc-reloc.s b/ld/testsuite/ld-loongarch-elf/local-ifunc-reloc.s new file mode 100644 index 0000000..77c4874 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/local-ifunc-reloc.s @@ -0,0 +1,28 @@ +.text +.align 2 + +.local ifunc +.type ifunc, @gnu_indirect_function +.set ifunc, resolver + +resolver: + la.local $a0, impl + jr $ra + +impl: + li.w $a0, 42 + jr $ra + +.global test +.type test, @function +test: + move $s0, $ra + bl ifunc + xori $a0, $a0, 42 + jr $s0 + +.data +.global ptr +.type ptr, @object +ptr: + .dword test |