Page MenuHomePhabricator

[WebAssembly] Reorder reloc sections to come after symtab
ClosedPublic

Authored by ncw on Mar 1 2018, 8:38 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

ncw created this revision.Mar 1 2018, 8:38 AM
sbc100 added a comment.Mar 1 2018, 9:30 AM

Interesting that no test changes needed. I guess its because obj2yaml doesn't display the reloc sections themselves... but injects them into the section they apply to.

wasm/Writer.cpp
637 ↗(On Diff #136533)

Why not just swap these two lines? I'm not sure we should care about where these sections come relative the name section.

ncw added inline comments.Mar 1 2018, 9:42 AM
wasm/Writer.cpp
637 ↗(On Diff #136533)

It's easier to have the name section come before the reloc section - it just makes the yaml2wasm logic a bit simpler. That's not really a good reason is it :( But it would be an extra few lines of code to have "name" come after "reloc".

You're right we do have free choice on that ordering; all the other orderings are driven by decent reasons.

sbc100 added inline comments.Mar 1 2018, 9:46 AM
wasm/Writer.cpp
637 ↗(On Diff #136533)

Can you remind me why it makes yaml2wasm simpler?b

ncw added inline comments.Mar 1 2018, 9:57 AM
wasm/Writer.cpp
637 ↗(On Diff #136533)

Sure, it's silly really, but yaml2wasm currently just iterates over all the sections and writes them out to Wasm - then does a second loop to catch the relocations and writes those out (since they're stored on the section to which the relocations apply).

So writing out relocs in between the "linking" and "name" section would just make the diff there fatter, so I took the line of least resistance. If there's some aesthetic or other reason to put "name" at the end I can do that though.

it sounds like we shouldn't care about the ordering of name vs reloc sections. It up to the generator. yaml2obj can always put the relocs last if it likes. that doesn't mean lld needs t to do the same.

ncw added a comment.Mar 2 2018, 1:25 AM

it sounds like we shouldn't care about the ordering of name vs reloc sections. It up to the generator. yaml2obj can always put the relocs last if it likes. that doesn't mean lld needs t to do the same.

I personally think things should be consistent - and spec'ed in as constrained a way as possible/reasonable.

This came up in the discussion about Wasm's new "exception" section, where there was some discussion about how strict the ordering for it should be, relative to the existing sections. Andreas Rossberg pointed out that the "Wasmy way" so far was to specify the precise ordering of all sections (built-in sections and also the custom "name" section), and that was generally preferable to allowing sections to be laid out in different orders by different tools. So the new "exception" section is having a precise ordering given to it.

I know that our custom linking/reloc sections aren't quite the same, but they are nonetheless semi-official "spec'ed" sections, just spec'ed in a different document. The Linking.md spec would ideally say exactly what their ordering is relative to the official sections - and it's simpler for everyone just to give one official order than list several possibilities.

I've decided overnight it's a big "ugly" to put the name section in between "linking" and "reloc.", so regardless of what we agree about how/whether to validate the order, I think I'll make it so that LLD and yaml2wasm are consistent and put the "name" section at the very end. I don't like different tools to have unnecessary differences in their output! Plus, things should roundtrip eg LLD -> obj2yaml -> yaml2obj shouldn't reorder sections.

ncw updated this revision to Diff 136744.Mar 2 2018, 7:01 AM

Updated as requested by Sam - just reordering the two lines.

Regardless of what think about how the section order will be validated - I think this change is good to go! Doesn't need anything in LLVM to land first.

sbc100 accepted this revision.Mar 2 2018, 9:34 AM
This revision is now accepted and ready to land.Mar 2 2018, 9:34 AM
This revision was automatically updated to reflect the committed changes.
This revision was automatically updated to reflect the committed changes.