Skip to content

Commit

Permalink
cmake, bootstrap.c: Set a 16 MiB stack size for zig1.
Browse files Browse the repository at this point in the history
This is the default stack size that the Zig compiler sets when linking Zig
programs. Since we're compiling a Zig program in C form here, it seems sensible
to do the same.

This might need to be increased even more for compilers like tcc and slimcc, as
is done for zig2, but that can come later.
  • Loading branch information
alexrp committed Dec 15, 2024
1 parent 6578d9b commit 7f9f91d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -805,19 +805,24 @@ if(MSVC)
set(ZIG_WASM2C_COMPILE_FLAGS "")
set(ZIG1_COMPILE_FLAGS "/Os")
set(ZIG2_COMPILE_FLAGS "/Od")
set(ZIG1_LINK_FLAGS "/STACK:16777216")
set(ZIG2_LINK_FLAGS "/STACK:16777216 /FORCE:MULTIPLE")
else()
set(ZIG_WASM2C_COMPILE_FLAGS "-std=c99 -O2")
set(ZIG1_COMPILE_FLAGS "-std=c99 -Os")
set(ZIG2_COMPILE_FLAGS "-std=c99 -O0 -fno-stack-protector")
if(APPLE)
set(ZIG1_LINK_FLAGS "-Wl,-stack_size,0x1000000")
set(ZIG2_LINK_FLAGS "-Wl,-stack_size,0x10000000")
elseif(MINGW)
set(ZIG1_LINK_FLAGS "-Wl,--stack,0x1000000")
set(ZIG2_LINK_FLAGS "-Wl,--stack,0x10000000")
# Solaris/illumos ld(1) does not provide a --stack-size option.
elseif(CMAKE_HOST_SOLARIS)
unset(ZIG1_LINK_FLAGS)
unset(ZIG2_LINK_FLAGS)
else()
set(ZIG1_LINK_FLAGS "-Wl,-z,stack-size=0x1000000")
set(ZIG2_LINK_FLAGS "-Wl,-z,stack-size=0x10000000")
endif()
endif()
Expand All @@ -839,7 +844,10 @@ add_custom_command(
)

add_executable(zig1 ${ZIG1_C_SOURCE} stage1/wasi.c)
set_target_properties(zig1 PROPERTIES COMPILE_FLAGS ${ZIG1_COMPILE_FLAGS})
set_target_properties(zig1 PROPERTIES
COMPILE_FLAGS ${ZIG1_COMPILE_FLAGS}
LINK_FLAGS "${ZIG1_LINK_FLAGS}"
)

if(MSVC)
target_link_options(zig1 PRIVATE /STACK:0x10000000)
Expand Down
9 changes: 8 additions & 1 deletion bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,14 @@ int main(int argc, char **argv) {
}
{
const char *child_argv[] = {
cc, "-o", "zig1", "zig1.c", "stage1/wasi.c", "-std=c99", "-Os", "-lm", NULL,
cc, "-o", "zig1", "zig1.c", "stage1/wasi.c",
"-std=c99", "-Os", "-lm",
#if defined(__APPLE__)
"-Wl,-stack_size,0x1000000",
#else
"-Wl,-z,stack-size=0x1000000",
#endif
NULL,
};
print_and_run(child_argv);
}
Expand Down

0 comments on commit 7f9f91d

Please sign in to comment.