This is an archive of the discontinued LLVM Phabricator instance.

[yaml2obj, obj2yaml] - Implement section header table as a special Chunk.
ClosedPublic

Authored by grimar on Jan 21 2021, 7:45 AM.

Details

Summary

This was discussed in D93678 thread.
Currently we have one special chunk - Fill.

This patch re implements the "SectionHeaderTable" key to become a special chunk too.
With that we are able to place the section header table at any location,
just like we place sections.

Diff Detail

Event Timeline

grimar created this revision.Jan 21 2021, 7:45 AM
grimar requested review of this revision.Jan 21 2021, 7:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 21 2021, 7:45 AM

Generally looks fine to me. Is there testing for the obj2yaml side of things? It feels like there needs to be testing there for writing the section header table in the right place in the YAML (with Offset if needed), but I don't see that yet.

llvm/include/llvm/ObjectYAML/ELFYAML.h
197

Maybe add a new line above this comment to clearly split the two varieties.

208–213

I feel like this reads a bit better.

295

getNumHeaders or maybe simply` size.

716
llvm/lib/ObjectYAML/ELFEmitter.cpp
337–338

I think this comment now best belongs with the second if inside the loop, below the section header table bit, as it isn't relevant ot the section header table stuff.

391
405
712

It probably deserves a comment here saying something about the section header information isn't all known yet, so fill with zeroes as a placeholder.

1841

Do you actually need the IsImplicit check here? The default values of NoHeaders and Excluded should be such that the ifs inside don't trigger anyway.

1973

I think it would be more self-documenting if this was if(!SHT.NoHeaders). If I understand it correctly, SHT.Offset will always be set when NoHeaders is false. If NoHeaders is false, specifying Offset explicitly doesn't make sense, and is prohibited.

llvm/lib/ObjectYAML/ELFYAML.cpp
1325
llvm/test/tools/yaml2obj/ELF/section-headers.yaml
339
grimar added a comment.EditedJan 22 2021, 1:46 AM

It feels like there needs to be testing there for writing the section header table in the right place in the YAML (with Offset if needed), but I don't see that yet.

It is not yet implemented. Currently obj2yaml can only emit the section header chunk at the end of the sections list (when the order of sections doesn't match the order in the section header table).
I supposed we can implement the dumping at a proper position in a follow-up(s). Does it sound OK for you?

It feels like there needs to be testing there for writing the section header table in the right place in the YAML (with Offset if needed), but I don't see that yet.

It is not yet implemented. Currently obj2yaml can only emit the section header chunk at the end of the sections list (when the order of sections doesn't match the order in the section header table).
I supposed we can implement the dumping at a proper position in a follow-up(s). Does it sound OK for you?

I suspected that was the case, but wasn't sure, so deferring is fine.

grimar updated this revision to Diff 318493.Jan 22 2021, 5:30 AM
grimar marked 12 inline comments as done.
  • Addressed review comments.
llvm/lib/ObjectYAML/ELFEmitter.cpp
1841

Right. Removed.

1973

Done.

jhenderson accepted this revision.Jan 25 2021, 12:40 AM

Thanks, LGTM!

This revision is now accepted and ready to land.Jan 25 2021, 12:40 AM