Index: lld/trunk/test/wasm/data-layout.ll =================================================================== --- lld/trunk/test/wasm/data-layout.ll +++ lld/trunk/test/wasm/data-layout.ll @@ -68,6 +68,16 @@ ; 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 Index: lld/trunk/test/wasm/import-memory.test =================================================================== --- lld/trunk/test/wasm/import-memory.test +++ lld/trunk/test/wasm/import-memory.test @@ -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: Index: lld/trunk/wasm/Config.h =================================================================== --- lld/trunk/wasm/Config.h +++ lld/trunk/wasm/Config.h @@ -28,6 +28,7 @@ bool ExportTable; bool GcSections; bool ImportMemory; + bool SharedMemory; bool ImportTable; bool MergeDataSegments; bool PrintGcSections; Index: lld/trunk/wasm/Driver.cpp =================================================================== --- lld/trunk/wasm/Driver.cpp +++ lld/trunk/wasm/Driver.cpp @@ -381,6 +381,7 @@ 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); Index: lld/trunk/wasm/Options.td =================================================================== --- lld/trunk/wasm/Options.td +++ lld/trunk/wasm/Options.td @@ -123,6 +123,9 @@ 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">; Index: lld/trunk/wasm/Writer.cpp =================================================================== --- lld/trunk/wasm/Writer.cpp +++ lld/trunk/wasm/Writer.cpp @@ -155,6 +155,9 @@ 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 @@ bool HasMax = MaxMemoryPages != 0; writeUleb128(OS, 1, "memory count"); - writeUleb128(OS, HasMax ? static_cast(WASM_LIMITS_FLAG_HAS_MAX) : 0, - "memory limits flags"); + unsigned Flags = HasMax ? static_cast(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");