This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by grimar on Dec 22 2020, 6:44 AM.

Details

Summary

Currently we crash when we have an object with SHT_SYMTAB/SHT_DYNSYM sections
of size 0.

With this patch instead of the crash we start to dump them properly.

Diff Detail

Event Timeline

grimar created this revision.Dec 22 2020, 6:44 AM
grimar requested review of this revision.Dec 22 2020, 6:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 22 2020, 6:44 AM

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.
llvm/test/tools/obj2yaml/ELF/no-symtab.yaml
41

A symbol table without index 0 is non-conforming, according to http://www.sco.com/developers/gabi/latest/ch4.symtab.html

llvm/tools/obj2yaml/elf2yaml.cpp
223

It happens with the non-conforming empty case.

grimar added a comment.EditedDec 22 2020, 11:21 PM
  1. I think Optional<std::vector<ELFYAML::Symbol>> and various emplace is to get rid of Symbols: [] when the size is 0.

Right.

Can we just print Symbols: [] along with Size: 0? From Size: 0 it should be clear there is no (normally implicit) index 0.

No, because yaml2obj doesn't accept "Symbols" and "Size" together. "Symbols: []" means we have a zero entry actually.

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.

I guess we will need to get rid of "Symbols" and "DynamicSymbols" tags and move these keys to corresponding sections.

jhenderson added inline comments.Jan 4 2021, 1:22 AM
llvm/tools/obj2yaml/elf2yaml.cpp
223
MaskRay accepted this revision.Jan 4 2021, 10:08 AM
This revision is now accepted and ready to land.Jan 4 2021, 10:08 AM
grimar updated this revision to Diff 315769.Jan 11 2021, 5:31 AM
grimar marked 3 inline comments as done.
  • Updated code and test case comments to address suggestions from reviewers.