mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-16 11:24:39 +00:00
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
This commit is contained in:
@@ -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<const MCSymbol *, 16> UsedInReloc;
|
||||
SmallPtrSet<const MCSymbol *, 16> WeakrefUsedInReloc;
|
||||
DenseMap<const MCSymbol *, const MCSymbol *> Renames;
|
||||
DenseMap<const MCSymbolELF *, const MCSymbolELF *> Renames;
|
||||
|
||||
llvm::DenseMap<const MCSectionELF *, std::vector<ELFRelocationEntry>>
|
||||
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<MCSymbolELF>(A);
|
||||
// Not an alias.
|
||||
if (!Alias.isVariable())
|
||||
continue;
|
||||
auto *Ref = dyn_cast<MCSymbolRefExpr>(Alias.getVariableValue());
|
||||
if (!Ref)
|
||||
continue;
|
||||
const MCSymbol &Symbol = Ref->getSymbol();
|
||||
const auto &Symbol = cast<MCSymbolELF>(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<MCSymbolELF>(*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<MCSymbolELF>(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<MCSymbolELF>(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<MCSymbolELF>(&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<MCSectionELF>(SecA);
|
||||
const MCSymbol *SectionSymbol = ELFSec ? ELFSec->getBeginSymbol() : nullptr;
|
||||
const auto *SectionSymbol =
|
||||
ELFSec ? cast<MCSymbolELF>(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<MCSymbolELF>(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<const MCSectionELF &>(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<MCSymbolELF>(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<MCSymbolELF>(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())
|
||||
|
Reference in New Issue
Block a user