This is an archive of the discontinued LLVM Phabricator instance.

[yaml2obj] - Introduce a way to set default values when using ShOffset, ShName and ShSize fields.
AbandonedPublic

Authored by grimar on Jul 23 2020, 6:17 AM.

Details

Summary

For some fields it might be convenient to specify the DEFAULT as a value.
E.g. instead of:

## 0x18 is the standard entsize value.
EntSize: [[ENTSIZE=0x18]]

we could write just:

EntSize: [[ENTSIZE=DEFAULT]]

and just ignore the EntSize key, like it doesn'y exist at all.

This patch adds a support for the DEFAULT value for ShOffset,
ShName and ShSize fields. It also updates a test for llvm-readobj,
which can use the new feature now.

If the whole idea is fine, I'll post patches for another
fields we have that might benefit from this approach.

Diff Detail

Event Timeline

grimar created this revision.Jul 23 2020, 6:17 AM
grimar edited the summary of this revision. (Show Details)Jul 23 2020, 6:17 AM

To be clear, is the intent here is to allow yaml2obj to produce two different outputs form the same input where the only difference is that one provides a custom value and the other doesn't? How about a slightly more general concept: have a "None" special value (or "NONE" etc), parallel to llvm::Optional, which is equivalent to not specifying the field at all. This would be applicable to any optional field then, and would allow testing cases where a field may or may not exist.

For example, it could be used to allow testing Size/Content interactions:

...
Sections:
  - Name: .aaa
    Size: [[SIZE=None]]
    Content: [[CONTENT=None]]

# RUN: yaml2obj -o %t-with-size -DSIZE=42
# RUN: yaml2obj -o %t-with-content -DCONTENT=aabbccddeeff
# RUN: yaml2obj -o %t-with-both -DSIZE=42 -DCONTENT=aabbccddeeff

For ShName etc, it works the same as the proposed DEFAULT, because their values would be the default if the field wasn't specified at all.

MaskRay added a comment.EditedJul 23 2020, 8:39 AM

The None proposal looks good to me. My only minor concern is how we differentiate it from a value called None. If we can't find other suitable syntactic form, then =None seems fine.

Other syntactic forms include ShOffset?: [[TEST]]. I don't particularly like the idea that ? is not in [[ ]], but maybe there are some transformations making this appealing.
At the worst, we can use [[TEST=ShOffset: 0]]

grimar abandoned this revision.Jul 24 2020, 3:03 AM

To be clear, is the intent here is to allow yaml2obj to produce two different outputs form the same input where the only difference is that one provides a custom value and the other doesn't?

Right.

How about a slightly more general concept: have a "None" special value (or "NONE" etc), parallel to llvm::Optional, which is equivalent to not specifying the field at all.

I like the idea too. I've prototyped a patch, it looks fine, I think, now I am working on tests, hope to post it soon.
(I've used <none> as a special value, btw. I think it has less chance to conflict with None/none. I've avoided using NONE because it looks like a macro, though I'd slightly
prefer to use NONE rather than None if we deside that <none> doesn't work for whatever reason).

I am abandoning this revision.