[llvm] r242752 - Don't do a walk over the dynamic table just to find DT_SONAME.
Rafael Espindola
rafael.espindola at gmail.com
Mon Jul 20 18:01:30 PDT 2015
Author: rafael
Date: Mon Jul 20 20:01:29 2015
New Revision: 242752
URL: http://llvm.org/viewvc/llvm-project?rev=242752&view=rev
Log:
Don't do a walk over the dynamic table just to find DT_SONAME.
Modified:
llvm/trunk/include/llvm/Object/ELF.h
Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=242752&r1=242751&r2=242752&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Mon Jul 20 20:01:29 2015
@@ -198,9 +198,8 @@ private:
DynRegionInfo DynStrRegion;
DynRegionInfo DynRelaRegion;
- // Pointer to SONAME entry in dynamic string table
- // This is set the first time getLoadName is called.
- mutable const char *dt_soname = nullptr;
+ // SONAME entry in dynamic string table
+ StringRef DTSoname;
// Records for each version index the corresponding Verdef or Vernaux entry.
// This is filled the first time LoadVersionMap() is called.
@@ -749,6 +748,7 @@ template <class ELFT> void ELFFile<ELFT>
return this->base() + Phdr.p_offset + Delta;
};
+ uint64_t SONameOffset = 0;
for (const Elf_Dyn &Dyn : dynamic_table()) {
switch (Dyn.d_tag) {
case ELF::DT_HASH:
@@ -774,8 +774,14 @@ template <class ELFT> void ELFFile<ELFT>
break;
case ELF::DT_RELAENT:
DynRelaRegion.EntSize = Dyn.getVal();
+ break;
+ case ELF::DT_SONAME:
+ SONameOffset = Dyn.getVal();
+ break;
}
}
+ if (SONameOffset)
+ DTSoname = getDynamicString(SONameOffset);
}
template <class ELFT>
@@ -826,16 +832,7 @@ ELFFile<ELFT>::dynamic_table_end() const
template <class ELFT>
StringRef ELFFile<ELFT>::getLoadName() const {
- if (!dt_soname) {
- 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;
+ return DTSoname;
}
template <class ELFT>
More information about the llvm-commits
mailing list