This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy] Add e_machine validity check for reserved section indexes
ClosedPublic

Authored by jakehehrlich on Sep 12 2017, 1:48 PM.

Details

Summary

As discussed on llvm-commits it was decided it would be best to check e_machine before declaring that a reserved section index is valid. The only special e_machine value that matters here is EM_HEXAGON. This change adds a special check for EM_HEXAGAON.

Diff Detail

Repository
rL LLVM

Event Timeline

jakehehrlich created this revision.Sep 12 2017, 1:48 PM
mcgrathr added inline comments.Sep 12 2017, 3:56 PM
tools/llvm-objcopy/Object.cpp
102 ↗(On Diff #114901)

This will work as written, but I think a different structure would better reflect what you're really doing.
That is, have a first switch for the common stuff, with no default.
Then do if (Machine == ...) switch ... for each set of machine-specific ones.
Then just return false at the end if no switch matched.
That will be right in the future when another machine has a different set that are actually the same numbers as SHN_HEXAGON_*.

Very true! I wasn't thinking about the fact that other architectures would reuse the same values.

jakehehrlich marked an inline comment as done.Sep 12 2017, 4:12 PM
This revision is now accepted and ready to land.Sep 12 2017, 4:21 PM
This revision was automatically updated to reflect the committed changes.
jhenderson edited edge metadata.Sep 18 2017, 6:23 AM

Would it be possible to add a test that shows that the special Hexagon types aren't valid for other targets, say x86?