Skip to content

Commit 9bf7075

Browse files
Add --no-growable-memory instead
1 parent 5f52f34 commit 9bf7075

File tree

7 files changed

+23
-58
lines changed

7 files changed

+23
-58
lines changed

lld/docs/WebAssembly.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ WebAssembly-specific options:
131131

132132
Initial size of the linear memory. Default: the sum of stack, static data and heap sizes.
133133

134-
.. option:: --max-memory-growth=<value>
135-
136-
Maximum size of memory that can be allocated dynamically. Default: unlimited.
137-
138134
.. option:: --max-memory=<value>
139135

140136
Maximum size of the linear memory. Default: unlimited.
141137

138+
.. option:: --no-growable-memory
139+
140+
Set maximum size of the linear memory to its initial size, disallowing memory growth.
141+
142142
By default the function table is neither imported nor exported, but defined
143143
for internal use only.
144144

lld/test/wasm/data-layout.s

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -103,37 +103,21 @@ local_struct_internal_ptr:
103103
# CHECK-MAX-NEXT: Minimum: 0x2
104104
# CHECK-MAX-NEXT: Maximum: 0x2
105105

106-
# RUN: wasm-ld --no-entry --initial-memory=327680 --max-memory-growth=0 \
106+
# RUN: wasm-ld --no-entry --initial-memory=327680 --no-growable-memory \
107107
# RUN: -o %t_max.wasm %t.hello32.o
108-
# RUN: obj2yaml %t_max.wasm | FileCheck %s -check-prefix=CHECK-MAX-GROWTH-ZERO
108+
# RUN: obj2yaml %t_max.wasm | FileCheck %s -check-prefix=CHECK-NO-GROWTH
109109

110-
# CHECK-MAX-GROWTH-ZERO: - Type: MEMORY
111-
# CHECK-MAX-GROWTH-ZERO-NEXT: Memories:
112-
# CHECK-MAX-GROWTH-ZERO: - Flags: [ HAS_MAX ]
113-
# CHECK-MAX-GROWTH-ZERO: Minimum: 0x5
114-
# CHECK-MAX-GROWTH-ZERO: Maximum: 0x5
110+
# CHECK-NO-GROWTH: - Type: MEMORY
111+
# CHECK-NO-GROWTH-NEXT: Memories:
112+
# CHECK-NO-GROWTH-NEXT: - Flags: [ HAS_MAX ]
113+
# CHECK-NO-GROWTH-NEXT: Minimum: 0x5
114+
# CHECK-NO-GROWTH-NEXT: Maximum: 0x5
115115

116-
# RUN: wasm-ld --initial-memory=196608 --max-memory-growth=262144 \
117-
# RUN: --no-entry -o %t_max.wasm %t.hello32.o
118-
# RUN: obj2yaml %t_max.wasm | FileCheck %s -check-prefix=CHECK-MAX-GROWTH-SOME
119-
120-
# CHECK-MAX-GROWTH-SOME: - Type: MEMORY
121-
# CHECK-MAX-GROWTH-SOME-NEXT: Memories:
122-
# CHECK-MAX-GROWTH-SOME: - Flags: [ HAS_MAX ]
123-
# CHECK-MAX-GROWTH-SOME: Minimum: 0x3
124-
# CHECK-MAX-GROWTH-SOME: Maximum: 0x7
125-
126-
# RUN: not wasm-ld --max-memory-growth=131073 \
127-
# RUN: --no-entry -o %t_max.wasm %t.hello32.o 2>&1 \
128-
# RUN: | FileCheck %s --check-prefix CHECK-MAX-GROWTH-ALIGN-ERROR
129-
130-
# CHECK-MAX-GROWTH-ALIGN-ERROR: maximum memory growth must be 65536-byte aligned
131-
132-
# RUN: not wasm-ld --initial-memory=131072 --max-memory=262144 --max-memory-growth=131072 \
116+
# RUN: not wasm-ld --max-memory=262144 --no-growable-memory \
133117
# RUN: --no-entry -o %t_max.wasm %t.hello32.o 2>&1 \
134-
# RUN: | FileCheck %s --check-prefix CHECK-MAX-GROWTH-COMPAT-ERROR
118+
# RUN: | FileCheck %s --check-prefix CHECK-NO-GROWTH-COMPAT-ERROR
135119

136-
# CHECK-MAX-GROWTH-COMPAT-ERROR: --max-memory-growth and --max-memory are mutually exclusive
120+
# CHECK-NO-GROWTH-COMPAT-ERROR: --max-memory and --no-growable-memory are mutually exclusive
137121

138122
# RUN: wasm-ld -no-gc-sections --allow-undefined --no-entry --shared-memory \
139123
# RUN: --features=atomics,bulk-memory --initial-memory=131072 \

lld/test/wasm/large-memory.test

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,10 @@ RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/start.s -o %
55
RUN: wasm-ld %t.o -o %t1.wasm --max-memory=2147483648
66
RUN: obj2yaml %t1.wasm | FileCheck %s --check-prefixes=CHECK,CHECK-2G
77

8-
RUN: wasm-ld %t.o -o %t1.wasm --initial-memory=131072 --max-memory-growth=2147352576
9-
RUN: obj2yaml %t1.wasm | FileCheck %s --check-prefixes=CHECK,CHECK-2G
10-
118
; And also 4G of total memory
129
RUN: wasm-ld %t.o -o %t2.wasm --max-memory=4294967296
1310
RUN: obj2yaml %t2.wasm | FileCheck %s --check-prefixes=CHECK,CHECK-4G
1411

