]> granicus.if.org Git - llvm/commitdiff
[llvm-readobj] - Do not report invalid amount of sections.
authorGeorge Rimar <grimar@accesssoftek.com>
Thu, 19 Jul 2018 14:52:57 +0000 (14:52 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Thu, 19 Jul 2018 14:52:57 +0000 (14:52 +0000)
When output style is GNU and amount of sections is >= SHN_LORESERVE,
llvm-readobj reports zero number of sections instead of actual value.

The patch fixes that.

Differential revision: https://reviews.llvm.org/D49544

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337462 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/llvm-readobj/many-sections.s
tools/llvm-readobj/ELFDumper.cpp

index 383df2661390361e3e9655df1dd8b32b882ec2e8..053dbbf9fb736027944a887c430d8091f69bbd3b 100644 (file)
 ## space, but its e_shnum, e_shstrndx, sh_size and sh_link fields are set
 ## according to the above description, so that we can test the dumper.
 
-# RUN: llvm-readobj -file-headers -elf-output-style GNU \
+# RUN: llvm-readobj -file-headers -sections -elf-output-style GNU \
 # RUN:   %p/Inputs/many-sections.elf-x86_64 | FileCheck %s --check-prefix=GNU1
 # GNU1: Number of section headers:         0 (5)
 # GNU1: Section header string table index: 65535 (3)
+# GNU1: There are 5 section headers, starting at offset 0xb8
 
 # RUN: llvm-readobj -file-headers -elf-output-style LLVM \
 # RUN:   %p/Inputs/many-sections.elf-x86_64 | FileCheck %s --check-prefix=LLVM1
index 951bc60108fb9b8947e8bd3ea9fa1d0fa6a7e783..5da66c4a6d86a33f4fdf16cc3d058b041392dad7 100644 (file)
@@ -2904,7 +2904,9 @@ template <class ELFT> void GNUStyle<ELFT>::printSections(const ELFO *Obj) {
     Bias = 8;
     Width = 8;
   }
-  OS << "There are " << to_string(Obj->getHeader()->e_shnum)
+
+  ArrayRef<Elf_Shdr> Sections = unwrapOrError(Obj->sections());
+  OS << "There are " << to_string(Sections.size())
      << " section headers, starting at offset "
      << "0x" << to_hexString(Obj->getHeader()->e_shoff, false) << ":\n\n";
   OS << "Section Headers:\n";
@@ -2923,7 +2925,7 @@ template <class ELFT> void GNUStyle<ELFT>::printSections(const ELFO *Obj) {
     printField(f);
   OS << "\n";
 
-  for (const Elf_Shdr &Sec : unwrapOrError(Obj->sections())) {
+  for (const Elf_Shdr &Sec : Sections) {
     Number = to_string(SectionIndex);
     Fields[0].Str = Number;
     Fields[1].Str = unwrapOrError(Obj->getSectionName(&Sec));