Browse Source
The %pcrel_lo addend may causes the overflow, and need more than one
%pcrel_hi values. But there may be only one auipc, shared by those
%pcrel_lo with addends. However, the existing check method in the
riscv_resolve_pcrel_lo_relocs, may not be able to work for some
special/corner cases.
Consider the testcases pcrel-lo-addend-2b. Before applying this patch,
I can compile it successfully. But in fact the addend cause the value
of %pcrel_hi to be different. This patch try to check the value of
%pcrel_hi directly, to make sure it won't be changed. Otherwise, linker
will report the following errors,
(.text+0xa): dangerous relocation: %pcrel_lo overflow with an addend,
the value of %pcrel_hi is 0x1000 without any addend, but may be 0x2000
after adding the %pcrel_lo addend
The toolchain regressions, rv64gc-linux/rv64gc-elf/rv32gc-linux/rv32i-elf,
pass expectedly and looks fine.
bfd/
* elfnn-riscv.c (riscv_resolve_pcrel_lo_relocs): Check the values
of %pcrel_hi, before and after adding the addend. Make sure the
value won't be changed, otherwise, report dangerous error.
ld/
* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
* testsuite/ld-riscv-elf/pcrel-lo-addend-2a.d: Renamed from
pcrel-lo-addend-2.
* testsuite/ld-riscv-elf/pcrel-lo-addend-2a.s: Likewise.
* testsuite/ld-riscv-elf/pcrel-lo-addend-2b.d: New testcase.
* testsuite/ld-riscv-elf/pcrel-lo-addend-2b.s: Likewise.
binutils-2_37-branch
9 changed files with 60 additions and 13 deletions
@ -1,5 +0,0 @@ |
|||
#name: %pcrel_lo overflow with an addend |
|||
#source: pcrel-lo-addend-2.s |
|||
#as: -march=rv32ic |
|||
#ld: -m[riscv_choose_ilp32_emul] --no-relax |
|||
#error: .*dangerous relocation: %pcrel_lo overflow with an addend |
|||
@ -0,0 +1,5 @@ |
|||
#name: %pcrel_lo overflow with an addend (2a) |
|||
#source: pcrel-lo-addend-2a.s |
|||
#as: -march=rv32ic |
|||
#ld: -m[riscv_choose_ilp32_emul] --no-relax |
|||
#error: .*dangerous relocation: %pcrel_lo overflow with an addend, the value of %pcrel_hi is 0x1000 without any addend, but may be 0x2000 after adding the %pcrel_lo addend |
|||
@ -0,0 +1,5 @@ |
|||
#name: %pcrel_lo overflow with an addend (2b) |
|||
#source: pcrel-lo-addend-2b.s |
|||
#as: -march=rv32ic |
|||
#ld: -m[riscv_choose_ilp32_emul] --no-relax |
|||
#error: .*dangerous relocation: %pcrel_lo overflow with an addend, the value of %pcrel_hi is 0x1000 without any addend, but may be 0x2000 after adding the %pcrel_lo addend |
|||
@ -0,0 +1,16 @@ |
|||
.text |
|||
.globl _start |
|||
.align 3 |
|||
_start: |
|||
nop |
|||
.LA0: auipc a5,%pcrel_hi(ll) |
|||
lw a0,%pcrel_lo(.LA0)(a5) |
|||
lw a0,%pcrel_lo(.LA0+0x1000)(a5) |
|||
ret |
|||
.globl ll |
|||
.data |
|||
.align 3 |
|||
.zero 2024 |
|||
ll: |
|||
.word 0 |
|||
.word 0 |
|||
Loading…
Reference in new issue