authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-03-09 12:02:58+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-03-10 11:28:36+00:00
log79e7b719a362959fd172bbe7f7d9abe3e2f6f0cc
tree80da616bafae5253858f6c0c4af44d2e5bd44f98
parent57114044db85717bea7204f2693d6c8a62111635
signaturelock-open Commit is signed but in an unrecognized format.

bootstrap: disable strict aliasing

The C backend has always gleefully violated C's strict aliasing rules, and I just got bitten by it for the first time when bootstrapping on macOS. This probably hasn't been helping with some of the weird bootstrap-related CI failures we've seen. So, update `bootstrap.c` and `CMakeLists.txt` to tell GCC/Clang to disable type-based alias analysis. No change is needed to the MSVC flags because MSVC does not, and never has, implemented TBAA.

2 files changed, 4 insertions(+), 3 deletions(-)

CMakeLists.txt+2-2
...@@ -608,8 +608,8 @@ if(MSVC)...@@ -608,8 +608,8 @@ if(MSVC)
608 set(ZIG2_LINK_FLAGS "/STACK:16777216 /FORCE:MULTIPLE")608 set(ZIG2_LINK_FLAGS "/STACK:16777216 /FORCE:MULTIPLE")
609else()609else()
610 set(ZIG_WASM2C_COMPILE_FLAGS "-std=c99 -O2")610 set(ZIG_WASM2C_COMPILE_FLAGS "-std=c99 -O2")
611 set(ZIG1_COMPILE_FLAGS "-std=c99 -Os")611 set(ZIG1_COMPILE_FLAGS "-std=c99 -Os -fno-strict-aliasing")
612 set(ZIG2_COMPILE_FLAGS "-std=c99 -O0 -fno-sanitize=undefined -fno-stack-protector")612 set(ZIG2_COMPILE_FLAGS "-std=c99 -O0 -fno-sanitize=undefined -fno-stack-protector -fno-strict-aliasing")
613 # Must match the condition in build.zig.613 # Must match the condition in build.zig.
614 if(ZIG_HOST_TARGET_ARCH MATCHES "^(arm|thumb)(eb)?$" OR ZIG_HOST_TARGET_ARCH MATCHES "^powerpc(64)?(le)?$")614 if(ZIG_HOST_TARGET_ARCH MATCHES "^(arm|thumb)(eb)?$" OR ZIG_HOST_TARGET_ARCH MATCHES "^powerpc(64)?(le)?$")
615 set(ZIG1_COMPILE_FLAGS "${ZIG1_COMPILE_FLAGS} -ffunction-sections -fdata-sections")615 set(ZIG1_COMPILE_FLAGS "${ZIG1_COMPILE_FLAGS} -ffunction-sections -fdata-sections")
bootstrap.c+2-1
...@@ -136,7 +136,7 @@ int main(int argc, char **argv) {...@@ -136,7 +136,7 @@ int main(int argc, char **argv) {
136 }136 }
137 {137 {
138 const char *child_argv[] = {138 const char *child_argv[] = {
139 cc, "-o", "zig1", "zig1.c", "stage1/wasi.c", "-std=c99", "-Os", "-lm", NULL,139 cc, "-o", "zig1", "zig1.c", "stage1/wasi.c", "-std=c99", "-Os", "-fno-strict-aliasing", "-lm", NULL,
140 };140 };
141 print_and_run(child_argv);141 print_and_run(child_argv);
142 }142 }
...@@ -213,6 +213,7 @@ int main(int argc, char **argv) {...@@ -213,6 +213,7 @@ int main(int argc, char **argv) {
213#if defined(__GNUC__)213#if defined(__GNUC__)
214 "-pthread",214 "-pthread",
215#endif215#endif
216 "-fno-strict-aliasing",
216 workaround_gcc_sra_miscomp ? "-fno-tree-sra" : NULL,217 workaround_gcc_sra_miscomp ? "-fno-tree-sra" : NULL,
217 NULL,218 NULL,
218 };219 };