mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-10-04 04:19:25 +00:00
Record in a MCSymbolELF if it has been used in a relocation.
No functionality change, just saves an on the side map. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238979 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -18,6 +18,7 @@ class MCSymbolELF : public MCSymbol {
|
|||||||
const MCExpr *SymbolSize = nullptr;
|
const MCExpr *SymbolSize = nullptr;
|
||||||
|
|
||||||
mutable unsigned BindingSet : 1;
|
mutable unsigned BindingSet : 1;
|
||||||
|
mutable unsigned UsedInReloc : 1;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MCSymbolELF(const StringMapEntry<bool> *Name, bool isTemporary)
|
MCSymbolELF(const StringMapEntry<bool> *Name, bool isTemporary)
|
||||||
@@ -40,6 +41,9 @@ public:
|
|||||||
|
|
||||||
bool isBindingSet() const { return BindingSet; }
|
bool isBindingSet() const { return BindingSet; }
|
||||||
|
|
||||||
|
void setUsedInReloc() const;
|
||||||
|
bool isUsedInReloc() const;
|
||||||
|
|
||||||
static bool classof(const MCSymbol *S) { return S->isELF(); }
|
static bool classof(const MCSymbol *S) { return S->isELF(); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -74,8 +74,7 @@ class ELFObjectWriter : public MCObjectWriter {
|
|||||||
static uint64_t SymbolValue(const MCSymbol &Sym, const MCAsmLayout &Layout);
|
static uint64_t SymbolValue(const MCSymbol &Sym, const MCAsmLayout &Layout);
|
||||||
static bool isInSymtab(const MCAsmLayout &Layout, const MCSymbolELF &Symbol,
|
static bool isInSymtab(const MCAsmLayout &Layout, const MCSymbolELF &Symbol,
|
||||||
bool Used, bool Renamed);
|
bool Used, bool Renamed);
|
||||||
static bool isLocal(const MCSymbol &Symbol, bool IsUsedInReloc,
|
static bool isLocal(const MCSymbolELF &Symbol, bool IsSignature);
|
||||||
bool IsSignature);
|
|
||||||
|
|
||||||
/// Helper struct for containing some precomputed information on symbols.
|
/// Helper struct for containing some precomputed information on symbols.
|
||||||
struct ELFSymbolData {
|
struct ELFSymbolData {
|
||||||
@@ -100,7 +99,6 @@ class ELFObjectWriter : public MCObjectWriter {
|
|||||||
/// The target specific ELF writer instance.
|
/// The target specific ELF writer instance.
|
||||||
std::unique_ptr<MCELFObjectTargetWriter> TargetObjectWriter;
|
std::unique_ptr<MCELFObjectTargetWriter> TargetObjectWriter;
|
||||||
|
|
||||||
SmallPtrSet<const MCSymbol *, 16> UsedInReloc;
|
|
||||||
SmallPtrSet<const MCSymbol *, 16> WeakrefUsedInReloc;
|
SmallPtrSet<const MCSymbol *, 16> WeakrefUsedInReloc;
|
||||||
DenseMap<const MCSymbolELF *, const MCSymbolELF *> Renames;
|
DenseMap<const MCSymbolELF *, const MCSymbolELF *> Renames;
|
||||||
|
|
||||||
@@ -144,7 +142,6 @@ class ELFObjectWriter : public MCObjectWriter {
|
|||||||
: MCObjectWriter(OS, IsLittleEndian), TargetObjectWriter(MOTW) {}
|
: MCObjectWriter(OS, IsLittleEndian), TargetObjectWriter(MOTW) {}
|
||||||
|
|
||||||
void reset() override {
|
void reset() override {
|
||||||
UsedInReloc.clear();
|
|
||||||
WeakrefUsedInReloc.clear();
|
WeakrefUsedInReloc.clear();
|
||||||
Renames.clear();
|
Renames.clear();
|
||||||
Relocations.clear();
|
Relocations.clear();
|
||||||
@@ -716,7 +713,7 @@ void ELFObjectWriter::RecordRelocation(MCAssembler &Asm,
|
|||||||
if (const MCSymbol *WeakRef = getWeakRef(*RefA))
|
if (const MCSymbol *WeakRef = getWeakRef(*RefA))
|
||||||
WeakrefUsedInReloc.insert(WeakRef);
|
WeakrefUsedInReloc.insert(WeakRef);
|
||||||
else
|
else
|
||||||
UsedInReloc.insert(SymA);
|
SymA->setUsedInReloc();
|
||||||
}
|
}
|
||||||
ELFRelocationEntry Rec(FixupOffset, SymA, Type, Addend);
|
ELFRelocationEntry Rec(FixupOffset, SymA, Type, Addend);
|
||||||
Relocations[&FixupSection].push_back(Rec);
|
Relocations[&FixupSection].push_back(Rec);
|
||||||
@@ -758,15 +755,14 @@ bool ELFObjectWriter::isInSymtab(const MCAsmLayout &Layout,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ELFObjectWriter::isLocal(const MCSymbol &Symbol, bool IsUsedInReloc,
|
bool ELFObjectWriter::isLocal(const MCSymbolELF &Symbol, bool IsSignature) {
|
||||||
bool IsSignature) {
|
|
||||||
if (Symbol.isExternal())
|
if (Symbol.isExternal())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (Symbol.isDefined())
|
if (Symbol.isDefined())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (IsUsedInReloc)
|
if (Symbol.isUsedInReloc())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return IsSignature;
|
return IsSignature;
|
||||||
@@ -802,7 +798,7 @@ void ELFObjectWriter::computeSymbolTable(
|
|||||||
bool HasLargeSectionIndex = false;
|
bool HasLargeSectionIndex = false;
|
||||||
for (const MCSymbol &S : Asm.symbols()) {
|
for (const MCSymbol &S : Asm.symbols()) {
|
||||||
const auto &Symbol = cast<MCSymbolELF>(S);
|
const auto &Symbol = cast<MCSymbolELF>(S);
|
||||||
bool Used = UsedInReloc.count(&Symbol);
|
bool Used = Symbol.isUsedInReloc();
|
||||||
bool WeakrefUsed = WeakrefUsedInReloc.count(&Symbol);
|
bool WeakrefUsed = WeakrefUsedInReloc.count(&Symbol);
|
||||||
bool isSignature = RevGroupMap.count(&Symbol);
|
bool isSignature = RevGroupMap.count(&Symbol);
|
||||||
|
|
||||||
@@ -815,7 +811,7 @@ void ELFObjectWriter::computeSymbolTable(
|
|||||||
|
|
||||||
// Undefined symbols are global, but this is the first place we
|
// Undefined symbols are global, but this is the first place we
|
||||||
// are able to set it.
|
// are able to set it.
|
||||||
bool Local = isLocal(Symbol, Used, isSignature);
|
bool Local = isLocal(Symbol, isSignature);
|
||||||
if (!Local && Symbol.getBinding() == ELF::STB_LOCAL)
|
if (!Local && Symbol.getBinding() == ELF::STB_LOCAL)
|
||||||
Symbol.setBinding(ELF::STB_GLOBAL);
|
Symbol.setBinding(ELF::STB_GLOBAL);
|
||||||
|
|
||||||
|
@@ -77,4 +77,13 @@ unsigned MCSymbolELF::getOther() const {
|
|||||||
unsigned Other = (getFlags() & (0x3f << ELF_STO_Shift)) >> ELF_STO_Shift;
|
unsigned Other = (getFlags() & (0x3f << ELF_STO_Shift)) >> ELF_STO_Shift;
|
||||||
return Other;
|
return Other;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MCSymbolELF::setUsedInReloc() const {
|
||||||
|
UsedInReloc = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MCSymbolELF::isUsedInReloc() const {
|
||||||
|
return UsedInReloc;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user