This is an archive of the discontinued LLVM Phabricator instance.

[yaml2obj/obj2yaml] - Move `Info` field out from `Section` class.
ClosedPublic

Authored by grimar on Feb 11 2019, 7:58 AM.

Details

Summary

ELFYAML.h contains a Section class which is a base for a few other
sections classes that are used for mapping different section types.

In rL230124 Info field was moved there from RelocationSection class
because patch reused it for Group section type. Info has a string type.

At the same time, sh_info has very different meanings for sections.
For SHT_GROUP the meaning of sh_info is "The symbol table index of an entry
in the associated symbol table. The name of the specified symbol table entry provides
a signature for the section group."
And for SHT_REL[A] is "The section header index of the section to which the relocation
applies."

So it cannot be processed in a similar way generally,
for example ELFDumper does not handle it in dumpCommonSection
but do that in dumpGroup and dumpCommonRelocationSection respectively.
(see patch).

At this moment, we have and handle it as a string, because that was possible for
the current use case. But also it can simply be a number,
see for example SHT_SUNW_verdef/SHT_SUNW_verneed sections (SHT_GNU_verdef/SHT_GNU_verneed):
https://docs.oracle.com/cd/E19683-01/816-1386/6m7qcoblj/index.html#chapter6-47976

Given above, I think keeping is as StringRef in a common Section class is probably wrong.
I want to move it out to be able to have it as a number and to implement dumping/parsing the versioning
sections mentioned above. With that change, each class will be able to decide what type and purpose
of the sh_info field it wants to use.

I also had to edit 2 test cases. This is because patch fixes a bug. Previously we accepted
yaml files with Info fields for all sections (for example, for SHT_DYNSYM too).
But we do not handle it and the resulting objects had zero sh_info fields set for such sections.
Now it is accepted only for sections that support it.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Feb 11 2019, 7:58 AM
grimar edited the summary of this revision. (Show Details)Feb 11 2019, 7:59 AM

Agree, because I've struggled on this for some time ...

ruiu accepted this revision.Feb 11 2019, 10:31 AM

LGTM

This revision is now accepted and ready to land.Feb 11 2019, 10:31 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 12 2019, 1:08 AM