[PATCH] D92098: [obj2yaml] - Don't crash when dumping an object with no sections.

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 26 01:10:31 PST 2020


jhenderson added inline comments.


================
Comment at: llvm/test/tools/obj2yaml/ELF/eshnum.yaml:15-20
+# CHECK:      --- !ELF
+# CHECK-NEXT: FileHeader:
+# CHECK-NEXT:   Class: ELFCLASS64
+# CHECK-NEXT:   Data:  ELFDATA2LSB
+# CHECK-NEXT:   Type:  ET_REL
+# CHECK-NEXT: ...
----------------
If you feed this output of obj2yaml back into yaml2obj, the final object doesn't really reflect what you had originally - it generates three section headers (.strtab and .shstrtab, plus the null one). Seems like we need to fix something, but not entirely sure what.


================
Comment at: llvm/tools/obj2yaml/elf2yaml.cpp:238
                                ArrayRef<ELFYAML::ProgramHeader> Phdrs,
                                std::vector<std::unique_ptr<ELFYAML::Chunk>> &V,
                                ArrayRef<typename ELFT::Shdr> S) {
----------------
grimar wrote:
> grimar wrote:
> > jhenderson wrote:
> > > I take it `V` doesn't normally contain a chunk for the null (index 0) section header?
> > `V` contains all sections that are dumped from an object. The `SHT_NULL` section is
> > normally present, it dumped as a regular section, and so `V` usually contains it. This is assumed below:
> > 
> > ```
> >   for (const std::unique_ptr<ELFYAML::Chunk> &C :
> >        makeArrayRef(V).drop_front()) {
> > ```
> > 
> > In the case revealed by this patch we have no section header and no sections are dumped,
> > that's why `V` is empty.
> "we have no section header" -> "we have 0 sections"
You've lost me a little. In the case when e_shnum and sh_size of section table index 0 are both 0, obj2yaml doesn't populate `V` with anything? So there is a section header table, it's just that no sections are read, because we say there are none. Is that right?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92098/new/

https://reviews.llvm.org/D92098



More information about the llvm-commits mailing list