diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index 00df02643f7..92b92f1fad1 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -112,6 +112,8 @@ private: uintX_t EntSize; }; + void parseDynamicTable(ArrayRef LoadSegments); + void printSymbolsHelper(bool IsDynamic); void printSymbol(const Elf_Sym *Symbol, const Elf_Shdr *SymTab, StringRef StrTable, bool IsDynamic); @@ -1032,8 +1034,19 @@ ELFDumper::ELFDumper(const ELFFile *Obj, StreamWriter &Writer) } } + parseDynamicTable(LoadSegments); + + if (opts::Output == opts::GNU) + ELFDumperStyle.reset(new GNUStyle(Writer)); + else + ELFDumperStyle.reset(new LLVMStyle(Writer)); +} + +template +void ELFDumper::parseDynamicTable( + ArrayRef LoadSegments) { auto toMappedAddr = [&](uint64_t VAddr) -> const uint8_t * { - const Elf_Phdr **I = std::upper_bound( + const Elf_Phdr *const *I = std::upper_bound( LoadSegments.begin(), LoadSegments.end(), VAddr, compareAddr); if (I == LoadSegments.begin()) report_fatal_error("Virtual address is not in any segment"); @@ -1095,10 +1108,6 @@ ELFDumper::ELFDumper(const ELFFile *Obj, StreamWriter &Writer) DynamicStringTable = StringRef(StringTableBegin, StringTableSize); if (SONameOffset) SOName = getDynamicString(SONameOffset); - if (opts::Output == opts::GNU) - ELFDumperStyle.reset(new GNUStyle(Writer)); - else - ELFDumperStyle.reset(new LLVMStyle(Writer)); } template