Don't do a walk over the dynamic table just to find DT_SONAME.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242752 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2015-07-21 01:01:29 +00:00
parent 052b66199d
commit 04d208815c

View File

@ -198,9 +198,8 @@ private:
DynRegionInfo DynStrRegion; DynRegionInfo DynStrRegion;
DynRegionInfo DynRelaRegion; DynRegionInfo DynRelaRegion;
// Pointer to SONAME entry in dynamic string table // SONAME entry in dynamic string table
// This is set the first time getLoadName is called. StringRef DTSoname;
mutable const char *dt_soname = nullptr;
// Records for each version index the corresponding Verdef or Vernaux entry. // Records for each version index the corresponding Verdef or Vernaux entry.
// This is filled the first time LoadVersionMap() is called. // This is filled the first time LoadVersionMap() is called.
@ -749,6 +748,7 @@ template <class ELFT> void ELFFile<ELFT>::scanDynamicTable() {
return this->base() + Phdr.p_offset + Delta; return this->base() + Phdr.p_offset + Delta;
}; };
uint64_t SONameOffset = 0;
for (const Elf_Dyn &Dyn : dynamic_table()) { for (const Elf_Dyn &Dyn : dynamic_table()) {
switch (Dyn.d_tag) { switch (Dyn.d_tag) {
case ELF::DT_HASH: case ELF::DT_HASH:
@ -774,8 +774,14 @@ template <class ELFT> void ELFFile<ELFT>::scanDynamicTable() {
break; break;
case ELF::DT_RELAENT: case ELF::DT_RELAENT:
DynRelaRegion.EntSize = Dyn.getVal(); DynRelaRegion.EntSize = Dyn.getVal();
break;
case ELF::DT_SONAME:
SONameOffset = Dyn.getVal();
break;
} }
} }
if (SONameOffset)
DTSoname = getDynamicString(SONameOffset);
} }
template <class ELFT> template <class ELFT>
@ -826,16 +832,7 @@ ELFFile<ELFT>::dynamic_table_end() const {
template <class ELFT> template <class ELFT>
StringRef ELFFile<ELFT>::getLoadName() const { StringRef ELFFile<ELFT>::getLoadName() const {
if (!dt_soname) { return DTSoname;
dt_soname = "";
// Find the DT_SONAME entry
for (const auto &Entry : dynamic_table())
if (Entry.getTag() == ELF::DT_SONAME) {
dt_soname = getDynamicString(Entry.getVal());
break;
}
}
return dt_soname;
} }
template <class ELFT> template <class ELFT>