[lld] r322911 - [WebAssembly] Export the stack pointer when using --emit-relocs

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 18 15:57:55 PST 2018


Author: sbc
Date: Thu Jan 18 15:57:55 2018
New Revision: 322911

URL: http://llvm.org/viewvc/llvm-project?rev=322911&view=rev
Log:
[WebAssembly] Export the stack pointer when using --emit-relocs

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.

Patch by Nicholas Wilson!

Differential Revision: https://reviews.llvm.org/D42237

Modified:
    lld/trunk/test/wasm/stack-pointer.ll
    lld/trunk/wasm/Writer.cpp

Modified: lld/trunk/test/wasm/stack-pointer.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/stack-pointer.ll?rev=322911&r1=322910&r2=322911&view=diff
==============================================================================
--- lld/trunk/test/wasm/stack-pointer.ll (original)
+++ lld/trunk/test/wasm/stack-pointer.ll Thu Jan 18 15:57:55 2018
@@ -58,6 +58,9 @@ entry:
 ; 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

Modified: lld/trunk/wasm/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Writer.cpp?rev=322911&r1=322910&r2=322911&view=diff
==============================================================================
--- lld/trunk/wasm/Writer.cpp (original)
+++ lld/trunk/wasm/Writer.cpp Thu Jan 18 15:57:55 2018
@@ -659,9 +659,12 @@ void Writer::calculateExports() {
   }
 
   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)
+    // Can't export the SP right now because its mutable, and mutuable globals
+    // are yet supported in the official binary format.  However, for
+    // intermediate output we need to export it in case it is the target of any
+    // relocations.
+    // TODO(sbc): Remove this if/when the "mutable global" proposal is accepted.
+    if (Sym == Config->StackPointerSymbol && !Config->EmitRelocs)
       continue;
     ExportedSymbols.emplace_back(WasmExportEntry{Sym, BudgeLocalName(Sym)});
   }




More information about the llvm-commits mailing list