bootstrap: work around GCC bug

GCC bug 119085, which affects versions 13.0--15.1, is being triggered by
the C backend, resulting in a (small but critical) miscompilation in
zig2. Unfortunately, we can't really work around that bug without a
command-line flag, because the bug is sensitive to things like the order
in which `struct` types are defined.

Therefore, I have added an option to `bootstrap.c` which causes it to
pass the appropriate flag to `gcc` to disable the optimization pass in
question. This flag can likely be removed in future, once the affected
GCC versions become less common.

At least one of our x86_64-linux CI machines is using an affected GCC
version, so I also updated the relevant CI script to pass this flag when
testing no-LLVM bootstrap.

CMakeLists also has a workaround, but no user intervention is required
there: the GCC version range is automatically detected by CMakeLists.
This commit is contained in:
Matthew Lugg
2026-03-04 10:52:54 +00:00
parent c73db56b45
commit a5219cd288
3 changed files with 33 additions and 3 deletions
+10 -2
View File
@@ -330,7 +330,6 @@ set(ZIG_STAGE2_SOURCES
src/Air/Liveness.zig
src/Air/Liveness/Verify.zig
src/Air/print.zig
src/Air/types_resolved.zig
src/Builtin.zig
src/Compilation.zig
src/Compilation/Config.zig
@@ -344,6 +343,7 @@ set(ZIG_STAGE2_SOURCES
src/Sema.zig
src/Sema/bitcast.zig
src/Sema/comptime_ptr_access.zig
src/Sema/type_resolution.zig
src/Type.zig
src/Value.zig
src/Zcu.zig
@@ -360,7 +360,8 @@ set(ZIG_STAGE2_SOURCES
src/codegen/aarch64/Mir.zig
src/codegen/aarch64/Select.zig
src/codegen/c.zig
src/codegen/c/Type.zig
src/codegen/c/type.zig
src/codegen/c/type/render_defs.zig
src/codegen/llvm.zig
src/codegen/llvm/bindings.zig
src/crash_report.zig
@@ -375,6 +376,7 @@ set(ZIG_STAGE2_SOURCES
src/libs/libunwind.zig
src/link.zig
src/link/C.zig
src/link/ConstPool.zig
src/link/Coff.zig
src/link/Dwarf.zig
src/link/Elf.zig
@@ -623,6 +625,12 @@ else()
else()
set(ZIG2_LINK_FLAGS "-Wl,-z,stack-size=0x10000000")
endif()
# Prevent GCC from miscompiling 'zig2.c'. See also 'workaround_gcc_sra_miscomp' in 'bootstrap.c'.
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "13.0" AND
CMAKE_C_COMPILER_VERSION VERSION_LESS_EQUAL "15.2")
set(ZIG2_COMPILE_FLAGS "${ZIG2_COMPILE_FLAGS} -fno-tree-sra")
endif()
endif()
set(ZIG1_WASM_MODULE "${PROJECT_SOURCE_DIR}/stage1/zig1.wasm")