This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Symbol changes #2: Table relocs, LLVM
ClosedPublic

Authored by ncw on Jan 15 2018, 10:48 AM.

Details

Summary

Second chunk split out of D41954.

Must be committed simultaneously with LLD change, D42081.

Changes:

  • Change the binary format for table relocations. Formerly, if you wanted to reloc against function "2", you'd put "2" in the table, then put the table index in the relocation. Now, you just put "2" in the relocation. For Clang output (or relocatable LLD output) the actual table is completely ignored - the relocation specifies which function.
  • Test expectations are updated accordingly. The new relocation values should match the old values from the ELEM section.
  • I haven't changed anything about the ELEM section itself. It's now unused, and has the same value it always has. This can freely changed in a future commit, since it now does nothing. (The next commit will change it, so that "relocatable" and non-relocatable Wasm objects have identical ELEM section. There's no need at all for the current artificial differences, so for the dummy values the Clang outputs there, we may as well write out the same values that LLD would.)

Reason for change

  • Due to pesky aliases, there can be more Symbols in a wasm file than Functions. I want in a future revision to get rid of the duplicate imports used to work around this problem.
  • But if the imports are removed, then it will no longer be legal to put the symbol index in the ELEM table! This is because Wasm ELEM sections contain a vector of funcid, ie the indexes in the ELEM section have to be valid Wasm functions. So we won't be able to put the generalised symbol indexes in there.
  • Hence, this change puts the symbol index directly in the relocation itself. This is a necessary change for getting rid of the duplicate imports in the Wasm object files.

Diff Detail

Repository
rL LLVM

Event Timeline

ncw created this revision.Jan 15 2018, 10:48 AM
ncw edited the summary of this revision. (Show Details)
ncw added inline comments.
test/MC/WebAssembly/global-ctor-dtor.ll
110 ↗(On Diff #129883)

Values here have changed from 0, 1 (the table indexes) to the values [ 5, 7 ] at those indexes. Similarly for other test output.

ncw edited the summary of this revision. (Show Details)Jan 16 2018, 3:26 AM
sbc100 added inline comments.Jan 16 2018, 1:54 PM
lib/MC/WasmObjectWriter.cpp
608 ↗(On Diff #129883)

Can you just use getRelocationIndexValue() here and drop getProvisionalTableIndex() completely?

ncw added inline comments.Jan 17 2018, 12:54 AM
lib/MC/WasmObjectWriter.cpp
608 ↗(On Diff #129883)

You're right that getProvisionalTableIndex doesn't do much at the moment...

The reason I kept the existing behaviour is to avoid changing the test output for the ELEM section in this commit. The next review (#3) then modifies getProvisionalTableIndex further. So this is just an intermediate stage to keep each commit in the chain from doing too many changes at once.

ncw added inline comments.Jan 18 2018, 10:38 AM
lib/MC/WasmObjectWriter.cpp
520 ↗(On Diff #129883)

NB. This todo is addressed in the next patch in the series, it's not that this patch is incomplete.

ncw updated this revision to Diff 130646.Jan 19 2018, 10:11 AM

Update:

  • Straightforward rebase
ncw updated this revision to Diff 130717.Jan 19 2018, 4:36 PM

Updated:

  • Another rebase after #4c and #4d landed
This revision was not accepted when it landed; it landed in state Needs Review.Jan 22 2018, 5:26 PM
This revision was automatically updated to reflect the committed changes.