[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

llvm-svn: 322911
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index 4cefe3a..05bb4c7 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -659,9 +659,12 @@
   }
 
   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)});
   }