Skip to content

Commit bf273b7

Browse files
zigazeljkoandrewrk
authored andcommitted
Add comment explaining --stack-first option
1 parent fb9d552 commit bf273b7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/link.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -2107,6 +2107,10 @@ static void construct_linker_job_wasm(LinkJob *lj) {
21072107
lj->args.append("-z");
21082108
lj->args.append(buf_ptr(buf_sprintf("stack-size=%" ZIG_PRI_usize, stack_size)));
21092109

2110+
// put stack before globals so that stack overflow results in segfault immediately before corrupting globals
2111+
// see https://github.com/ziglang/zig/issues/4496
2112+
lj->args.append("--stack-first");
2113+
21102114
if (g->out_type != OutTypeExe) {
21112115
lj->args.append("--no-entry"); // So lld doesn't look for _start.
21122116

0 commit comments

Comments
 (0)