[lld] r180691 - [lld][ELF] (no testable functionality change) resize the number of entries in the string table for static linking
Shankar Easwaran
shankare at codeaurora.org
Sun Apr 28 21:10:11 PDT 2013
Author: shankare
Date: Sun Apr 28 23:10:11 2013
New Revision: 180691
URL: http://llvm.org/viewvc/llvm-project?rev=180691&view=rev
Log:
[lld][ELF] (no testable functionality change) resize the number of entries in the string table for static linking
Modified:
lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h
lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
Modified: lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h?rev=180691&r1=180690&r2=180691&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h Sun Apr 28 23:10:11 2013
@@ -58,7 +58,7 @@ protected:
// Build the atom to address map, this has to be called
// before applying relocations
- virtual void buildAtomToAddressMap();
+ virtual void buildAtomToAddressMap(const File &file);
// Build the symbol table for static linking
virtual void buildStaticSymbolTable(const File &file);
@@ -167,14 +167,25 @@ void OutputELFWriter<ELFT>::buildDynamic
_dynamicSymbolTable->addSymbolsToHashTable();
}
-template <class ELFT> void OutputELFWriter<ELFT>::buildAtomToAddressMap() {
+template <class ELFT>
+void OutputELFWriter<ELFT>::buildAtomToAddressMap(const File &file) {
+ int64_t totalAbsAtoms = _layout->absoluteAtoms().size();
+ int64_t totalUndefinedAtoms = file.undefined().size();
+ int64_t totalDefinedAtoms = 0;
for (auto sec : _layout->sections())
- if (auto section = dyn_cast<AtomSection<ELFT>>(sec))
+ if (auto section = dyn_cast<AtomSection<ELFT> >(sec)) {
+ totalDefinedAtoms += section->atoms().size();
for (const auto &atom : section->atoms())
_atomToAddressMap[atom->_atom] = atom->_virtualAddr;
+ }
// build the atomToAddressMap that contains absolute symbols too
for (auto &atom : _layout->absoluteAtoms())
_atomToAddressMap[atom->_atom] = atom->_virtualAddr;
+
+ // Set the total number of atoms in the symbol table, so that appropriate
+ // resizing of the string table can be done
+ _symtab->setNumEntries(totalDefinedAtoms + totalAbsAtoms +
+ totalUndefinedAtoms);
}
template<class ELFT>
@@ -287,7 +298,7 @@ error_code OutputELFWriter<ELFT>::buildO
finalizeDefaultAtomValues();
// Build the Atom To Address map for applying relocations
- buildAtomToAddressMap();
+ buildAtomToAddressMap(file);
// Create symbol table and section string table
buildStaticSymbolTable(file);
Modified: lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h?rev=180691&r1=180690&r2=180691&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h Sun Apr 28 23:10:11 2013
@@ -510,6 +510,10 @@ public:
virtual void write(ELFWriter *writer, llvm::FileOutputBuffer &buffer);
+ inline void setNumEntries(int64_t numEntries) {
+ _stringMap.resize(numEntries);
+ }
+
private:
std::vector<StringRef> _strings;
@@ -597,8 +601,15 @@ class SymbolTable : public Section<ELFT>
public:
SymbolTable(const ELFTargetInfo &ti, const char *str, int32_t order);
- void addSymbol(const Atom *atom, int32_t sectionIndex,
- uint64_t addr = 0, const AtomLayout *layout=nullptr);
+ /// \brief set the number of entries that would exist in the symbol
+ /// table for the current link
+ void setNumEntries(int64_t numEntries) const {
+ if (_stringSection)
+ _stringSection->setNumEntries(numEntries);
+ }
+
+ void addSymbol(const Atom *atom, int32_t sectionIndex, uint64_t addr = 0,
+ const AtomLayout *layout = nullptr);
/// \brief Get the symbol table index for an Atom. If it's not in the symbol
/// table, return STN_UNDEF.
More information about the llvm-commits
mailing list