Skip to content

Commit fffece1

Browse files
Luukdegramandrewrk
authored andcommitted
wasm-lld: set stack size to 1MB by default
Regardless of the build mode (build-exe, build-lib), always set the default stack size to 1MB. Previously, this was only done when using build-exe, making the inconsistancy confusing. The user can still override this behavior by providing the `--stack <size>` flag.
1 parent d2d42cf commit fffece1

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/link/Wasm.zig

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2836,24 +2836,19 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
28362836
try argv.append(entry);
28372837
}
28382838

2839-
if (self.base.options.output_mode == .Exe) {
2840-
// Increase the default stack size to a more reasonable value of 1MB instead of
2841-
// the default of 1 Wasm page being 64KB, unless overridden by the user.
2842-
try argv.append("-z");
2843-
const stack_size = self.base.options.stack_size_override orelse 1048576;
2844-
const arg = try std.fmt.allocPrint(arena, "stack-size={d}", .{stack_size});
2845-
try argv.append(arg);
2839+
// Increase the default stack size to a more reasonable value of 1MB instead of
2840+
// the default of 1 Wasm page being 64KB, unless overridden by the user.
2841+
try argv.append("-z");
2842+
const stack_size = self.base.options.stack_size_override orelse wasm.page_size * 16;
2843+
const arg = try std.fmt.allocPrint(arena, "stack-size={d}", .{stack_size});
2844+
try argv.append(arg);
28462845

2846+
if (self.base.options.output_mode == .Exe) {
28472847
if (self.base.options.wasi_exec_model == .reactor) {
28482848
// Reactor execution model does not have _start so lld doesn't look for it.
28492849
try argv.append("--no-entry");
28502850
}
2851-
} else {
2852-
if (self.base.options.stack_size_override) |stack_size| {
2853-
try argv.append("-z");
2854-
const arg = try std.fmt.allocPrint(arena, "stack-size={d}", .{stack_size});
2855-
try argv.append(arg);
2856-
}
2851+
} else if (self.base.options.entry == null) {
28572852
try argv.append("--no-entry"); // So lld doesn't look for _start.
28582853
}
28592854
try argv.appendSlice(&[_][]const u8{

0 commit comments

Comments
 (0)