[PATCH] D42237: [WebAssembly] Symbol changes #4b: export stack-pointer, LLD only

Nicholas Wilson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 18 02:42:10 PST 2018


ncw created this revision.
ncw added reviewers: sbc100, sunfish.
Herald added subscribers: llvm-commits, aheejin, jgravelle-google, dschuff, jfb.

Split out of https://reviews.llvm.org/D41955.

This solves the problem that `--emit-relocs` needs the stack-pointer to be exported, in order to write out any relocations that reference the `__stack_pointer` symbol by its symbol index.

Rationale: `--emit-relocs` is only ever going to be used by downstream tools (such as Emscripten's binaryen tools). In particular, we don't expect that the output from `--emit-relocs` will be sent to browsers without further post-processing. Although browsers don't allow mutable globals to be imported/exported (yet), tools like binaryen do accept it.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D42237

Files:
  test/wasm/stack-pointer.ll
  wasm/Writer.cpp


Index: wasm/Writer.cpp
===================================================================
--- wasm/Writer.cpp
+++ wasm/Writer.cpp
@@ -658,8 +658,10 @@
 
   for (const Symbol *Sym : DefinedGlobals) {
     // Can't export the SP right now because it's mutable and mutable globals
-    // cannot be exported.
-    if (Sym == Config->StackPointerSymbol)
+    // cannot be exported.  However, for output that's intended for processing
+    // by downstream tools, we can rely on the "mutable global" proposal
+    // being present.
+    if (Sym == Config->StackPointerSymbol && !Config->EmitRelocs)
       continue;
     ExportedSymbols.emplace_back(WasmExportEntry{Sym, BudgeName(Sym)});
   }
Index: test/wasm/stack-pointer.ll
===================================================================
--- test/wasm/stack-pointer.ll
+++ test/wasm/stack-pointer.ll
@@ -58,6 +58,9 @@
 ; CHECK-NEXT:       - Name:            __wasm_call_ctors
 ; CHECK-NEXT:         Kind:            FUNCTION
 ; CHECK-NEXT:         Index:           1
+; CHECK-NEXT:       - Name:            __stack_pointer
+; CHECK-NEXT:         Kind:            GLOBAL
+; CHECK-NEXT:         Index:           0
 ; CHECK-NEXT:       - Name:            __heap_base
 ; CHECK-NEXT:         Kind:            GLOBAL
 ; CHECK-NEXT:         Index:           1


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42237.130378.patch
Type: text/x-patch
Size: 1307 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180118/a1944c9c/attachment.bin>


More information about the llvm-commits mailing list