[PATCH] D87663: [lld][WebAssembly] Fix --export-all when __stack_pointer is present

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 14 18:32:19 PDT 2020


sbc100 created this revision.
Herald added subscribers: llvm-commits, ecnelises, sunfish, jgravelle-google, dschuff.
Herald added a project: LLVM.
sbc100 requested review of this revision.
Herald added a subscriber: aheejin.

With https://reviews.llvm.org/D87537 we made it an error
to export a mutable global with the +mutable-globals feature
present.  However, this broke the use of the `--export-all`
flag because the `__stack_pointer` which is present in almost
all programs is a mutable global.

This also revealed that we didn't have any test coverage for
the `--export-all` flag.

This change fixes the current breakage on the emscripten-releases
roller.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87663

Files:
  lld/test/wasm/export-all.s
  lld/wasm/Writer.cpp


Index: lld/wasm/Writer.cpp
===================================================================
--- lld/wasm/Writer.cpp
+++ lld/wasm/Writer.cpp
@@ -462,7 +462,8 @@
   if (!config->checkFeatures)
     return;
 
-  if (!config->relocatable && used.count("mutable-globals") == 0) {
+  if (!config->exportAll && !config->relocatable &&
+      used.count("mutable-globals") == 0) {
     for (Symbol *sym : symtab->getSymbols()) {
       if (auto *global = dyn_cast<GlobalSymbol>(sym)) {
         if (global->getGlobalType()->Mutable) {
Index: lld/test/wasm/export-all.s
===================================================================
--- /dev/null
+++ lld/test/wasm/export-all.s
@@ -0,0 +1,48 @@
+# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
+# RUN: wasm-ld --export-all -o %t.wasm %t.o
+# RUN: obj2yaml %t.wasm | FileCheck %s
+
+.globl _start
+
+_start:
+  .functype _start () -> ()
+  i32.const 3
+  global.set __stack_pointer
+  end_function
+
+foo:
+  .functype foo () -> (i32)
+  i32.const 42
+  end_function
+
+.globaltype __stack_pointer, i32
+
+#      CHECK:   - Type:            EXPORT
+# CHECK-NEXT:     Exports:
+# CHECK-NEXT:       - Name:            memory
+# CHECK-NEXT:         Kind:            MEMORY
+# CHECK-NEXT:         Index:           0
+# CHECK-NEXT:       - Name:            __wasm_call_ctors
+# CHECK-NEXT:         Kind:            FUNCTION
+# CHECK-NEXT:         Index:           0
+# CHECK-NEXT:       - Name:            _start
+# CHECK-NEXT:         Kind:            FUNCTION
+# CHECK-NEXT:         Index:           1
+# CHECK-NEXT:       - Name:            __dso_handle
+# CHECK-NEXT:         Kind:            GLOBAL
+# CHECK-NEXT:         Index:           1
+# CHECK-NEXT:       - Name:            __data_end
+# CHECK-NEXT:         Kind:            GLOBAL
+# CHECK-NEXT:         Index:           2
+# CHECK-NEXT:       - Name:            __global_base
+# CHECK-NEXT:         Kind:            GLOBAL
+# CHECK-NEXT:         Index:           3
+# CHECK-NEXT:       - Name:            __heap_base
+# CHECK-NEXT:         Kind:            GLOBAL
+# CHECK-NEXT:         Index:           4
+# CHECK-NEXT:       - Name:            __memory_base
+# CHECK-NEXT:         Kind:            GLOBAL
+# CHECK-NEXT:         Index:           5
+# CHECK-NEXT:       - Name:            __table_base
+# CHECK-NEXT:         Kind:            GLOBAL
+# CHECK-NEXT:         Index:           6


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87663.291754.patch
Type: text/x-patch
Size: 2421 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200915/10ec0567/attachment.bin>


More information about the llvm-commits mailing list