[PATCH] D41955: [WebAssembly] Refactor symbol index handling (LLD)

Nicholas Wilson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 12 16:45:19 PST 2018


ncw updated this revision to Diff 129732.
ncw added a comment.

More updates, fixed all but two tests.

The remaining two tests are rather hard to fix; my changes unfortunately don't play well with "relocatable" output.

Problem #1
----------

The `stack-pointer.ll` test uses `--emit-relocs` but not `--relocatable`. This means that the `__stack_pointer` symbol is _not_ imported; it's instead defined, but we can't export it (because it's mutable). Thus, the  _global_ has an output index, but there is no _symbol_ index for it (so far, behaviour hasn't changed...). What this breaks is that I've made it so that relocs reference the symbol index - so relocs against the stack pointer won't work with `--emit-relocs` but not `--relocatable`.

Hmm. Maybe we can just fix the test to use `--relocatable` :( at least until we can export mutable globals.

Problem #2
----------

The other failing test is `init-fini.ll`. What causes the problem is that we take the address of a BINDING_LOCAL symbol. When linking with `--relocatable`, we try and create a relocation against the function and fail. This is because the function isn't exported as a Symbol in the relocatable output.

This can probably be fixed by just exporting Symbols for the locals as well when doing relocatable. We'd need to budge the names to keep them unique, which they won't be if we export the locals from all object files. That would at least make LLD's relocatable output match what Clang outputs.

Conclusion
----------

Linking (relocating) against Symbols rather than functions/globals does make aliases nice and elegant... but breaks some other things.

Another (less good?) solution might be to split the relocations into "FUNCTION_SYMBOL_INDEX_LEB" and "FUNCTION_WASM_INDEX_LEB", where the SYMBOL_INDEX version in outputted by WasmObjectWriter (Clang) and the WASM_INDEX version is outputted by LLD when it's creating relocatable output. The we can cope with both the cases above, at the expense of even more code handling different types of relocations.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D41955

Files:
  test/wasm/archive.ll
  test/wasm/data-layout.ll
  test/wasm/relocatable.ll
  test/wasm/weak-symbols.ll
  wasm/InputChunks.cpp
  wasm/InputChunks.h
  wasm/InputFiles.cpp
  wasm/InputFiles.h
  wasm/Symbols.cpp
  wasm/Symbols.h
  wasm/Writer.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41955.129732.patch
Type: text/x-patch
Size: 27057 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180113/c86be72f/attachment.bin>


More information about the llvm-commits mailing list