This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readelf] - Don't crash when e_shstrndx=SHN_XINDEX, but there is no section header.
ClosedPublic

Authored by grimar on Jun 23 2020, 6:03 AM.

Details

Summary

Currently we crash when trying to print --sections and the SHN_XINDEX escape value
is used for the e_shstrndx field, but there is no section header at index 0 to
read the value from.

Diff Detail

Event Timeline

grimar created this revision.Jun 23 2020, 6:03 AM
Herald added a project: Restricted Project. · View Herald Transcript
MaskRay accepted this revision.Jun 23 2020, 11:04 AM

Thanks!

llvm/include/llvm/Object/ELF.h
521

Considering using the ELF spec wording:

... the actual index of the section name string table section is contained in the sh_link field of the section header at index 0.

This revision is now accepted and ready to land.Jun 23 2020, 11:04 AM
jhenderson accepted this revision.Jun 24 2020, 1:15 AM

LGTM, aside from the nit, I think my other comments are probably best left for another patch.

llvm/include/llvm/Object/ELF.h
526

Nit: either e_shstrndx == SHN_XINDEX or e_shstrndx is SHN_XINDEX

llvm/test/tools/llvm-readobj/ELF/many-sections.s
46

This being an error rather than a warning is a bit surprising, given that it would be trivial to treat the behaviour as no string table instead. I take it that's a different patch of code that would need changing though.

53–54

In a similar manner, the lack of a warning here is surprising.

This revision was automatically updated to reflect the committed changes.
grimar marked 2 inline comments as done.