summaryrefslogtreecommitdiffstats
path: root/llvm/tools/obj2yaml/elf2yaml.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2015-08-10 21:29:35 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2015-08-10 21:29:35 +0000
commitaae5541455a0251f1e1e55b169c4c6c5fe7a70a3 (patch)
treefaac46391773706e04a40f54be3ac4e459fc8c64 /llvm/tools/obj2yaml/elf2yaml.cpp
parentcc6554361c6cf4150ce3bcb9d1e76b60f85f2821 (diff)
downloadbcm5719-llvm-aae5541455a0251f1e1e55b169c4c6c5fe7a70a3.tar.gz
bcm5719-llvm-aae5541455a0251f1e1e55b169c4c6c5fe7a70a3.zip
Don't iterate over all sections in the ELFFile constructor.
With this we finally have an ELFFile that is O(1) to construct. This is helpful for programs like lld which have to do their own section walk. llvm-svn: 244510
Diffstat (limited to 'llvm/tools/obj2yaml/elf2yaml.cpp')
-rw-r--r--llvm/tools/obj2yaml/elf2yaml.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp
index 214148d41b8..6aea437aba7 100644
--- a/llvm/tools/obj2yaml/elf2yaml.cpp
+++ b/llvm/tools/obj2yaml/elf2yaml.cpp
@@ -26,9 +26,10 @@ class ELFDumper {
typedef typename object::ELFFile<ELFT>::Elf_Word Elf_Word;
const object::ELFFile<ELFT> &Obj;
+ ArrayRef<Elf_Word> ShndxTable;
- std::error_code dumpSymbol(const Elf_Sym *Sym, StringRef StrTable,
- ELFYAML::Symbol &S);
+ std::error_code dumpSymbol(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
+ StringRef StrTable, ELFYAML::Symbol &S);
std::error_code dumpCommonSection(const Elf_Shdr *Shdr, ELFYAML::Section &S);
std::error_code dumpCommonRelocationSection(const Elf_Shdr *Shdr,
ELFYAML::RelocationSection &S);
@@ -81,6 +82,13 @@ ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
case ELF::SHT_SYMTAB:
Symtab = &Sec;
break;
+ case ELF::SHT_SYMTAB_SHNDX: {
+ ErrorOr<ArrayRef<Elf_Word>> TableOrErr = Obj.getSHNDXTable(Sec);
+ if (std::error_code EC = TableOrErr.getError())
+ return EC;
+ ShndxTable = *TableOrErr;
+ break;
+ }
case ELF::SHT_RELA: {
ErrorOr<ELFYAML::RelocationSection *> S = dumpRelaSection(&Sec);
if (std::error_code EC = S.getError())
@@ -139,7 +147,8 @@ ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
}
ELFYAML::Symbol S;
- if (std::error_code EC = ELFDumper<ELFT>::dumpSymbol(&Sym, StrTable, S))
+ if (std::error_code EC =
+ ELFDumper<ELFT>::dumpSymbol(&Sym, Symtab, StrTable, S))
return EC;
switch (Sym.getBinding())
@@ -162,9 +171,9 @@ ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
}
template <class ELFT>
-std::error_code ELFDumper<ELFT>::dumpSymbol(const Elf_Sym *Sym,
- StringRef StrTable,
- ELFYAML::Symbol &S) {
+std::error_code
+ELFDumper<ELFT>::dumpSymbol(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
+ StringRef StrTable, ELFYAML::Symbol &S) {
S.Type = Sym->getType();
S.Value = Sym->st_value;
S.Size = Sym->st_size;
@@ -175,7 +184,7 @@ std::error_code ELFDumper<ELFT>::dumpSymbol(const Elf_Sym *Sym,
return EC;
S.Name = NameOrErr.get();
- ErrorOr<const Elf_Shdr *> ShdrOrErr = Obj.getSection(Sym);
+ ErrorOr<const Elf_Shdr *> ShdrOrErr = Obj.getSection(Sym, SymTab, ShndxTable);
if (std::error_code EC = ShdrOrErr.getError())
return EC;
const Elf_Shdr *Shdr = *ShdrOrErr;
OpenPOWER on IntegriCloud