[PATCH] D78072: [lld][WebAssembly] Do not require --shared-memory with --relocatable

Thomas Lively via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 13 19:34:05 PDT 2020


tlively created this revision.
tlively added a reviewer: sbc100.
Herald added subscribers: llvm-commits, jfb, sunfish, aheejin, jgravelle-google, dschuff.
Herald added a project: LLVM.

wasm-ld requires --shared-memory to be passed when the atomics feature
is enabled because historically atomic operations were only valid with
shared memories. This change relaxes that requirement for when
building relocatable objects because their memories are not
meaningful. This technically maintains the validity of object files
because the threads spec now allows atomic operations with unshared
memories, although we don't support that elsewhere in the tools yet.

This fixes and Emscripten build issue reported at
https://bugs.chromium.org/p/webp/issues/detail?id=463.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78072

Files:
  lld/test/wasm/shared-memory.yaml
  lld/wasm/Writer.cpp


Index: lld/wasm/Writer.cpp
===================================================================
--- lld/wasm/Writer.cpp
+++ lld/wasm/Writer.cpp
@@ -421,7 +421,8 @@
     for (const auto &key : used.keys())
       allowed.insert(std::string(key));
 
-  if (allowed.count("atomics") && !config->sharedMemory) {
+  if (allowed.count("atomics") && !config->sharedMemory &&
+      !config->relocatable) {
     if (inferFeatures)
       error(Twine("'atomics' feature is used by ") + used["atomics"] +
             ", so --shared-memory must be used");
Index: lld/test/wasm/shared-memory.yaml
===================================================================
--- lld/test/wasm/shared-memory.yaml
+++ lld/test/wasm/shared-memory.yaml
@@ -10,6 +10,8 @@
 
 # RUN: not wasm-ld --no-entry --features=atomics %t1.o -o - 2>&1 | FileCheck %s --check-prefix ATOMICS-NO-SHARED
 
+# RUN: wasm-ld --relocatable --features=atomics %t1.o -o - | obj2yaml | FileCheck %s --check-prefix ATOMICS-RELOCATABLE
+
 # RUN: wasm-ld --no-entry --shared-memory --max-memory=131072 --features=atomics,bulk-memory %t1.o -o - | obj2yaml | FileCheck %s --check-prefix SHARED
 
 --- !WASM
@@ -65,6 +67,11 @@
 
 # ATOMICS-NO-SHARED: 'atomics' feature is used, so --shared-memory must be used{{$}}
 
+# ATOMICS-RELOCATABLE:        - Type:            MEMORY
+# ATOMICS-RELOCATABLE-NEXT:     Memories:
+# ATOMICS-RELOCATABLE-NEXT:         Initial:         0x00000001
+# ATOMICS-RELOCATABLE-NEXT:   - Type:
+
 # SHARED:        - Type:            MEMORY
 # SHARED-NEXT:     Memories:
 # SHARED-NEXT:       - Flags:           [ HAS_MAX, IS_SHARED ]


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78072.257180.patch
Type: text/x-patch
Size: 1605 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200414/71a3687e/attachment.bin>


More information about the llvm-commits mailing list