This is an archive of the discontinued LLVM Phabricator instance.

[yaml2obj] - Add a way to override sh_type section field.
ClosedPublic

Authored by grimar on Jul 28 2020, 2:57 AM.

Details

Summary

This adds the ShType key similar to others Sh* keys we have.

My use case is the following. Imagine we have a SHT_SYMTAB_SHNDX
section and want to hide it from a dumper. The natural way would be to
do something like:

- Name:    .symtab_shndx
  Type:    [[TYPE=SHT_SYMTAB_SHNDX]]
  Entries: [ 0, 1 ]

and then change the TYPE from SHT_SYMTAB_SHNDX to something else,
for example to SHT_PROGBITS.

But we have a problem: regular sections does not have Entries key,
so yaml2obj will be unable to produce a section.

The solution is to introduce a ShType key to override the final type.

This is not the first time I am facing the need to change the type. I
was able to invent workarounds or solved issues differently in the past,
but finally came to conclusion that we just should support the ShType.

Diff Detail

Event Timeline

grimar created this revision.Jul 28 2020, 2:57 AM
Herald added a project: Restricted Project. · View Herald Transcript
grimar requested review of this revision.Jul 28 2020, 2:57 AM
grimar edited the summary of this revision. (Show Details)
jhenderson accepted this revision.Jul 28 2020, 3:56 AM

LGTM, with nit. I think the use-case makes sense.

llvm/test/tools/yaml2obj/ELF/override-shtype.yaml
35

As you don't use the YAML for a non-overridden type, you can omit the =SHT_GNU_verneed, right?

This revision is now accepted and ready to land.Jul 28 2020, 3:56 AM
grimar added inline comments.Jul 28 2020, 4:01 AM
llvm/test/tools/yaml2obj/ELF/override-shtype.yaml
35

It is used for a non-overridden type:

# RUN: yaml2obj %s -o %t1
# RUN: llvm-readobj --sections --section-data %t1 | FileCheck %s --check-prefixes=COMMON,ORIGINAL

If I omitted the =SHT_GNU_verneed here, I would need to use yaml2obj -DTYPE=SHT_GNU_verneed.

jhenderson added inline comments.Jul 28 2020, 4:03 AM
llvm/test/tools/yaml2obj/ELF/override-shtype.yaml
35

Oh, I missed the first run somehow, thanks.

This revision was automatically updated to reflect the committed changes.