Skip to content

Commit e9262ed

Browse files
committed
[ELF] SymbolTable::symbols: don't filter out PlaceholderKind
Placeholders (-y and redirectSymbols removed versioned symbols) are very rare and the check just makes symbol table iteration slower. Most iterations filter out placeholders anyway, so this change just drops the filter behavior. For "Add symbols to symtabs", we need to ensure that redirectSymbols sets isUsedInRegularObj to false when making a symbol placeholder, to avoid an assertion failure in SymbolTableSection<ELFT>::writeTo. My .text is 2KiB smaller. The speed-up linking chrome is 0.x%.
1 parent 70a9800 commit e9262ed

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed

Diff for: lld/ELF/Driver.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1724,7 +1724,7 @@ static void handleUndefinedGlob(StringRef arg) {
17241724
// symbols to the symbol table, invalidating the current iterator.
17251725
std::vector<Symbol *> syms;
17261726
for (Symbol *sym : symtab->symbols())
1727-
if (pat->match(sym->getName()))
1727+
if (!sym->isPlaceholder() && pat->match(sym->getName()))
17281728
syms.push_back(sym);
17291729

17301730
for (Symbol *sym : syms)
@@ -2106,6 +2106,7 @@ static void redirectSymbols(ArrayRef<WrappedSymbol> wrapped) {
21062106
sym2->resolve(*sym);
21072107
// Eliminate foo@v1 from the symbol table.
21082108
sym->symbolKind = Symbol::PlaceholderKind;
2109+
sym->isUsedInRegularObj = false;
21092110
} else if (auto *sym1 = dyn_cast<Defined>(sym)) {
21102111
if (sym2->versionId > VER_NDX_GLOBAL
21112112
? config->versionDefinitions[sym2->versionId].name == suffix1 + 1
@@ -2118,6 +2119,7 @@ static void redirectSymbols(ArrayRef<WrappedSymbol> wrapped) {
21182119
// defined in the same place.
21192120
map.try_emplace(sym2, sym);
21202121
sym2->symbolKind = Symbol::PlaceholderKind;
2122+
sym2->isUsedInRegularObj = false;
21212123
}
21222124
}
21232125
}

Diff for: lld/ELF/LTO.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ BitcodeCompiler::BitcodeCompiler() {
207207
if (bitcodeFiles.empty())
208208
return;
209209
for (Symbol *sym : symtab->symbols()) {
210+
if (sym->isPlaceholder())
211+
continue;
210212
StringRef s = sym->getName();
211213
for (StringRef prefix : {"__start_", "__stop_"})
212214
if (s.startswith(prefix))

Diff for: lld/ELF/SymbolTable.h

+1-10
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,8 @@ namespace elf {
3232
// add*() functions, which are called by input files as they are parsed. There
3333
// is one add* function per symbol type.
3434
class SymbolTable {
35-
struct FilterOutPlaceholder {
36-
bool operator()(Symbol *S) const { return !S->isPlaceholder(); }
37-
};
38-
using iterator =
39-
llvm::filter_iterator<SmallVector<Symbol *, 0>::const_iterator,
40-
FilterOutPlaceholder>;
41-
4235
public:
43-
llvm::iterator_range<iterator> symbols() const {
44-
return llvm::make_filter_range(symVector, FilterOutPlaceholder());
45-
}
36+
ArrayRef<Symbol *> symbols() const { return symVector; }
4637

4738
void wrap(Symbol *sym, Symbol *real, Symbol *wrap);
4839

Diff for: lld/ELF/Symbols.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ void elf::maybeWarnUnorderableSymbol(const Symbol *sym) {
355355
// Returns true if a symbol can be replaced at load-time by a symbol
356356
// with the same name defined in other ELF executable or DSO.
357357
bool elf::computeIsPreemptible(const Symbol &sym) {
358-
assert(!sym.isLocal());
358+
assert(!sym.isLocal() || sym.isPlaceholder());
359359

360360
// Only symbols with default visibility that appear in dynsym can be
361361
// preempted. Symbols with protected visibility cannot be preempted.

0 commit comments

Comments
 (0)