diff options
author | Lifang Xia <lifang_xia@linux.alibaba.com> | 2023-11-29 17:17:22 +0800 |
---|---|---|
committer | Nelson Chu <nelson@rivosinc.com> | 2023-12-12 17:04:23 +0800 |
commit | dff565fcca8137954d6ad571ef39f6aec5c0429c (patch) | |
tree | 6a14ffd97a42d3ad207503ee84b1ae732b26b3a7 /gas/testsuite | |
parent | e61ea34e74f1c29f320906c11300697d15b1a1c0 (diff) | |
download | gdb-dff565fcca8137954d6ad571ef39f6aec5c0429c.zip gdb-dff565fcca8137954d6ad571ef39f6aec5c0429c.tar.gz gdb-dff565fcca8137954d6ad571ef39f6aec5c0429c.tar.bz2 |
RISC-V: Resolve PCREL_HI20/LO12_I/S fixups with local symbols while `-mno-relax'
In the scenario of generating .ko files, the kernel does not relax the .ko
files. However, due to the large amount of relax and local relocation
information, this increases the size of the .ko files. In this patch, it
will finish the fixup of the local relocations while with `-mno-relax' option.
This can reduce the size of the relocation table.
The implemntation is based on the code from bfd/elfnn-riscv.c. We probably
can move the code to bfd/elfxx-riscv.c, so that can reduce duplicate code,
just like what we did for the architecture parser.
Besides, maybe not only pcrel_hi/lo12 relocation with local symbols can be
resolved at assembler time. Other pc-relative relocation, like branch,
may also be able to perform related optimizations.
Passed the gcc/binutils regressions of riscv-gnu-toolchain.
gas/
* config/tc-riscv.c (riscv_pcrel_hi_reloc): New structure. Record all
PC-relative high-part relocation that we have encountered to help us
resolve the corresponding low-part relocation later.
(riscv_pcrel_hi_fixup_hash): The hash table to record pcrel_hi fixups.
(riscv_pcrel_fixup_hash): New function. Likewise.
(riscv_pcrel_fixup_eq): Likewise.
(riscv_record_pcrel_fixup): Likewise.
(md_begin): Init pcrel_hi hash table.
(md_apply_fix): For PCREL_HI20 relocation, do fixup and record
the pcrel_hi relocs, mark as done while with `-mno-relax'. For
PCREL_LO12_I/S relocation, do fixup and mark as done while with
`-mno-relax'.
(riscv_md_end): New function. Free pcrel_hi hash table.
* config/tc-riscv.h (md_end): Define md_end with riscv_md_end.
gas/
* testsuite/gas/riscv/fixup-local*: New tests.
Diffstat (limited to 'gas/testsuite')
-rw-r--r-- | gas/testsuite/gas/riscv/fixup-local-norelax.d | 22 | ||||
-rw-r--r-- | gas/testsuite/gas/riscv/fixup-local-relax.d | 41 | ||||
-rw-r--r-- | gas/testsuite/gas/riscv/fixup-local.s | 13 |
3 files changed, 76 insertions, 0 deletions
diff --git a/gas/testsuite/gas/riscv/fixup-local-norelax.d b/gas/testsuite/gas/riscv/fixup-local-norelax.d new file mode 100644 index 0000000..3169c69 --- /dev/null +++ b/gas/testsuite/gas/riscv/fixup-local-norelax.d @@ -0,0 +1,22 @@ +#as: -march=rv64i -mno-relax +#source: fixup-local.s +#objdump: -dr + +.*:[ ]+file format .* + +Disassembly of section .text: + +0+0000 <foo>: +[ ]+0:[ ]+00000517[ ]+auipc[ ]+a0,0x0 +[ ]+4:[ ]+00850513[ ]+addi[ ]+a0,a0,8 # 8 <foo\+0x8> +[ ]+8:[ ]+00000517[ ]+auipc[ ]+a0,0x0 +[ ]+8:[ ]+R_RISCV_PCREL_HI20[ ]+bar.* +[ ]+c:[ ]+00050513[ ]+mv[ ]+a0,a0 +[ ]+c:[ ]+R_RISCV_PCREL_LO12_I[ ]+.L0.* +[ ]+10:[ ]+00000517[ ]+auipc[ ]+a0,0x0 +[ ]+10:[ ]+R_RISCV_PCREL_HI20[ ]+foo.* +[ ]+14:[ ]+00050513[ ]+mv[ ]+a0,a0 +[ ]+14:[ ]+R_RISCV_PCREL_LO12_I[ ]+.L0.* +[ ]+18:[ ]+00000517[ ]+auipc[ ]a0,0x0 +[ ]+1c:[ ]+00852503[ ]+lw[ ]+a0,8\(a0\) # 20 <foo\+0x20> +[ ]+20:[ ]+00008067[ ]+ret diff --git a/gas/testsuite/gas/riscv/fixup-local-relax.d b/gas/testsuite/gas/riscv/fixup-local-relax.d new file mode 100644 index 0000000..3738de1 --- /dev/null +++ b/gas/testsuite/gas/riscv/fixup-local-relax.d @@ -0,0 +1,41 @@ +#as: -march=rv64i -mrelax +#source: fixup-local.s +#objdump: -dr + +.*:[ ]+file format .* + + +Disassembly of section .text: + +0+0000 <foo>: +[ ]+0:[ ]+00000517[ ]+auipc[ ]+a0,0x0 +[ ]+0:[ ]+R_RISCV_PCREL_HI20[ ]+.LL0.* +[ ]+0:[ ]+R_RISCV_RELAX.* +[ ]+4:[ ]+00850513[ ]+addi[ ]+a0,a0,8 # 8 <.LL0> +[ ]+4:[ ]+R_RISCV_PCREL_LO12_I[ ]+.L0.* +[ ]+4:[ ]+R_RISCV_RELAX.* + +0+0008 <.LL0>: +[ ]+8:[ ]+00000517[ ]+auipc[ ]+a0,0x0 +[ ]+8:[ ]+R_RISCV_PCREL_HI20[ ]+bar.* +[ ]+8:[ ]+R_RISCV_RELAX.* +[ ]+c:[ ]+00050513[ ]+mv[ ]+a0,a0 +[ ]+c:[ ]+R_RISCV_PCREL_LO12_I[ ]+.L0.* +[ ]+c:[ ]+R_RISCV_RELAX.* +[ ]+10:[ ]+00000517[ ]+auipc[ ]+a0,0x0 +[ ]+10:[ ]+R_RISCV_PCREL_HI20[ ]+foo.* +[ ]+10:[ ]+R_RISCV_RELAX.* +[ ]+14:[ ]+00050513[ ]+mv[ ]+a0,a0 +[ ]+14:[ ]+R_RISCV_PCREL_LO12_I[ ]+.L0.* +[ ]+14:[ ]+R_RISCV_RELAX.* + +0+0018 <.LL1>: +[ ]+18:[ ]+00000517[ ]+auipc[ ]a0,0x0 +[ ]+18:[ ]+R_RISCV_PCREL_HI20[ ]+.LL2.* +[ ]+18:[ ]R_RISCV_RELAX.* +[ ]+1c:[ ]+00852503[ ]+lw[ ]+a0,8\(a0\) # 20 <.LL2> +[ ]+1c:[ ]+R_RISCV_PCREL_LO12_I[ ]+.LL1.* +[ ]+1c:[ ]+R_RISCV_RELAX.* + +0+0020 <.LL2>: +[ ]+20:[ ]+00008067[ ]+ret diff --git a/gas/testsuite/gas/riscv/fixup-local.s b/gas/testsuite/gas/riscv/fixup-local.s new file mode 100644 index 0000000..44b4731 --- /dev/null +++ b/gas/testsuite/gas/riscv/fixup-local.s @@ -0,0 +1,13 @@ +.global foo +.global bar +foo: + la a0, .LL0 +.LL0: + la a0, bar + la a0, foo +.LL1: + auipc a0, %pcrel_hi(.LL2) + lw a0, %pcrel_lo(.LL1)(a0) + +.LL2: + ret |