This is an archive of the discontinued LLVM Phabricator instance.

[yaml2obj]Allow symbol Index field to take values lower than SHN_LORESERVE
ClosedPublic

Authored by jhenderson on Feb 20 2019, 6:21 AM.

Details

Summary

In order to test tool handling of invalid section indexes, I need to create an object contianing such an invalid section index. I could create a hex-edited binary, but having the ability to use yaml2obj is preferable. Prior to this change, yaml2obj would reject any explicit section indexes less than SHN_LORESERVE. This patch changes it to allow any value.

I had to change the test to use llvm-readelf instead of llvm-readobj, because llvm-readobj does not like invalid section indexes. I've also expanded the test to show that the most common SHN_* values are accepted (SHN_UNDEF, SHN_ABS, SHN_COMMON).

Diff Detail

Repository
rL LLVM

Event Timeline

jhenderson created this revision.Feb 20 2019, 6:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 20 2019, 6:21 AM
Herald added a subscriber: arphaman. · View Herald Transcript

I thought before about some kind of conflict we might see in situations like this.
From one side we might want to keep (and maybe improve) the validating because it is probably a useful thing in general.
But we still want to have a way to produce invalid outputs when we want, as this patch does.

Should we instead of removing the validation code add an option to yaml2obj, something like -no-validate?

I thought before about some kind of conflict we might see in situations like this.
From one side we might want to keep (and maybe improve) the validating because it is probably a useful thing in general.
But we still want to have a way to produce invalid outputs when we want, as this patch does.

Should we instead of removing the validation code add an option to yaml2obj, something like -no-validate?

Hmm... interesting thought. In this case, I think if you've explicitly used Index, you probably know what you are doing by specifying an explicit section index outside the reserved range, instead of using one of the SHN_* values or using the Section field. I could be persuaded otherwise though. On a related note, without this change, you cannot specify Index: SHN_UNDEF, because SHN_UNDEF is less than SHN_LORESERVE. It's not strictly necessary, because the default is undefined, but it's still slightly weird behaviour.

By the way, I could see a use for a validate/no-validate option in other cases. Perhaps with the Index field it would validate that the index is either a valid section index or a reserved value.

grimar accepted this revision.Feb 20 2019, 7:29 AM

@jhenderson wrote:
In this case, I think if you've explicitly used Index, you probably know what you are doing by specifying an explicit section index outside the reserved range, instead of using one of the SHN_* values or using the Section field.

Yes, for this case you are right I think.

LGTM.

This revision is now accepted and ready to land.Feb 20 2019, 7:29 AM

Thanks @grimar! I'm going to sit on this for a day or two and see if any other reviewers want to chime in before I go ahead.

jakehehrlich accepted this revision.Feb 20 2019, 1:51 PM

This emphatically looks good to me. Thanks for doing this.

This revision was automatically updated to reflect the committed changes.