Skip to content

Commit 9262ac3

Browse files
committed
Revert "ELFObjectWriter: Optimize isInSymtab"
This reverts commit 1108cf6. Caused a regression for a weird but interesting case (STT_SECTION symbol as group signature). We no longer define `sec` ``` .section sec,"ax" .section .foo,"axG",@progbits,sec nop ``` Fix #146581
1 parent eac1a1d commit 9262ac3

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

llvm/lib/MC/ELFObjectWriter.cpp

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

122122
uint64_t symbolValue(const MCSymbol &Sym);
123-
bool isInSymtab(const MCSymbolELF &Symbol);
123+
bool isInSymtab(const MCSymbolELF &Symbol, bool Used, bool Renamed);
124124

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

471-
bool ELFWriter::isInSymtab(const MCSymbolELF &Symbol) {
471+
bool ELFWriter::isInSymtab(const MCSymbolELF &Symbol, bool Used, bool Renamed) {
472472
if (Symbol.isVariable()) {
473473
const MCExpr *Expr = Symbol.getVariableValue();
474474
// Target Expressions that are always inlined do not appear in the symtab
@@ -478,18 +478,27 @@ bool ELFWriter::isInSymtab(const MCSymbolELF &Symbol) {
478478
// The .weakref alias does not appear in the symtab.
479479
if (Symbol.isWeakref())
480480
return false;
481+
}
481482

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

489495
if (Symbol.isTemporary())
490496
return false;
491497

492-
return Symbol.getType() != ELF::STT_SECTION;
498+
if (Symbol.getType() == ELF::STT_SECTION)
499+
return false;
500+
501+
return true;
493502
}
494503

495504
void ELFWriter::computeSymbolTable(const RevGroupMapTy &RevGroupMap) {
@@ -521,7 +530,8 @@ void ELFWriter::computeSymbolTable(const RevGroupMapTy &RevGroupMap) {
521530
const auto &Symbol = cast<MCSymbolELF>(It.value());
522531
bool Used = Symbol.isUsedInReloc();
523532
bool isSignature = Symbol.isSignature();
524-
if (!(Used || (!OWriter.Renames.count(&Symbol) && isInSymtab(Symbol))))
533+
if (!isInSymtab(Symbol, Used || isSignature,
534+
OWriter.Renames.count(&Symbol)))
525535
continue;
526536

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

0 commit comments

Comments
 (0)