Skip to content

Commit fc5d815

Browse files
committed
[ELF] Merge demoteSymbols and isPreemptible computation. NFC
Remove one iteration of symtab and slightly improve the performance.
1 parent 3472d4d commit fc5d815

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

lld/ELF/Writer.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -255,16 +255,19 @@ void elf::addReservedSymbols() {
255255
// DT_NEEDED. If that happens, replace ShardSymbol with Undefined to avoid
256256
// dangling references to an unneeded DSO. Use a weak binding to avoid
257257
// --no-allow-shlib-undefined diagnostics. Similarly, demote lazy symbols.
258-
static void demoteSymbols() {
258+
static void demoteSymbolsAndComputeIsPreemptible() {
259259
llvm::TimeTraceScope timeScope("Demote symbols");
260260
for (Symbol *sym : symtab.getSymbols()) {
261261
auto *s = dyn_cast<SharedSymbol>(sym);
262-
if (!(s && !cast<SharedFile>(s->file)->isNeeded) && !sym->isLazy())
263-
continue;
264-
uint8_t binding = sym->isLazy() ? sym->binding : uint8_t(STB_WEAK);
265-
Undefined(nullptr, sym->getName(), binding, sym->stOther, sym->type)
266-
.overwrite(*sym);
267-
sym->versionId = VER_NDX_GLOBAL;
262+
if (sym->isLazy() || (s && !cast<SharedFile>(s->file)->isNeeded)) {
263+
uint8_t binding = sym->isLazy() ? sym->binding : uint8_t(STB_WEAK);
264+
Undefined(nullptr, sym->getName(), binding, sym->stOther, sym->type)
265+
.overwrite(*sym);
266+
sym->versionId = VER_NDX_GLOBAL;
267+
}
268+
269+
if (config->hasDynSymTab)
270+
sym->isPreemptible = computeIsPreemptible(*sym);
268271
}
269272
}
270273

@@ -1954,12 +1957,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
19541957
}
19551958
}
19561959

1957-
demoteSymbols();
1958-
if (config->hasDynSymTab) {
1959-
parallelForEach(symtab.getSymbols(), [](Symbol *sym) {
1960-
sym->isPreemptible = computeIsPreemptible(*sym);
1961-
});
1962-
}
1960+
demoteSymbolsAndComputeIsPreemptible();
19631961

19641962
// Change values of linker-script-defined symbols from placeholders (assigned
19651963
// by declareSymbols) to actual definitions.

0 commit comments

Comments
 (0)