From: Rafael Espindola Date: Tue, 2 Jun 2015 20:38:46 +0000 (+0000) Subject: Merge MCELF.h into MCSymbolELF.h. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=569f382a463eb5cf279fd972aa9f2fcbc1b6c07d;p=oota-llvm.git Merge MCELF.h into MCSymbolELF.h. Now that we have a dedicated type for ELF symbol, these helper functions can become member function of MCSymbolELF. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238864 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/MC/MCELF.h b/include/llvm/MC/MCELF.h deleted file mode 100644 index 14274cf5370..00000000000 --- a/include/llvm/MC/MCELF.h +++ /dev/null @@ -1,35 +0,0 @@ -//===- lib/MC/MCELF.h - ELF MC --------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file contains some support functions used by the ELF Streamer and -// ObjectWriter. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_MC_MCELF_H -#define LLVM_MC_MCELF_H - -namespace llvm { -class MCSymbol; - -class MCELF { - public: - static void SetBinding(const MCSymbol &Sym, unsigned Binding); - static unsigned GetBinding(const MCSymbol &Sym); - static void SetType(const MCSymbol &Sym, unsigned Type); - static unsigned GetType(const MCSymbol &Sym); - static void SetVisibility(MCSymbol &Sym, unsigned Visibility); - static unsigned GetVisibility(const MCSymbol &Sym); - static void setOther(MCSymbol &Sym, unsigned Other); - static unsigned getOther(const MCSymbol &Sym); -}; - -} - -#endif diff --git a/include/llvm/MC/MCELFObjectWriter.h b/include/llvm/MC/MCELFObjectWriter.h index 3fffcf2a780..01f694d3b75 100644 --- a/include/llvm/MC/MCELFObjectWriter.h +++ b/include/llvm/MC/MCELFObjectWriter.h @@ -21,16 +21,17 @@ class MCFixup; class MCFragment; class MCObjectWriter; class MCSymbol; +class MCSymbolELF; class MCValue; class raw_pwrite_stream; struct ELFRelocationEntry { uint64_t Offset; // Where is the relocation. - const MCSymbol *Symbol; // The symbol to relocate with. + const MCSymbolELF *Symbol; // The symbol to relocate with. unsigned Type; // The type of the relocation. uint64_t Addend; // The addend to use. - ELFRelocationEntry(uint64_t Offset, const MCSymbol *Symbol, unsigned Type, + ELFRelocationEntry(uint64_t Offset, const MCSymbolELF *Symbol, unsigned Type, uint64_t Addend) : Offset(Offset), Symbol(Symbol), Type(Type), Addend(Addend) {} }; diff --git a/include/llvm/MC/MCSymbolELF.h b/include/llvm/MC/MCSymbolELF.h index 6442d3d0240..87fcc492955 100644 --- a/include/llvm/MC/MCSymbolELF.h +++ b/include/llvm/MC/MCSymbolELF.h @@ -24,6 +24,18 @@ public: const MCExpr *getSize() const { return SymbolSize; } + void setVisibility(unsigned Visibility); + unsigned getVisibility() const; + + void setOther(unsigned Other); + unsigned getOther() const; + + void setType(unsigned Type) const; + unsigned getType() const; + + void setBinding(unsigned Binding) const; + unsigned getBinding() const; + static bool classof(const MCSymbol *S) { return S->isELF(); } }; } diff --git a/lib/MC/CMakeLists.txt b/lib/MC/CMakeLists.txt index 3cee0c43494..13c5ca9561d 100644 --- a/lib/MC/CMakeLists.txt +++ b/lib/MC/CMakeLists.txt @@ -12,7 +12,6 @@ add_llvm_library(LLVMMC MCCodeGenInfo.cpp MCContext.cpp MCDwarf.cpp - MCELF.cpp MCELFObjectTargetWriter.cpp MCELFStreamer.cpp MCExpr.cpp @@ -36,6 +35,7 @@ add_llvm_library(LLVMMC MCStreamer.cpp MCSubtargetInfo.cpp MCSymbol.cpp + MCSymbolELF.cpp MCSymbolizer.cpp MCTargetOptions.cpp MCValue.cpp diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index 927180c48dd..7d15f17684e 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -21,7 +21,6 @@ #include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" -#include "llvm/MC/MCELF.h" #include "llvm/MC/MCELFSymbolFlags.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCFixupKindInfo.h" @@ -73,7 +72,7 @@ public: class ELFObjectWriter : public MCObjectWriter { static bool isFixupKindPCRel(const MCAssembler &Asm, unsigned Kind); static uint64_t SymbolValue(const MCSymbol &Sym, const MCAsmLayout &Layout); - static bool isInSymtab(const MCAsmLayout &Layout, const MCSymbol &Symbol, + static bool isInSymtab(const MCAsmLayout &Layout, const MCSymbolELF &Symbol, bool Used, bool Renamed); static bool isLocal(const MCSymbol &Symbol, bool IsUsedInReloc, bool IsSignature); @@ -86,8 +85,8 @@ class ELFObjectWriter : public MCObjectWriter { // Support lexicographic sorting. bool operator<(const ELFSymbolData &RHS) const { - unsigned LHSType = MCELF::GetType(*Symbol); - unsigned RHSType = MCELF::GetType(*RHS.Symbol); + unsigned LHSType = Symbol->getType(); + unsigned RHSType = RHS.Symbol->getType(); if (LHSType == ELF::STT_SECTION && RHSType != ELF::STT_SECTION) return false; if (LHSType != ELF::STT_SECTION && RHSType == ELF::STT_SECTION) @@ -103,7 +102,7 @@ class ELFObjectWriter : public MCObjectWriter { SmallPtrSet UsedInReloc; SmallPtrSet WeakrefUsedInReloc; - DenseMap Renames; + DenseMap Renames; llvm::DenseMap> Relocations; @@ -378,14 +377,15 @@ void ELFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm, // The presence of symbol versions causes undefined symbols and // versions declared with @@@ to be renamed. - for (const MCSymbol &Alias : Asm.symbols()) { + for (const MCSymbol &A : Asm.symbols()) { + const auto &Alias = cast(A); // Not an alias. if (!Alias.isVariable()) continue; auto *Ref = dyn_cast(Alias.getVariableValue()); if (!Ref) continue; - const MCSymbol &Symbol = Ref->getSymbol(); + const auto &Symbol = cast(Ref->getSymbol()); StringRef AliasName = Alias.getName(); size_t Pos = AliasName.find('@'); @@ -395,7 +395,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. Alias.setExternal(Symbol.isExternal()); - MCELF::SetBinding(Alias, MCELF::GetBinding(Symbol)); + Alias.setBinding(Symbol.getBinding()); StringRef Rest = AliasName.substr(Pos); if (!Symbol.isUndefined() && !Rest.startswith("@@@")) @@ -448,7 +448,7 @@ static uint8_t mergeTypeForSet(uint8_t origType, uint8_t newType) { void ELFObjectWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex, ELFSymbolData &MSD, const MCAsmLayout &Layout) { - const MCSymbol &Symbol = *MSD.Symbol; + const auto &Symbol = cast(*MSD.Symbol); assert((!Symbol.getFragment() || (Symbol.getFragment()->getParent() == &Symbol.getSection())) && "The symbol's section doesn't match the fragment's symbol"); @@ -460,17 +460,17 @@ void ELFObjectWriter::writeSymbol(SymbolTableWriter &Writer, bool IsReserved = !Base || Symbol.isCommon(); // Binding and Type share the same byte as upper and lower nibbles - uint8_t Binding = MCELF::GetBinding(Symbol); - uint8_t Type = MCELF::GetType(Symbol); + uint8_t Binding = Symbol.getBinding(); + uint8_t Type = Symbol.getType(); if (Base) { - Type = mergeTypeForSet(Type, MCELF::GetType(*Base)); + Type = mergeTypeForSet(Type, Base->getType()); } 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(Symbol); - uint8_t Other = MCELF::getOther(Symbol) << (ELF_STO_Shift - ELF_STV_Shift); + uint8_t Visibility = Symbol.getVisibility(); + uint8_t Other = Symbol.getOther() << (ELF_STO_Shift - ELF_STV_Shift); Other |= Visibility; uint64_t Value = SymbolValue(*MSD.Symbol, Layout); @@ -497,8 +497,9 @@ void ELFObjectWriter::writeSymbol(SymbolTableWriter &Writer, // allows us to omit some local symbols from the symbol table. bool ELFObjectWriter::shouldRelocateWithSymbol(const MCAssembler &Asm, const MCSymbolRefExpr *RefA, - const MCSymbol *Sym, uint64_t C, + const MCSymbol *S, uint64_t C, unsigned Type) const { + const auto *Sym = cast_or_null(S); // A PCRel relocation to an absolute value has no symbol (or section). We // represent that with a relocation to a null section. if (!RefA) @@ -537,7 +538,7 @@ bool ELFObjectWriter::shouldRelocateWithSymbol(const MCAssembler &Asm, if (Sym->isUndefined()) return true; - unsigned Binding = MCELF::GetBinding(*Sym); + unsigned Binding = Sym->getBinding(); switch(Binding) { default: llvm_unreachable("Invalid Binding"); @@ -614,11 +615,11 @@ static const MCSymbol *getWeakRef(const MCSymbolRefExpr &Ref) { // True if the assembler knows nothing about the final value of the symbol. // This doesn't cover the comdat issues, since in those cases the assembler // can at least know that all symbols in the section will move together. -static bool isWeak(const MCSymbol &Sym) { - if (MCELF::GetType(Sym) == ELF::STT_GNU_IFUNC) +static bool isWeak(const MCSymbolELF &Sym) { + if (Sym.getType() == ELF::STT_GNU_IFUNC) return true; - switch (MCELF::GetBinding(Sym)) { + switch (Sym.getBinding()) { default: llvm_unreachable("Unknown binding"); case ELF::STB_LOCAL: @@ -656,7 +657,7 @@ void ELFObjectWriter::RecordRelocation(MCAssembler &Asm, Fixup.getLoc(), "No relocation available to represent this relative expression"); - const MCSymbol &SymB = RefB->getSymbol(); + const auto &SymB = cast(RefB->getSymbol()); if (SymB.isUndefined()) Asm.getContext().reportFatalError( @@ -682,7 +683,7 @@ void ELFObjectWriter::RecordRelocation(MCAssembler &Asm, // We either rejected the fixup or folded B into C at this point. const MCSymbolRefExpr *RefA = Target.getSymA(); - const MCSymbol *SymA = RefA ? &RefA->getSymbol() : nullptr; + const auto *SymA = RefA ? cast(&RefA->getSymbol()) : nullptr; unsigned Type = GetRelocType(Target, Fixup, IsPCRel); bool RelocateWithSymbol = shouldRelocateWithSymbol(Asm, RefA, SymA, C, Type); @@ -701,14 +702,15 @@ void ELFObjectWriter::RecordRelocation(MCAssembler &Asm, const MCSection *SecA = (SymA && !SymA->isUndefined()) ? &SymA->getSection() : nullptr; auto *ELFSec = cast_or_null(SecA); - const MCSymbol *SectionSymbol = ELFSec ? ELFSec->getBeginSymbol() : nullptr; + const auto *SectionSymbol = + ELFSec ? cast(ELFSec->getBeginSymbol()) : nullptr; ELFRelocationEntry Rec(FixupOffset, SectionSymbol, Type, Addend); Relocations[&FixupSection].push_back(Rec); return; } if (SymA) { - if (const MCSymbol *R = Renames.lookup(SymA)) + if (const MCSymbolELF *R = Renames.lookup(SymA)) SymA = R; if (const MCSymbol *WeakRef = getWeakRef(*RefA)) @@ -722,7 +724,7 @@ void ELFObjectWriter::RecordRelocation(MCAssembler &Asm, } bool ELFObjectWriter::isInSymtab(const MCAsmLayout &Layout, - const MCSymbol &Symbol, bool Used, + const MCSymbolELF &Symbol, bool Used, bool Renamed) { if (Symbol.isVariable()) { const MCExpr *Expr = Symbol.getVariableValue(); @@ -747,11 +749,11 @@ bool ELFObjectWriter::isInSymtab(const MCAsmLayout &Layout, return false; } - bool IsGlobal = MCELF::GetBinding(Symbol) == ELF::STB_GLOBAL; + bool IsGlobal = Symbol.getBinding() == ELF::STB_GLOBAL; if (!Symbol.isVariable() && Symbol.isUndefined() && !IsGlobal) return false; - if (MCELF::GetType(Symbol) == ELF::STT_SECTION) + if (Symbol.getType() == ELF::STT_SECTION) return true; if (Symbol.isTemporary()) @@ -802,7 +804,8 @@ void ELFObjectWriter::computeSymbolTable( // Add the data for the symbols. bool HasLargeSectionIndex = false; - for (const MCSymbol &Symbol : Asm.symbols()) { + for (const MCSymbol &S : Asm.symbols()) { + const auto &Symbol = cast(S); bool Used = UsedInReloc.count(&Symbol); bool WeakrefUsed = WeakrefUsedInReloc.count(&Symbol); bool isSignature = RevGroupMap.count(&Symbol); @@ -817,8 +820,8 @@ void ELFObjectWriter::computeSymbolTable( // Undefined symbols are global, but this is the first place we // are able to set it. bool Local = isLocal(Symbol, Used, isSignature); - if (!Local && MCELF::GetBinding(Symbol) == ELF::STB_LOCAL) - MCELF::SetBinding(Symbol, ELF::STB_GLOBAL); + if (!Local && Symbol.getBinding() == ELF::STB_LOCAL) + Symbol.setBinding(ELF::STB_GLOBAL); if (Symbol.isAbsolute()) { MSD.SectionIndex = ELF::SHN_ABS; @@ -834,7 +837,7 @@ void ELFObjectWriter::computeSymbolTable( MSD.SectionIndex = ELF::SHN_UNDEF; } if (!Used && WeakrefUsed) - MCELF::SetBinding(Symbol, ELF::STB_WEAK); + Symbol.setBinding(ELF::STB_WEAK); } else { const MCSectionELF &Section = static_cast(Symbol.getSection()); @@ -884,7 +887,7 @@ void ELFObjectWriter::computeSymbolTable( } // Sections have their own string table - if (MCELF::GetType(Symbol) != ELF::STT_SECTION) + if (Symbol.getType() != ELF::STT_SECTION) MSD.Name = StrTabBuilder.add(Name); if (Local) @@ -920,7 +923,7 @@ void ELFObjectWriter::computeSymbolTable( unsigned Index = FileNames.size() + 1; for (ELFSymbolData &MSD : LocalSymbolData) { - unsigned StringIndex = MCELF::GetType(*MSD.Symbol) == ELF::STT_SECTION + unsigned StringIndex = MSD.Symbol->getType() == ELF::STT_SECTION ? 0 : StrTabBuilder.getOffset(MSD.Name); MSD.Symbol->setIndex(Index++); @@ -934,7 +937,7 @@ void ELFObjectWriter::computeSymbolTable( unsigned StringIndex = StrTabBuilder.getOffset(MSD.Name); MSD.Symbol->setIndex(Index++); writeSymbol(Writer, StringIndex, MSD, Layout); - assert(MCELF::GetBinding(*MSD.Symbol) != ELF::STB_LOCAL); + assert(MSD.Symbol->getBinding() != ELF::STB_LOCAL); } uint64_t SecEnd = OS.tell(); @@ -1346,8 +1349,9 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm, } bool ELFObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl( - const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB, + const MCAssembler &Asm, const MCSymbol &SA, const MCFragment &FB, bool InSet, bool IsPCRel) const { + const auto &SymA = cast(SA); if (IsPCRel) { assert(!InSet); if (::isWeak(SymA)) @@ -1357,7 +1361,8 @@ bool ELFObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl( InSet, IsPCRel); } -bool ELFObjectWriter::isWeak(const MCSymbol &Sym) const { +bool ELFObjectWriter::isWeak(const MCSymbol &S) const { + const auto &Sym = cast(S); if (::isWeak(Sym)) return true; @@ -1367,7 +1372,7 @@ bool ELFObjectWriter::isWeak(const MCSymbol &Sym) const { // We could try to return false for more cases, like the reference // being in the same comdat or Sym being an alias to another global, // but it is not clear if it is worth the effort. - if (MCELF::GetBinding(Sym) != ELF::STB_GLOBAL) + if (Sym.getBinding() != ELF::STB_GLOBAL) return false; if (!Sym.isInSection()) diff --git a/lib/MC/MCELF.cpp b/lib/MC/MCELF.cpp deleted file mode 100644 index 8d7fbf25549..00000000000 --- a/lib/MC/MCELF.cpp +++ /dev/null @@ -1,85 +0,0 @@ -//===- lib/MC/MCELF.cpp - MC ELF ------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file implements ELF object file writer information. -// -//===----------------------------------------------------------------------===// - -#include "llvm/MC/MCELF.h" -#include "llvm/MC/MCAssembler.h" -#include "llvm/MC/MCSymbol.h" -#include "llvm/MC/MCELFSymbolFlags.h" -#include "llvm/MC/MCFixupKindInfo.h" -#include "llvm/Support/ELF.h" - -namespace llvm { - -void MCELF::SetBinding(const MCSymbol &Sym, unsigned Binding) { - assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL || - Binding == ELF::STB_WEAK || Binding == ELF::STB_GNU_UNIQUE); - uint32_t OtherFlags = Sym.getFlags() & ~(0xf << ELF_STB_Shift); - Sym.setFlags(OtherFlags | (Binding << ELF_STB_Shift)); -} - -unsigned MCELF::GetBinding(const MCSymbol &Sym) { - uint32_t Binding = (Sym.getFlags() & (0xf << ELF_STB_Shift)) >> ELF_STB_Shift; - assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL || - Binding == ELF::STB_WEAK || Binding == ELF::STB_GNU_UNIQUE); - return Binding; -} - -void MCELF::SetType(const MCSymbol &Sym, unsigned Type) { - assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT || - Type == ELF::STT_FUNC || Type == ELF::STT_SECTION || - Type == ELF::STT_COMMON || Type == ELF::STT_TLS || - Type == ELF::STT_GNU_IFUNC); - - uint32_t OtherFlags = Sym.getFlags() & ~(0xf << ELF_STT_Shift); - Sym.setFlags(OtherFlags | (Type << ELF_STT_Shift)); -} - -unsigned MCELF::GetType(const MCSymbol &Sym) { - uint32_t Type = (Sym.getFlags() & (0xf << ELF_STT_Shift)) >> ELF_STT_Shift; - assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT || - Type == ELF::STT_FUNC || Type == ELF::STT_SECTION || - Type == ELF::STT_COMMON || Type == ELF::STT_TLS || Type == ELF::STT_GNU_IFUNC); - return Type; -} - -// Visibility is stored in the first two bits of st_other -// st_other values are stored in the second byte of get/setFlags -void MCELF::SetVisibility(MCSymbol &Sym, unsigned Visibility) { - assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL || - Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED); - - uint32_t OtherFlags = Sym.getFlags() & ~(0x3 << ELF_STV_Shift); - Sym.setFlags(OtherFlags | (Visibility << ELF_STV_Shift)); -} - -unsigned MCELF::GetVisibility(const MCSymbol &Sym) { - unsigned Visibility = - (Sym.getFlags() & (0x3 << ELF_STV_Shift)) >> ELF_STV_Shift; - assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL || - Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED); - return Visibility; -} - -// Other is stored in the last six bits of st_other -// st_other values are stored in the second byte of get/setFlags -void MCELF::setOther(MCSymbol &Sym, unsigned Other) { - uint32_t OtherFlags = Sym.getFlags() & ~(0x3f << ELF_STO_Shift); - Sym.setFlags(OtherFlags | (Other << ELF_STO_Shift)); -} - -unsigned MCELF::getOther(const MCSymbol &Sym) { - unsigned Other = (Sym.getFlags() & (0x3f << ELF_STO_Shift)) >> ELF_STO_Shift; - return Other; -} - -} diff --git a/lib/MC/MCELFStreamer.cpp b/lib/MC/MCELFStreamer.cpp index 01c8e2825e9..a24388a26ca 100644 --- a/lib/MC/MCELFStreamer.cpp +++ b/lib/MC/MCELFStreamer.cpp @@ -20,7 +20,6 @@ #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCCodeEmitter.h" #include "llvm/MC/MCContext.h" -#include "llvm/MC/MCELF.h" #include "llvm/MC/MCELFSymbolFlags.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInst.h" @@ -107,7 +106,8 @@ void MCELFStreamer::InitSections(bool NoExecStack) { SwitchSection(Ctx.getAsmInfo()->getNonexecutableStackSection(Ctx)); } -void MCELFStreamer::EmitLabel(MCSymbol *Symbol) { +void MCELFStreamer::EmitLabel(MCSymbol *S) { + auto *Symbol = cast(S); assert(Symbol->isUndefined() && "Cannot define a symbol twice!"); MCObjectStreamer::EmitLabel(Symbol); @@ -115,7 +115,7 @@ void MCELFStreamer::EmitLabel(MCSymbol *Symbol) { const MCSectionELF &Section = static_cast(Symbol->getSection()); if (Section.getFlags() & ELF::SHF_TLS) - MCELF::SetType(*Symbol, ELF::STT_TLS); + Symbol->setType(ELF::STT_TLS); } void MCELFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) { @@ -160,14 +160,14 @@ void MCELFStreamer::ChangeSection(MCSection *Section, this->MCObjectStreamer::ChangeSection(Section, Subsection); MCContext &Ctx = getContext(); - MCSymbol *Begin = Section->getBeginSymbol(); + auto *Begin = cast_or_null(Section->getBeginSymbol()); if (!Begin) { Begin = Ctx.getOrCreateSectionSymbol(*SectionELF); Section->setBeginSymbol(Begin); } if (Begin->isUndefined()) { Asm.registerSymbol(*Begin); - MCELF::SetType(*Begin, ELF::STT_SECTION); + Begin->setType(ELF::STT_SECTION); } } @@ -197,8 +197,8 @@ static unsigned CombineSymbolTypes(unsigned T1, unsigned T2) { return T2; } -bool MCELFStreamer::EmitSymbolAttribute(MCSymbol *Symbol, - MCSymbolAttr Attribute) { +bool MCELFStreamer::EmitSymbolAttribute(MCSymbol *S, MCSymbolAttr Attribute) { + auto *Symbol = cast(S); // Indirect symbols are handled differently, to match how 'as' handles // them. This makes writing matching .o files easier. if (Attribute == MCSA_IndirectSymbol) { @@ -238,91 +238,85 @@ bool MCELFStreamer::EmitSymbolAttribute(MCSymbol *Symbol, break; case MCSA_ELF_TypeGnuUniqueObject: - MCELF::SetType( - *Symbol, CombineSymbolTypes(MCELF::GetType(*Symbol), ELF::STT_OBJECT)); - MCELF::SetBinding(*Symbol, ELF::STB_GNU_UNIQUE); + Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT)); + Symbol->setBinding(ELF::STB_GNU_UNIQUE); Symbol->setExternal(true); BindingExplicitlySet.insert(Symbol); break; case MCSA_Global: - MCELF::SetBinding(*Symbol, ELF::STB_GLOBAL); + Symbol->setBinding(ELF::STB_GLOBAL); Symbol->setExternal(true); BindingExplicitlySet.insert(Symbol); break; case MCSA_WeakReference: case MCSA_Weak: - MCELF::SetBinding(*Symbol, ELF::STB_WEAK); + Symbol->setBinding(ELF::STB_WEAK); Symbol->setExternal(true); BindingExplicitlySet.insert(Symbol); break; case MCSA_Local: - MCELF::SetBinding(*Symbol, ELF::STB_LOCAL); + Symbol->setBinding(ELF::STB_LOCAL); Symbol->setExternal(false); BindingExplicitlySet.insert(Symbol); break; case MCSA_ELF_TypeFunction: - MCELF::SetType(*Symbol, - CombineSymbolTypes(MCELF::GetType(*Symbol), ELF::STT_FUNC)); + Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_FUNC)); break; case MCSA_ELF_TypeIndFunction: - MCELF::SetType(*Symbol, CombineSymbolTypes(MCELF::GetType(*Symbol), - ELF::STT_GNU_IFUNC)); + Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_GNU_IFUNC)); break; case MCSA_ELF_TypeObject: - MCELF::SetType( - *Symbol, CombineSymbolTypes(MCELF::GetType(*Symbol), ELF::STT_OBJECT)); + Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT)); break; case MCSA_ELF_TypeTLS: - MCELF::SetType(*Symbol, - CombineSymbolTypes(MCELF::GetType(*Symbol), ELF::STT_TLS)); + Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_TLS)); break; case MCSA_ELF_TypeCommon: // TODO: Emit these as a common symbol. - MCELF::SetType( - *Symbol, CombineSymbolTypes(MCELF::GetType(*Symbol), ELF::STT_OBJECT)); + Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT)); break; case MCSA_ELF_TypeNoType: - MCELF::SetType( - *Symbol, CombineSymbolTypes(MCELF::GetType(*Symbol), ELF::STT_NOTYPE)); + Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_NOTYPE)); break; case MCSA_Protected: - MCELF::SetVisibility(*Symbol, ELF::STV_PROTECTED); + Symbol->setVisibility(ELF::STV_PROTECTED); break; case MCSA_Hidden: - MCELF::SetVisibility(*Symbol, ELF::STV_HIDDEN); + Symbol->setVisibility(ELF::STV_HIDDEN); break; case MCSA_Internal: - MCELF::SetVisibility(*Symbol, ELF::STV_INTERNAL); + Symbol->setVisibility(ELF::STV_INTERNAL); break; } return true; } -void MCELFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, +void MCELFStreamer::EmitCommonSymbol(MCSymbol *S, uint64_t Size, unsigned ByteAlignment) { + auto *Symbol = cast(S); getAssembler().registerSymbol(*Symbol); if (!BindingExplicitlySet.count(Symbol)) { - MCELF::SetBinding(*Symbol, ELF::STB_GLOBAL); + Symbol->setBinding(ELF::STB_GLOBAL); Symbol->setExternal(true); } - MCELF::SetType(*Symbol, ELF::STT_OBJECT); + Symbol->setType(ELF::STT_OBJECT); - if (MCELF::GetBinding(*Symbol) == ELF_STB_Local) { + if (Symbol->getBinding() == ELF_STB_Local) { MCSection *Section = getAssembler().getContext().getELFSection( ".bss", ELF::SHT_NOBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC); @@ -342,11 +336,12 @@ void MCELFStreamer::emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) { Symbol->setSize(Value); } -void MCELFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, +void MCELFStreamer::EmitLocalCommonSymbol(MCSymbol *S, uint64_t Size, unsigned ByteAlignment) { + auto *Symbol = cast(S); // FIXME: Should this be caught and done earlier? getAssembler().registerSymbol(*Symbol); - MCELF::SetBinding(*Symbol, ELF::STB_LOCAL); + Symbol->setBinding(ELF::STB_LOCAL); Symbol->setExternal(false); BindingExplicitlySet.insert(Symbol); EmitCommonSymbol(Symbol, Size, ByteAlignment); @@ -463,7 +458,7 @@ void MCELFStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) { break; } getAssembler().registerSymbol(symRef.getSymbol()); - MCELF::SetType(symRef.getSymbol(), ELF::STT_TLS); + cast(symRef.getSymbol()).setType(ELF::STT_TLS); break; } diff --git a/lib/MC/MCSymbolELF.cpp b/lib/MC/MCSymbolELF.cpp new file mode 100644 index 00000000000..1893bb0f8dc --- /dev/null +++ b/lib/MC/MCSymbolELF.cpp @@ -0,0 +1,79 @@ +//===- lib/MC/MCSymbolELF.cpp ---------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/MC/MCAssembler.h" +#include "llvm/MC/MCSymbolELF.h" +#include "llvm/MC/MCELFSymbolFlags.h" +#include "llvm/MC/MCFixupKindInfo.h" +#include "llvm/Support/ELF.h" + +namespace llvm { + +void MCSymbolELF::setBinding(unsigned Binding) const { + assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL || + Binding == ELF::STB_WEAK || Binding == ELF::STB_GNU_UNIQUE); + uint32_t OtherFlags = getFlags() & ~(0xf << ELF_STB_Shift); + setFlags(OtherFlags | (Binding << ELF_STB_Shift)); +} + +unsigned MCSymbolELF::getBinding() const { + uint32_t Binding = (getFlags() & (0xf << ELF_STB_Shift)) >> ELF_STB_Shift; + assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL || + Binding == ELF::STB_WEAK || Binding == ELF::STB_GNU_UNIQUE); + return Binding; +} + +void MCSymbolELF::setType(unsigned Type) const { + assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT || + Type == ELF::STT_FUNC || Type == ELF::STT_SECTION || + Type == ELF::STT_COMMON || Type == ELF::STT_TLS || + Type == ELF::STT_GNU_IFUNC); + + uint32_t OtherFlags = getFlags() & ~(0xf << ELF_STT_Shift); + setFlags(OtherFlags | (Type << ELF_STT_Shift)); +} + +unsigned MCSymbolELF::getType() const { + uint32_t Type = (getFlags() & (0xf << ELF_STT_Shift)) >> ELF_STT_Shift; + assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT || + Type == ELF::STT_FUNC || Type == ELF::STT_SECTION || + Type == ELF::STT_COMMON || Type == ELF::STT_TLS || + Type == ELF::STT_GNU_IFUNC); + return Type; +} + +// Visibility is stored in the first two bits of st_other +// st_other values are stored in the second byte of get/setFlags +void MCSymbolELF::setVisibility(unsigned Visibility) { + assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL || + Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED); + + uint32_t OtherFlags = getFlags() & ~(0x3 << ELF_STV_Shift); + setFlags(OtherFlags | (Visibility << ELF_STV_Shift)); +} + +unsigned MCSymbolELF::getVisibility() const { + unsigned Visibility = (getFlags() & (0x3 << ELF_STV_Shift)) >> ELF_STV_Shift; + assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL || + Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED); + return Visibility; +} + +// Other is stored in the last six bits of st_other +// st_other values are stored in the second byte of get/setFlags +void MCSymbolELF::setOther(unsigned Other) { + uint32_t OtherFlags = getFlags() & ~(0x3f << ELF_STO_Shift); + setFlags(OtherFlags | (Other << ELF_STO_Shift)); +} + +unsigned MCSymbolELF::getOther() const { + unsigned Other = (getFlags() & (0x3f << ELF_STO_Shift)) >> ELF_STO_Shift; + return Other; +} +} diff --git a/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp index 094f90d0fec..1434018fdbe 100644 --- a/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp +++ b/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp @@ -23,7 +23,6 @@ #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCCodeEmitter.h" #include "llvm/MC/MCContext.h" -#include "llvm/MC/MCELF.h" #include "llvm/MC/MCELFStreamer.h" #include "llvm/MC/MCELFSymbolFlags.h" #include "llvm/MC/MCExpr.h" @@ -32,7 +31,7 @@ #include "llvm/MC/MCSection.h" #include "llvm/MC/MCSectionELF.h" #include "llvm/MC/MCStreamer.h" -#include "llvm/MC/MCSymbol.h" +#include "llvm/MC/MCSymbolELF.h" #include "llvm/MC/MCValue.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ELF.h" @@ -161,12 +160,12 @@ private: MCSymbol *Start = getContext().createTempSymbol(); EmitLabel(Start); - MCSymbol *Symbol = getContext().getOrCreateSymbol( - Name + "." + Twine(MappingSymbolCounter++)); + auto *Symbol = cast(getContext().getOrCreateSymbol( + Name + "." + Twine(MappingSymbolCounter++))); getAssembler().registerSymbol(*Symbol); - MCELF::SetType(*Symbol, ELF::STT_NOTYPE); - MCELF::SetBinding(*Symbol, ELF::STB_LOCAL); + Symbol->setType(ELF::STT_NOTYPE); + Symbol->setBinding(ELF::STB_LOCAL); Symbol->setExternal(false); auto Sec = getCurrentSection().first; assert(Sec && "need a section"); diff --git a/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp b/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp index 9d22f00e066..eede51a2858 100644 --- a/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp +++ b/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp @@ -15,9 +15,8 @@ #include "AArch64MCExpr.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" -#include "llvm/MC/MCELF.h" #include "llvm/MC/MCStreamer.h" -#include "llvm/MC/MCSymbol.h" +#include "llvm/MC/MCSymbolELF.h" #include "llvm/MC/MCValue.h" #include "llvm/Object/ELF.h" #include "llvm/Support/ErrorHandling.h" @@ -121,7 +120,7 @@ static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) { // We're known to be under a TLS fixup, so any symbol should be // modified. There should be only one. const MCSymbolRefExpr &SymRef = *cast(Expr); - MCELF::SetType(SymRef.getSymbol(), ELF::STT_TLS); + cast(SymRef.getSymbol()).setType(ELF::STT_TLS); break; } diff --git a/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp index 795c1ba6314..35c289d8444 100644 --- a/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp +++ b/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp @@ -22,7 +22,6 @@ #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCCodeEmitter.h" #include "llvm/MC/MCContext.h" -#include "llvm/MC/MCELF.h" #include "llvm/MC/MCELFStreamer.h" #include "llvm/MC/MCELFSymbolFlags.h" #include "llvm/MC/MCExpr.h" @@ -34,7 +33,7 @@ #include "llvm/MC/MCSection.h" #include "llvm/MC/MCSectionELF.h" #include "llvm/MC/MCStreamer.h" -#include "llvm/MC/MCSymbol.h" +#include "llvm/MC/MCSymbolELF.h" #include "llvm/MC/MCValue.h" #include "llvm/Support/ARMBuildAttributes.h" #include "llvm/Support/ARMEHABI.h" @@ -562,13 +561,12 @@ private: MCSymbol *Start = getContext().createTempSymbol(); EmitLabel(Start); - MCSymbol *Symbol = - getContext().getOrCreateSymbol(Name + "." + - Twine(MappingSymbolCounter++)); + auto *Symbol = cast(getContext().getOrCreateSymbol( + Name + "." + Twine(MappingSymbolCounter++))); getAssembler().registerSymbol(*Symbol); - MCELF::SetType(*Symbol, ELF::STT_NOTYPE); - MCELF::SetBinding(*Symbol, ELF::STB_LOCAL); + Symbol->setType(ELF::STT_NOTYPE); + Symbol->setBinding(ELF::STB_LOCAL); Symbol->setExternal(false); AssignSection(Symbol, getCurrentSection().first); @@ -973,7 +971,7 @@ void ARMTargetELFStreamer::emitLabel(MCSymbol *Symbol) { return; Streamer.getOrCreateSymbolData(Symbol); - unsigned Type = MCELF::GetType(*Symbol); + unsigned Type = cast(Symbol)->getType(); if (Type == ELF_STT_Func || Type == ELF_STT_GnuIFunc) Streamer.EmitThumbFunc(Symbol); } diff --git a/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp b/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp index 4df92d067ea..82ae41330bc 100644 --- a/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp +++ b/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp @@ -12,10 +12,10 @@ #include "MCTargetDesc/MipsMCTargetDesc.h" #include "llvm/ADT/STLExtras.h" #include "llvm/MC/MCAssembler.h" -#include "llvm/MC/MCELF.h" #include "llvm/MC/MCELFObjectWriter.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCSection.h" +#include "llvm/MC/MCSymbolELF.h" #include "llvm/MC/MCValue.h" #include "llvm/Support/ErrorHandling.h" #include @@ -224,7 +224,7 @@ static unsigned getMatchingLoType(const MCAssembler &Asm, if (Type == ELF::R_MIPS16_HI16) return ELF::R_MIPS16_LO16; - if (MCELF::GetBinding(*Reloc.Symbol) != ELF::STB_LOCAL) + if (Reloc.Symbol->getBinding() != ELF::STB_LOCAL) return ELF::R_MIPS_NONE; if (Type == ELF::R_MIPS_GOT16) @@ -384,7 +384,7 @@ bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCSymbol &Sym, return true; case ELF::R_MIPS_32: - if (MCELF::getOther(Sym) & (ELF::STO_MIPS_MICROMIPS >> 2)) + if (cast(Sym).getOther() & (ELF::STO_MIPS_MICROMIPS >> 2)) return true; // falltrough case ELF::R_MIPS_26: diff --git a/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp b/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp index 8abd93bd668..1cba713ec8f 100644 --- a/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp +++ b/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp @@ -9,8 +9,8 @@ #include "MipsELFStreamer.h" #include "MipsTargetStreamer.h" -#include "llvm/MC/MCELF.h" #include "llvm/MC/MCInst.h" +#include "llvm/MC/MCSymbolELF.h" #include "llvm/Support/ELF.h" using namespace llvm; @@ -41,12 +41,13 @@ void MipsELFStreamer::createPendingLabelRelocs() { // FIXME: Also mark labels when in MIPS16 mode. if (ELFTargetStreamer->isMicroMipsEnabled()) { - for (auto Label : Labels) { + for (auto *L : Labels) { + auto *Label = cast(L); getOrCreateSymbolData(Label); // The "other" values are stored in the last 6 bits of the second byte. // The traditional defines for STO values assume the full byte and thus // the shift to pack it. - MCELF::setOther(*Label, ELF::STO_MIPS_MICROMIPS >> 2); + Label->setOther(ELF::STO_MIPS_MICROMIPS >> 2); } } diff --git a/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp b/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp index 9a0ffb27f59..8d9f80a7e6f 100644 --- a/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp +++ b/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp @@ -17,10 +17,9 @@ #include "MipsTargetObjectFile.h" #include "MipsTargetStreamer.h" #include "llvm/MC/MCContext.h" -#include "llvm/MC/MCELF.h" #include "llvm/MC/MCSectionELF.h" #include "llvm/MC/MCSubtargetInfo.h" -#include "llvm/MC/MCSymbol.h" +#include "llvm/MC/MCSymbolELF.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ELF.h" #include "llvm/Support/ErrorHandling.h" @@ -454,18 +453,19 @@ MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S, MCA.setELFHeaderEFlags(EFlags); } -void MipsTargetELFStreamer::emitLabel(MCSymbol *Symbol) { +void MipsTargetELFStreamer::emitLabel(MCSymbol *S) { + auto *Symbol = cast(S); if (!isMicroMipsEnabled()) return; getStreamer().getOrCreateSymbolData(Symbol); - uint8_t Type = MCELF::GetType(*Symbol); + uint8_t Type = Symbol->getType(); if (Type != ELF::STT_FUNC) return; // The "other" values are stored in the last 6 bits of the second byte // The traditional defines for STO values assume the full byte and thus // the shift to pack it. - MCELF::setOther(*Symbol, ELF::STO_MIPS_MICROMIPS >> 2); + Symbol->setOther(ELF::STO_MIPS_MICROMIPS >> 2); } void MipsTargetELFStreamer::finish() { @@ -519,21 +519,21 @@ void MipsTargetELFStreamer::finish() { emitMipsAbiFlags(); } -void MipsTargetELFStreamer::emitAssignment(MCSymbol *Symbol, - const MCExpr *Value) { +void MipsTargetELFStreamer::emitAssignment(MCSymbol *S, const MCExpr *Value) { + auto *Symbol = cast(S); // If on rhs is micromips symbol then mark Symbol as microMips. if (Value->getKind() != MCExpr::SymbolRef) return; - const MCSymbol &RhsSym = - static_cast(Value)->getSymbol(); + const auto &RhsSym = cast( + static_cast(Value)->getSymbol()); - if (!(MCELF::getOther(RhsSym) & (ELF::STO_MIPS_MICROMIPS >> 2))) + if (!(RhsSym.getOther() & (ELF::STO_MIPS_MICROMIPS >> 2))) return; // The "other" values are stored in the last 6 bits of the second byte. // The traditional defines for STO values assume the full byte and thus // the shift to pack it. - MCELF::setOther(*Symbol, ELF::STO_MIPS_MICROMIPS >> 2); + Symbol->setOther(ELF::STO_MIPS_MICROMIPS >> 2); } MCELFStreamer &MipsTargetELFStreamer::getStreamer() { diff --git a/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp b/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp index c3956091ebf..1736d03961f 100644 --- a/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp +++ b/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp @@ -24,6 +24,7 @@ #include "llvm/MC/MCParser/MCParsedAsmOperand.h" #include "llvm/MC/MCRegisterInfo.h" #include "llvm/MC/MCStreamer.h" +#include "llvm/MC/MCSymbolELF.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCTargetAsmParser.h" #include "llvm/Support/SourceMgr.h" @@ -1863,7 +1864,7 @@ bool PPCAsmParser::ParseDirectiveLocalEntry(SMLoc L) { Error(L, "expected identifier in directive"); return false; } - MCSymbol *Sym = getContext().getOrCreateSymbol(Name); + MCSymbolELF *Sym = cast(getContext().getOrCreateSymbol(Name)); if (getLexer().isNot(AsmToken::Comma)) { Error(L, "unexpected token in directive"); diff --git a/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp b/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp index 0fe3534ad62..4602b904d9d 100644 --- a/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp +++ b/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp @@ -11,12 +11,12 @@ #include "MCTargetDesc/PPCFixupKinds.h" #include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAssembler.h" -#include "llvm/MC/MCELF.h" #include "llvm/MC/MCELFObjectWriter.h" #include "llvm/MC/MCFixupKindInfo.h" #include "llvm/MC/MCMachObjectWriter.h" #include "llvm/MC/MCObjectWriter.h" #include "llvm/MC/MCSectionMachO.h" +#include "llvm/MC/MCSymbolELF.h" #include "llvm/MC/MCValue.h" #include "llvm/Support/ELF.h" #include "llvm/Support/ErrorHandling.h" @@ -142,12 +142,14 @@ public: // to resolve the fixup directly. Emit a relocation and leave // resolution of the final target address to the linker. if (const MCSymbolRefExpr *A = Target.getSymA()) { - // The "other" values are stored in the last 6 bits of the second byte. - // The traditional defines for STO values assume the full byte and thus - // the shift to pack it. - unsigned Other = MCELF::getOther(A->getSymbol()) << 2; - if ((Other & ELF::STO_PPC64_LOCAL_MASK) != 0) - IsResolved = false; + if (const auto *S = dyn_cast(&A->getSymbol())) { + // The "other" values are stored in the last 6 bits of the second + // byte. The traditional defines for STO values assume the full byte + // and thus the shift to pack it. + unsigned Other = S->getOther() << 2; + if ((Other & ELF::STO_PPC64_LOCAL_MASK) != 0) + IsResolved = false; + } } break; } diff --git a/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp b/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp index c0147763dbc..992be5b966c 100644 --- a/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp +++ b/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp @@ -11,9 +11,9 @@ #include "MCTargetDesc/PPCFixupKinds.h" #include "MCTargetDesc/PPCMCExpr.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/MC/MCELF.h" #include "llvm/MC/MCELFObjectWriter.h" #include "llvm/MC/MCExpr.h" +#include "llvm/MC/MCSymbolELF.h" #include "llvm/MC/MCValue.h" #include "llvm/Support/ErrorHandling.h" @@ -407,7 +407,7 @@ bool PPCELFObjectWriter::needsRelocateWithSymbol(const MCSymbol &Sym, // The "other" values are stored in the last 6 bits of the second byte. // The traditional defines for STO values assume the full byte and thus // the shift to pack it. - unsigned Other = MCELF::getOther(Sym) << 2; + unsigned Other = cast(Sym).getOther() << 2; return (Other & ELF::STO_PPC64_LOCAL_MASK) != 0; } } diff --git a/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp b/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp index c879a38dede..0f9697bb141 100644 --- a/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp +++ b/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp @@ -16,14 +16,13 @@ #include "PPCMCAsmInfo.h" #include "PPCTargetStreamer.h" #include "llvm/MC/MCCodeGenInfo.h" -#include "llvm/MC/MCELF.h" #include "llvm/MC/MCELFStreamer.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInstrInfo.h" #include "llvm/MC/MCRegisterInfo.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSubtargetInfo.h" -#include "llvm/MC/MCSymbol.h" +#include "llvm/MC/MCSymbolELF.h" #include "llvm/MC/MachineLocation.h" #include "llvm/Support/ELF.h" #include "llvm/Support/ErrorHandling.h" @@ -132,7 +131,7 @@ public: void emitAbiVersion(int AbiVersion) override { OS << "\t.abiversion " << AbiVersion << '\n'; } - void emitLocalEntry(MCSymbol *S, const MCExpr *LocalOffset) override { + void emitLocalEntry(MCSymbolELF *S, const MCExpr *LocalOffset) override { OS << "\t.localentry\t" << *S << ", " << *LocalOffset << '\n'; } }; @@ -159,7 +158,7 @@ public: Flags |= (AbiVersion & ELF::EF_PPC64_ABI); MCA.setELFHeaderEFlags(Flags); } - void emitLocalEntry(MCSymbol *S, const MCExpr *LocalOffset) override { + void emitLocalEntry(MCSymbolELF *S, const MCExpr *LocalOffset) override { MCAssembler &MCA = getStreamer().getAssembler(); int64_t Res; @@ -173,10 +172,10 @@ public: // The "other" values are stored in the last 6 bits of the second byte. // The traditional defines for STO values assume the full byte and thus // the shift to pack it. - unsigned Other = MCELF::getOther(*S) << 2; + unsigned Other = S->getOther() << 2; Other &= ~ELF::STO_PPC64_LOCAL_MASK; Other |= Encoded; - MCELF::setOther(*S, Other >> 2); + S->setOther(Other >> 2); // For GAS compatibility, unless we already saw a .abiversion directive, // set e_flags to indicate ELFv2 ABI. @@ -184,20 +183,21 @@ public: if ((Flags & ELF::EF_PPC64_ABI) == 0) MCA.setELFHeaderEFlags(Flags | 2); } - void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override { + void emitAssignment(MCSymbol *S, const MCExpr *Value) override { + auto *Symbol = cast(S); // When encoding an assignment to set symbol A to symbol B, also copy // the st_other bits encoding the local entry point offset. if (Value->getKind() != MCExpr::SymbolRef) return; - const MCSymbol &RhsSym = - static_cast(Value)->getSymbol(); + const auto &RhsSym = cast( + static_cast(Value)->getSymbol()); // The "other" values are stored in the last 6 bits of the second byte. // The traditional defines for STO values assume the full byte and thus // the shift to pack it. - unsigned Other = MCELF::getOther(*Symbol) << 2; + unsigned Other = Symbol->getOther() << 2; Other &= ~ELF::STO_PPC64_LOCAL_MASK; - Other |= (MCELF::getOther(RhsSym) << 2) & ELF::STO_PPC64_LOCAL_MASK; - MCELF::setOther(*Symbol, Other >> 2); + Other |= (RhsSym.getOther() << 2) & ELF::STO_PPC64_LOCAL_MASK; + Symbol->setOther(Other >> 2); } }; @@ -214,7 +214,7 @@ public: void emitAbiVersion(int AbiVersion) override { llvm_unreachable("Unknown pseudo-op: .abiversion"); } - void emitLocalEntry(MCSymbol *S, const MCExpr *LocalOffset) override { + void emitLocalEntry(MCSymbolELF *S, const MCExpr *LocalOffset) override { llvm_unreachable("Unknown pseudo-op: .localentry"); } }; diff --git a/lib/Target/PowerPC/PPCAsmPrinter.cpp b/lib/Target/PowerPC/PPCAsmPrinter.cpp index 87b0bf4418b..b1f85c14bbf 100644 --- a/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -49,7 +49,7 @@ #include "llvm/MC/MCSectionELF.h" #include "llvm/MC/MCSectionMachO.h" #include "llvm/MC/MCStreamer.h" -#include "llvm/MC/MCSymbol.h" +#include "llvm/MC/MCSymbolELF.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ELF.h" @@ -1166,7 +1166,7 @@ void PPCLinuxAsmPrinter::EmitFunctionBodyStart() { static_cast(OutStreamer->getTargetStreamer()); if (TS) - TS->emitLocalEntry(CurrentFnSym, LocalOffsetExp); + TS->emitLocalEntry(cast(CurrentFnSym), LocalOffsetExp); } } diff --git a/lib/Target/PowerPC/PPCTargetStreamer.h b/lib/Target/PowerPC/PPCTargetStreamer.h index 8aaf5e18890..dbe7617d354 100644 --- a/lib/Target/PowerPC/PPCTargetStreamer.h +++ b/lib/Target/PowerPC/PPCTargetStreamer.h @@ -20,7 +20,7 @@ public: virtual void emitTCEntry(const MCSymbol &S) = 0; virtual void emitMachine(StringRef CPU) = 0; virtual void emitAbiVersion(int AbiVersion) = 0; - virtual void emitLocalEntry(MCSymbol *S, const MCExpr *LocalOffset) = 0; + virtual void emitLocalEntry(MCSymbolELF *S, const MCExpr *LocalOffset) = 0; }; } diff --git a/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp b/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp index 9c651ddfc9f..ebc9fa6997d 100644 --- a/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp +++ b/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp @@ -15,9 +15,8 @@ #include "SparcMCExpr.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" -#include "llvm/MC/MCELF.h" #include "llvm/MC/MCObjectStreamer.h" -#include "llvm/MC/MCSymbol.h" +#include "llvm/MC/MCSymbolELF.h" #include "llvm/Object/ELF.h" @@ -184,7 +183,7 @@ static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) { case MCExpr::SymbolRef: { const MCSymbolRefExpr &SymRef = *cast(Expr); - MCELF::SetType(SymRef.getSymbol(), ELF::STT_TLS); + cast(SymRef.getSymbol()).setType(ELF::STT_TLS); break; }