diff options
author | Nelson Chu <nelson@rivosinc.com> | 2025-08-21 12:33:04 +0800 |
---|---|---|
committer | Nelson Chu <nelson@rivosinc.com> | 2025-09-04 16:33:50 +0800 |
commit | 519349b57d72abc64175d2341dd6b40426212eb4 (patch) | |
tree | 162dffd7b4b9ab7f63542fb752281d9527dab98a | |
parent | 672a326e2c1a0eb5e318637df205fcdf10cc48a0 (diff) | |
download | binutils-519349b57d72abc64175d2341dd6b40426212eb4.zip binutils-519349b57d72abc64175d2341dd6b40426212eb4.tar.gz binutils-519349b57d72abc64175d2341dd6b40426212eb4.tar.bz2 |
RISC-V: Don't generate R_RISCV_RELATIVE if symbol referenced section is SH_ABS
It's werid if it's absolute symbol but have a relative reloc for got entry
under pie. So don't generate relative reloc if symbol referenced section is
SH_ABS. However, x86 allows the absolute symbol defined in linker script has
a relative reloc, not sure if risc-v needs this or not.
-rw-r--r-- | bfd/elfnn-riscv.c | 3 | ||||
-rw-r--r-- | ld/testsuite/ld-riscv-elf/absolute-no-relative.d | 9 | ||||
-rw-r--r-- | ld/testsuite/ld-riscv-elf/absolute-no-relative.ld | 6 | ||||
-rw-r--r-- | ld/testsuite/ld-riscv-elf/absolute-no-relative.s | 8 | ||||
-rw-r--r-- | ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp | 1 |
5 files changed, 26 insertions, 1 deletions
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index 6ff6432..aac061f 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -2880,7 +2880,8 @@ riscv_elf_relocate_section (bfd *output_bfd, if (h->dynindx == -1 && !h->forced_local && h->root.type != bfd_link_hash_undefweak - && bfd_link_pic (info)) + && bfd_link_pic (info) + && !bfd_is_abs_section(h->root.u.def.section)) relative_got = true; bfd_put_NN (output_bfd, relocation, diff --git a/ld/testsuite/ld-riscv-elf/absolute-no-relative.d b/ld/testsuite/ld-riscv-elf/absolute-no-relative.d new file mode 100644 index 0000000..6699ac1 --- /dev/null +++ b/ld/testsuite/ld-riscv-elf/absolute-no-relative.d @@ -0,0 +1,9 @@ +#source: absolute-no-relative.s +#as: +#ld: -Tabsolute-no-relative.ld -pie +#readelf: -Wr + +Relocation section '.rela.dyn' at .* +[ ]+Offset[ ]+Info[ ]+Type[ ]+.* +0+[ ]+0+[ ]+R_RISCV_NONE[ ]+0 +0+[ ]+0+[ ]+R_RISCV_NONE[ ]+0 diff --git a/ld/testsuite/ld-riscv-elf/absolute-no-relative.ld b/ld/testsuite/ld-riscv-elf/absolute-no-relative.ld new file mode 100644 index 0000000..34bbcba --- /dev/null +++ b/ld/testsuite/ld-riscv-elf/absolute-no-relative.ld @@ -0,0 +1,6 @@ +ENTRY(_start) +SECTIONS { + __symbol_abs__ = 0x1234; + .text 0x10000 : { *(.text*)} + .got 0x20000 : { *(.got*) } +} diff --git a/ld/testsuite/ld-riscv-elf/absolute-no-relative.s b/ld/testsuite/ld-riscv-elf/absolute-no-relative.s new file mode 100644 index 0000000..4515661 --- /dev/null +++ b/ld/testsuite/ld-riscv-elf/absolute-no-relative.s @@ -0,0 +1,8 @@ +.text +.global _start +_start: +lga x1, symbol_abs +lga x1, __symbol_abs__ + +.global symbol_abs +.set symbol_abs, 0x100 diff --git a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp index bae1105..b0d510a 100644 --- a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp +++ b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp @@ -338,4 +338,5 @@ if [istarget "riscv*-*-*"] { } run_dump_test "tls" run_dump_test "tlsbin" + run_dump_test "absolute-no-relative" } |