Skip to content

Commit

Permalink
Fix trap in UI example:
Browse files Browse the repository at this point in the history
- new min/max macros create an ungodly amount of locals in unoptimized builds, which caused stack overflows when recursing in UI layout code. As a quick fix, we now pass -O1 when building the wasm sdk to do the bare minimum cleanup.
- Also set the wasm3 stack to a more reasonable 1MB size
- TODO: investigate why such simple macros generate so much locals... maybe reintroduce a simpler version of our old hygienic macros if it's worth it for debug builds.
- TODO: convert UI layout code to an iterative version to completely avoid potential stack overflows.
  • Loading branch information
martinfouilleul committed Jun 4, 2024
1 parent ffc3c8a commit 8596cc0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions scripts/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def build_wasm3(release):


def build_wasm3_lib_win(release):
debug_flags = ["/O2", "/Zi"] if release else ["/Zi"]
debug_flags = ["/O2", "/Zi"] if release else ["/O1", "/Zi"]

for f in glob.iglob("./src/ext/wasm3/source/*.c"):
name = os.path.splitext(os.path.basename(f))[0]
Expand All @@ -548,7 +548,7 @@ def build_wasm3_lib_win(release):

def build_wasm3_lib_mac(release):
includes = ["-Isrc/ext/wasm3/source"]
debug_flags = ["-g", "-O2"]
debug_flags = ["-g", "-O2"] if release else ["-g", "-O1"]
flags = [
*debug_flags,
"-foptimize-sibling-calls",
Expand Down Expand Up @@ -958,7 +958,8 @@ def build_sdk_internal(release):
"-I", "build/orca-libc/include",
]

debug_flags = ["-O2", "-DNDEBUG"] if release else ["-g"]
# we still use -O1 for debug, otherwise clang generates an ungodly amount of locals for no reason
debug_flags = ["-O2", "-DNDEBUG"] if release else ["-g", "-O1"]

flags = [
*debug_flags,
Expand Down
2 changes: 1 addition & 1 deletion src/wasm/backend_wasm3.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ oc_wasm* oc_wasm_create(void)
wasm->arena = arena;
oc_list_init(&wasm->bindings);

u32 stackSize = 65536;
u32 stackSize = 1 << 20;
wasm->m3Env = m3_NewEnvironment();
wasm->m3Runtime = m3_NewRuntime(wasm->m3Env, stackSize, NULL);

Expand Down

0 comments on commit 8596cc0

Please sign in to comment.