From bf273b7aec8fe9957967c635bd01b2b92909b192 Mon Sep 17 00:00:00 2001 From: zigazeljko Date: Wed, 3 Jun 2020 01:58:30 +0800 Subject: [PATCH] Add comment explaining --stack-first option --- src/link.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/link.cpp b/src/link.cpp index 80baffe51c..b54fdf6b93 100644 --- a/src/link.cpp +++ b/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.