From cfac75ad0edabdc2a337eb9dcba82dbc31b73d58 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 29 May 2015 21:45:01 +0000 Subject: [PATCH] Remove getData. This completes the mechanical part of merging MCSymbol and MCSymbolData. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238617 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCSymbol.h | 2 -- lib/MC/ELFObjectWriter.cpp | 34 +++++++------------ lib/MC/MCAssembler.cpp | 12 +++---- lib/MC/MCELFStreamer.cpp | 17 ++++------ lib/MC/MCExpr.cpp | 9 ++--- lib/MC/MCMachOStreamer.cpp | 23 +++++-------- lib/MC/MCObjectStreamer.cpp | 14 +++----- lib/MC/MCObjectWriter.cpp | 6 ++-- lib/MC/MachObjectWriter.cpp | 19 ++++------- lib/MC/WinCOFFObjectWriter.cpp | 28 ++++++--------- lib/MC/WinCOFFStreamer.cpp | 13 +++---- .../MCTargetDesc/AArch64ELFStreamer.cpp | 3 +- .../MCTargetDesc/AArch64MachObjectWriter.cpp | 16 ++++----- lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp | 3 +- .../ARM/MCTargetDesc/ARMELFStreamer.cpp | 3 +- .../ARM/MCTargetDesc/ARMMachObjectWriter.cpp | 24 ++++++------- .../MCTargetDesc/PPCMachObjectWriter.cpp | 12 +++---- .../X86/MCTargetDesc/X86MachObjectWriter.cpp | 25 ++++++-------- 18 files changed, 99 insertions(+), 164 deletions(-) diff --git a/include/llvm/MC/MCSymbol.h b/include/llvm/MC/MCSymbol.h index 7db5bade8e2..b9bb7c3d659 100644 --- a/include/llvm/MC/MCSymbol.h +++ b/include/llvm/MC/MCSymbol.h @@ -117,8 +117,6 @@ public: bool hasData() const { return HasData; } - MCSymbol &getData() const { return *const_cast(this); } - /// Initialize symbol data. /// /// Nothing really to do here, but this is enables an assertion that \a diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index a96e7a272ac..50b848aec27 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -359,8 +359,7 @@ void ELFObjectWriter::writeHeader(const MCAssembler &Asm) { uint64_t ELFObjectWriter::SymbolValue(const MCSymbol &Sym, const MCAsmLayout &Layout) { - MCSymbol &Data = Sym.getData(); - if (Sym.isCommon() && Data.isExternal()) + if (Sym.isCommon() && Sym.isExternal()) return Sym.getCommonAlignment(); uint64_t Res; @@ -379,8 +378,6 @@ void ELFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm, // versions declared with @@@ to be renamed. for (const MCSymbol &Alias : Asm.symbols()) { - MCSymbol &OriginalData = Alias.getData(); - // Not an alias. if (!Alias.isVariable()) continue; @@ -388,7 +385,6 @@ void ELFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm, if (!Ref) continue; const MCSymbol &Symbol = Ref->getSymbol(); - MCSymbol &SD = Symbol.getData(); StringRef AliasName = Alias.getName(); size_t Pos = AliasName.find('@'); @@ -397,7 +393,7 @@ void ELFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm, // Aliases defined with .symvar copy the binding from the symbol they alias. // This is the first place we are able to copy this information. - OriginalData.setExternal(SD.isExternal()); + Alias.setExternal(Symbol.isExternal()); MCELF::SetBinding(Alias, MCELF::GetBinding(Symbol)); StringRef Rest = AliasName.substr(Pos); @@ -451,33 +447,28 @@ static uint8_t mergeTypeForSet(uint8_t origType, uint8_t newType) { void ELFObjectWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex, ELFSymbolData &MSD, const MCAsmLayout &Layout) { -#ifndef NDEBUG - MCSymbol &OrigData = MSD.Symbol->getData(); - assert((!OrigData.getFragment() || - (OrigData.getFragment()->getParent() == &MSD.Symbol->getSection())) && + const MCSymbol &Symbol = *MSD.Symbol; + assert((!Symbol.getFragment() || + (Symbol.getFragment()->getParent() == &Symbol.getSection())) && "The symbol's section doesn't match the fragment's symbol"); -#endif - const MCSymbol *Base = Layout.getBaseSymbol(*MSD.Symbol); + const MCSymbol *Base = Layout.getBaseSymbol(Symbol); // This has to be in sync with when computeSymbolTable uses SHN_ABS or // SHN_COMMON. - bool IsReserved = !Base || MSD.Symbol->isCommon(); + bool IsReserved = !Base || Symbol.isCommon(); // Binding and Type share the same byte as upper and lower nibbles - uint8_t Binding = MCELF::GetBinding(*MSD.Symbol); - uint8_t Type = MCELF::GetType(*MSD.Symbol); - MCSymbol *BaseSD = nullptr; + uint8_t Binding = MCELF::GetBinding(Symbol); + uint8_t Type = MCELF::GetType(Symbol); if (Base) { - BaseSD = &Base->getData(); Type = mergeTypeForSet(Type, MCELF::GetType(*Base)); } uint8_t Info = (Binding << ELF_STB_Shift) | (Type << ELF_STT_Shift); // Other and Visibility share the same byte with Visibility using the lower // 2 bits - uint8_t Visibility = MCELF::GetVisibility(*MSD.Symbol); - uint8_t Other = MCELF::getOther(*MSD.Symbol) - << (ELF_STO_Shift - ELF_STV_Shift); + uint8_t Visibility = MCELF::GetVisibility(Symbol); + uint8_t Other = MCELF::getOther(Symbol) << (ELF_STO_Shift - ELF_STV_Shift); Other |= Visibility; uint64_t Value = SymbolValue(*MSD.Symbol, Layout); @@ -769,8 +760,7 @@ bool ELFObjectWriter::isInSymtab(const MCAsmLayout &Layout, bool ELFObjectWriter::isLocal(const MCSymbol &Symbol, bool IsUsedInReloc, bool IsSignature) { - const MCSymbol &Data = Symbol.getData(); - if (Data.isExternal()) + if (Symbol.isExternal()) return false; if (Symbol.isDefined()) diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 208c06ce4f9..e9e903ed12a 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -120,14 +120,13 @@ uint64_t MCAsmLayout::getFragmentOffset(const MCFragment *F) const { // Simple getSymbolOffset helper for the non-varibale case. static bool getLabelOffset(const MCAsmLayout &Layout, const MCSymbol &S, bool ReportError, uint64_t &Val) { - const MCSymbol &SD = S.getData(); - if (!SD.getFragment()) { + if (!S.getFragment()) { if (ReportError) report_fatal_error("unable to evaluate offset to undefined symbol '" + S.getName() + "'"); return false; } - Val = Layout.getFragmentOffset(SD.getFragment()) + S.getOffset(); + Val = Layout.getFragmentOffset(S.getFragment()) + S.getOffset(); return true; } @@ -377,17 +376,17 @@ const MCSymbol *MCAssembler::getAtom(const MCSymbol &S) const { return &S; // Absolute and undefined symbols have no defining atom. - if (!S.getData().getFragment()) + if (!S.getFragment()) return nullptr; // Non-linker visible symbols in sections which can't be atomized have no // defining atom. if (!getContext().getAsmInfo()->isSectionAtomizableBySymbols( - *S.getData().getFragment()->getParent())) + *S.getFragment()->getParent())) return nullptr; // Otherwise, return the atom for the containing fragment. - return S.getData().getFragment()->getAtom(); + return S.getFragment()->getAtom(); } bool MCAssembler::evaluateFixup(const MCAsmLayout &Layout, @@ -1200,7 +1199,6 @@ void MCAssembler::dump() { OS << "("; it->dump(); OS << ", Index:" << it->getIndex() << ", "; - it->getData().dump(); OS << ")"; } OS << "]>\n"; diff --git a/lib/MC/MCELFStreamer.cpp b/lib/MC/MCELFStreamer.cpp index c1d12c6c37d..efb3dde2428 100644 --- a/lib/MC/MCELFStreamer.cpp +++ b/lib/MC/MCELFStreamer.cpp @@ -214,7 +214,6 @@ bool MCELFStreamer::EmitSymbolAttribute(MCSymbol *Symbol, // important side effect of calling registerSymbol here is to register // the symbol with the assembler. getAssembler().registerSymbol(*Symbol); - MCSymbol &SD = Symbol->getData(); // The implementation of symbol attributes is designed to match 'as', but it // leaves much to desired. It doesn't really make sense to arbitrarily add and @@ -241,26 +240,26 @@ bool MCELFStreamer::EmitSymbolAttribute(MCSymbol *Symbol, MCELF::SetType( *Symbol, CombineSymbolTypes(MCELF::GetType(*Symbol), ELF::STT_OBJECT)); MCELF::SetBinding(*Symbol, ELF::STB_GNU_UNIQUE); - SD.setExternal(true); + Symbol->setExternal(true); BindingExplicitlySet.insert(Symbol); break; case MCSA_Global: MCELF::SetBinding(*Symbol, ELF::STB_GLOBAL); - SD.setExternal(true); + Symbol->setExternal(true); BindingExplicitlySet.insert(Symbol); break; case MCSA_WeakReference: case MCSA_Weak: MCELF::SetBinding(*Symbol, ELF::STB_WEAK); - SD.setExternal(true); + Symbol->setExternal(true); BindingExplicitlySet.insert(Symbol); break; case MCSA_Local: MCELF::SetBinding(*Symbol, ELF::STB_LOCAL); - SD.setExternal(false); + Symbol->setExternal(false); BindingExplicitlySet.insert(Symbol); break; @@ -314,11 +313,10 @@ bool MCELFStreamer::EmitSymbolAttribute(MCSymbol *Symbol, void MCELFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) { getAssembler().registerSymbol(*Symbol); - MCSymbol &SD = Symbol->getData(); if (!BindingExplicitlySet.count(Symbol)) { MCELF::SetBinding(*Symbol, ELF::STB_GLOBAL); - SD.setExternal(true); + Symbol->setExternal(true); } MCELF::SetType(*Symbol, ELF::STT_OBJECT); @@ -346,9 +344,8 @@ void MCELFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) { // FIXME: Should this be caught and done earlier? getAssembler().registerSymbol(*Symbol); - MCSymbol &SD = Symbol->getData(); MCELF::SetBinding(*Symbol, ELF::STB_LOCAL); - SD.setExternal(false); + Symbol->setExternal(false); BindingExplicitlySet.insert(Symbol); EmitCommonSymbol(Symbol, Size, ByteAlignment); } @@ -648,7 +645,7 @@ void MCELFStreamer::Flush() { new MCAlignFragment(ByteAlignment, 0, 1, ByteAlignment, &Section); MCFragment *F = new MCFillFragment(0, 0, Size, &Section); - Symbol.getData().setFragment(F); + Symbol.setFragment(F); // Update the maximum alignment of the section if necessary. if (ByteAlignment > Section.getAlignment()) diff --git a/lib/MC/MCExpr.cpp b/lib/MC/MCExpr.cpp index b850971e691..d784f9a405a 100644 --- a/lib/MC/MCExpr.cpp +++ b/lib/MC/MCExpr.cpp @@ -471,10 +471,7 @@ static void AttemptToFoldSymbolOffsetDifference( if (!Asm->getWriter().IsSymbolRefDifferenceFullyResolved(*Asm, A, B, InSet)) return; - const MCSymbol &AD = SA.getData(); - const MCSymbol &BD = SB.getData(); - - if (AD.getFragment() == BD.getFragment()) { + if (SA.getFragment() == SB.getFragment()) { Addend += (SA.getOffset() - SB.getOffset()); // Pointers to Thumb symbols need to have their low-bit set to allow @@ -491,8 +488,8 @@ static void AttemptToFoldSymbolOffsetDifference( if (!Layout) return; - const MCSection &SecA = *AD.getFragment()->getParent(); - const MCSection &SecB = *BD.getFragment()->getParent(); + const MCSection &SecA = *SA.getFragment()->getParent(); + const MCSection &SecB = *SB.getFragment()->getParent(); if ((&SecA != &SecB) && !Addrs) return; diff --git a/lib/MC/MCMachOStreamer.cpp b/lib/MC/MCMachOStreamer.cpp index a84bf7e86cb..74ec6a8fe26 100644 --- a/lib/MC/MCMachOStreamer.cpp +++ b/lib/MC/MCMachOStreamer.cpp @@ -173,12 +173,11 @@ void MCMachOStreamer::ChangeSection(MCSection *Section, void MCMachOStreamer::EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol) { getAssembler().registerSymbol(*Symbol); - MCSymbol &SD = Symbol->getData(); - if (SD.isExternal()) + if (Symbol->isExternal()) EmitSymbolAttribute(EHSymbol, MCSA_Global); if (Symbol->getFlags() & SF_WeakDefinition) EmitSymbolAttribute(EHSymbol, MCSA_WeakDefinition); - if (SD.isPrivateExtern()) + if (Symbol->isPrivateExtern()) EmitSymbolAttribute(EHSymbol, MCSA_PrivateExtern); } @@ -296,7 +295,6 @@ bool MCMachOStreamer::EmitSymbolAttribute(MCSymbol *Symbol, // important side effect of calling registerSymbol here is to register // the symbol with the assembler. getAssembler().registerSymbol(*Symbol); - MCSymbol &SD = Symbol->getData(); // The implementation of symbol attributes is designed to match 'as', but it // leaves much to desired. It doesn't really make sense to arbitrarily add and @@ -322,7 +320,7 @@ bool MCMachOStreamer::EmitSymbolAttribute(MCSymbol *Symbol, return false; case MCSA_Global: - SD.setExternal(true); + Symbol->setExternal(true); // This effectively clears the undefined lazy bit, in Darwin 'as', although // it isn't very consistent because it implements this as part of symbol // lookup. @@ -351,8 +349,8 @@ bool MCMachOStreamer::EmitSymbolAttribute(MCSymbol *Symbol, break; case MCSA_PrivateExtern: - SD.setExternal(true); - SD.setPrivateExtern(true); + Symbol->setExternal(true); + Symbol->setPrivateExtern(true); break; case MCSA_WeakReference: @@ -391,8 +389,7 @@ void MCMachOStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, AssignSection(Symbol, nullptr); getAssembler().registerSymbol(*Symbol); - MCSymbol &SD = Symbol->getData(); - SD.setExternal(true); + Symbol->setExternal(true); Symbol->setCommon(Size, ByteAlignment); } @@ -417,14 +414,13 @@ void MCMachOStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol, assert(Symbol->isUndefined() && "Cannot define a symbol twice!"); getAssembler().registerSymbol(*Symbol); - MCSymbol &SD = Symbol->getData(); // Emit an align fragment if necessary. if (ByteAlignment != 1) new MCAlignFragment(ByteAlignment, 0, 0, ByteAlignment, Section); MCFragment *F = new MCFillFragment(0, 0, Size, Section); - SD.setFragment(F); + Symbol->setFragment(F); AssignSection(Symbol, Section); @@ -469,12 +465,11 @@ void MCMachOStreamer::FinishImpl() { // defining symbols. DenseMap DefiningSymbolMap; for (const MCSymbol &Symbol : getAssembler().symbols()) { - MCSymbol &SD = Symbol.getData(); - if (getAssembler().isSymbolLinkerVisible(Symbol) && SD.getFragment()) { + if (getAssembler().isSymbolLinkerVisible(Symbol) && Symbol.getFragment()) { // An atom defining symbol should never be internal to a fragment. assert(Symbol.getOffset() == 0 && "Invalid offset in atom defining symbol!"); - DefiningSymbolMap[SD.getFragment()] = &Symbol; + DefiningSymbolMap[Symbol.getFragment()] = &Symbol; } } diff --git a/lib/MC/MCObjectStreamer.cpp b/lib/MC/MCObjectStreamer.cpp index e61b9ddc803..b82ea9dd4d6 100644 --- a/lib/MC/MCObjectStreamer.cpp +++ b/lib/MC/MCObjectStreamer.cpp @@ -47,8 +47,7 @@ void MCObjectStreamer::flushPendingLabels(MCFragment *F, uint64_t FOffset) { F->setParent(CurSection); } for (MCSymbol *Sym : PendingLabels) { - MCSymbol *SD = &Sym->getData(); - SD->setFragment(F); + Sym->setFragment(F); Sym->setOffset(FOffset); } PendingLabels.clear(); @@ -61,15 +60,13 @@ bool MCObjectStreamer::emitAbsoluteSymbolDiff(const MCSymbol *Hi, // Must have symbol data. if (!Assembler->hasSymbolData(*Hi) || !Assembler->hasSymbolData(*Lo)) return false; - auto &HiD = Hi->getData(); - auto &LoD = Lo->getData(); // Must both be assigned to the same (valid) fragment. - if (!HiD.getFragment() || HiD.getFragment() != LoD.getFragment()) + if (!Hi->getFragment() || Hi->getFragment() != Lo->getFragment()) return false; // Must be a data fragment. - if (!isa(HiD.getFragment())) + if (!isa(Hi->getFragment())) return false; assert(Hi->getOffset() >= Lo->getOffset() && @@ -164,8 +161,7 @@ void MCObjectStreamer::EmitLabel(MCSymbol *Symbol) { MCStreamer::EmitLabel(Symbol); getAssembler().registerSymbol(*Symbol); - MCSymbol &SD = Symbol->getData(); - assert(!SD.getFragment() && "Unexpected fragment on symbol data!"); + assert(!Symbol->getFragment() && "Unexpected fragment on symbol data!"); // If there is a current fragment, mark the symbol as pointing into it. // Otherwise queue the label and set its fragment pointer when we emit the @@ -173,7 +169,7 @@ void MCObjectStreamer::EmitLabel(MCSymbol *Symbol) { auto *F = dyn_cast_or_null(getCurrentFragment()); if (F && !(getAssembler().isBundlingEnabled() && getAssembler().getRelaxAll())) { - SD.setFragment(F); + Symbol->setFragment(F); Symbol->setOffset(F->getContents().size()); } else { PendingLabels.push_back(Symbol); diff --git a/lib/MC/MCObjectWriter.cpp b/lib/MC/MCObjectWriter.cpp index 727b754d753..773dab22f61 100644 --- a/lib/MC/MCObjectWriter.cpp +++ b/lib/MC/MCObjectWriter.cpp @@ -30,12 +30,10 @@ bool MCObjectWriter::IsSymbolRefDifferenceFullyResolved( if (SA.isUndefined() || SB.isUndefined()) return false; - const MCSymbol &DataA = SA.getData(); - const MCSymbol &DataB = SB.getData(); - if(!DataA.getFragment() || !DataB.getFragment()) + if (!SA.getFragment() || !SB.getFragment()) return false; - return IsSymbolRefDifferenceFullyResolvedImpl(Asm, SA, *DataB.getFragment(), + return IsSymbolRefDifferenceFullyResolvedImpl(Asm, SA, *SB.getFragment(), InSet, false); } diff --git a/lib/MC/MachObjectWriter.cpp b/lib/MC/MachObjectWriter.cpp index 77e7a5a4e1c..0726f6ab8ec 100644 --- a/lib/MC/MachObjectWriter.cpp +++ b/lib/MC/MachObjectWriter.cpp @@ -101,7 +101,7 @@ uint64_t MachObjectWriter::getSymbolAddress(const MCSymbol &S, return Address; } - return getSectionAddress(S.getData().getFragment()->getParent()) + + return getSectionAddress(S.getFragment()->getParent()) + Layout.getSymbolOffset(S); } @@ -329,7 +329,7 @@ const MCSymbol &MachObjectWriter::findAliasedSymbol(const MCSymbol &Sym) const { void MachObjectWriter::WriteNlist(MachSymbolData &MSD, const MCAsmLayout &Layout) { const MCSymbol *Symbol = MSD.Symbol; - MCSymbol &Data = Symbol->getData(); + const MCSymbol &Data = *Symbol; const MCSymbol *AliasedSymbol = &findAliasedSymbol(*Symbol); uint8_t SectionIndex = MSD.SectionIndex; uint8_t Type = 0; @@ -554,13 +554,11 @@ void MachObjectWriter::ComputeSymbolTable( // match 'as'. Even though it doesn't matter for correctness, this is // important for letting us diff .o files. for (const MCSymbol &Symbol : Asm.symbols()) { - MCSymbol &SD = Symbol.getData(); - // Ignore non-linker visible symbols. if (!Asm.isSymbolLinkerVisible(Symbol)) continue; - if (!SD.isExternal() && !Symbol.isUndefined()) + if (!Symbol.isExternal() && !Symbol.isUndefined()) continue; MachSymbolData MSD; @@ -582,13 +580,11 @@ void MachObjectWriter::ComputeSymbolTable( // Now add the data for local symbols. for (const MCSymbol &Symbol : Asm.symbols()) { - MCSymbol &SD = Symbol.getData(); - // Ignore non-linker visible symbols. if (!Asm.isSymbolLinkerVisible(Symbol)) continue; - if (SD.isExternal() || Symbol.isUndefined()) + if (Symbol.isExternal() || Symbol.isUndefined()) continue; MachSymbolData MSD; @@ -692,8 +688,7 @@ bool MachObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl( bool hasReliableSymbolDifference = isX86_64(); if (!hasReliableSymbolDifference) { if (!SA.isInSection() || &SecA != &SecB || - (!SA.isTemporary() && - FB.getAtom() != SA.getData().getFragment()->getAtom() && + (!SA.isTemporary() && FB.getAtom() != SA.getFragment()->getAtom() && Asm.getSubsectionsViaSymbols())) return false; return true; @@ -717,7 +712,7 @@ bool MachObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl( if (&SecA != &SecB) return false; - const MCFragment *FA = SA.getData().getFragment(); + const MCFragment *FA = SA.getFragment(); // Bail if the symbol has no fragment. if (!FA) @@ -968,7 +963,7 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm, static_cast(*it->Section); if (Section.getType() == MachO::S_NON_LAZY_SYMBOL_POINTERS) { // If this symbol is defined and internal, mark it as such. - if (it->Symbol->isDefined() && !it->Symbol->getData().isExternal()) { + if (it->Symbol->isDefined() && !it->Symbol->isExternal()) { uint32_t Flags = MachO::INDIRECT_SYMBOL_LOCAL; if (it->Symbol->isAbsolute()) Flags |= MachO::INDIRECT_SYMBOL_ABS; diff --git a/lib/MC/WinCOFFObjectWriter.cpp b/lib/MC/WinCOFFObjectWriter.cpp index e5af4ab8321..ddec16cd42e 100644 --- a/lib/MC/WinCOFFObjectWriter.cpp +++ b/lib/MC/WinCOFFObjectWriter.cpp @@ -364,8 +364,7 @@ void WinCOFFObjectWriter::defineSection(MCSectionCOFF const &Sec) { static uint64_t getSymbolValue(const MCSymbol &Symbol, const MCAsmLayout &Layout) { - const MCSymbol &Data = Symbol.getData(); - if (Symbol.isCommon() && Data.isExternal()) + if (Symbol.isCommon() && Symbol.isExternal()) return Symbol.getCommonSize(); uint64_t Res; @@ -414,7 +413,6 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &Symbol, coff_symbol->MC = &Symbol; } else { - const MCSymbol &ResSymData = Symbol.getData(); const MCSymbol *Base = Layout.getBaseSymbol(Symbol); coff_symbol->Data.Value = getSymbolValue(Symbol, Layout); @@ -423,8 +421,8 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &Symbol, // If no storage class was specified in the streamer, define it here. if (coff_symbol->Data.StorageClass == 0) { - bool IsExternal = ResSymData.isExternal() || - (!ResSymData.getFragment() && !Symbol.isVariable()); + bool IsExternal = Symbol.isExternal() || + (!Symbol.getFragment() && !Symbol.isVariable()); coff_symbol->Data.StorageClass = IsExternal ? COFF::IMAGE_SYM_CLASS_EXTERNAL @@ -434,9 +432,8 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &Symbol, if (!Base) { coff_symbol->Data.SectionNumber = COFF::IMAGE_SYM_ABSOLUTE; } else { - const MCSymbol &BaseData = Base->getData(); - if (BaseData.getFragment()) { - COFFSection *Sec = SectionMap[BaseData.getFragment()->getParent()]; + if (Base->getFragment()) { + COFFSection *Sec = SectionMap[Base->getFragment()->getParent()]; if (coff_symbol->Section && coff_symbol->Section != Sec) report_fatal_error("conflicting sections for symbol"); @@ -672,8 +669,7 @@ bool WinCOFFObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl( } bool WinCOFFObjectWriter::isWeak(const MCSymbol &Sym) const { - const MCSymbol &SD = Sym.getData(); - if (!SD.isExternal()) + if (!Sym.isExternal()) return false; if (!Sym.isInSection()) @@ -701,8 +697,6 @@ void WinCOFFObjectWriter::RecordRelocation( Twine("symbol '") + A.getName() + "' can not be undefined"); - const MCSymbol &A_SD = A.getData(); - MCSection *Section = Fragment->getParent(); // Mark this symbol as requiring an entry in the symbol table. @@ -718,14 +712,13 @@ void WinCOFFObjectWriter::RecordRelocation( if (SymB) { const MCSymbol *B = &SymB->getSymbol(); - const MCSymbol &B_SD = B->getData(); - if (!B_SD.getFragment()) + if (!B->getFragment()) Asm.getContext().reportFatalError( Fixup.getLoc(), Twine("symbol '") + B->getName() + "' can not be undefined in a subtraction expression"); - if (!A_SD.getFragment()) + if (!A.getFragment()) Asm.getContext().reportFatalError( Fixup.getLoc(), Twine("symbol '") + Symbol.getName() + @@ -762,9 +755,8 @@ void WinCOFFObjectWriter::RecordRelocation( // Turn relocations for temporary symbols into section relocations. if (coff_symbol->MC->isTemporary() || CrossSection) { Reloc.Symb = coff_symbol->Section->Symbol; - FixedValue += - Layout.getFragmentOffset(coff_symbol->MC->getData().getFragment()) + - coff_symbol->MC->getOffset(); + FixedValue += Layout.getFragmentOffset(coff_symbol->MC->getFragment()) + + coff_symbol->MC->getOffset(); } else Reloc.Symb = coff_symbol; diff --git a/lib/MC/WinCOFFStreamer.cpp b/lib/MC/WinCOFFStreamer.cpp index bbc748a4ac8..e4520022a41 100644 --- a/lib/MC/WinCOFFStreamer.cpp +++ b/lib/MC/WinCOFFStreamer.cpp @@ -97,17 +97,16 @@ bool MCWinCOFFStreamer::EmitSymbolAttribute(MCSymbol *Symbol, "Got non-COFF section in the COFF backend!"); getAssembler().registerSymbol(*Symbol); - MCSymbol &SD = Symbol->getData(); switch (Attribute) { default: return false; case MCSA_WeakReference: case MCSA_Weak: Symbol->modifyFlags(COFF::SF_WeakExternal, COFF::SF_WeakExternal); - SD.setExternal(true); + Symbol->setExternal(true); break; case MCSA_Global: - SD.setExternal(true); + Symbol->setExternal(true); break; } @@ -197,8 +196,7 @@ void MCWinCOFFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, AssignSection(Symbol, nullptr); getAssembler().registerSymbol(*Symbol); - MCSymbol &SD = Symbol->getData(); - SD.setExternal(true); + Symbol->setExternal(true); Symbol->setCommon(Size, ByteAlignment); if (!T.isKnownWindowsMSVCEnvironment() && ByteAlignment > 1) { @@ -227,8 +225,7 @@ void MCWinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, Section->setAlignment(ByteAlignment); getAssembler().registerSymbol(*Symbol); - MCSymbol &SD = Symbol->getData(); - SD.setExternal(false); + Symbol->setExternal(false); AssignSection(Symbol, Section); @@ -238,7 +235,7 @@ void MCWinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, MCFillFragment *Fragment = new MCFillFragment( /*Value=*/0, /*ValueSize=*/0, Size, Section); - SD.setFragment(Fragment); + Symbol->setFragment(Fragment); } void MCWinCOFFStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol, diff --git a/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp index ad126f779cb..a3ec011ef25 100644 --- a/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp +++ b/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp @@ -165,10 +165,9 @@ private: Name + "." + Twine(MappingSymbolCounter++)); getAssembler().registerSymbol(*Symbol); - MCSymbol &SD = Symbol->getData(); MCELF::SetType(*Symbol, ELF::STT_NOTYPE); MCELF::SetBinding(*Symbol, ELF::STB_LOCAL); - SD.setExternal(false); + Symbol->setExternal(false); auto Sec = getCurrentSection().first; assert(Sec && "need a section"); Symbol->setSection(*Sec); diff --git a/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp b/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp index 38765a01bb7..b9f5173ba8b 100644 --- a/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp +++ b/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp @@ -209,11 +209,9 @@ void AArch64MachObjectWriter::RecordRelocation( } } else if (Target.getSymB()) { // A - B + constant const MCSymbol *A = &Target.getSymA()->getSymbol(); - const MCSymbol &A_SD = A->getData(); const MCSymbol *A_Base = Asm.getAtom(*A); const MCSymbol *B = &Target.getSymB()->getSymbol(); - const MCSymbol &B_SD = B->getData(); const MCSymbol *B_Base = Asm.getAtom(*B); // Check for "_foo@got - .", which comes through here as: @@ -264,14 +262,12 @@ void AArch64MachObjectWriter::RecordRelocation( Asm.getContext().reportFatalError(Fixup.getLoc(), "unsupported relocation with identical base"); - Value += (!A_SD.getFragment() ? 0 : Writer->getSymbolAddress(*A, Layout)) - - (!A_Base || !A_Base->getData().getFragment() - ? 0 - : Writer->getSymbolAddress(*A_Base, Layout)); - Value -= (!B_SD.getFragment() ? 0 : Writer->getSymbolAddress(*B, Layout)) - - (!B_Base || !B_Base->getData().getFragment() - ? 0 - : Writer->getSymbolAddress(*B_Base, Layout)); + Value += (!A->getFragment() ? 0 : Writer->getSymbolAddress(*A, Layout)) - + (!A_Base || !A_Base->getFragment() ? 0 : Writer->getSymbolAddress( + *A_Base, Layout)); + Value -= (!B->getFragment() ? 0 : Writer->getSymbolAddress(*B, Layout)) - + (!B_Base || !B_Base->getFragment() ? 0 : Writer->getSymbolAddress( + *B_Base, Layout)); Type = MachO::ARM64_RELOC_UNSIGNED; diff --git a/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp b/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp index 2050a8b8305..5d4429b3145 100644 --- a/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp +++ b/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp @@ -601,8 +601,7 @@ void ARMAsmBackend::processFixupValue(const MCAssembler &Asm, // the offset when the destination has the same MCFragment. if (A && (unsigned)Fixup.getKind() == ARM::fixup_arm_thumb_bl) { const MCSymbol &Sym = A->getSymbol(); - const MCSymbol &SymData = Sym.getData(); - IsResolved = (SymData.getFragment() == DF); + IsResolved = (Sym.getFragment() == DF); } // We must always generate a relocation for BL/BLX instructions if we have // a symbol to reference, as the linker relies on knowing the destination diff --git a/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp index da5d94e2d2f..1759b7adb7b 100644 --- a/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp +++ b/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp @@ -567,10 +567,9 @@ private: Twine(MappingSymbolCounter++)); getAssembler().registerSymbol(*Symbol); - MCSymbol &SD = Symbol->getData(); MCELF::SetType(*Symbol, ELF::STT_NOTYPE); MCELF::SetBinding(*Symbol, ELF::STB_LOCAL); - SD.setExternal(false); + Symbol->setExternal(false); AssignSection(Symbol, getCurrentSection().first); const MCExpr *Value = MCSymbolRefExpr::Create(Start, getContext()); diff --git a/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp b/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp index 07b3c4ce936..16015b51004 100644 --- a/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp +++ b/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp @@ -152,23 +152,21 @@ RecordARMScatteredHalfRelocation(MachObjectWriter *Writer, // See . const MCSymbol *A = &Target.getSymA()->getSymbol(); - const MCSymbol *A_SD = &A->getData(); - if (!A_SD->getFragment()) + if (!A->getFragment()) Asm.getContext().reportFatalError(Fixup.getLoc(), "symbol '" + A->getName() + "' can not be undefined in a subtraction expression"); uint32_t Value = Writer->getSymbolAddress(*A, Layout); uint32_t Value2 = 0; - uint64_t SecAddr = - Writer->getSectionAddress(A_SD->getFragment()->getParent()); + uint64_t SecAddr = Writer->getSectionAddress(A->getFragment()->getParent()); FixedValue += SecAddr; if (const MCSymbolRefExpr *B = Target.getSymB()) { - const MCSymbol *B_SD = &B->getSymbol().getData(); + const MCSymbol *SB = &B->getSymbol(); - if (!B_SD->getFragment()) + if (!SB->getFragment()) Asm.getContext().reportFatalError(Fixup.getLoc(), "symbol '" + B->getSymbol().getName() + "' can not be undefined in a subtraction expression"); @@ -176,7 +174,7 @@ RecordARMScatteredHalfRelocation(MachObjectWriter *Writer, // Select the appropriate difference relocation type. Type = MachO::ARM_RELOC_HALF_SECTDIFF; Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout); - FixedValue -= Writer->getSectionAddress(B_SD->getFragment()->getParent()); + FixedValue -= Writer->getSectionAddress(SB->getFragment()->getParent()); } // Relocations are written out in reverse order, so the PAIR comes first. @@ -255,24 +253,22 @@ void ARMMachObjectWriter::RecordARMScatteredRelocation(MachObjectWriter *Writer, // See . const MCSymbol *A = &Target.getSymA()->getSymbol(); - const MCSymbol *A_SD = &A->getData(); - if (!A_SD->getFragment()) + if (!A->getFragment()) Asm.getContext().reportFatalError(Fixup.getLoc(), "symbol '" + A->getName() + "' can not be undefined in a subtraction expression"); uint32_t Value = Writer->getSymbolAddress(*A, Layout); - uint64_t SecAddr = - Writer->getSectionAddress(A_SD->getFragment()->getParent()); + uint64_t SecAddr = Writer->getSectionAddress(A->getFragment()->getParent()); FixedValue += SecAddr; uint32_t Value2 = 0; if (const MCSymbolRefExpr *B = Target.getSymB()) { assert(Type == MachO::ARM_RELOC_VANILLA && "invalid reloc for 2 symbols"); - const MCSymbol *B_SD = &B->getSymbol().getData(); + const MCSymbol *SB = &B->getSymbol(); - if (!B_SD->getFragment()) + if (!SB->getFragment()) Asm.getContext().reportFatalError(Fixup.getLoc(), "symbol '" + B->getSymbol().getName() + "' can not be undefined in a subtraction expression"); @@ -280,7 +276,7 @@ void ARMMachObjectWriter::RecordARMScatteredRelocation(MachObjectWriter *Writer, // Select the appropriate difference relocation type. Type = MachO::ARM_RELOC_SECTDIFF; Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout); - FixedValue -= Writer->getSectionAddress(B_SD->getFragment()->getParent()); + FixedValue -= Writer->getSectionAddress(SB->getFragment()->getParent()); } // Relocations are written out in reverse order, so the PAIR comes first. diff --git a/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp b/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp index f54018a8942..d8e45b8af49 100644 --- a/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp +++ b/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp @@ -206,28 +206,26 @@ bool PPCMachObjectWriter::RecordScatteredRelocation( // See . const MCSymbol *A = &Target.getSymA()->getSymbol(); - const MCSymbol *A_SD = &A->getData(); - if (!A_SD->getFragment()) + if (!A->getFragment()) report_fatal_error("symbol '" + A->getName() + "' can not be undefined in a subtraction expression"); uint32_t Value = Writer->getSymbolAddress(*A, Layout); - uint64_t SecAddr = - Writer->getSectionAddress(A_SD->getFragment()->getParent()); + uint64_t SecAddr = Writer->getSectionAddress(A->getFragment()->getParent()); FixedValue += SecAddr; uint32_t Value2 = 0; if (const MCSymbolRefExpr *B = Target.getSymB()) { - const MCSymbol *B_SD = &B->getSymbol().getData(); + const MCSymbol *SB = &B->getSymbol(); - if (!B_SD->getFragment()) + if (!SB->getFragment()) report_fatal_error("symbol '" + B->getSymbol().getName() + "' can not be undefined in a subtraction expression"); // FIXME: is Type correct? see include/llvm/Support/MachO.h Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout); - FixedValue -= Writer->getSectionAddress(B_SD->getFragment()->getParent()); + FixedValue -= Writer->getSectionAddress(SB->getFragment()->getParent()); } // FIXME: does FixedValue get used?? diff --git a/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp b/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp index 531b8a75427..8c7492dd808 100644 --- a/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp +++ b/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp @@ -142,13 +142,11 @@ void X86MachObjectWriter::RecordX86_64Relocation( const MCSymbol *A = &Target.getSymA()->getSymbol(); if (A->isTemporary()) A = &Writer->findAliasedSymbol(*A); - const MCSymbol &A_SD = A->getData(); const MCSymbol *A_Base = Asm.getAtom(*A); const MCSymbol *B = &Target.getSymB()->getSymbol(); if (B->isTemporary()) B = &Writer->findAliasedSymbol(*B); - const MCSymbol &B_SD = B->getData(); const MCSymbol *B_Base = Asm.getAtom(*B); // Neither symbol can be modified. @@ -190,7 +188,7 @@ void X86MachObjectWriter::RecordX86_64Relocation( (!B_Base ? 0 : Writer->getSymbolAddress(*B_Base, Layout)); if (!A_Base) - Index = A_SD.getFragment()->getParent()->getOrdinal() + 1; + Index = A->getFragment()->getParent()->getOrdinal() + 1; Type = MachO::X86_64_RELOC_UNSIGNED; MachO::any_relocation_info MRE; @@ -202,7 +200,7 @@ void X86MachObjectWriter::RecordX86_64Relocation( if (B_Base) RelSymbol = B_Base; else - Index = B_SD.getFragment()->getParent()->getOrdinal() + 1; + Index = B->getFragment()->getParent()->getOrdinal() + 1; Type = MachO::X86_64_RELOC_SUBTRACTOR; } else { const MCSymbol *Symbol = &Target.getSymA()->getSymbol(); @@ -211,7 +209,6 @@ void X86MachObjectWriter::RecordX86_64Relocation( if (!Asm.getContext().getAsmInfo()->isSectionAtomizableBySymbols(Sec)) Asm.addLocalUsedInReloc(*Symbol); } - const MCSymbol &SD = Symbol->getData(); RelSymbol = Asm.getAtom(*Symbol); // Relocations inside debug sections always use local relocations when @@ -235,7 +232,7 @@ void X86MachObjectWriter::RecordX86_64Relocation( Layout.getSymbolOffset(*RelSymbol); } else if (Symbol->isInSection() && !Symbol->isVariable()) { // The index is the section ordinal (1-based). - Index = SD.getFragment()->getParent()->getOrdinal() + 1; + Index = Symbol->getFragment()->getParent()->getOrdinal() + 1; Value += Writer->getSymbolAddress(*Symbol, Layout); if (IsPCRel) @@ -354,23 +351,21 @@ bool X86MachObjectWriter::RecordScatteredRelocation(MachObjectWriter *Writer, // See . const MCSymbol *A = &Target.getSymA()->getSymbol(); - const MCSymbol *A_SD = &A->getData(); - if (!A_SD->getFragment()) + if (!A->getFragment()) report_fatal_error("symbol '" + A->getName() + "' can not be undefined in a subtraction expression", false); uint32_t Value = Writer->getSymbolAddress(*A, Layout); - uint64_t SecAddr = - Writer->getSectionAddress(A_SD->getFragment()->getParent()); + uint64_t SecAddr = Writer->getSectionAddress(A->getFragment()->getParent()); FixedValue += SecAddr; uint32_t Value2 = 0; if (const MCSymbolRefExpr *B = Target.getSymB()) { - const MCSymbol *B_SD = &B->getSymbol().getData(); + const MCSymbol *SB = &B->getSymbol(); - if (!B_SD->getFragment()) + if (!SB->getFragment()) report_fatal_error("symbol '" + B->getSymbol().getName() + "' can not be undefined in a subtraction expression", false); @@ -380,10 +375,10 @@ bool X86MachObjectWriter::RecordScatteredRelocation(MachObjectWriter *Writer, // Note that there is no longer any semantic difference between these two // relocation types from the linkers point of view, this is done solely for // pedantic compatibility with 'as'. - Type = A_SD->isExternal() ? (unsigned)MachO::GENERIC_RELOC_SECTDIFF : - (unsigned)MachO::GENERIC_RELOC_LOCAL_SECTDIFF; + Type = A->isExternal() ? (unsigned)MachO::GENERIC_RELOC_SECTDIFF + : (unsigned)MachO::GENERIC_RELOC_LOCAL_SECTDIFF; Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout); - FixedValue -= Writer->getSectionAddress(B_SD->getFragment()->getParent()); + FixedValue -= Writer->getSectionAddress(SB->getFragment()->getParent()); } // Relocations are written out in reverse order, so the PAIR comes first. -- 2.34.1