[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 04:12:19 PDT 2018


grimar added inline comments.


================
Comment at: tools/llvm-readobj/ELFDumper.cpp:2478-2479
+    return to_string(ElfHeader->e_shnum);
+  const typename ELFFile<ELFT>::Elf_Shdr *Sec = unwrapOrError(Obj->getSection(0));
+  return "0 (" + to_string(Sec->sh_size) + ")";
+}
----------------
jhenderson wrote:
> What about the situation where a file has no section headers? This will crash, I think. Please fix and add a test for this case. I think if e_shnum is zero, you need to check e_shoff to see if it has a non-zero value to decide if there are section headers.
It would report "Error reading file: invalid section index" actually (because 'unwrapOrError' catches and reports an error and exit() then). It still was an issue though. Fixed, added test case.


================
Comment at: tools/llvm-readobj/ELFDumper.cpp:2487
+    return to_string(ElfHeader->e_shstrndx);
+  const typename ELFFile<ELFT>::Elf_Shdr *Sec = unwrapOrError(Obj->getSection(0));
+  return to_string(ElfHeader->e_shstrndx) + " (" + to_string(Sec->sh_link) + ")";
----------------
jhenderson wrote:
> Again, what happens if there are no section headers here? In this case, the object is malformed, and we should probably report an error or warning, but still write the actual value in the field.
I am printing "corrupt: out of range" here, it what readelf do.


https://reviews.llvm.org/D49369





More information about the llvm-commits mailing list