Commit bf273b7aec

zigazeljko <ziga.zeljko@gmail.com>
2020-06-02 19:58:30
Add comment explaining --stack-first option
1 parent fb9d552
Changed files (1)
src/link.cpp
@@ -2107,6 +2107,10 @@ static void construct_linker_job_wasm(LinkJob *lj) {
     lj->args.append("-z");
     lj->args.append(buf_ptr(buf_sprintf("stack-size=%" ZIG_PRI_usize, stack_size)));
 
+    // put stack before globals so that stack overflow results in segfault immediately before corrupting globals
+    // see https://github.com/ziglang/zig/issues/4496
+    lj->args.append("--stack-first");
+
     if (g->out_type != OutTypeExe) {
         lj->args.append("--no-entry"); // So lld doesn't look for _start.