summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC/ELFObjectWriter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/MC/ELFObjectWriter.cpp')
-rw-r--r--llvm/lib/MC/ELFObjectWriter.cpp60
1 files changed, 27 insertions, 33 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 00986d63258..05a779c1b1e 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -85,8 +85,8 @@ class ELFObjectWriter : public MCObjectWriter {
// Support lexicographic sorting.
bool operator<(const ELFSymbolData &RHS) const {
- unsigned LHSType = MCELF::GetType(Symbol->getData());
- unsigned RHSType = MCELF::GetType(RHS.Symbol->getData());
+ unsigned LHSType = MCELF::GetType(*Symbol);
+ unsigned RHSType = MCELF::GetType(*RHS.Symbol);
if (LHSType == ELF::STT_SECTION && RHSType != ELF::STT_SECTION)
return false;
if (LHSType != ELF::STT_SECTION && RHSType == ELF::STT_SECTION)
@@ -398,7 +398,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());
- MCELF::SetBinding(OriginalData, MCELF::GetBinding(SD));
+ MCELF::SetBinding(Alias, MCELF::GetBinding(Symbol));
StringRef Rest = AliasName.substr(Pos);
if (!Symbol.isUndefined() && !Rest.startswith("@@@"))
@@ -462,19 +462,20 @@ void ELFObjectWriter::writeSymbol(SymbolTableWriter &Writer,
bool IsReserved = !Base || MSD.Symbol->isCommon();
// Binding and Type share the same byte as upper and lower nibbles
- uint8_t Binding = MCELF::GetBinding(OrigData);
- uint8_t Type = MCELF::GetType(OrigData);
+ uint8_t Binding = MCELF::GetBinding(*MSD.Symbol);
+ uint8_t Type = MCELF::GetType(*MSD.Symbol);
MCSymbolData *BaseSD = nullptr;
if (Base) {
BaseSD = &Base->getData();
- Type = mergeTypeForSet(Type, MCELF::GetType(*BaseSD));
+ 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(OrigData);
- uint8_t Other = MCELF::getOther(OrigData) << (ELF_STO_Shift - ELF_STV_Shift);
+ uint8_t Visibility = MCELF::GetVisibility(*MSD.Symbol);
+ uint8_t Other = MCELF::getOther(*MSD.Symbol)
+ << (ELF_STO_Shift - ELF_STV_Shift);
Other |= Visibility;
uint64_t Value = SymbolValue(*MSD.Symbol, Layout);
@@ -503,8 +504,6 @@ bool ELFObjectWriter::shouldRelocateWithSymbol(const MCAssembler &Asm,
const MCSymbolRefExpr *RefA,
const MCSymbol *Sym, uint64_t C,
unsigned Type) const {
- MCSymbolData *SD = Sym ? &Sym->getData() : nullptr;
-
// A PCRel relocation to an absolute value has no symbol (or section). We
// represent that with a relocation to a null section.
if (!RefA)
@@ -543,7 +542,7 @@ bool ELFObjectWriter::shouldRelocateWithSymbol(const MCAssembler &Asm,
if (Sym->isUndefined())
return true;
- unsigned Binding = MCELF::GetBinding(*SD);
+ unsigned Binding = MCELF::GetBinding(*Sym);
switch(Binding) {
default:
llvm_unreachable("Invalid Binding");
@@ -620,11 +619,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 MCSymbolData &D) {
- if (MCELF::GetType(D) == ELF::STT_GNU_IFUNC)
+static bool isWeak(const MCSymbol &Sym) {
+ if (MCELF::GetType(Sym) == ELF::STT_GNU_IFUNC)
return true;
- switch (MCELF::GetBinding(D)) {
+ switch (MCELF::GetBinding(Sym)) {
default:
llvm_unreachable("Unknown binding");
case ELF::STB_LOCAL:
@@ -676,7 +675,7 @@ void ELFObjectWriter::RecordRelocation(MCAssembler &Asm,
Asm.getContext().reportFatalError(
Fixup.getLoc(), "Cannot represent a difference across sections");
- if (::isWeak(SymB.getData()))
+ if (::isWeak(SymB))
Asm.getContext().reportFatalError(
Fixup.getLoc(), "Cannot represent a subtraction with a weak symbol");
@@ -730,7 +729,6 @@ void ELFObjectWriter::RecordRelocation(MCAssembler &Asm,
bool ELFObjectWriter::isInSymtab(const MCAsmLayout &Layout,
const MCSymbol &Symbol, bool Used,
bool Renamed) {
- const MCSymbolData &Data = Symbol.getData();
if (Symbol.isVariable()) {
const MCExpr *Expr = Symbol.getVariableValue();
if (const MCSymbolRefExpr *Ref = dyn_cast<MCSymbolRefExpr>(Expr)) {
@@ -754,11 +752,11 @@ bool ELFObjectWriter::isInSymtab(const MCAsmLayout &Layout,
return false;
}
- bool IsGlobal = MCELF::GetBinding(Data) == ELF::STB_GLOBAL;
+ bool IsGlobal = MCELF::GetBinding(Symbol) == ELF::STB_GLOBAL;
if (!Symbol.isVariable() && Symbol.isUndefined() && !IsGlobal)
return false;
- if (MCELF::GetType(Data) == ELF::STT_SECTION)
+ if (MCELF::GetType(Symbol) == ELF::STT_SECTION)
return true;
if (Symbol.isTemporary())
@@ -811,8 +809,6 @@ void ELFObjectWriter::computeSymbolTable(
// Add the data for the symbols.
bool HasLargeSectionIndex = false;
for (const MCSymbol &Symbol : Asm.symbols()) {
- MCSymbolData &SD = Symbol.getData();
-
bool Used = UsedInReloc.count(&Symbol);
bool WeakrefUsed = WeakrefUsedInReloc.count(&Symbol);
bool isSignature = RevGroupMap.count(&Symbol);
@@ -827,8 +823,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(SD) == ELF::STB_LOCAL)
- MCELF::SetBinding(SD, ELF::STB_GLOBAL);
+ if (!Local && MCELF::GetBinding(Symbol) == ELF::STB_LOCAL)
+ MCELF::SetBinding(Symbol, ELF::STB_GLOBAL);
if (Symbol.isAbsolute()) {
MSD.SectionIndex = ELF::SHN_ABS;
@@ -844,7 +840,7 @@ void ELFObjectWriter::computeSymbolTable(
MSD.SectionIndex = ELF::SHN_UNDEF;
}
if (!Used && WeakrefUsed)
- MCELF::SetBinding(SD, ELF::STB_WEAK);
+ MCELF::SetBinding(Symbol, ELF::STB_WEAK);
} else {
const MCSectionELF &Section =
static_cast<const MCSectionELF &>(Symbol.getSection());
@@ -894,7 +890,7 @@ void ELFObjectWriter::computeSymbolTable(
}
// Sections have their own string table
- if (MCELF::GetType(SD) != ELF::STT_SECTION)
+ if (MCELF::GetType(Symbol) != ELF::STT_SECTION)
MSD.Name = StrTabBuilder.add(Name);
if (Local)
@@ -930,10 +926,9 @@ void ELFObjectWriter::computeSymbolTable(
unsigned Index = FileNames.size() + 1;
for (ELFSymbolData &MSD : LocalSymbolData) {
- unsigned StringIndex =
- MCELF::GetType(MSD.Symbol->getData()) == ELF::STT_SECTION
- ? 0
- : StrTabBuilder.getOffset(MSD.Name);
+ unsigned StringIndex = MCELF::GetType(*MSD.Symbol) == ELF::STT_SECTION
+ ? 0
+ : StrTabBuilder.getOffset(MSD.Name);
MSD.Symbol->setIndex(Index++);
writeSymbol(Writer, StringIndex, MSD, Layout);
}
@@ -945,7 +940,7 @@ void ELFObjectWriter::computeSymbolTable(
unsigned StringIndex = StrTabBuilder.getOffset(MSD.Name);
MSD.Symbol->setIndex(Index++);
writeSymbol(Writer, StringIndex, MSD, Layout);
- assert(MCELF::GetBinding(MSD.Symbol->getData()) != ELF::STB_LOCAL);
+ assert(MCELF::GetBinding(*MSD.Symbol) != ELF::STB_LOCAL);
}
uint64_t SecEnd = OS.tell();
@@ -1361,7 +1356,7 @@ bool ELFObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(
bool InSet, bool IsPCRel) const {
if (IsPCRel) {
assert(!InSet);
- if (::isWeak(SymA.getData()))
+ if (::isWeak(SymA))
return false;
}
return MCObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(Asm, SymA, FB,
@@ -1369,8 +1364,7 @@ bool ELFObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(
}
bool ELFObjectWriter::isWeak(const MCSymbol &Sym) const {
- const MCSymbolData &SD = Sym.getData();
- if (::isWeak(SD))
+ if (::isWeak(Sym))
return true;
// It is invalid to replace a reference to a global in a comdat
@@ -1379,7 +1373,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(SD) != ELF::STB_GLOBAL)
+ if (MCELF::GetBinding(Sym) != ELF::STB_GLOBAL)
return false;
if (!Sym.isInSection())
OpenPOWER on IntegriCloud