This is an archive of the discontinued LLVM Phabricator instance.

[yaml2obj] - Refine handling of the NoHeaders key.
ClosedPublic

Authored by grimar on Jul 13 2020, 5:52 AM.

Details

Summary

Imagine we have an YAML description for some object and we want to
produce 2 outputs: with and without the section header.
A natural way to do it would look like:

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_REL
  Machine: EM_X86_64
Sections:
...
SectionHeaderTable:
  NoHeaders: [[NOHEADERS]]

But currently, we do not distinguish between no NoHeaders key case
and NoHeaders == false. Because of this we can't simply specify
NOHEADERS = false, as tool starts to complain.

With this patch the behavior changed. When we have:

SectionHeaderTable:
  NoHeaders: false

it is the same as we have no SectionHeaderTable at all.
(NoHeaders key still can't be used with Sections/Excluded keys)

Diff Detail

Event Timeline

grimar created this revision.Jul 13 2020, 5:52 AM
Herald added a project: Restricted Project. · View Herald Transcript
grimar edited the summary of this revision. (Show Details)Jul 13 2020, 5:52 AM
MaskRay added inline comments.Jul 13 2020, 8:49 AM
llvm/include/llvm/ObjectYAML/ELFYAML.h
101

Does bool NoHeaders = false; work? If absence is equal to false.

jhenderson added inline comments.Jul 14 2020, 1:03 AM
llvm/test/tools/yaml2obj/ELF/section-headers.yaml
122–123

produce -> produces
like when there is -> as if there were

grimar updated this revision to Diff 277700.Jul 14 2020, 1:25 AM
grimar marked 3 inline comments as done.
  • Addressed review comments.
llvm/include/llvm/ObjectYAML/ELFYAML.h
101

No. This is the same what we implicitly already have:

IO.mapOptional("NoHeaders", SectionHeader.NoHeaders, false);

When there is no NoHeaders or just NoHeaders = false in an YAML, and nothing else, then we have an error currently:

YAML:11:3: error: SectionHeaderTable can't be empty. Use 'NoHeaders' key to drop the section header table
  NoHeaders: false

This is what this patch solves.

This revision is now accepted and ready to land.Jul 14 2020, 1:42 AM
This revision was automatically updated to reflect the committed changes.