15-
RUN: wasm-ld %t.o -o %t2.wasm --initial-memory=131072 --max-memory-growth=4294836224
16-
RUN: obj2yaml %t2.wasm | FileCheck %s --check-prefixes=CHECK,CHECK-4G
17-
1812
CHECK: - Type: MEMORY
1913
CHECK-NEXT: Memories:
2014
CHECK-NEXT: - Flags: [ HAS_MAX ]
@@ -25,8 +19,6 @@ CHECK-4G-NEXT: Maximum: 0x10000
2519
; Test error for more than 4G of memory
2620
RUN: not wasm-ld %t.o -o %t3.wasm --initial-memory=4295032832 2>&1 | FileCheck %s --check-prefix INIT-ERROR
2721
RUN: not wasm-ld %t.o -o %t4.wasm --max-memory=4295032832 2>&1 | FileCheck %s --check-prefix MAX-ERROR
28-
RUN: not wasm-ld %t.o -o %t4.wasm --initial-memory=131072 --max-memory-growth=4294901760 2>&1 | FileCheck %s --check-prefix MAX-GROWTH-ERROR
2922

3023
INIT-ERROR: initial memory too large, cannot be greater than 4294967296
3124
MAX-ERROR: maximum memory too large, cannot be greater than 4294967296
32-
MAX-GROWTH-ERROR: maximum memory growth too large, cannot be greater than 4294836224

lld/wasm/Config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ struct Configuration {
7777
uint64_t globalBase;
7878
uint64_t initialHeap;
7979
uint64_t initialMemory;
80-
uint64_t maxMemoryGrowth;
8180
uint64_t maxMemory;
81+
bool noGrowableMemory;
8282
// The table offset at which to place function addresses. We reserve zero
8383
// for the null function pointer. This gets set to 1 for executables and 0
8484
// for shared libraries (since they always added to a dynamic offset at

lld/wasm/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ static void readConfigs(opt::InputArgList &args) {
541541
config->globalBase = args::getInteger(args, OPT_global_base, 0);
542542
config->initialHeap = args::getInteger(args, OPT_initial_heap, 0);
543543
config->initialMemory = args::getInteger(args, OPT_initial_memory, 0);
544-
config->maxMemoryGrowth = args::getInteger(args, OPT_max_memory_growth, -1);
545544
config->maxMemory = args::getInteger(args, OPT_max_memory, 0);
545+
config->noGrowableMemory = args.hasArg(OPT_no_growable_memory);
546546
config->zStackSize =
547547
args::getZOptionValue(args, OPT_z, "stack-size", WasmPageSize);
548548

lld/wasm/Options.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ def initial_heap: JJ<"initial-heap=">,
227227
def initial_memory: JJ<"initial-memory=">,
228228
HelpText<"Initial size of the linear memory">;
229229

230-
def max_memory_growth: JJ<"max-memory-growth=">,
231-
HelpText<"Maximum size of dynamically allocatable linear memory">;
232-
233230
def max_memory: JJ<"max-memory=">,
234231
HelpText<"Maximum size of the linear memory">;
235232

233+
def no_growable_memory: FF<"no-growable-memory">,
234+
HelpText<"Set maximum size of the linear memory to its initial size">;
235+
236236
def no_entry: FF<"no-entry">,
237237
HelpText<"Do not output any entry point">;
238238

lld/wasm/Writer.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -473,25 +473,12 @@ void Writer::layoutMemory() {
473473
WasmSym::heapEnd->setVA(memoryPtr);
474474
}
475475

476-
if (config->maxMemory != 0 && config->maxMemoryGrowth != -1) {
476+
if (config->maxMemory != 0 && config->noGrowableMemory) {
477477
// Erroring out here is simpler than defining precedence rules.
478-
error("--max-memory-growth and --max-memory are mutually exclusive");
478+
error("--max-memory and --no-growable-memory are mutually exclusive");
479479
}
480480

481481
uint64_t maxMemory = 0;
482-
if (config->maxMemoryGrowth != -1) {
483-
if (config->maxMemoryGrowth !=
484-
alignTo(config->maxMemoryGrowth, WasmPageSize))
485-
error("maximum memory growth must be " + Twine(WasmPageSize) +
486-
"-byte aligned");
487-
uint64_t maxMaxMemoryGrowth = maxMemorySetting - memoryPtr;
488-
if (config->maxMemoryGrowth > maxMaxMemoryGrowth)
489-
error("maximum memory growth too large, cannot be greater than " +
490-
Twine(maxMaxMemoryGrowth));
491-
492-
maxMemory = memoryPtr + config->maxMemoryGrowth;
493-
}
494-
495482
if (config->maxMemory != 0) {
496483
if (config->maxMemory != alignTo(config->maxMemory, WasmPageSize))
497484
error("maximum memory must be " + Twine(WasmPageSize) + "-byte aligned");
@@ -502,6 +489,8 @@ void Writer::layoutMemory() {
502489
Twine(maxMemorySetting));
503490

504491
maxMemory = config->maxMemory;
492+
} else if (config->noGrowableMemory) {
493+
maxMemory = memoryPtr;
505494
}
506495

507496
// If no maxMemory config was supplied but we are building with

0 commit comments

Comments
 (0)