diff options
| author | George Rimar <grimar@accesssoftek.com> | 2018-07-18 08:19:58 +0000 |
|---|---|---|
| committer | George Rimar <grimar@accesssoftek.com> | 2018-07-18 08:19:58 +0000 |
| commit | 6fdac3b23ad9229c953a0cede9c01af6c5605792 (patch) | |
| tree | 41b1c8d67ca734736de9796e46849d5eba2157c4 /llvm/tools/llvm-readobj | |
| parent | ad50ae82ad4dafefdaf0779258bf164d5687e984 (diff) | |
| download | bcm5719-llvm-6fdac3b23ad9229c953a0cede9c01af6c5605792.tar.gz bcm5719-llvm-6fdac3b23ad9229c953a0cede9c01af6c5605792.zip | |
[llvm-readobj] - Teach tool to dump objects with >= SHN_LORESERVE of sections.
http://www.sco.com/developers/gabi/2003-12-17/ch4.eheader.html
says that e_shnum and/or e_shstrndx may have special values if
"the number of sections is greater than or equal to SHN_LORESERVE" or
"the section name string table section index is greater than or equal to SHN_LORESERVE (0xff00)"
Previously llvm-readobj was unable to dump such files, patch changes that.
I had to add a precompiled test case because it does not seem possible to
prepare a test using yaml2obj or llvm-mc (not clear how to make .shstrtab
to have index >= SHN_LORESERVE).
Differential revision: https://reviews.llvm.org/D49369
llvm-svn: 337360
Diffstat (limited to 'llvm/tools/llvm-readobj')
| -rw-r--r-- | llvm/tools/llvm-readobj/ELFDumper.cpp | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index 130c19cc888..db551de274f 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -2486,6 +2486,30 @@ static inline void printFields(formatted_raw_ostream &OS, StringRef Str1, OS.flush(); } +template <class ELFT> +static std::string getSectionHeadersNumString(const ELFFile<ELFT> *Obj) { + const typename ELFT::Ehdr *ElfHeader = Obj->getHeader(); + if (ElfHeader->e_shnum != 0) + return to_string(ElfHeader->e_shnum); + + ArrayRef<typename ELFT::Shdr> Arr = unwrapOrError(Obj->sections()); + if (Arr.empty()) + return "0"; + return "0 (" + to_string(Arr[0].sh_size) + ")"; +} + +template <class ELFT> +static std::string getSectionHeaderTableIndexString(const ELFFile<ELFT> *Obj) { + const typename ELFT::Ehdr *ElfHeader = Obj->getHeader(); + if (ElfHeader->e_shstrndx != SHN_XINDEX) + return to_string(ElfHeader->e_shstrndx); + + ArrayRef<typename ELFT::Shdr> Arr = unwrapOrError(Obj->sections()); + if (Arr.empty()) + return "65535 (corrupt: out of range)"; + return to_string(ElfHeader->e_shstrndx) + " (" + to_string(Arr[0].sh_link) + ")"; +} + template <class ELFT> void GNUStyle<ELFT>::printFileHeaders(const ELFO *Obj) { const Elf_Ehdr *e = Obj->getHeader(); OS << "ELF Header:\n"; @@ -2531,9 +2555,9 @@ template <class ELFT> void GNUStyle<ELFT>::printFileHeaders(const ELFO *Obj) { printFields(OS, "Number of program headers:", Str); Str = to_string(e->e_shentsize) + " (bytes)"; printFields(OS, "Size of section headers:", Str); - Str = to_string(e->e_shnum); + Str = getSectionHeadersNumString(Obj); printFields(OS, "Number of section headers:", Str); - Str = to_string(e->e_shstrndx); + Str = getSectionHeaderTableIndexString(Obj); printFields(OS, "Section header string table index:", Str); } @@ -4019,8 +4043,8 @@ template <class ELFT> void LLVMStyle<ELFT>::printFileHeaders(const ELFO *Obj) { W.printNumber("ProgramHeaderEntrySize", e->e_phentsize); W.printNumber("ProgramHeaderCount", e->e_phnum); W.printNumber("SectionHeaderEntrySize", e->e_shentsize); - W.printNumber("SectionHeaderCount", e->e_shnum); - W.printNumber("StringTableSectionIndex", e->e_shstrndx); + W.printString("SectionHeaderCount", getSectionHeadersNumString(Obj)); + W.printString("StringTableSectionIndex", getSectionHeaderTableIndexString(Obj)); } } |

