forked from OSchip/llvm-project
[lld][ELF] (no testable functionality change) resize the number of entries in the string table for static linking
llvm-svn: 180691
This commit is contained in:
parent
45a5f93517
commit
d846d9852e
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue