[lld] r346248 - [WebAssembly] Support creation and import of shared memories
Derek Schuff via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 6 09:59:32 PST 2018
Author: dschuff
Date: Tue Nov 6 09:59:32 2018
New Revision: 346248
URL: http://llvm.org/viewvc/llvm-project?rev=346248&view=rev
Log:
[WebAssembly] Support creation and import of shared memories
Used for WebAssembly threads proposal. Add a flag --shared-memory
which sets the IS_SHARED bit in WasmLimits
Differential Revision: https://reviews.llvm.org/D54130
Modified:
lld/trunk/test/wasm/data-layout.ll
lld/trunk/test/wasm/import-memory.test
lld/trunk/wasm/Config.h
lld/trunk/wasm/Driver.cpp
lld/trunk/wasm/Options.td
lld/trunk/wasm/Writer.cpp
Modified: lld/trunk/test/wasm/data-layout.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/data-layout.ll?rev=346248&r1=346247&r2=346248&view=diff
==============================================================================
--- lld/trunk/test/wasm/data-layout.ll (original)
+++ lld/trunk/test/wasm/data-layout.ll Tue Nov 6 09:59:32 2018
@@ -68,6 +68,16 @@ target triple = "wasm32-unknown-unknown"
; CHECK-MAX-NEXT: Initial: 0x00000002
; CHECK-MAX-NEXT: Maximum: 0x00000002
+; RUN: wasm-ld -no-gc-sections --allow-undefined --no-entry --shared-memory \
+; RUN: --initial-memory=131072 --max-memory=131072 -o %t_max.wasm %t.o \
+; RUN: %t.hello.o
+; RUN: obj2yaml %t_max.wasm | FileCheck %s -check-prefix=CHECK-SHARED
+
+; CHECK-SHARED: - Type: MEMORY
+; CHECK-SHARED-NEXT: Memories:
+; CHECK-SHARED-NEXT: - Flags: [ HAS_MAX, IS_SHARED ]
+; CHECK-SHARED-NEXT: Initial: 0x00000002
+; CHECK-SHARED-NEXT: Maximum: 0x00000002
; RUN: wasm-ld --relocatable -o %t_reloc.wasm %t.o %t.hello.o
; RUN: obj2yaml %t_reloc.wasm | FileCheck %s -check-prefix=RELOC
Modified: lld/trunk/test/wasm/import-memory.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/import-memory.test?rev=346248&r1=346247&r2=346248&view=diff
==============================================================================
--- lld/trunk/test/wasm/import-memory.test (original)
+++ lld/trunk/test/wasm/import-memory.test Tue Nov 6 09:59:32 2018
@@ -31,3 +31,20 @@
# CHECK-MAX-NEXT: Initial: 0x00000004
# CHECK-MAX-NEXT: Maximum: 0x00000005
# CHECK-MAX-NEXT: - Type:
+
+# RUN: wasm-ld --import-memory --shared-memory --initial-memory=262144 \
+# RUN: --max-memory=327680 -o %t.max.wasm %t.start.o
+# RUN: obj2yaml %t.max.wasm | FileCheck -check-prefix=CHECK-SHARED %s
+
+# Verify the --shared-memory flag works with imports
+
+# CHECK-SHARED: - Type: IMPORT
+# CHECK-SHARED-NEXT: Imports:
+# CHECK-SHARED-NEXT: - Module: env
+# CHECK-SHARED-NEXT: Field: memory
+# CHECK-SHARED-NEXT: Kind: MEMORY
+# CHECK-SHARED-NEXT: Memory:
+# CHECK-SHARED-NEXT: Flags: [ HAS_MAX, IS_SHARED ]
+# CHECK-SHARED-NEXT: Initial: 0x00000004
+# CHECK-SHARED-NEXT: Maximum: 0x00000005
+# CHECK-SHARED-NEXT: - Type:
Modified: lld/trunk/wasm/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Config.h?rev=346248&r1=346247&r2=346248&view=diff
==============================================================================
--- lld/trunk/wasm/Config.h (original)
+++ lld/trunk/wasm/Config.h Tue Nov 6 09:59:32 2018
@@ -28,6 +28,7 @@ struct Configuration {
bool ExportTable;
bool GcSections;
bool ImportMemory;
+ bool SharedMemory;
bool ImportTable;
bool MergeDataSegments;
bool PrintGcSections;
Modified: lld/trunk/wasm/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Driver.cpp?rev=346248&r1=346247&r2=346248&view=diff
==============================================================================
--- lld/trunk/wasm/Driver.cpp (original)
+++ lld/trunk/wasm/Driver.cpp Tue Nov 6 09:59:32 2018
@@ -381,6 +381,7 @@ void LinkerDriver::link(ArrayRef<const c
errorHandler().FatalWarnings =
Args.hasFlag(OPT_fatal_warnings, OPT_no_fatal_warnings, false);
Config->ImportMemory = Args.hasArg(OPT_import_memory);
+ Config->SharedMemory = Args.hasArg(OPT_shared_memory);
Config->ImportTable = Args.hasArg(OPT_import_table);
Config->LTOO = args::getInteger(Args, OPT_lto_O, 2);
Config->LTOPartitions = args::getInteger(Args, OPT_lto_partitions, 1);
Modified: lld/trunk/wasm/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Options.td?rev=346248&r1=346247&r2=346248&view=diff
==============================================================================
--- lld/trunk/wasm/Options.td (original)
+++ lld/trunk/wasm/Options.td Tue Nov 6 09:59:32 2018
@@ -123,6 +123,9 @@ def global_base: J<"global-base=">,
def import_memory: F<"import-memory">,
HelpText<"Import memory from the environment">;
+def shared_memory: F<"shared-memory">,
+ HelpText<"Use shared linear memory">;
+
def import_table: F<"import-table">,
HelpText<"Import function table from the environment">;
Modified: lld/trunk/wasm/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Writer.cpp?rev=346248&r1=346247&r2=346248&view=diff
==============================================================================
--- lld/trunk/wasm/Writer.cpp (original)
+++ lld/trunk/wasm/Writer.cpp Tue Nov 6 09:59:32 2018
@@ -155,6 +155,9 @@ void Writer::createImportSection() {
Import.Memory.Flags |= WASM_LIMITS_FLAG_HAS_MAX;
Import.Memory.Maximum = MaxMemoryPages;
}
+ if (Config->SharedMemory) {
+ Import.Memory.Flags |= WASM_LIMITS_FLAG_IS_SHARED;
+ }
writeImport(OS, Import);
}
@@ -214,8 +217,10 @@ void Writer::createMemorySection() {
bool HasMax = MaxMemoryPages != 0;
writeUleb128(OS, 1, "memory count");
- writeUleb128(OS, HasMax ? static_cast<unsigned>(WASM_LIMITS_FLAG_HAS_MAX) : 0,
- "memory limits flags");
+ unsigned Flags = HasMax ? static_cast<unsigned>(WASM_LIMITS_FLAG_HAS_MAX) : 0;
+ if (Config->SharedMemory)
+ Flags |= WASM_LIMITS_FLAG_IS_SHARED;
+ writeUleb128(OS, Flags, "memory limits flags");
writeUleb128(OS, NumMemoryPages, "initial pages");
if (HasMax)
writeUleb128(OS, MaxMemoryPages, "max pages");
More information about the llvm-commits
mailing list