[all-commits] [llvm/llvm-project] c5ba61: [BOLT][RISCV] Add support for linker relaxation
Job Noorman via All-commits
all-commits at lists.llvm.org
Fri Sep 15 02:57:45 PDT 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: c5ba61978c3364b31c00130561285c28306655b7
https://github.com/llvm/llvm-project/commit/c5ba61978c3364b31c00130561285c28306655b7
Author: Job Noorman <jnoorman at igalia.com>
Date: 2023-09-15 (Fri, 15 Sep 2023)
Changed paths:
M bolt/include/bolt/Core/MCPlusBuilder.h
M bolt/include/bolt/Passes/FixRISCVCallsPass.h
M bolt/lib/Core/BinaryContext.cpp
M bolt/lib/Passes/FixRISCVCallsPass.cpp
M bolt/lib/Rewrite/JITLinkLinker.cpp
M bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp
M bolt/test/RISCV/internal-func-reloc.s
M bolt/test/RISCV/lit.local.cfg
A bolt/test/RISCV/relax.s
M bolt/test/RISCV/reloc-call.s
Log Message:
-----------
[BOLT][RISCV] Add support for linker relaxation
Calls on RISC-V are typically compiled to `auipc`/`jalr` pairs to allow
a maximum target range (32-bit pc-relative). In order to optimize calls
to near targets, linker relaxation may replace those pairs with, for
example, single `jal` instructions.
To allow BOLT to freely reassign function addresses in relaxed binaries,
this patch proposes the following approach:
- Expand all relaxed calls back to `auipc`/`jalr`;
- Rely on JITLink to relax those back to shorter forms where possible.
This is implemented by detecting all possible call instructions and
replacing them with `PseudoCALL` (or `PseudoTAIL`) instructions. The
RISC-V backend then expands those and adds the necessary relocations for
relaxation.
Since BOLT generally ignores pseudo instruction, this patch makes
`MCPlusBuilder::isPseudo` virtual so that `RISCVMCPlusBuilder` can
override it to exclude `PseudoCALL` and `PseudoTAIL`.
To ensure JITLink knows about the correct section addresses while
relaxing, reassignment of addresses has been moved to a post-allocation
pass. Note that this is probably the time it had to be done in the
first place since in `notifyResolved` (where it was done before), all
symbols are supposed to be resolved already.
Depends on D159082
Reviewed By: maksfb
Differential Revision: https://reviews.llvm.org/D159089
More information about the All-commits
mailing list