From 821d122c82af499c2a5b2fc0223cf399faa10d16 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Fri, 7 Aug 2026 03:02:58 -0400 Subject: [PATCH] bootstrap: change/enable c compiler optimizations for zig1/zig2 --- CMakeLists.txt | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 14df4e9b568d8fb6c5b924f6cd4e3c9778dc5e21..ce1289ceecfab1a3fc063e923c73400bac030020 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -602,24 +602,17 @@ if(MSVC) set(ZIG2_COMPILE_FLAGS "/Od") set(ZIG2_LINK_FLAGS "/STACK:16777216 /FORCE:MULTIPLE") else() - set(ZIG_WASM2C_COMPILE_FLAGS "-std=c99 -O2") - set(ZIG1_COMPILE_FLAGS "-std=c99 -Os -fno-strict-aliasing") - set(ZIG2_COMPILE_FLAGS "-std=c99 -O0 -fno-sanitize=undefined -fno-stack-protector -fno-strict-aliasing") + set(ZIG_WASM2C_COMPILE_FLAGS "-std=c99") + set(ZIG1_COMPILE_FLAGS "-std=c99 -Oz -fno-strict-aliasing") + set(ZIG2_COMPILE_FLAGS "-std=c99 -Oz -fno-sanitize=undefined -fno-stack-protector -fno-strict-aliasing") + if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND ZIG_HOST_TARGET_ARCH STREQUAL "s390x") + string(REPLACE -Oz -O0 ZIG2_COMPILE_FLAGS "${ZIG2_COMPILE_FLAGS}") # llvm 22 assertion failure + endif() # Must match the condition in build.zig. if(ZIG_HOST_TARGET_ARCH MATCHES "^(arm|thumb)(eb)?$" OR ZIG_HOST_TARGET_ARCH EQUAL "hexagon" OR ZIG_HOST_TARGET_ARCH MATCHES "^powerpc(64)?(le)?$") set(ZIG1_COMPILE_FLAGS "${ZIG1_COMPILE_FLAGS} -ffunction-sections -fdata-sections") set(ZIG2_COMPILE_FLAGS "${ZIG2_COMPILE_FLAGS} -ffunction-sections -fdata-sections") endif() - if(APPLE) - set(ZIG2_LINK_FLAGS "-Wl,-stack_size,0x10000000") - elseif(MINGW) - set(ZIG2_LINK_FLAGS "-Wl,--stack,0x10000000") - # Solaris/illumos ld(1) does not provide a --stack-size option. - elseif(CMAKE_HOST_SOLARIS) - unset(ZIG2_LINK_FLAGS) - else() - set(ZIG2_LINK_FLAGS "-Wl,-z,stack-size=0x10000000") - endif() if (CMAKE_C_COMPILER_ID STREQUAL "GNU") # Prevent GCC from miscompiling 'zig2.c'. See also 'GCC_BUG_119085_PRESENT' workaround details in 'bootstrap.c'. if ( -- 2.54.0