Skip to content

Fix issues in CMakeLists.txt (see #996)#998

Merged
MarkCallow merged 4 commits intoKhronosGroup:mainfrom
DanielGibson:cmake-fixes
Apr 15, 2025
Merged

Fix issues in CMakeLists.txt (see #996)#998
MarkCallow merged 4 commits intoKhronosGroup:mainfrom
DanielGibson:cmake-fixes

Conversation

@DanielGibson
Copy link
Contributor

@DanielGibson DanielGibson commented Mar 22, 2025

I fixed some of the issues mentioned in #996:

  • -DASTCENC_DECOMPRESSOR=ON doesn't break the build anymore
    ASTCENC_DECOMPRESSOR is forced OFF and not shown as an option in cmake-gui anymore.
  • Set -fno-strict-aliasing for basisu
  • remove the unused ${BASISU_ENCODER_C_SRC} variable from the basisu source list (this one wasn't mentioned in Issues in the CMakeLists.txt #996, I just noticed this while fixing the other stuff)

@CLAassistant
Copy link

CLAassistant commented Mar 22, 2025

CLA assistant check
All committers have signed the CLA.

@DanielGibson
Copy link
Contributor Author

uhh.. this CLA thing is kinda fishy.

The text of the conditions was in light grey on lighter grey, and when I logged in there with Github (hoping that I could then select what applies to me and see the text black on white) it automatically signs it.
Going back to that page it turns out that it doesn't even have much useful information and the actual CLA is somewhere else, only "linked" there as a non-clickable URL in that unreadable text...

To be clear, I'm fine with the actual CLA conditions, I just find the implementation dubious.

@KhronosWebservices
Copy link
Member

@DanielGibson We are using CLA-Assistant to handle our CLA signings (cla-assistant.io). The text colouring is a bit odd. We will see if we can adjust our Gist to clean that up. Thanks.

Copy link
Collaborator

@MarkCallow MarkCallow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our CI for GNU/Linux, iOS, macOS and the web is undergoing remodelling. Once that is complete I will ask you to rebase this so we can run it through all the compilation checks. I will not merge it until it successfully passes CI. Sorry for the delay.

@DanielGibson
Copy link
Contributor Author

I did the requested changes and rebased to the current main branch

@DanielGibson
Copy link
Contributor Author

DanielGibson commented Apr 5, 2025

image
and
image

Why does this now pretend that I didn't sign the CLA yet?
I did and that was also reflected in the status here, why is it reset?

@MarkCallow
Copy link
Collaborator

Why does this now pretend that I didn't sign the CLA yet?
I did and that was also reflected in the status here, why is it reset?

I don't know. Although this is the first time I am aware of a reset happening during an open PR my own status has been reset between PRs several times. CLAssistant seems to be a black hole. @KhronosWebservices any thoughts on how to prevent this?

Copy link
Collaborator

@MarkCallow MarkCallow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now. Thanks. Please fix the typos I've pointed out. Then we'll have to wait until the CI remodel is finished at which point another rebase will be needed.

@MarkCallow
Copy link
Collaborator

Please investigate the GCC compile failure in the MingW build. Is this due to the change here or a change in the compiler used in the runner? I do not think it is the latter because the runner is using a version of GCC 12 which is now quite old.

@DanielGibson
Copy link
Contributor Author

DanielGibson commented Apr 5, 2025

[75/165] Building CXX object CMakeFiles/ktx.dir/Release/external/basisu/encoder/basisu_uastc_enc.cpp.obj
FAILED: CMakeFiles/ktx.dir/Release/external/basisu/encoder/basisu_uastc_enc.cpp.obj 
C:\mingw64\bin\g++.exe -DBASISD_SUPPORT_FXT1=0 -DBASISD_SUPPORT_KTX2=1 -DBASISD_SUPPORT_KTX2_ZSTD=0 -DBASISU_NO_ITERATOR_DEBUG_LEVEL -DBASISU_SUPPORT_OPENCL=0 -DBASISU_SUPPORT_SSE=1 -DKTX_API=__declspec(dllexport) -DKTX_FEATURE_KTX1 -DKTX_FEATURE_KTX2 -DKTX_FEATURE_WRITE -DLIBKTX -DSUPPORT_SOFTWARE_ETC_UNPACK=1 -DWIN32_HAS_PTHREADS -Dktx_EXPORTS -DCMAKE_INTDIR=\"Release\" -ID:/a/KTX-Software/KTX-Software/include -ID:/a/KTX-Software/KTX-Software/external/basisu/transcoder -ID:/a/KTX-Software/KTX-Software/external -ID:/a/KTX-Software/KTX-Software/external/basisu/zstd -ID:/a/KTX-Software/KTX-Software/utils -ID:/a/KTX-Software/KTX-Software/external/dfdutils -ID:/a/KTX-Software/KTX-Software/external/basisu -ID:/a/KTX-Software/KTX-Software/external/astc-encoder/Source -isystem D:/a/KTX-Software/KTX-Software/other_include -O3 -DNDEBUG -Wall -Wextra -Werror -O3 -ffp-contract=off -Wno-cast-function-type -Wno-pedantic -msse4.1 -Wno-sign-compare -Wno-unused-variable -Wno-class-memaccess -Wno-misleading-indentation -Wno-extra -Wno-deprecated-copy -Wno-parentheses -fno-strict-aliasing -MD -MT CMakeFiles/ktx.dir/Release/external/basisu/encoder/basisu_uastc_enc.cpp.obj -MF CMakeFiles\ktx.dir\Release\external\basisu\encoder\basisu_uastc_enc.cpp.obj.d -o CMakeFiles/ktx.dir/Release/external/basisu/encoder/basisu_uastc_enc.cpp.obj -c D:/a/KTX-Software/KTX-Software/external/basisu/encoder/basisu_uastc_enc.cpp
In file included from C:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/c++/bits/stl_pair.h:61,
                 from C:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/c++/bits/stl_algobase.h:64,
                 from C:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/c++/bits/specfun.h:45,
                 from C:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/c++/cmath:1935,
                 from C:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/c++/math.h:36,
                 from D:/a/KTX-Software/KTX-Software/external/basisu/transcoder/basisu.h:59,
                 from D:/a/KTX-Software/KTX-Software/external/basisu/encoder/basisu_etc.h:16,
                 from D:/a/KTX-Software/KTX-Software/external/basisu/encoder/basisu_uastc_enc.h:16,
                 from D:/a/KTX-Software/KTX-Software/external/basisu/encoder/basisu_uastc_enc.cpp:15:
In function 'std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = unsigned char]',
    inlined from 'void basisu::pack_uastc(basist::uastc_block&, const uastc_encode_results&, const etc_block&, uint32_t, const eac_a8_block&, bool, bool)' at D:/a/KTX-Software/KTX-Software/external/basisu/encoder/basisu_uastc_enc.cpp:326:18:
C:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/c++/bits/move.h:205:11: error: writing 2 bytes into a region of size 0 [-Werror=stringop-overflow=]
  205 |       __a = _GLIBCXX_MOVE(__b);
      |           ^
D:/a/KTX-Software/KTX-Software/external/basisu/encoder/basisu_uastc_enc.cpp: In function 'void basisu::pack_uastc(basist::uastc_block&, const uastc_encode_results&, const etc_block&, uint32_t, const eac_a8_block&, bool, bool)':
D:/a/KTX-Software/KTX-Software/external/basisu/encoder/basisu_uastc_enc.cpp:253:25: note: at offset 18 into destination object 'endpoints' of size 18
  253 |                 uint8_t endpoints[18];
      |                         ^~~~~~~~~
cc1plus.exe: all warnings being treated as errors

I don't see how my changes should cause this and I don't even think it's a valid warning.

If I understand correctly, the compiler says that

std::swap(endpoints[c * 2 + 0], endpoints[c * 2 + 1]);

can access endpoints[18] ("at offset 18 into destination object 'endpoints' of size 18") which would be out of bounds because it only has 18 elements, see
But I have no idea where that assumption comes from, because c < total_comps, which comes from some global array:
const uint32_t total_comps = g_uastc_mode_comps[result.m_uastc_mode];

I don't know why the compiler assumes that c can be 9 (then endpoints[c * 2 + 0] would be endpoints[18]). It probably can't "see" the values of that array (it's defined in external/basisu/transcoder/basisu_transcoder.cpp and its biggest value is 4 so c will be <= 3), but if it assumes that it can have invalid values, it could as well assume that c is 254 and that it would access endpoints[508] and endpoints[509] which is even more out of bounds...

Did the compiler version on the runner change? Even if GCC12 is "quite old", if it was an even older version before it could be that the warning only turned up in GCC12

@MarkCallow
Copy link
Collaborator

Did the compiler version on the runner change? Even if GCC12 is "quite old", if it was an even older version before it could be that the warning only turned up in GCC12

Thank you for the analysis. I agree the warning seems strange. However the compiler version did not change and builds on other branches are compiling without warning using this compiler. See https://github.com/KhronosGroup/KTX-Software/actions/runs/14324522719/job/40147530265?pr=1010. Therefore something here is triggering the compiler into issuing that warning. Please check if it is the removal of the suppression of the strict aliasing warning or the addition of `-fno-strict-aliasing. I want to understand what is going on before, possibly, adding yet another warning suppression. Never mind. I just figured out the cause. This code disables stringop-overflow on 2 encoder files and on the transcoder.

KTX-Software/CMakeLists.txt

Lines 873 to 901 in 70ed9b9

if (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL "12.0")
# Version 12 newly raises this warning on basisu_uastc_enc.cpp.
# There seems no way for the index calculated by the code at
# line 326, where the error is raised, to be > the array length.
# Also we have never seen any crashes.
set_source_files_properties(
external/basisu/encoder/basisu_uastc_enc.cpp
PROPERTIES COMPILE_OPTIONS "-Wno-stringop-overflow"
)
endif()
if (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL "14.0")
# Version 14 raises stringop-overflow on these files.
get_source_file_property(cur_options
external/basisu/encoder/basisu_comp.cpp
COMPILE_OPTIONS
)
set_source_files_properties(
external/basisu/transcoder/basisu_transcoder.cpp
PROPERTIES COMPILE_OPTIONS "${cur_options};-Wno-stringop-overflow"
)
get_source_file_property(cur_options
external/basisu/encoder/basisu_bc7enc.cpp
COMPILE_OPTIONS
)
set_source_files_properties(
external/basisu/encoder/basisu_bc7enc.cpp
PROPERTIES COMPILE_OPTIONS "${cur_options};-Wno-stringop-overflow"
)
endif()

However your change is taking the COMPILE_OPTIONS from basisu_comp.cpp adding -fno-strict-aliasing and applying those to all the encoder source thereby removing the -Wno-stringop-overflow from the 2 files where it is set. Please fix.

I just noticed a similar bug in the code above w.r.t basisu_transcoder.cpp. It is taking the COMPILE_OPTIONS from basisu_comp.cpp and applying them to basisu_transcoder.cpp Please fix this too.

@DanielGibson
Copy link
Contributor Author

Oh, right.

These hyperspecific disabled warnings per source file and per compiler version are confusing and painful to handle :-/
I'll try to figure out a better way to add -fno-strict-aliasing.

@DanielGibson
Copy link
Contributor Author

There are other similar bugs in that cmake code, by the way.

https://github.com/KhronosGroup/KTX-Software/blob/v4.4.0/CMakeLists.txt#L885-L892
gets the COMPILE_OPTIONS from basisu_comp.cpp and then sets them for basisu_transcoder.cpp

https://github.com/KhronosGroup/KTX-Software/blob/v4.4.0/CMakeLists.txt#L878-L881
sets the compile options for basisu_uastc_enc.cpp without getting them first, so the generic ones set in https://github.com/KhronosGroup/KTX-Software/blob/v4.4.0/CMakeLists.txt#L847-L852 are lost

@DanielGibson
Copy link
Contributor Author

should be better now :)

@DanielGibson DanielGibson force-pushed the cmake-fixes branch 3 times, most recently from 0f401c3 to 0540531 Compare April 8, 2025 18:16
Copy link
Collaborator

@MarkCallow MarkCallow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this nice refactoring.

I will wait until Emscripten, iOS, Linux and macOS CI is functional again before merging. I'll let you know when it is functional then you can rebase this and let the updated CI run it.

@MarkCallow
Copy link
Collaborator

Please rebase against latest main to run CI on all platforms.

it's never set, probably a leftover from an older basisu version that
also contained C code?
Several basisu headers demand doing this ("Important: If compiling with
 gcc, be sure strict aliasing is disabled: -fno-strict-aliasing") and
their own CMakeLists.txt (that's not used here) also sets it and
explicitly mentions (in a comment in its first line) that strict
aliasing optimizations must be disabled for both the encoder and decoder
It's an option provided by external/astc-encoder/CMakeLists.txt
but setting it to ON in KTX-Software breaks the build.
So set it to OFF and make it an INTERNAL variable so it's not shown
in cmake-gui where it could lure users to enable it.

While at it, also fixed the line number in a comment,
and a typo in another comment.
There were bugs where get_source_file_property() was called on a
different file than set_source_file_properties() were called on
afterwards, which lead to eat least one new compiler warning.

A helper function makes this more readable and less error-prone, and
allows appending an option to multiple files without overwriting their
existing options.
@DanielGibson
Copy link
Contributor Author

done (you may have to manually approve running github actions for them to run)

@MarkCallow MarkCallow merged commit c033ac8 into KhronosGroup:main Apr 15, 2025
36 checks passed
richgel999 pushed a commit to BinomialLLC/KTX-Software-Binomial-Fork that referenced this pull request Mar 9, 2026
* `ASTCENC_DECOMPRESSOR` is forced OFF and not shown as an option in
    cmake-gui anymore.
* Set `-fno-strict-aliasing` for basisu
* remove the unused `${BASISU_ENCODER_C_SRC}` variable from the basisu
   source list.

Fixes KhronosGroup#996.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants