Skip to content

Commit 1f9e7d5

Browse files
MaskRaygithub-actions[bot]
authored andcommitted
Automerge: 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: llvm/llvm-project#152240
2 parents c652996 + f9b6883 commit 1f9e7d5

File tree

3 files changed

+3
-7
lines changed

3 files changed

+3
-7
lines changed

lld/ELF/Arch/LoongArch.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,9 +1396,6 @@ void LoongArch::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
13961396
// change in section sizes can have cascading effect and require another
13971397
// relaxation pass.
13981398
bool LoongArch::relaxOnce(int pass) const {
1399-
if (ctx.arg.relocatable)
1400-
return false;
1401-
14021399
if (pass == 0)
14031400
initSymbolAnchors(ctx);
14041401

lld/ELF/Arch/RISCV.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -942,9 +942,6 @@ static bool relax(Ctx &ctx, int pass, InputSection &sec) {
942942
// relaxation pass.
943943
bool RISCV::relaxOnce(int pass) const {
944944
llvm::TimeTraceScope timeScope("RISC-V relaxOnce");
945-
if (ctx.arg.relocatable)
946-
return false;
947-
948945
if (pass == 0)
949946
initSymbolAnchors(ctx);
950947

lld/ELF/Writer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1541,8 +1541,10 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
15411541
if (ctx.arg.randomizeSectionPadding)
15421542
randomizeSectionPadding(ctx);
15431543

1544+
// Iterate until a fixed point is reached, skipping relocatable links since
1545+
// the final addresses are unavailable.
15441546
uint32_t pass = 0, assignPasses = 0;
1545-
for (;;) {
1547+
while (!ctx.arg.relocatable) {
15461548
bool changed = ctx.target->needsThunks
15471549
? tc.createThunks(pass, ctx.outputSections)
15481550
: ctx.target->relaxOnce(pass);

0 commit comments

Comments
 (0)