[PATCH] D49369: [llvm-readobj] - Teach tool to dump objects with >= SHN_LORESERVE of sections.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 17 06:40:34 PDT 2018


grimar added inline comments.


================
Comment at: tools/llvm-readobj/ELFDumper.cpp:2492-2493
+  ArrayRef<typename ELFT::Shdr> Arr = unwrapOrError(Obj->sections());
+  if (Arr.empty())
+    return "0 (corrupt: out of range)";
+  return to_string(ElfHeader->e_shstrndx) + " (" + to_string(Arr[0].sh_link) + ")";
----------------
jhenderson wrote:
> I'm not seeing this behaviour in readelf? If there are no section headers, I just get a value of 0 for the section header string table index, and no warning. A non-zero value on the other hand, when there are no sections (or indeed any value outside that range) does give me that error.
I tested many-sections-stripped.elf-x86_64
(shared it here: https://drive.google.com/open?id=1HgUSb15a6WQY_lwMIUCDXBxD25VX8I-S)
which has e_shoff set to zero. And it has e_shstrndx == SHN_XINDEX.

It reports the following for me:

```
readelf -v
GNU readelf (GNU Binutils for Ubuntu) 2.28
...

readelf -a many-sections-stripped.elf-x86_64 
ELF Header:
...
  Number of section headers:         0
  Section header string table index: 65535 <corrupt: out of range>
```

I think when we have e_shstrndx == SHN_XINDEX, we expect that "The actual number of section header table entries is contained in the sh_size field of the section header at index 0". And since actual number is always > 0 ("If the number of sections is greater than or equal to SHN_LORESERVE...").
(https://docs.oracle.com/cd/E19120-01/open.solaris/819-0690/chapter6-43405/index.html),
we are fine reporting "out of range" here when having no sections. Isn't that look valid behavior?



https://reviews.llvm.org/D49369





More information about the llvm-commits mailing list