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 void Writer::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);