From 5a76c59e8eb8abdef8272507d31d375ed2be4d2c Mon Sep 17 00:00:00 2001 From: Sava Znatnov Date: Mon, 2 Nov 2026 18:15:01 +0700 Subject: [PATCH] Build ISA-specific sources with -fno-lto With GCC LTO, the static initializers of the sources built with per-file -msse/-mavx/-mavx2/-mavx512f flags are merged into the library's single load-time constructor. That constructor can then contain AVX-512 instructions, so loading the library crashes with SIGILL on CPUs without them. OpenEXR 3.5.3 hit this with its bundled copy of OpenJPH. Keep these files out of LTO so their initializers stay in their own functions. The AVX-512 kernels are unchanged and still selected at run time. Co-Authored-By: Claude Sonnet 5.5 --- src/core/CMakeLists.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index c624c108..6b08f65a 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -108,6 +108,24 @@ else() set_source_files_properties(transform/ojph_transform_avx.cpp PROPERTIES COMPILE_FLAGS -mavx) set_source_files_properties(transform/ojph_transform_avx2.cpp PROPERTIES COMPILE_FLAGS -mavx2) set_source_files_properties(transform/ojph_transform_avx512.cpp PROPERTIES COMPILE_FLAGS "-mavx512f -mavx512cd") + + # The files above are compiled with ISA flags (-mavx2, -mavx512f, ...). + # Under LTO, GCC merges the static initializers of all translation units + # into one constructor that inherits those ISA flags, so merely loading + # the library can execute AVX/AVX2/AVX-512 instructions on any CPU. + # Keep these files out of LTO so their initializers stay in their own + # functions. + set_source_files_properties( + codestream/ojph_codestream_sse.cpp codestream/ojph_codestream_sse2.cpp + codestream/ojph_codestream_avx.cpp codestream/ojph_codestream_avx2.cpp + coding/ojph_block_decoder_ssse3.cpp coding/ojph_block_decoder_avx2.cpp + coding/ojph_block_encoder_avx2.cpp coding/ojph_block_encoder_avx512.cpp + transform/ojph_colour_sse.cpp transform/ojph_colour_sse2.cpp + transform/ojph_colour_avx.cpp transform/ojph_colour_avx2.cpp + transform/ojph_transform_sse.cpp transform/ojph_transform_sse2.cpp + transform/ojph_transform_avx.cpp transform/ojph_transform_avx2.cpp + transform/ojph_transform_avx512.cpp + PROPERTIES COMPILE_OPTIONS "-fno-lto") endif() endif()