File tree 6 files changed +39
-2
lines changed
6 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,16 @@ target triple = "wasm32-unknown-unknown"
68
68
; CHECK-MAX-NEXT: Initial: 0x00000002
69
69
; CHECK-MAX-NEXT: Maximum: 0x00000002
70
70
71
+ ; RUN: wasm-ld -no-gc-sections --allow-undefined --no-entry --shared-memory \
72
+ ; RUN: --initial-memory=131072 --max-memory=131072 -o %t_max.wasm %t.o \
73
+ ; RUN: %t.hello.o
74
+ ; RUN: obj2yaml %t_max.wasm | FileCheck %s -check-prefix=CHECK-SHARED
75
+
76
+ ; CHECK-SHARED: - Type: MEMORY
77
+ ; CHECK-SHARED-NEXT: Memories:
78
+ ; CHECK-SHARED-NEXT: - Flags: [ HAS_MAX, IS_SHARED ]
79
+ ; CHECK-SHARED-NEXT: Initial: 0x00000002
80
+ ; CHECK-SHARED-NEXT: Maximum: 0x00000002
71
81
72
82
; RUN: wasm-ld --relocatable -o %t_reloc.wasm %t.o %t.hello.o
73
83
; RUN: obj2yaml %t_reloc.wasm | FileCheck %s -check-prefix=RELOC
Original file line number Diff line number Diff line change 31
31
# CHECK-MAX-NEXT: Initial: 0x00000004
32
32
# CHECK-MAX-NEXT: Maximum: 0x00000005
33
33
# CHECK-MAX-NEXT: - Type:
34
+
35
+ # RUN: wasm-ld --import-memory --shared-memory --initial-memory=262144 \
36
+ # RUN: --max-memory=327680 -o %t.max.wasm %t.start.o
37
+ # RUN: obj2yaml %t.max.wasm | FileCheck -check-prefix=CHECK-SHARED %s
38
+
39
+ # Verify the --shared-memory flag works with imports
40
+
41
+ # CHECK-SHARED: - Type: IMPORT
42
+ # CHECK-SHARED-NEXT: Imports:
43
+ # CHECK-SHARED-NEXT: - Module: env
44
+ # CHECK-SHARED-NEXT: Field: memory
45
+ # CHECK-SHARED-NEXT: Kind: MEMORY
46
+ # CHECK-SHARED-NEXT: Memory:
47
+ # CHECK-SHARED-NEXT: Flags: [ HAS_MAX, IS_SHARED ]
48
+ # CHECK-SHARED-NEXT: Initial: 0x00000004
49
+ # CHECK-SHARED-NEXT: Maximum: 0x00000005
50
+ # CHECK-SHARED-NEXT: - Type:
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ struct Configuration {
28
28
bool ExportTable;
29
29
bool GcSections;
30
30
bool ImportMemory;
31
+ bool SharedMemory;
31
32
bool ImportTable;
32
33
bool MergeDataSegments;
33
34
bool PrintGcSections;
Original file line number Diff line number Diff line change @@ -381,6 +381,7 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
381
381
errorHandler ().FatalWarnings =
382
382
Args.hasFlag (OPT_fatal_warnings, OPT_no_fatal_warnings, false );
383
383
Config->ImportMemory = Args.hasArg (OPT_import_memory);
384
+ Config->SharedMemory = Args.hasArg (OPT_shared_memory);
384
385
Config->ImportTable = Args.hasArg (OPT_import_table);
385
386
Config->LTOO = args::getInteger (Args, OPT_lto_O, 2 );
386
387
Config->LTOPartitions = args::getInteger (Args, OPT_lto_partitions, 1 );
Original file line number Diff line number Diff line change @@ -123,6 +123,9 @@ def global_base: J<"global-base=">,
123
123
def import_memory: F<"import-memory">,
124
124
HelpText<"Import memory from the environment">;
125
125
126
+ def shared_memory: F<"shared-memory">,
127
+ HelpText<"Use shared linear memory">;
128
+
126
129
def import_table: F<"import-table">,
127
130
HelpText<"Import function table from the environment">;
128
131
Original file line number Diff line number Diff line change @@ -155,6 +155,9 @@ void Writer::createImportSection() {
155
155
Import.Memory .Flags |= WASM_LIMITS_FLAG_HAS_MAX;
156
156
Import.Memory .Maximum = MaxMemoryPages;
157
157
}
158
+ if (Config->SharedMemory ) {
159
+ Import.Memory .Flags |= WASM_LIMITS_FLAG_IS_SHARED;
160
+ }
158
161
writeImport (OS, Import);
159
162
}
160
163
@@ -214,8 +217,10 @@ void Writer::createMemorySection() {
214
217
215
218
bool HasMax = MaxMemoryPages != 0 ;
216
219
writeUleb128 (OS, 1 , " memory count" );
217
- writeUleb128 (OS, HasMax ? static_cast <unsigned >(WASM_LIMITS_FLAG_HAS_MAX) : 0 ,
218
- " memory limits flags" );
220
+ unsigned Flags = HasMax ? static_cast <unsigned >(WASM_LIMITS_FLAG_HAS_MAX) : 0 ;
221
+ if (Config->SharedMemory )
222
+ Flags |= WASM_LIMITS_FLAG_IS_SHARED;
223
+ writeUleb128 (OS, Flags, " memory limits flags" );
219
224
writeUleb128 (OS, NumMemoryPages, " initial pages" );
220
225
if (HasMax)
221
226
writeUleb128 (OS, MaxMemoryPages, " max pages" );
You can’t perform that action at this time.
0 commit comments