Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions src/link/Wasm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is correct here? The previous version of the code did not check for entry at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but a little bit above we set the entry if the user provided it. It's invalid to pass both an entry point and --no-entry. I figured I'd get that fix in while at it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's invalid, should we perhaps flag it up as an error to the user?

Copy link
Contributor Author

@Luukdegram Luukdegram Aug 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. --entry is given by the user, whereas --no-entry is a flag we set by default depending on the output mode. So the user never creates this invalid state, it's the Zig toolchain that should ensure it doesn't occur. Unless we disallow have an entry point in non build-exe modes, but given how Wasm runs in runtimes I think it's perfectly valid to have an environment where you do have a custom entry, but not the _start logic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, so we don't expose --no-entry to the user? I'm curious though, what is the behavior of LLD upon receiving both flags in a single linker line, do you know perhaps?

Copy link
Contributor Author

@Luukdegram Luukdegram Aug 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLD will ignore the --entry flag in such case, which may confuse the user, as they may be unaware that --no-entry was passed to lld also and therefore have their own flag ignored.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for double checking! I am fine with the current approach. In the future though, I wonder if we should perhaps make it a hard error. Food for thought!

try argv.append("--no-entry"); // So lld doesn't look for _start.
}
try argv.appendSlice(&[_][]const u8{
Expand Down