@@ -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
495504void 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