Repository navigation
Fix JPEG XL crash with upstream MinGW GCC (#211) - #212
Merged
Merged
Conversation
Issue #211 crashed in libjxl's AVX2 upsampling stage on MinGW GCC, and no CI job built the bundled codecs with that toolchain. Add a windows-mingw-gcc job (UCRT64 Debug/Release, MINGW64 Debug static). Add lossy, progressive and upsampled JXL fixtures so JpegXLTest also runs VarDCT and the upsampling stages' SIMD row code.
The first MinGW GCC run passed without the #211 fix: alignment inside the decoder depends only on the caller's stack depth, so repeating a decode from the same frame repeats the same alignment. Offset the stack by 16-byte steps so the fixtures cover every 32- and 64-byte alignment class.
MSYS2 patches its GCC to default to unaligned vector moves (0200-add-m-no-align-vector-insn-option-for-i386), so the MSYS2 jobs passed without the fix. Build the bundled codecs with the preinstalled mingw-builds GCC in C:\mingw64 for Debug and Release, and keep one MSYS2 job as build coverage. Cap ctest at 300 s per test so a hang fails fast.
GCC targeting Windows cannot realign the stack past 16 bytes (GCC bug 54412) but still spills AVX registers with vmovaps/vmovdqa. libjxl's N_AVX2::UpsamplingStage constructor, built at -O0, stored to a 16-byte aligned slot and faulted. Pass -Wa,-muse-unaligned-vector-move when the assembler supports it, as MSYS2 does for its packages. The bundled codecs inherit it through CMAKE_C_FLAGS/CMAKE_CXX_FLAGS.
danoli3
force-pushed
the
fix/211-jxl-mingw-crash
branch
from
October 26, 2026 12:31
a41c2df to
903e9c7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #211.
Cause
GCC targeting 64-bit Windows cannot realign the stack past 16 bytes (GCC bug 54412), but it still spills AVX registers with aligned
vmovaps/vmovdqa. Those instructions fault when the stack slot is not 32-byte aligned.libjxl builds an 8x upsampling stage on every decode (
PassesDecoderState::Init,dec_cache.h:174), so every JPEG XL load runsjxl::N_AVX2::UpsamplingStage's constructor. Built with mingw GCC at-O0, that constructor stores to-192(%rbp)withvmovdqa, and%rbpthere is only 16-byte aligned. Optimized builds have fewer such stores, but still crash.Fix
On MinGW GCC, CMake passes
-Wa,-muse-unaligned-vector-move(binutils 2.38+) after checking the assembler accepts it. The assembler then emits unaligned moves, which are correct at any alignment. It applies to FreeImage's own sources (LibWebP and OpenEXR also have AVX2 paths) and to every bundled codec throughCMAKE_C_FLAGS/CMAKE_CXX_FLAGS. Onstage_upsampling.ccthis takes the aligned vector moves from 5765 to 0.Why CI did not catch it
0200-add-m-no-align-vector-insn-option-for-i386.patch), so MSYS2 jobs cannot reproduce this. The first version of the new job used MSYS2 and passed without the fix.Changes
CMakeLists.txt: the assembler flag for MinGW GCC.bundled-codecs.yml:windows-mingw-gccbuilds the bundled codecs with the runner's unpatched mingw-builds GCC 15.2 (C:\mingw64), Debug and Release.windows-msys2-gccstays as build coverage. ctest stops any test after 300 s.TestAPI/jxl/: lossy, progressive, 2x/4x upsampled and alpha-upsampled fixtures with a reference PNG and a README giving thecjxlcommands.JpegXLTestdecodes the fixtures with the stack offset in 16-byte steps, and checks alpha-weighted error against the reference.Verification
JpegXLTestSegFaultJpegXLTestSegFaultAll 18 jobs in the fixed run pass.
Possibly related
cmake.yml'swindows-mingwjob uses the same unpatched toolchain and forcesBUILD_OPENEXR=OFFbecause the test binary hung beforemain(). MSYS2 never hit that hang. It may be the same bug, but the new job builds OpenEXR and did not hang even without the fix, so this PR leaves that workaround alone.