From be9635569401b9a40984c02c6e171aa9da9ad0a2 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Wed, 26 Aug 2009 13:57:54 +0000 Subject: [PATCH] llvm-mc/Mach-O: Move symbol indices into the MCSymbolData structure. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80088 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCAssembler.h | 13 +++++++++++-- lib/MC/MCAssembler.cpp | 34 +++++++++++++--------------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/include/llvm/MC/MCAssembler.h b/include/llvm/MC/MCAssembler.h index 0da729b3eeb..74a4748658b 100644 --- a/include/llvm/MC/MCAssembler.h +++ b/include/llvm/MC/MCAssembler.h @@ -286,7 +286,7 @@ public: unsigned getAlignment() const { return Alignment; } void setAlignment(unsigned Value) { Alignment = Value; } - /// @name Section List Access + /// @name Fragment Access /// @{ const FragmentListType &getFragmentList() const { return Fragments; } @@ -324,7 +324,7 @@ public: assert(FileSize != ~UINT64_C(0) && "File size not set!"); return FileSize; } - void setFileSize(uint64_t Value) { FileSize = Value; } + void setFileSize(uint64_t Value) { FileSize = Value; } /// @} }; @@ -352,6 +352,9 @@ public: /// additional per symbol information which is not easily classified. uint32_t Flags; + /// Index - Index field, for use by the object file implementation. + uint64_t Index; + public: // Only for use as sentinel. MCSymbolData(); @@ -385,6 +388,12 @@ public: /// setFlags - Set the (implementation defined) symbol flags. void setFlags(uint32_t Value) { Flags = 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; } + /// @} }; diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 26f6d5c9c7d..a9bbfa17e10 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -333,7 +333,7 @@ public: } void BindIndirectSymbols(MCAssembler &Asm, - DenseMap &SymbolMap) { + DenseMap &SymbolMap) { // This is the point where 'as' creates actual symbols for indirect symbols // (in the following two passes). It would be easier for us to do this // sooner when we see the attribute, but that makes getting the order in the @@ -475,6 +475,15 @@ public: std::sort(ExternalSymbolData.begin(), ExternalSymbolData.end()); std::sort(UndefinedSymbolData.begin(), UndefinedSymbolData.end()); + // Set the symbol indices. + Index = 0; + for (unsigned i = 0, e = LocalSymbolData.size(); i != e; ++i) + LocalSymbolData[i].SymbolData->setIndex(Index++); + for (unsigned i = 0, e = ExternalSymbolData.size(); i != e; ++i) + ExternalSymbolData[i].SymbolData->setIndex(Index++); + for (unsigned i = 0, e = UndefinedSymbolData.size(); i != e; ++i) + UndefinedSymbolData[i].SymbolData->setIndex(Index++); + // The string table is padded to a multiple of 4. // // FIXME: Check to see if this varies per arch. @@ -488,7 +497,7 @@ public: // Compute the symbol -> symbol data map. // // FIXME: This should not be here. - DenseMap SymbolMap; + DenseMap SymbolMap; for (MCAssembler::symbol_iterator it = Asm.symbol_begin(), ie = Asm.symbol_end(); it != ie; ++it) SymbolMap[&it->getSymbol()] = it; @@ -576,24 +585,7 @@ public: // Write the symbol table data, if used. if (NumSymbols) { - // FIXME: We shouldn't need this index table. - DenseMap SymbolIndexMap; - for (unsigned i = 0, e = LocalSymbolData.size(); i != e; ++i) { - MCSymbol &Symbol = LocalSymbolData[i].SymbolData->getSymbol(); - SymbolIndexMap.insert(std::make_pair(&Symbol, SymbolIndexMap.size())); - } - for (unsigned i = 0, e = ExternalSymbolData.size(); i != e; ++i) { - MCSymbol &Symbol = ExternalSymbolData[i].SymbolData->getSymbol(); - SymbolIndexMap.insert(std::make_pair(&Symbol, SymbolIndexMap.size())); - } - for (unsigned i = 0, e = UndefinedSymbolData.size(); i != e; ++i) { - MCSymbol &Symbol = UndefinedSymbolData[i].SymbolData->getSymbol(); - SymbolIndexMap.insert(std::make_pair(&Symbol, SymbolIndexMap.size())); - } - // Write the indirect symbol entries. - // - // FIXME: We need the symbol index map for this. for (MCAssembler::indirect_symbol_iterator it = Asm.indirect_symbol_begin(), ie = Asm.indirect_symbol_end(); it != ie; ++it) { @@ -615,7 +607,7 @@ public: } } - Write32(SymbolIndexMap[it->Symbol]); + Write32(SymbolMap[it->Symbol]->getIndex()); } // FIXME: Check that offsets match computed ones. @@ -678,7 +670,7 @@ MCSymbolData::MCSymbolData() : Symbol(*(MCSymbol*)0) {} MCSymbolData::MCSymbolData(MCSymbol &_Symbol, MCFragment *_Fragment, uint64_t _Offset, MCAssembler *A) : Symbol(_Symbol), Fragment(_Fragment), Offset(_Offset), - IsExternal(false), IsPrivateExtern(false), Flags(0) + IsExternal(false), IsPrivateExtern(false), Flags(0), Index(0) { if (A) A->getSymbolList().push_back(this); -- 2.34.1