aboutsummaryrefslogtreecommitdiff
path: root/src/link/Wasm.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-11-09 14:29:20 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-11-09 14:29:20 -0700
commitd2cdfb949033cfd463cdd4ef1bbf93f94d4d190a (patch)
tree6f329fbd1402f5776dc0b8f654452a8ae1471956 /src/link/Wasm.zig
parent9bb7ff68ccab8700cb787a83359df02a5bb4370f (diff)
downloadzig-d2cdfb949033cfd463cdd4ef1bbf93f94d4d190a.tar.gz
zig-d2cdfb949033cfd463cdd4ef1bbf93f94d4d190a.zip
stage2: add 4 new linker flags for WebAssembly
--import-memory import memory from the environment --initial-memory=[bytes] initial size of the linear memory --max-memory=[bytes] maximum size of the linear memory --global-base=[addr] where to start to place global data See #8633
Diffstat (limited to 'src/link/Wasm.zig')
-rw-r--r--src/link/Wasm.zig23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig
index a75ad1b2f7..80c529ff94 100644
--- a/src/link/Wasm.zig
+++ b/src/link/Wasm.zig
@@ -681,6 +681,10 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
try man.addOptionalFile(compiler_rt_path);
man.hash.addOptional(self.base.options.stack_size_override);
man.hash.addListOfBytes(self.base.options.extra_lld_args);
+ man.hash.add(self.base.options.import_memory);
+ man.hash.addOptional(self.base.options.initial_memory);
+ man.hash.addOptional(self.base.options.max_memory);
+ man.hash.addOptional(self.base.options.global_base);
// We don't actually care whether it's a cache hit or miss; we just need the digest and the lock.
_ = try man.hit();
@@ -754,6 +758,25 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
}
}
+ if (self.base.options.import_memory) {
+ try argv.append("--import-memory");
+ }
+
+ if (self.base.options.initial_memory) |initial_memory| {
+ const arg = try std.fmt.allocPrint(arena, "--initial-memory={d}", .{initial_memory});
+ try argv.append(arg);
+ }
+
+ if (self.base.options.max_memory) |max_memory| {
+ const arg = try std.fmt.allocPrint(arena, "--max-memory={d}", .{max_memory});
+ try argv.append(arg);
+ }
+
+ if (self.base.options.global_base) |global_base| {
+ const arg = try std.fmt.allocPrint(arena, "--global-base={d}", .{global_base});
+ try argv.append(arg);
+ }
+
if (self.base.options.output_mode == .Exe) {
// Increase the default stack size to a more reasonable value of 1MB instead of
// the default of 1 Wasm page being 64KB, unless overridden by the user.