From ada43f6337e430a38f007778a5ebb7e022bb9c2d Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 3 Jun 2015 21:30:10 +0000 Subject: [PATCH] Record in a MCSymbolELF if it has been used in a relocation. No functionality change, just saves an on the side map. llvm-svn: 238979 --- llvm/include/llvm/MC/MCSymbolELF.h | 4 ++++ llvm/lib/MC/ELFObjectWriter.cpp | 16 ++++++---------- llvm/lib/MC/MCSymbolELF.cpp | 9 +++++++++ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/llvm/include/llvm/MC/MCSymbolELF.h b/llvm/include/llvm/MC/MCSymbolELF.h index 7ef97ce..22ade52 100644 --- a/llvm/include/llvm/MC/MCSymbolELF.h +++ b/llvm/include/llvm/MC/MCSymbolELF.h @@ -18,6 +18,7 @@ class MCSymbolELF : public MCSymbol { const MCExpr *SymbolSize = nullptr; mutable unsigned BindingSet : 1; + mutable unsigned UsedInReloc : 1; public: MCSymbolELF(const StringMapEntry *Name, bool isTemporary) @@ -40,6 +41,9 @@ public: bool isBindingSet() const { return BindingSet; } + void setUsedInReloc() const; + bool isUsedInReloc() const; + static bool classof(const MCSymbol *S) { return S->isELF(); } }; } diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index bb1b9a5..6165533 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -74,8 +74,7 @@ class ELFObjectWriter : public MCObjectWriter { static uint64_t SymbolValue(const MCSymbol &Sym, const MCAsmLayout &Layout); static bool isInSymtab(const MCAsmLayout &Layout, const MCSymbolELF &Symbol, bool Used, bool Renamed); - static bool isLocal(const MCSymbol &Symbol, bool IsUsedInReloc, - bool IsSignature); + static bool isLocal(const MCSymbolELF &Symbol, bool IsSignature); /// Helper struct for containing some precomputed information on symbols. struct ELFSymbolData { @@ -100,7 +99,6 @@ class ELFObjectWriter : public MCObjectWriter { /// The target specific ELF writer instance. std::unique_ptr TargetObjectWriter; - SmallPtrSet UsedInReloc; SmallPtrSet WeakrefUsedInReloc; DenseMap Renames; @@ -144,7 +142,6 @@ class ELFObjectWriter : public MCObjectWriter { : MCObjectWriter(OS, IsLittleEndian), TargetObjectWriter(MOTW) {} void reset() override { - UsedInReloc.clear(); WeakrefUsedInReloc.clear(); Renames.clear(); Relocations.clear(); @@ -716,7 +713,7 @@ void ELFObjectWriter::RecordRelocation(MCAssembler &Asm, if (const MCSymbol *WeakRef = getWeakRef(*RefA)) WeakrefUsedInReloc.insert(WeakRef); else - UsedInReloc.insert(SymA); + SymA->setUsedInReloc(); } ELFRelocationEntry Rec(FixupOffset, SymA, Type, Addend); Relocations[&FixupSection].push_back(Rec); @@ -758,15 +755,14 @@ bool ELFObjectWriter::isInSymtab(const MCAsmLayout &Layout, return true; } -bool ELFObjectWriter::isLocal(const MCSymbol &Symbol, bool IsUsedInReloc, - bool IsSignature) { +bool ELFObjectWriter::isLocal(const MCSymbolELF &Symbol, bool IsSignature) { if (Symbol.isExternal()) return false; if (Symbol.isDefined()) return true; - if (IsUsedInReloc) + if (Symbol.isUsedInReloc()) return false; return IsSignature; @@ -802,7 +798,7 @@ void ELFObjectWriter::computeSymbolTable( bool HasLargeSectionIndex = false; for (const MCSymbol &S : Asm.symbols()) { const auto &Symbol = cast(S); - bool Used = UsedInReloc.count(&Symbol); + bool Used = Symbol.isUsedInReloc(); bool WeakrefUsed = WeakrefUsedInReloc.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 // are able to set it. - bool Local = isLocal(Symbol, Used, isSignature); + bool Local = isLocal(Symbol, isSignature); if (!Local && Symbol.getBinding() == ELF::STB_LOCAL) Symbol.setBinding(ELF::STB_GLOBAL); diff --git a/llvm/lib/MC/MCSymbolELF.cpp b/llvm/lib/MC/MCSymbolELF.cpp index cf609e5..f8a90b9 100644 --- a/llvm/lib/MC/MCSymbolELF.cpp +++ b/llvm/lib/MC/MCSymbolELF.cpp @@ -77,4 +77,13 @@ unsigned MCSymbolELF::getOther() const { unsigned Other = (getFlags() & (0x3f << ELF_STO_Shift)) >> ELF_STO_Shift; return Other; } + +void MCSymbolELF::setUsedInReloc() const { + UsedInReloc = true; +} + +bool MCSymbolELF::isUsedInReloc() const { + return UsedInReloc; +} + } -- 2.7.4