]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
LoongArch: Fix assertion failure with DT_RELR
authorXi Ruoyao <xry111@xry111.site>
Mon, 12 Aug 2024 10:23:46 +0000 (18:23 +0800)
committerliuzhensong <liuzhensong@loongson.cn>
Wed, 14 Aug 2024 09:45:02 +0000 (17:45 +0800)
commit91e0b4655109a38b631baba310cb93a49f94c434
tree0e2ab6a61c48f22c58d29099613c0f377a9cf3c9
parent8c1cd8603443ffeee6e9cc97b738527ea1e2b3e5
LoongArch: Fix assertion failure with DT_RELR

In the DT_RELR implementation I missed a code path emiting relative
reloc entries.  Then the already packed relative reloc entries will be
(unnecessarily) pushed into .rela.dyn but we've not allocated the space
for them, triggering an assertion failure.

Unfortunately I failed to notice the issue until profiled bootstrapping
GCC with LTO and -Wl,-z,pack-relative-relocs.  The failure can be easily
triggered by linking a "hello world" program with -fprofile-generate and
LTO:

    $ PATH=$HOME/ld-test:$PATH gcc hw.c -fprofile-generate -Wl,-z,pack-relative-relocs -flto
    /home/xry111/git-repos/binutils-build/TEST/ld: BFD (GNU Binutils) 2.43.50.20240802 assertion fail ../../binutils-gdb/bfd/elfnn-loongarch.c:2628
    /home/xry111/git-repos/binutils-build/TEST/ld: BFD (GNU Binutils) 2.43.50.20240802 assertion fail ../../binutils-gdb/bfd/elfnn-loongarch.c:2628
    collect2: error: ld returned 1 exit status

And the reduced test case is just incredibly simple (included in the
patch) so it seems I'm just stupid enough to fail to detect it before.
Let's fix it now anyway.

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