Skip to content

Commit 1108cf6

Browse files
committed
ELFObjectWriter: Optimize isInSymtab
1 parent 3cc78a8 commit 1108cf6

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ struct ELFWriter {
121121
} Mode;
122122

123123
uint64_t symbolValue(const MCSymbol &Sym);
124-
bool isInSymtab(const MCSymbolELF &Symbol, bool Used, bool Renamed);
124+
bool isInSymtab(const MCSymbolELF &Symbol);
125125

126126
/// Helper struct for containing some precomputed information on symbols.
127127
struct ELFSymbolData {
@@ -469,7 +469,7 @@ void ELFWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
469469
IsReserved);
470470
}
471471

472-
bool ELFWriter::isInSymtab(const MCSymbolELF &Symbol, bool Used, bool Renamed) {
472+
bool ELFWriter::isInSymtab(const MCSymbolELF &Symbol) {
473473
if (Symbol.isVariable()) {
474474
const MCExpr *Expr = Symbol.getVariableValue();
475475
// Target Expressions that are always inlined do not appear in the symtab
@@ -479,27 +479,18 @@ bool ELFWriter::isInSymtab(const MCSymbolELF &Symbol, bool Used, bool Renamed) {
479479
// The .weakref alias does not appear in the symtab.
480480
if (Symbol.isWeakref())
481481
return false;
482-
}
483-
484-
if (Used)
485-
return true;
486482

487-
if (Renamed)
488-
return false;
489-
490-
if (Symbol.isVariable() && Symbol.isUndefined()) {
491-
// FIXME: this is here just to diagnose the case of a var = commmon_sym.
492-
Asm.getBaseSymbol(Symbol);
493-
return false;
483+
if (Symbol.isUndefined()) {
484+
// FIXME: this is here just to diagnose the case of a var = commmon_sym.
485+
Asm.getBaseSymbol(Symbol);
486+
return false;
487+
}
494488
}
495489

496490
if (Symbol.isTemporary())
497491
return false;
498492

499-
if (Symbol.getType() == ELF::STT_SECTION)
500-
return false;
501-
502-
return true;
493+
return Symbol.getType() != ELF::STT_SECTION;
503494
}
504495

505496
void ELFWriter::computeSymbolTable(const RevGroupMapTy &RevGroupMap) {
@@ -531,8 +522,7 @@ void ELFWriter::computeSymbolTable(const RevGroupMapTy &RevGroupMap) {
531522
const auto &Symbol = cast<MCSymbolELF>(It.value());
532523
bool Used = Symbol.isUsedInReloc();
533524
bool isSignature = Symbol.isSignature();
534-
if (!isInSymtab(Symbol, Used || isSignature,
535-
OWriter.Renames.count(&Symbol)))
525+
if (!(Used || (!OWriter.Renames.count(&Symbol) && isInSymtab(Symbol))))
536526
continue;
537527

538528
if (Symbol.isTemporary() && Symbol.isUndefined()) {

0 commit comments

Comments
 (0)