summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter
diff options
context:
space:
mode:
authorShankar Easwaran <shankare@codeaurora.org>2013-04-29 04:10:11 +0000
committerShankar Easwaran <shankare@codeaurora.org>2013-04-29 04:10:11 +0000
commitd846d9852e4fd63215ee3c24e048aba5bc0a87ab (patch)
tree3ac1d5c1e9af7c4850b7c43eba049973ac0311b4 /lld/lib/ReaderWriter
parent45a5f93517eead76b1f88be15958ff55a1e119f2 (diff)
downloadbcm5719-llvm-d846d9852e4fd63215ee3c24e048aba5bc0a87ab.tar.gz
bcm5719-llvm-d846d9852e4fd63215ee3c24e048aba5bc0a87ab.zip
[lld][ELF] (no testable functionality change) resize the number of entries in the string table for static linking
llvm-svn: 180691
Diffstat (limited to 'lld/lib/ReaderWriter')
-rw-r--r--lld/lib/ReaderWriter/ELF/OutputELFWriter.h19
-rw-r--r--lld/lib/ReaderWriter/ELF/SectionChunks.h15
2 files changed, 28 insertions, 6 deletions
diff --git a/lld/lib/ReaderWriter/ELF/OutputELFWriter.h b/lld/lib/ReaderWriter/ELF/OutputELFWriter.h
index 40f14bb5f03..7a3fedb5100 100644
--- a/lld/lib/ReaderWriter/ELF/OutputELFWriter.h
+++ b/lld/lib/ReaderWriter/ELF/OutputELFWriter.h
@@ -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>::buildDynamicSymbolTable(const File &file) {
_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>::buildOutput(const File &file) {
finalizeDefaultAtomValues();
// Build the Atom To Address map for applying relocations
- buildAtomToAddressMap();
+ buildAtomToAddressMap(file);
// Create symbol table and section string table
buildStaticSymbolTable(file);
diff --git a/lld/lib/ReaderWriter/ELF/SectionChunks.h b/lld/lib/ReaderWriter/ELF/SectionChunks.h
index 8237529629f..89d313fa902 100644
--- a/lld/lib/ReaderWriter/ELF/SectionChunks.h
+++ b/lld/lib/ReaderWriter/ELF/SectionChunks.h
@@ -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.
OpenPOWER on IntegriCloud