[ELF] Optimize copyLocalSymbols. NFC

This commit is contained in:
Fangrui Song 2021-12-23 00:59:29 -08:00
parent 58ad3428d1
commit 5d0be553fa
1 changed files with 3 additions and 9 deletions

View File

@ -674,9 +674,6 @@ static bool shouldKeepInSymtab(const Defined &sym) {
}
static bool includeInSymtab(const Symbol &b) {
if (!b.isLocal() && !b.isUsedInRegularObj)
return false;
if (auto *d = dyn_cast<Defined>(&b)) {
// Always include absolute symbols.
SectionBase *sec = d->section;
@ -712,11 +709,8 @@ template <class ELFT> void Writer<ELFT>::copyLocalSymbols() {
// No reason to keep local undefined symbol in symtab.
if (!dr)
continue;
if (!includeInSymtab(*b))
continue;
if (!shouldKeepInSymtab(*dr))
continue;
in.symTab->addSymbol(b);
if (includeInSymtab(*b) && shouldKeepInSymtab(*dr))
in.symTab->addSymbol(b);
}
}
}
@ -1985,7 +1979,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
// Now that we have defined all possible global symbols including linker-
// synthesized ones. Visit all symbols to give the finishing touches.
for (Symbol *sym : symtab->symbols()) {
if (!includeInSymtab(*sym))
if (!sym->isUsedInRegularObj || !includeInSymtab(*sym))
continue;
if (in.symTab)
in.symTab->addSymbol(sym);