@@ -120,7 +120,7 @@ struct ELFWriter {
120120 } Mode;
121121
122122 uint64_t symbolValue (const MCSymbol &Sym);
123- bool isInSymtab (const MCSymbolELF &Symbol, bool Used, bool Renamed );
123+ bool isInSymtab (const MCSymbolELF &Symbol);
124124
125125 // / Helper struct for containing some precomputed information on symbols.
126126 struct ELFSymbolData {
@@ -468,7 +468,13 @@ void ELFWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
468468 IsReserved);
469469}
470470
471- bool ELFWriter::isInSymtab (const MCSymbolELF &Symbol, bool Used, bool Renamed) {
471+ bool ELFWriter::isInSymtab (const MCSymbolELF &Symbol) {
472+ if (Symbol.isUsedInReloc () || Symbol.isSignature ())
473+ return true ;
474+
475+ if (OWriter.Renames .count (&Symbol))
476+ return false ;
477+
472478 if (Symbol.isVariable ()) {
473479 const MCExpr *Expr = Symbol.getVariableValue ();
474480 // Target Expressions that are always inlined do not appear in the symtab
@@ -478,27 +484,18 @@ bool ELFWriter::isInSymtab(const MCSymbolELF &Symbol, bool Used, bool Renamed) {
478484 // The .weakref alias does not appear in the symtab.
479485 if (Symbol.isWeakref ())
480486 return false ;
481- }
482-
483- if (Used)
484- return true ;
485487
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 ;
488+ if (Symbol.isUndefined ()) {
489+ // FIXME: this is here just to diagnose the case of a var = commmon_sym.
490+ Asm.getBaseSymbol (Symbol);
491+ return false ;
492+ }
493493 }
494494
495495 if (Symbol.isTemporary ())
496496 return false ;
497497
498- if (Symbol.getType () == ELF::STT_SECTION)
499- return false ;
500-
501- return true ;
498+ return Symbol.getType () != ELF::STT_SECTION;
502499}
503500
504501void ELFWriter::computeSymbolTable (const RevGroupMapTy &RevGroupMap) {
@@ -528,10 +525,7 @@ void ELFWriter::computeSymbolTable(const RevGroupMapTy &RevGroupMap) {
528525 bool HasLargeSectionIndex = false ;
529526 for (auto It : llvm::enumerate (Asm.symbols ())) {
530527 const auto &Symbol = cast<MCSymbolELF>(It.value ());
531- bool Used = Symbol.isUsedInReloc ();
532- bool isSignature = Symbol.isSignature ();
533- if (!isInSymtab (Symbol, Used || isSignature,
534- OWriter.Renames .count (&Symbol)))
528+ if (!isInSymtab (Symbol))
535529 continue ;
536530
537531 if (Symbol.isTemporary () && Symbol.isUndefined ()) {
@@ -556,7 +550,7 @@ void ELFWriter::computeSymbolTable(const RevGroupMapTy &RevGroupMap) {
556550 MSD.SectionIndex = ELF::SHN_COMMON;
557551 }
558552 } else if (Symbol.isUndefined ()) {
559- if (isSignature && !Used ) {
553+ if (Symbol. isSignature () && !Symbol. isUsedInReloc () ) {
560554 MSD.SectionIndex = RevGroupMap.lookup (&Symbol);
561555 if (MSD.SectionIndex >= ELF::SHN_LORESERVE)
562556 HasLargeSectionIndex = true ;
0 commit comments