This is an archive of the discontinued LLVM Phabricator instance.

[yaml2obj/obj2yaml] - Make fields of the `Symbol` to be optional.
AbandonedPublic

Authored by grimar on Dec 2 2020, 6:02 AM.

Details

Summary

This is similar to what we did earlier for fields of the Section class.

When a field is optional we can use the =<none> syntax in macros.
I am using this functionality in the patch that going to post soon.

I've added few test cases, I am not sure if we want to test all of fields,
as handling of "Optional<>" is generic and common.

Diff Detail

Event Timeline

grimar created this revision.Dec 2 2020, 6:02 AM
Herald added a project: Restricted Project. · View Herald Transcript
grimar requested review of this revision.Dec 2 2020, 6:02 AM
grimar retitled this revision from [yaml2obj/obj2yaml] - Make the fields of the `Symbol` to be optional. to [yaml2obj/obj2yaml] - Make fields of the `Symbol` to be optional..
MaskRay added inline comments.Dec 2 2020, 12:57 PM
llvm/tools/obj2yaml/elf2yaml.cpp
675

For undefined symbols, STB_GLOBAL is the default.
For defined symbols, STB_LOCAL is the default.

grimar marked an inline comment as done.Dec 2 2020, 11:19 PM
grimar added inline comments.
llvm/tools/obj2yaml/elf2yaml.cpp
675

Before this patch our default binding was always ELF_STB (0), what is STB_LOCAL (0).

IO.mapOptional("Binding", Symbol.Binding, ELFYAML::ELF_STB(0));

I don't think that this patch is the right place to change defaults?

MaskRay accepted this revision.Dec 2 2020, 11:28 PM

LGTM.

This revision is now accepted and ready to land.Dec 2 2020, 11:28 PM

In general terms, I think we should have the following test cases for each field:

  1. That a non-default value can be specified explicitly. If the value is an enum (like binding), each possible value should be specified.
  2. That =<none> can be used where relevant, and that if it is, the value is whatever the default is.
  3. That the field can be omitted entirely and the value is whatever the default is.

I don't think you need to test that =<none> values can be overridden. However, if you do override them, I wouldn't use the default value as the overriding value, personally. So, for example, with symbol binding, I'd override with STB_WEAK or STB_GLOBAL, rather than STB_LOCAL, to show that the default is not used still.

llvm/tools/obj2yaml/elf2yaml.cpp
668

Don't we need obj2yaml testing for these changes?

grimar abandoned this revision.Dec 3 2020, 1:47 AM
grimar marked an inline comment as done.

I'll split this and post a patch for each field instead.