zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit fffece1533d37b917c6e301c984c1cb3eb0040e4 (tree)
parent d2d42cf7ba5d965786d4bfb2fdc61dbd9a0d2ae5
Author: Luuk de Gram <luuk@degram.dev>
Date:   Tue, 23 Aug 2022 12:45:12 +0200

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.

Diffstat:
Msrc/link/Wasm.zig | 21++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig @@ -2836,24 +2836,19 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) ! try argv.append(entry); } - 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. - try argv.append("-z"); - const stack_size = self.base.options.stack_size_override orelse 1048576; - const arg = try std.fmt.allocPrint(arena, "stack-size={d}", .{stack_size}); - try argv.append(arg); + // 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. + try argv.append("-z"); + const stack_size = self.base.options.stack_size_override orelse wasm.page_size * 16; + const arg = try std.fmt.allocPrint(arena, "stack-size={d}", .{stack_size}); + try argv.append(arg); + if (self.base.options.output_mode == .Exe) { if (self.base.options.wasi_exec_model == .reactor) { // Reactor execution model does not have _start so lld doesn't look for it. try argv.append("--no-entry"); } - } else { - if (self.base.options.stack_size_override) |stack_size| { - try argv.append("-z"); - const arg = try std.fmt.allocPrint(arena, "stack-size={d}", .{stack_size}); - try argv.append(arg); - } + } else if (self.base.options.entry == null) { try argv.append("--no-entry"); // So lld doesn't look for _start. } try argv.appendSlice(&[_][]const u8{