diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/MC/MCSymbol.cpp | 12 | ||||
-rw-r--r-- | llvm/lib/MC/MachObjectWriter.cpp | 16 | ||||
-rw-r--r-- | llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp | 4 |
3 files changed, 16 insertions, 16 deletions
diff --git a/llvm/lib/MC/MCSymbol.cpp b/llvm/lib/MC/MCSymbol.cpp index 6582574ae94..ccb9f8def9e 100644 --- a/llvm/lib/MC/MCSymbol.cpp +++ b/llvm/lib/MC/MCSymbol.cpp @@ -39,18 +39,6 @@ static bool NameNeedsQuoting(StringRef Str) { return false; } -const MCSymbol &MCSymbol::AliasedSymbol() const { - const MCSymbol *S = this; - while (S->isVariable()) { - const MCExpr *Value = S->getVariableValue(); - if (Value->getKind() != MCExpr::SymbolRef) - return *S; - const MCSymbolRefExpr *Ref = static_cast<const MCSymbolRefExpr*>(Value); - S = &Ref->getSymbol(); - } - return *S; -} - void MCSymbol::setVariableValue(const MCExpr *Value) { assert(!IsUsed && "Cannot set a variable that has already been used."); assert(Value && "Invalid variable value!"); diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp index f04d0edc688..97143a94fb1 100644 --- a/llvm/lib/MC/MachObjectWriter.cpp +++ b/llvm/lib/MC/MachObjectWriter.cpp @@ -321,11 +321,23 @@ MachObjectWriter::findSymbolData(const MCSymbol &Sym) { return nullptr; } +const MCSymbol &MachObjectWriter::findAliasedSymbol(const MCSymbol &Sym) const { + const MCSymbol *S = &Sym; + while (S->isVariable()) { + const MCExpr *Value = S->getVariableValue(); + const auto *Ref = dyn_cast<MCSymbolRefExpr>(Value); + if (!Ref) + return *S; + S = &Ref->getSymbol(); + } + return *S; +} + void MachObjectWriter::WriteNlist(MachSymbolData &MSD, const MCAsmLayout &Layout) { MCSymbolData &Data = *MSD.SymbolData; const MCSymbol *Symbol = &Data.getSymbol(); - const MCSymbol *AliasedSymbol = &Symbol->AliasedSymbol(); + const MCSymbol *AliasedSymbol = &findAliasedSymbol(*Symbol); uint8_t SectionIndex = MSD.SectionIndex; uint8_t Type = 0; uint16_t Flags = Data.getFlags(); @@ -674,7 +686,7 @@ IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, // addr(atom(A)) - addr(atom(B)) == 0. const MCSymbolData *A_Base = nullptr, *B_Base = nullptr; - const MCSymbol &SA = DataA.getSymbol().AliasedSymbol(); + const MCSymbol &SA = findAliasedSymbol(DataA.getSymbol()); const MCSection &SecA = SA.getSection(); const MCSection &SecB = FB.getParent()->getSection(); diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp index 38539cd7bee..b0ddd767459 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp @@ -141,13 +141,13 @@ void X86MachObjectWriter::RecordX86_64Relocation( } else if (Target.getSymB()) { // A - B + constant const MCSymbol *A = &Target.getSymA()->getSymbol(); if (A->isTemporary()) - A = &A->AliasedSymbol(); + A = &Writer->findAliasedSymbol(*A); const MCSymbolData &A_SD = Asm.getSymbolData(*A); const MCSymbolData *A_Base = Asm.getAtom(&A_SD); const MCSymbol *B = &Target.getSymB()->getSymbol(); if (B->isTemporary()) - B = &B->AliasedSymbol(); + B = &Writer->findAliasedSymbol(*B); const MCSymbolData &B_SD = Asm.getSymbolData(*B); const MCSymbolData *B_Base = Asm.getAtom(&B_SD); |