@@ -98,7 +98,6 @@ class ELFObjectWriter : public MCObjectWriter {
98
98
// / The target specific ELF writer instance.
99
99
std::unique_ptr<MCELFObjectTargetWriter> TargetObjectWriter;
100
100
101
- SmallPtrSet<const MCSymbol *, 16 > WeakrefUsedInReloc;
102
101
DenseMap<const MCSymbolELF *, const MCSymbolELF *> Renames;
103
102
104
103
llvm::DenseMap<const MCSectionELF *, std::vector<ELFRelocationEntry>>
@@ -141,7 +140,6 @@ class ELFObjectWriter : public MCObjectWriter {
141
140
: MCObjectWriter(OS, IsLittleEndian), TargetObjectWriter(MOTW) {}
142
141
143
142
void reset () override {
144
- WeakrefUsedInReloc.clear ();
145
143
Renames.clear ();
146
144
Relocations.clear ();
147
145
StrTabBuilder.clear ();
@@ -589,25 +587,6 @@ bool ELFObjectWriter::shouldRelocateWithSymbol(const MCAssembler &Asm,
589
587
return false ;
590
588
}
591
589
592
- static const MCSymbol *getWeakRef (const MCSymbolRefExpr &Ref) {
593
- const MCSymbol &Sym = Ref.getSymbol ();
594
-
595
- if (Ref.getKind () == MCSymbolRefExpr::VK_WEAKREF)
596
- return &Sym;
597
-
598
- if (!Sym.isVariable ())
599
- return nullptr ;
600
-
601
- const MCExpr *Expr = Sym.getVariableValue ();
602
- const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr);
603
- if (!Inner)
604
- return nullptr ;
605
-
606
- if (Inner->getKind () == MCSymbolRefExpr::VK_WEAKREF)
607
- return &Inner->getSymbol ();
608
- return nullptr ;
609
- }
610
-
611
590
// True if the assembler knows nothing about the final value of the symbol.
612
591
// This doesn't cover the comdat issues, since in those cases the assembler
613
592
// can at least know that all symbols in the section will move together.
@@ -681,6 +660,17 @@ void ELFObjectWriter::RecordRelocation(MCAssembler &Asm,
681
660
const MCSymbolRefExpr *RefA = Target.getSymA ();
682
661
const auto *SymA = RefA ? cast<MCSymbolELF>(&RefA->getSymbol ()) : nullptr ;
683
662
663
+ bool ViaWeakRef = false ;
664
+ if (SymA && SymA->isVariable ()) {
665
+ const MCExpr *Expr = SymA->getVariableValue ();
666
+ if (const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr)) {
667
+ if (Inner->getKind () == MCSymbolRefExpr::VK_WEAKREF) {
668
+ SymA = cast<MCSymbolELF>(&Inner->getSymbol ());
669
+ ViaWeakRef = true ;
670
+ }
671
+ }
672
+ }
673
+
684
674
unsigned Type = GetRelocType (Target, Fixup, IsPCRel);
685
675
bool RelocateWithSymbol = shouldRelocateWithSymbol (Asm, RefA, SymA, C, Type);
686
676
if (!RelocateWithSymbol && SymA && !SymA->isUndefined ())
@@ -709,8 +699,8 @@ void ELFObjectWriter::RecordRelocation(MCAssembler &Asm,
709
699
if (const MCSymbolELF *R = Renames.lookup (SymA))
710
700
SymA = R;
711
701
712
- if (const MCSymbol *WeakRef = getWeakRef (*RefA) )
713
- WeakrefUsedInReloc. insert (WeakRef );
702
+ if (ViaWeakRef )
703
+ SymA-> setIsWeakrefUsedInReloc ( );
714
704
else
715
705
SymA->setUsedInReloc ();
716
706
}
@@ -785,7 +775,7 @@ void ELFObjectWriter::computeSymbolTable(
785
775
for (const MCSymbol &S : Asm.symbols ()) {
786
776
const auto &Symbol = cast<MCSymbolELF>(S);
787
777
bool Used = Symbol.isUsedInReloc ();
788
- bool WeakrefUsed = WeakrefUsedInReloc. count (&Symbol );
778
+ bool WeakrefUsed = Symbol. isWeakrefUsedInReloc ( );
789
779
bool isSignature = Symbol.isSignature ();
790
780
791
781
if (!isInSymtab (Layout, Symbol, Used || WeakrefUsed || isSignature,
@@ -809,8 +799,6 @@ void ELFObjectWriter::computeSymbolTable(
809
799
} else {
810
800
MSD.SectionIndex = ELF::SHN_UNDEF;
811
801
}
812
- if (!Used && WeakrefUsed)
813
- Symbol.setBinding (ELF::STB_WEAK);
814
802
} else {
815
803
const MCSectionELF &Section =
816
804
static_cast <const MCSectionELF &>(Symbol.getSection ());
0 commit comments