Skip to content

Commit 085f7fb

Browse files
committed
[ELF] Remove redundant isExported computation
Commit 2a26292 made `isExported` accurate except a few linker-synthesized symbols in finalizeSections. We can collect these linker-synthesized symbols into a vector and avoid recomputation for other symbols. This is reland of 1a4d6de after `isExported` has been made accurate by f10441a
1 parent 5e43dd5 commit 085f7fb

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lld/ELF/Config.h

+1
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ struct Ctx : CommonLinkerContext {
619619
};
620620
ElfSym sym{};
621621
std::unique_ptr<SymbolTable> symtab;
622+
SmallVector<Symbol *, 0> synthesizedSymbols;
622623

623624
SmallVector<std::unique_ptr<MemoryBuffer>> memoryBuffers;
624625
SmallVector<ELFFileBase *, 0> objectFiles;

lld/ELF/Writer.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ static Defined *addOptionalRegular(Ctx &ctx, StringRef name, SectionBase *sec,
149149
if (!s || s->isDefined() || s->isCommon())
150150
return nullptr;
151151

152+
ctx.synthesizedSymbols.push_back(s);
152153
s->resolve(ctx, Defined{ctx, ctx.internalFile, StringRef(), STB_GLOBAL,
153154
stOther, STT_NOTYPE, val,
154155
/*size=*/0, sec});
@@ -295,13 +296,13 @@ static void demoteSymbolsAndComputeIsPreemptible(Ctx &ctx) {
295296
sym->type)
296297
.overwrite(*sym);
297298
sym->versionId = VER_NDX_GLOBAL;
299+
if (hasDynsym && sym->includeInDynsym(ctx))
300+
sym->isExported = true;
298301
}
299302
}
300303

301-
if (hasDynsym) {
302-
sym->isExported = sym->includeInDynsym(ctx);
304+
if (hasDynsym)
303305
sym->isPreemptible = sym->isExported && computeIsPreemptible(ctx, *sym);
304-
}
305306
}
306307
}
307308

@@ -1838,6 +1839,12 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
18381839
}
18391840
}
18401841

1842+
// If the previous code block defines any non-hidden symbols (e.g.
1843+
// __global_pointer$), they may be exported.
1844+
if (ctx.hasDynsym)
1845+
for (Symbol *sym : ctx.synthesizedSymbols)
1846+
sym->isExported = sym->includeInDynsym(ctx);
1847+
18411848
demoteSymbolsAndComputeIsPreemptible(ctx);
18421849

18431850
if (ctx.arg.copyRelocs && ctx.arg.discard != DiscardPolicy::None)

0 commit comments

Comments
 (0)