From 1247bbd82a9c47c3571e100a63b6e84c079bfc60 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Fri, 22 May 2015 05:54:01 +0000 Subject: [PATCH] MC: Lift MCSymbolData::Index up to MCSymbol::Index, NFC Lift `MCSymbolData::Index` up a level to `MCSymbol`, as preparation for packing it into the bitfield in `MCSymbol`. llvm-svn: 238001 --- llvm/include/llvm/MC/MCSymbol.h | 24 +++++++++++++++--------- llvm/lib/MC/ELFObjectWriter.cpp | 10 +++++----- llvm/lib/MC/MCAssembler.cpp | 4 ++-- llvm/lib/MC/MachObjectWriter.cpp | 10 +++++----- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/llvm/include/llvm/MC/MCSymbol.h b/llvm/include/llvm/MC/MCSymbol.h index b4b5518..b39c271 100644 --- a/llvm/include/llvm/MC/MCSymbol.h +++ b/llvm/include/llvm/MC/MCSymbol.h @@ -56,9 +56,6 @@ class MCSymbolData { /// additional per symbol information which is not easily classified. uint32_t Flags = 0; - /// Index - Index field, for use by the object file implementation. - uint64_t Index = 0; - public: MCSymbolData() { Offset = 0; } @@ -128,12 +125,6 @@ public: Flags = (Flags & ~Mask) | Value; } - /// getIndex - Get the (implementation defined) index. - uint64_t getIndex() const { return Index; } - - /// setIndex - Set the (implementation defined) index. - void setIndex(uint64_t Value) { Index = Value; } - /// @} void dump() const; @@ -178,6 +169,9 @@ class MCSymbol { mutable bool HasData : 1; mutable MCSymbolData Data; + /// Index field, for use by the object file implementation. + mutable uint64_t Index = 0; + private: // MCContext creates and uniques these. friend class MCExpr; friend class MCContext; @@ -287,6 +281,18 @@ public: /// @} + /// Get the (implementation defined) index. + uint64_t getIndex() const { + assert(HasData && "Uninitialized symbol data"); + return Index; + } + + /// Set the (implementation defined) index. + void setIndex(uint64_t Value) const { + assert(HasData && "Uninitialized symbol data"); + Index = Value; + } + /// print - Print the value to the stream \p OS. void print(raw_ostream &OS) const; diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index cdd6b17..87aacaa 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -858,8 +858,8 @@ void ELFObjectWriter::RecordRelocation(MCAssembler &Asm, uint64_t ELFObjectWriter::getSymbolIndexInSymbolTable(const MCAssembler &Asm, const MCSymbol *S) { - const MCSymbolData &SD = Asm.getSymbolData(*S); - return SD.getIndex(); + assert(S->hasData()); + return S->getIndex(); } bool ELFObjectWriter::isInSymtab(const MCAsmLayout &Layout, @@ -1049,12 +1049,12 @@ void ELFObjectWriter::computeSymbolTable( // symbols with non-local bindings. unsigned Index = FileSymbolData.size() + 1; for (unsigned i = 0, e = LocalSymbolData.size(); i != e; ++i) - LocalSymbolData[i].Symbol->getData().setIndex(Index++); + LocalSymbolData[i].Symbol->setIndex(Index++); for (unsigned i = 0, e = ExternalSymbolData.size(); i != e; ++i) - ExternalSymbolData[i].Symbol->getData().setIndex(Index++); + ExternalSymbolData[i].Symbol->setIndex(Index++); for (unsigned i = 0, e = UndefinedSymbolData.size(); i != e; ++i) - UndefinedSymbolData[i].Symbol->getData().setIndex(Index++); + UndefinedSymbolData[i].Symbol->setIndex(Index++); } MCSectionELF * diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index 481f91f..2c041e2 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -1268,7 +1268,7 @@ void MCSymbolData::dump() const { << " Fragment:" << getFragment(); if (!isCommon()) OS << " Offset:" << getOffset(); - OS << " Flags:" << getFlags() << " Index:" << getIndex(); + OS << " Flags:" << getFlags(); if (isCommon()) OS << " (common, size:" << getCommonSize() << " align: " << getCommonAlignment() << ")"; @@ -1295,7 +1295,7 @@ void MCAssembler::dump() { if (it != symbol_begin()) OS << ",\n "; OS << "("; it->dump(); - OS << ","; + OS << ", Index:" << it->getIndex() << ", "; it->getData().dump(); OS << ")"; } diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp index 759b8c5..1eaf2a9 100644 --- a/llvm/lib/MC/MachObjectWriter.cpp +++ b/llvm/lib/MC/MachObjectWriter.cpp @@ -616,11 +616,11 @@ void MachObjectWriter::ComputeSymbolTable( // Set the symbol indices. Index = 0; for (unsigned i = 0, e = LocalSymbolData.size(); i != e; ++i) - LocalSymbolData[i].Symbol->getData().setIndex(Index++); + LocalSymbolData[i].Symbol->setIndex(Index++); for (unsigned i = 0, e = ExternalSymbolData.size(); i != e; ++i) - ExternalSymbolData[i].Symbol->getData().setIndex(Index++); + ExternalSymbolData[i].Symbol->setIndex(Index++); for (unsigned i = 0, e = UndefinedSymbolData.size(); i != e; ++i) - UndefinedSymbolData[i].Symbol->getData().setIndex(Index++); + UndefinedSymbolData[i].Symbol->setIndex(Index++); for (const MCSectionData &SD : Asm) { std::vector &Relocs = Relocations[&SD]; @@ -629,7 +629,7 @@ void MachObjectWriter::ComputeSymbolTable( continue; // Set the Index and the IsExtern bit. - unsigned Index = Rel.Sym->getData().getIndex(); + unsigned Index = Rel.Sym->getIndex(); assert(isInt<24>(Index)); if (IsLittleEndian) Rel.MRE.r_word1 = (Rel.MRE.r_word1 & (~0U << 24)) | Index | (1 << 27); @@ -982,7 +982,7 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm, } } - Write32(Asm.getSymbolData(*it->Symbol).getIndex()); + Write32(it->Symbol->getIndex()); } // FIXME: Check that offsets match computed ones. -- 2.7.4