This is an archive of the discontinued LLVM Phabricator instance.

[Object/ELF] - Allow to parse files with e_shstrndx set to SHN_UNDEF
AbandonedPublic

Authored by grimar on Jan 11 2017, 6:09 AM.

Details

Reviewers
davide
rafael
Summary

According to specification,

e_shstrndx
The section header table index of the entry that is associated with the section name string table. If the file has no section name string table, this member holds the value SHN_UNDEF.

Previously objdump just reported error on such files. Though gnu readelf is able to parse them, below
is sample output from readelf:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 0] <no-name>         NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] <no-name>         PROGBITS        0000000000000000 001000 00000e 00  AX  0   0  4
  [ 2] <no-name>         PROGBITS        000000000000000e 00100e 000020 00  WA  0   0  1
  [ 3] <no-name>         PROGBITS        000000000000002e 00102e 000003 00  WA  0   0  1
  [ 4] <no-name>         NOBITS          0000000000000031 001031 000002 00  WA  0   0  1
  [ 5] <no-name>         PROGBITS        0000000000000000 001031 000008 01  MS  0   0  1
  [ 6] <no-name>         SYMTAB          0000000000000000 001040 000030 18      7   1  8
  [ 7] <no-name>         STRTAB          0000000000000000 001070 000008 00      0   0  1

Diff Detail

Event Timeline

grimar updated this revision to Diff 83966.Jan 11 2017, 6:09 AM
grimar retitled this revision from to [Object/ELF] - Allow to parse files with e_shstrndx set to SHN_UNDEF.
grimar updated this object.
grimar added reviewers: rafael, davide.
grimar added subscribers: llvm-commits, grimar, evgeny777.

I am using this in one of patches for LLD, will add link shortly.

emaste added a subscriber: emaste.Jan 11 2017, 7:15 AM

I think this LGTM but I'm curious if !Index was just from a misunderstanding, or if @rafael encountered an object with e_shstrndx == 0?

grimar added a comment.EditedJan 11 2017, 7:25 AM

I think this LGTM but I'm curious if !Index was just from a misunderstanding, or if @rafael encountered an object with e_shstrndx == 0?

ELF::SHN_UNDEF has int value 0, I just replaced it with enum constant to make code more clear.

grimar abandoned this revision.Jan 13 2017, 8:33 AM

LLD does not allow to discard .shstrtab anymore. That was the only known producer.
+ seems it is anyways incorrect to have offset set for name when there is no .shstrtab in file
(though readelf is able to parse such files).