@@ -120,7 +120,7 @@ struct ELFWriter {
120
120
} Mode;
121
121
122
122
uint64_t symbolValue (const MCSymbol &Sym);
123
- bool isInSymtab (const MCSymbolELF &Symbol);
123
+ bool isInSymtab (const MCSymbolELF &Symbol, bool Used, bool Renamed );
124
124
125
125
// / Helper struct for containing some precomputed information on symbols.
126
126
struct ELFSymbolData {
@@ -468,7 +468,7 @@ void ELFWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
468
468
IsReserved);
469
469
}
470
470
471
- bool ELFWriter::isInSymtab (const MCSymbolELF &Symbol) {
471
+ bool ELFWriter::isInSymtab (const MCSymbolELF &Symbol, bool Used, bool Renamed ) {
472
472
if (Symbol.isVariable ()) {
473
473
const MCExpr *Expr = Symbol.getVariableValue ();
474
474
// Target Expressions that are always inlined do not appear in the symtab
@@ -478,18 +478,27 @@ bool ELFWriter::isInSymtab(const MCSymbolELF &Symbol) {
478
478
// The .weakref alias does not appear in the symtab.
479
479
if (Symbol.isWeakref ())
480
480
return false ;
481
+ }
481
482
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 ;
487
493
}
488
494
489
495
if (Symbol.isTemporary ())
490
496
return false ;
491
497
492
- return Symbol.getType () != ELF::STT_SECTION;
498
+ if (Symbol.getType () == ELF::STT_SECTION)
499
+ return false ;
500
+
501
+ return true ;
493
502
}
494
503
495
504
void ELFWriter::computeSymbolTable (const RevGroupMapTy &RevGroupMap) {
@@ -521,7 +530,8 @@ void ELFWriter::computeSymbolTable(const RevGroupMapTy &RevGroupMap) {
521
530
const auto &Symbol = cast<MCSymbolELF>(It.value ());
522
531
bool Used = Symbol.isUsedInReloc ();
523
532
bool isSignature = Symbol.isSignature ();
524
- if (!(Used || (!OWriter.Renames .count (&Symbol) && isInSymtab (Symbol))))
533
+ if (!isInSymtab (Symbol, Used || isSignature,
534
+ OWriter.Renames .count (&Symbol)))
525
535
continue ;
526
536
527
537
if (Symbol.isTemporary () && Symbol.isUndefined ()) {
0 commit comments