[lld] f9b6883 - ELF: -r: Call assignAddresses only once
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 7 08:31:31 PDT 2025
Author: Fangrui Song
Date: 2025-08-07T08:31:27-07:00
New Revision: f9b68838f61972fadfbe70787befc3abeb2efcb5
URL: https://github.com/llvm/llvm-project/commit/f9b68838f61972fadfbe70787befc3abeb2efcb5
DIFF: https://github.com/llvm/llvm-project/commit/f9b68838f61972fadfbe70787befc3abeb2efcb5.diff
LOG: ELF: -r: Call assignAddresses only once
The fixed-point layout algorithm handles linker scripts, thunks, and
relaxOnce (to suppress out-of-range GOT-indirect-to-PC-relative
optimization). These passes are not needed for relocatable links because
they require address information that is not yet available.
Since we don't scan relocations for relocatable links, the
`createThunks` and `relaxOnce` functions are no-ops anyway, making these
passes redundant.
To prevent cluttering the line history, I place the `if (...) break;`
inside the for loop.
Pull Request: https://github.com/llvm/llvm-project/pull/152240
Added:
Modified:
lld/ELF/Arch/LoongArch.cpp
lld/ELF/Arch/RISCV.cpp
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Arch/LoongArch.cpp b/lld/ELF/Arch/LoongArch.cpp
index 8802c8c2e7f01..838ca4d242c7b 100644
--- a/lld/ELF/Arch/LoongArch.cpp
+++ b/lld/ELF/Arch/LoongArch.cpp
@@ -1396,9 +1396,6 @@ void LoongArch::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
// change in section sizes can have cascading effect and require another
// relaxation pass.
bool LoongArch::relaxOnce(int pass) const {
- if (ctx.arg.relocatable)
- return false;
-
if (pass == 0)
initSymbolAnchors(ctx);
diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 72d83159ad8ac..ba0584bb1799b 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -942,9 +942,6 @@ static bool relax(Ctx &ctx, int pass, InputSection &sec) {
// relaxation pass.
bool RISCV::relaxOnce(int pass) const {
llvm::TimeTraceScope timeScope("RISC-V relaxOnce");
- if (ctx.arg.relocatable)
- return false;
-
if (pass == 0)
initSymbolAnchors(ctx);
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 2b0e097766d2c..4fa80397cbfa7 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -1541,8 +1541,10 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
if (ctx.arg.randomizeSectionPadding)
randomizeSectionPadding(ctx);
+ // Iterate until a fixed point is reached, skipping relocatable links since
+ // the final addresses are unavailable.
uint32_t pass = 0, assignPasses = 0;
- for (;;) {
+ while (!ctx.arg.relocatable) {
bool changed = ctx.target->needsThunks
? tc.createThunks(pass, ctx.outputSections)
: ctx.target->relaxOnce(pass);
More information about the llvm-commits
mailing list