From e7670e58dd602803d8335b9996639003844bc4c3 Mon Sep 17 00:00:00 2001 From: Laytan Date: Tue, 29 Jul 2025 18:50:27 +0200 Subject: [PATCH 1/2] saner stack linker flags for WASM Supersedes #5425 --- src/build_settings.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/build_settings.cpp b/src/build_settings.cpp index e1b9c4156..5afc9c44f 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -1887,6 +1887,13 @@ gb_internal void init_build_context(TargetMetrics *cross_target, Subtarget subta str_lit("-target "), bc->metrics.target_triplet, str_lit(" ")); } else if (is_arch_wasm()) { gbString link_flags = gb_string_make(heap_allocator(), " "); + + // NOTE(laytan): Put the stack first in the memory, + // causing a stack overflow to error immediately instead of corrupting globals. + link_flags = gb_string_appendc(link_flags, "--stack-first "); + // NOTE(laytan): default stack size is 64KiB, up to a more reasonable 1MiB. + link_flags = gb_string_appendc(link_flags, "--stack-size=1048576 "); + // link_flags = gb_string_appendc(link_flags, "--export-all "); // link_flags = gb_string_appendc(link_flags, "--export-table "); // if (bc->metrics.arch == TargetArch_wasm64) { From af0b90bd3e0ef7d11eec9cc07aac3b6774c7c818 Mon Sep 17 00:00:00 2001 From: Laytan Date: Tue, 29 Jul 2025 19:07:28 +0200 Subject: [PATCH 2/2] fix flag --- src/build_settings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build_settings.cpp b/src/build_settings.cpp index 5afc9c44f..46a4f9ae5 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -1892,7 +1892,7 @@ gb_internal void init_build_context(TargetMetrics *cross_target, Subtarget subta // causing a stack overflow to error immediately instead of corrupting globals. link_flags = gb_string_appendc(link_flags, "--stack-first "); // NOTE(laytan): default stack size is 64KiB, up to a more reasonable 1MiB. - link_flags = gb_string_appendc(link_flags, "--stack-size=1048576 "); + link_flags = gb_string_appendc(link_flags, "-z stack-size=1048576 "); // link_flags = gb_string_appendc(link_flags, "--export-all "); // link_flags = gb_string_appendc(link_flags, "--export-table ");