From 6474d1b20ea74982f9446a11b367a5936b6bbbdd Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Mon, 13 Apr 2020 19:16:20 -0700 Subject: [PATCH] [lld][WebAssembly] Do not require --shared-memory with --relocatable Summary: 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. Reviewers: sbc100 Subscribers: dschuff, jgravelle-google, aheejin, sunfish, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78072 --- lld/test/wasm/driver.ll | 4 ++++ lld/test/wasm/relocatable.ll | 12 ++---------- lld/test/wasm/shared-memory.yaml | 7 +++++++ lld/wasm/Driver.cpp | 2 ++ lld/wasm/Writer.cpp | 3 ++- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lld/test/wasm/driver.ll b/lld/test/wasm/driver.ll index 22e6bc1..995b10a 100644 --- a/lld/test/wasm/driver.ll +++ b/lld/test/wasm/driver.ll @@ -20,3 +20,7 @@ entry: ; RUN: not wasm-ld --export-table --import-table %t.o 2>&1 \ ; RUN: | FileCheck -check-prefix=TABLE %s ; TABLE: error: --import-table and --export-table may not be used together + +; RUN: not wasm-ld --relocatable --shared-memory %t.o 2>&1 \ +; RUN: | FileCheck -check-prefix=SHARED-MEM %s +; SHARED-MEM: error: -r and --shared-memory may not be used together diff --git a/lld/test/wasm/relocatable.ll b/lld/test/wasm/relocatable.ll index c3d67b1..a43a06e 100644 --- a/lld/test/wasm/relocatable.ll +++ b/lld/test/wasm/relocatable.ll @@ -1,12 +1,7 @@ ; RUN: llc -filetype=obj %p/Inputs/hello.ll -o %t.hello.o ; RUN: llc -filetype=obj %s -o %t.o ; RUN: wasm-ld -r -o %t.wasm %t.hello.o %t.o -; RUN: obj2yaml %t.wasm | FileCheck %s --check-prefixes CHECK,NORMAL - -; RUN: llc -filetype=obj %p/Inputs/hello.ll -o %t.hello.bm.o -mattr=+bulk-memory,+atomics -; RUN: llc -filetype=obj %s -o %t.bm.o -mattr=+bulk-memory -; RUN: wasm-ld -r -o %t.mt.wasm %t.hello.bm.o %t.bm.o --shared-memory --max-memory=131072 -; RUN: obj2yaml %t.mt.wasm | FileCheck %s --check-prefixes CHECK,SHARED +; RUN: obj2yaml %t.wasm | FileCheck %s target triple = "wasm32-unknown-unknown" @@ -79,10 +74,7 @@ entry: ; CHECK-NEXT: Maximum: 0x00000004 ; CHECK-NEXT: - Type: MEMORY ; CHECK-NEXT: Memories: -; NORMAL-NEXT: - Initial: 0x00000001 -; SHARED-NEXT: - Flags: [ HAS_MAX, IS_SHARED ] -; SHARED-NEXT: Initial: 0x00000001 -; SHARED-NEXT: Maximum: 0x00000002 +; CHECK-NEXT: - Initial: 0x00000001 ; CHECK-NEXT: - Type: ELEM ; CHECK-NEXT: Segments: ; CHECK-NEXT: - Offset: diff --git a/lld/test/wasm/shared-memory.yaml b/lld/test/wasm/shared-memory.yaml index 7ccbb77..8a03e0e 100644 --- a/lld/test/wasm/shared-memory.yaml +++ b/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 @@ Sections: # 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 ] diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp index b6cd879..c2a4e61 100644 --- a/lld/wasm/Driver.cpp +++ b/lld/wasm/Driver.cpp @@ -453,6 +453,8 @@ static void checkOptions(opt::InputArgList &args) { error("-r -and --undefined may not be used together"); if (config->pie) error("-r and -pie may not be used together"); + if (config->sharedMemory) + error("-r and --shared-memory may not be used together"); } } diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp index a6b2153..7c6c2de 100644 --- a/lld/wasm/Writer.cpp +++ b/lld/wasm/Writer.cpp @@ -429,7 +429,8 @@ void Writer::populateTargetFeatures() { for (const auto &key : used.keys()) allowed.insert(std::string(key)); - if (allowed.count("atomics") && !config->sharedMemory) { + if (!config->relocatable && allowed.count("atomics") && + !config->sharedMemory) { if (inferFeatures) error(Twine("'atomics' feature is used by ") + used["atomics"] + ", so --shared-memory must be used"); -- 2.7.4