mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-06 12:09:26 +08:00
50331d64f1
The original discussion was here, https://github.com/riscv/riscv-elf-psabi-doc/issues/184 After discussing with Kito Cheng, I think the addends of %pcrel_hi and %pcrel_lo are both allowed in GNU toolchain. However, both of the them mean the offset of symbols, rather than the pc address. But the addends of %got_pcrel_hi and it's %pcrel_lo do not look reasonable. I believe gcc won't generate the got patterns with addends, so linker should report dangerous relocation errors, in case the assembly code use them. Another issue was here, https://sourceware.org/pipermail/binutils/2021-June/116983.html At the beginnig, I suppose %pcrel_hi and %pcrel_lo are valid only when they are in the same input section. But Jim Wilson points out that gcc may generate %hi and %lo in the different input sections, when -freorder-blocks-and-partition option is used. So that a memory references for a loop may have the %hi outside the loop, but the %lo remain in the loop. However, it is hard to create the testcases, to see if %pcrel_hi and %pcrel_lo have the same behavior. Unfortunately, I notice that the current pcrel resolver cannot work for the above case. For now we build a hash table for pcrel at the start of riscv_elf_relocate_section, and then free the hash at the end. But riscv_elf_relocate_section only handles an input section at a time, so that means we can only resolve the %pcrel_hi and %pcrel_lo which are in the same input section. Otherwise, like the above case, we will report "%pcrel_lo missing matching %pcrel_hi" for them. I have no plan to improve this in the short-term, so maybe we can wait until someone meets the problem before we deal with it. bfd/ * elfnn-riscv.c (riscv_pcrel_hi_reloc): Added field to store the original relocation type, in case the type is converted to R_RISCV_HI20. (riscv_pcrel_lo_reloc): Removed unused name field. (riscv_pcrel_relocs): Added comments. (riscv_zero_pcrel_hi_reloc): Removed unused input_bfd. (riscv_record_pcrel_hi_reloc): Updated. (riscv_record_pcrel_lo_reloc): Likewise. (riscv_resolve_pcrel_lo_relocs): Likewise. Check the original type of auipc, to make sure the %pcrel_lo without any addends. Otherwise, report dangerous relocation error. (riscv_elf_relocate_section): Updated above functions are changed. For R_RISCV_GOT_HI20, report dangerous relocation error when addend isn't zero. ld/ * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated. * testsuite/ld-riscv-elf/pcrel-lo-addend-3a.d: New testcase. * testsuite/ld-riscv-elf/pcrel-lo-addend-3a.s: Likewise. * testsuite/ld-riscv-elf/pcrel-lo-addend-3b.d: New testcase. Should report error since the %pcrel_lo with addend refers to %got_pcrel_hi. * testsuite/ld-riscv-elf/pcrel-lo-addend-3b.s: Likewise. * testsuite/ld-riscv-elf/pcrel-lo-addend-3c.d: New testcase. Should report error since the %got_pcrel_hi with addend. * testsuite/ld-riscv-elf/pcrel-lo-addend-3c.s: Likewise. * testsuite/ld-riscv-elf/pcrel-lo-addend-3.ld: Likewise. |
||
---|---|---|
.. | ||
attr-merge-arch-01.d | ||
attr-merge-arch-01a.s | ||
attr-merge-arch-01b.s | ||
attr-merge-arch-02.d | ||
attr-merge-arch-02a.s | ||
attr-merge-arch-02b.s | ||
attr-merge-arch-03.d | ||
attr-merge-arch-03a.s | ||
attr-merge-arch-03b.s | ||
attr-merge-arch-failed-01.d | ||
attr-merge-arch-failed-01a.s | ||
attr-merge-arch-failed-01b.s | ||
attr-merge-arch-failed-02.d | ||
attr-merge-arch-failed-02a.s | ||
attr-merge-arch-failed-02b.s | ||
attr-merge-arch-failed-02c.s | ||
attr-merge-arch-failed-02d.s | ||
attr-merge-priv-spec-01.d | ||
attr-merge-priv-spec-02.d | ||
attr-merge-priv-spec-03.d | ||
attr-merge-priv-spec-a.s | ||
attr-merge-priv-spec-b.s | ||
attr-merge-priv-spec-c.s | ||
attr-merge-priv-spec-d.s | ||
attr-merge-priv-spec-failed-01.d | ||
attr-merge-priv-spec-failed-02.d | ||
attr-merge-priv-spec-failed-03.d | ||
attr-merge-priv-spec-failed-04.d | ||
attr-merge-priv-spec-failed-05.d | ||
attr-merge-priv-spec-failed-06.d | ||
attr-merge-stack-align-a.s | ||
attr-merge-stack-align-b.s | ||
attr-merge-stack-align-failed-a.s | ||
attr-merge-stack-align-failed-b.s | ||
attr-merge-stack-align-failed.d | ||
attr-merge-stack-align.d | ||
attr-merge-strict-align-01.d | ||
attr-merge-strict-align-01a.s | ||
attr-merge-strict-align-01b.s | ||
attr-merge-strict-align-02.d | ||
attr-merge-strict-align-02a.s | ||
attr-merge-strict-align-02b.s | ||
attr-merge-strict-align-03.d | ||
attr-merge-strict-align-03a.s | ||
attr-merge-strict-align-03b.s | ||
attr-merge-strict-align-04.d | ||
attr-merge-strict-align-04a.s | ||
attr-merge-strict-align-04b.s | ||
attr-merge-strict-align-05.d | ||
attr-merge-strict-align-05a.s | ||
attr-merge-strict-align-05b.s | ||
c-lui-2.d | ||
c-lui-2.ld | ||
c-lui-2.s | ||
c-lui.d | ||
c-lui.s | ||
call-relax-0.s | ||
call-relax-1.s | ||
call-relax-2.s | ||
call-relax-3.s | ||
call-relax.d | ||
disas-jalr.d | ||
disas-jalr.s | ||
gp-test-lib.sd | ||
gp-test.s | ||
gp-test.sd | ||
ifunc-nonplt-exe.rd | ||
ifunc-nonplt-pic.rd | ||
ifunc-nonplt-pie.rd | ||
ifunc-nonplt.d | ||
ifunc-nonplt.s | ||
ifunc-plt-01-exe.rd | ||
ifunc-plt-01-pic.rd | ||
ifunc-plt-01-pie.rd | ||
ifunc-plt-01.d | ||
ifunc-plt-01.s | ||
ifunc-plt-02-exe.rd | ||
ifunc-plt-02-pic.rd | ||
ifunc-plt-02-pie.rd | ||
ifunc-plt-02.d | ||
ifunc-plt-02.s | ||
ifunc-plt-got-overwrite-exe.rd | ||
ifunc-plt-got-overwrite-pic.rd | ||
ifunc-plt-got-overwrite-pie.rd | ||
ifunc-plt-got-overwrite.d | ||
ifunc-plt-got-overwrite.s | ||
ifunc-reloc-call-01-exe.rd | ||
ifunc-reloc-call-01-pic.rd | ||
ifunc-reloc-call-01-pie.rd | ||
ifunc-reloc-call-01.d | ||
ifunc-reloc-call-01.s | ||
ifunc-reloc-call-02-exe.rd | ||
ifunc-reloc-call-02-pic.rd | ||
ifunc-reloc-call-02-pie.rd | ||
ifunc-reloc-call-02.d | ||
ifunc-reloc-call-02.s | ||
ifunc-reloc-data-exe.rd | ||
ifunc-reloc-data-pic.rd | ||
ifunc-reloc-data-pie.rd | ||
ifunc-reloc-data.d | ||
ifunc-reloc-data.s | ||
ifunc-reloc-got-exe.rd | ||
ifunc-reloc-got-pic.rd | ||
ifunc-reloc-got-pie.rd | ||
ifunc-reloc-got.d | ||
ifunc-reloc-got.s | ||
ifunc-reloc-pcrel-exe.rd | ||
ifunc-reloc-pcrel-pic.rd | ||
ifunc-reloc-pcrel-pie.rd | ||
ifunc-reloc-pcrel.d | ||
ifunc-reloc-pcrel.s | ||
ifunc-seperate-caller-nonplt.s | ||
ifunc-seperate-caller-pcrel.s | ||
ifunc-seperate-caller-plt.s | ||
ifunc-seperate-nonplt-exe.d | ||
ifunc-seperate-nonplt-pic.d | ||
ifunc-seperate-nonplt-pie.d | ||
ifunc-seperate-pcrel-pic.d | ||
ifunc-seperate-pcrel-pie.d | ||
ifunc-seperate-plt-exe.d | ||
ifunc-seperate-plt-pic.d | ||
ifunc-seperate-plt-pie.d | ||
ifunc-seperate-resolver.s | ||
ld-riscv-elf.exp | ||
lib-nopic-01a.s | ||
lib-nopic-01b.d | ||
lib-nopic-01b.s | ||
pcgp-relax.d | ||
pcgp-relax.s | ||
pcrel-lo-addend-2a.d | ||
pcrel-lo-addend-2a.s | ||
pcrel-lo-addend-2b.d | ||
pcrel-lo-addend-2b.s | ||
pcrel-lo-addend-3.ld | ||
pcrel-lo-addend-3a.d | ||
pcrel-lo-addend-3a.s | ||
pcrel-lo-addend-3b.d | ||
pcrel-lo-addend-3b.s | ||
pcrel-lo-addend-3c.d | ||
pcrel-lo-addend-3c.s | ||
pcrel-lo-addend.d | ||
pcrel-lo-addend.s | ||
relro-relax-lui.d | ||
relro-relax-lui.s | ||
relro-relax-pcrel.d | ||
relro-relax-pcrel.s | ||
restart-relax.d | ||
restart-relax.s | ||
weakref32.d | ||
weakref32.s | ||
weakref64.d | ||
weakref64.s | ||
weakref.ld |