[PATCH] D93697: [obj2yaml] - Don't crash when an object has an empty symbol table.

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 22 09:14:20 PST 2020


MaskRay added a comment.

According to http://www.sco.com/developers/gabi/latest/ch4.symtab.html , an empty SHT_SYMTAB/SHT_DYNSYM is non-conforming.

1. I think `Optional<std::vector<ELFYAML::Symbol>>` and various emplace is to get rid of `Symbols:  []` when the size is 0. Can we just print `Symbols: []` along with `Size: 0`? From `Size: 0` it should be clear there is no (normally implicit) index 0.
2. If yaml2obj is going to support multiple symbol tables, what will the display style be like? The use cases are narrow but raising this may helps think about how point 1 should be handled.



================
Comment at: llvm/test/tools/obj2yaml/ELF/no-symtab.yaml:41
+
+## Normally symbol tables can't be empty because of the first null
+## entry they contain. Check we dump them when they are.
----------------
A symbol table without index 0 is non-conforming, according to http://www.sco.com/developers/gabi/latest/ch4.symtab.html


================
Comment at: llvm/tools/obj2yaml/elf2yaml.cpp:230
+  // We also dump symbol tables when the Size field is set. It happens when they
+  // are empty, what normally should not happen.
   if (S.Type == ELF::SHT_STRTAB || S.Type == ELF::SHT_SYMTAB ||
----------------
It happens with the non-conforming empty case.


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

https://reviews.llvm.org/D93697



More information about the llvm-commits mailing list