This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readelf/llvm-readobj] - Test the case when e_shstrndx==SHN_XINDEX, but sec[0].sh_link is broken.
AbandonedPublic

Authored by grimar on Jul 29 2019, 2:51 AM.

Details

Summary

When e_shstrndx is equal to SHN_XINDEX,
the index of the section string table section should
be taken from zero section sh_link field.
If sh_link is broken, e.g. contains an index that is
larger than number of sections, then error is reported.

This error message was untested before.

Diff Detail

Event Timeline

grimar created this revision.Jul 29 2019, 2:51 AM

It seems to me like the code here and the equivalent code in D65391 are basically identical and should be deduplicated, to avoid the need for two different test cases. Could you merge the two, by adding a "CheckType" parameter or similar to the getSectionName code in ELF.h? I was completely independently looking at this myself, after running into an issue with this code relating to some local patches we have, caused by the code duplication.

It seems to me like the code here and the equivalent code in D65391 are basically identical and should be deduplicated, to avoid the need for two different test cases. Could you merge the two, by adding a "CheckType" parameter or similar to the getSectionName code in ELF.h? I was completely independently looking at this myself, after running into an issue with this code relating to some local patches we have, caused by the code duplication.

This duplication was introduced in D63266. The intention was to skip non-critical errors to allow readelf to dump things.
I though about this and possible similar situations today too, btw. My idea was to add some kind of error policy for stuff in ELF.h.
For example ERR_MODE_STRICT which would act as now, reporting everything, and mode ERR_MODE_DUMP which dumpers and tools
like obj2yaml could use (obj2yaml can win from relaxing the error checking a lot).
I had no chance to investigate this, can take a look closer tomorrow.

This duplication was introduced in D63266. The intention was to skip non-critical errors to allow readelf to dump things.
I though about this and possible similar situations today too, btw. My idea was to add some kind of error policy for stuff in ELF.h.
For example ERR_MODE_STRICT which would act as now, reporting everything, and mode ERR_MODE_DUMP which dumpers and tools
like obj2yaml could use (obj2yaml can win from relaxing the error checking a lot).
I had no chance to investigate this, can take a look closer tomorrow.

Thanks, that sounds like a good plan to explore to me.

This duplication was introduced in D63266. The intention was to skip non-critical errors to allow readelf to dump things.
I though about this and possible similar situations today too, btw. My idea was to add some kind of error policy for stuff in ELF.h.
For example ERR_MODE_STRICT which would act as now, reporting everything, and mode ERR_MODE_DUMP which dumpers and tools
like obj2yaml could use (obj2yaml can win from relaxing the error checking a lot).
I had no chance to investigate this, can take a look closer tomorrow.

Thanks, that sounds like a good plan to explore to me.

I investigated this and ended up with a warning handler passed as a parameter.
It seems that making a global warning handler for ELFFile<ELFT> it too intrusive,
but such a local solution looks flexible and seems works good: D65515

grimar planned changes to this revision.Aug 5 2019, 4:11 AM

I am suspending this. If we land D65515, this one will be excessive.

grimar abandoned this revision.Aug 8 2019, 12:17 AM

D65515 was landed.

test/tools/llvm-readobj/elf-invalid-sechdr-strtab-index.test