]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
RISC-V: Resolve PCREL_HI20/LO12_I/S fixups with local symbols while `-mno-relax'
authorLifang Xia <lifang_xia@linux.alibaba.com>
Wed, 29 Nov 2023 09:17:22 +0000 (17:17 +0800)
committerNelson Chu <nelson@rivosinc.com>
Tue, 12 Dec 2023 09:04:23 +0000 (17:04 +0800)
commitdff565fcca8137954d6ad571ef39f6aec5c0429c
tree6a14ffd97a42d3ad207503ee84b1ae732b26b3a7
parente61ea34e74f1c29f320906c11300697d15b1a1c0
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.
gas/config/tc-riscv.c
gas/config/tc-riscv.h
gas/testsuite/gas/riscv/fixup-local-norelax.d [new file with mode: 0644]
gas/testsuite/gas/riscv/fixup-local-relax.d [new file with mode: 0644]
gas/testsuite/gas/riscv/fixup-local.s [new file with mode: 0644]