Harden the cmake Address Sanitizer detection code.#960
Conversation
|
The sanitizer CMake is too borrowed from zlib-ng, so I'm uncomfortable changing it. |
| endif() | ||
| if(NOT MZ_STATUS) | ||
| set(MZ_SANITIZER_ENABLED OFF) | ||
| message(FATAL_ERROR "Cannot enable the Address Sanitizer '${MZ_SANITIZER}' option") |
There was a problem hiding this comment.
Let's just log "Sanitizer" without "Address", as it can be any of them.
| endif() | ||
| elseif(MZ_SANITIZER_LOWER STREQUAL "none") | ||
| set(MZ_SANITIZER_ENABLED OFF) | ||
| message(STATUS " Address Sanitizer not enabled") |
There was a problem hiding this comment.
Let's just log "Sanitizer" without "Address", as it can be any of them.
| add_feature_info(MZ_BUILD_UNIT_TESTS MZ_BUILD_UNIT_TESTS "Builds minizip unit test project") | ||
| add_feature_info(MZ_BUILD_FUZZ_TESTS MZ_BUILD_FUZZ_TESTS "Builds minizip fuzzer executables") | ||
| add_feature_info(MZ_CODE_COVERAGE MZ_CODE_COVERAGE "Builds with code coverage flags") | ||
| add_feature_info(MZ_SANITIZER MZ_SANITIZER_ENABLED "Builds with Address Sanitizer") |
There was a problem hiding this comment.
Let's just log "Sanitizer Support" instead of "Address Sanitizer", as it can be any of them.
The change looks good to me. @pmqs can you also offer a PR for the zlib-ng repository eventually? |
@Coeur, as it happens I'm ahead of you. Already looking at the equivalent change in zlib-ng because there is a knock-on impact with it for Sanitizer support with the Microsoft C compiler. Will write up the details in the zlib-ng PR. I'll park this change for now & get the same fix done in the much simpler zlib-ng use case sorted first. |
| add_thread_sanitizer() | ||
| elseif(MZ_SANITIZER STREQUAL "Undefined") | ||
| add_undefined_sanitizer() | ||
| message(STATUS "Checking for Address Sanitizer Option") |
There was a problem hiding this comment.
maybe remove "Address" here?
53fc513 to
5bede13
Compare
| cxx-compiler: g++ | ||
| cmake-args: -D MZ_SANITIZER=Memory | ||
| codecov: ubuntu_gcc_msan | ||
| # Memory Sanitizer not currenly supported on GitHub |
There was a problem hiding this comment.
https://stackoverflow.com/questions/71675493/how-use-memory-sanitizer-with-use-gcc
From what I have seen, MSAN is not supported with GCC, so I think this can be removed.
There was a problem hiding this comment.
https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html
No --fsanitize=memory.
There was a problem hiding this comment.
Yep, that's my understanding as well -- clang only
|
Has this been updated with the latest changes from zlib-ng? |
Yes, it has. |
|
@pmqs can you please rebase this and see if those Windows builds are fixed? I would do it myself, but last time it messed it up for you. |
|
Rather than deleting the MSAN job, change it to use clang, matching zlib-ng's approach:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis PR switches the CI MSAN job from GCC to Clang, updates MSAN-related CI tooling and build flags, normalizes and lowercases CMake sanitizer option handling, and turns several sanitizer detection failures (Memory/Thread/UB) into fatal CMake errors while adjusting ASan handling on MSVC. Changes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b074582b-6336-49c5-9a24-b172582c5a7d
📒 Files selected for processing (3)
.github/workflows/build.ymlCMakeLists.txtcmake/detect-sanitizer.cmake
| build-config: Debug | ||
| # https://github.com/llvm/llvm-project/issues/55785 | ||
| msan-options: use_sigaltstack=0 |
There was a problem hiding this comment.
build-config: Debug and msan-options are both effectively no-ops here.
Two problems in the same matrix entry:
build-config: Debugis consumed at build/test time (--config ${{ matrix.build-config || 'Release' }}on lines 260 and 263), but the configure step on line 252 hardcodes-D CMAKE_BUILD_TYPE=Release, and this job uses-GNinja(a single-config generator) so--configis ignored. Net result: the MSAN job compiles and runs a Release binary, which is exactly the configuration you don't want for triaging sanitizer reports (inlining/opt noise, poor origin tracking).msan-options: use_sigaltstack=0is defined but never exported. There is no reference tomatrix.msan-optionsanywhere in theenv:blocks of theCompile source codeorRun test casessteps, soMSAN_OPTIONSis never set and the sigaltstack workaround (the reason the llvm issue is even linked on line 36) won't take effect at runtime.
Suggested wiring:
🔧 Proposed fix
- name: Generate project files
shell: bash
run: |
cmake -S . -B ${{ matrix.build-dir || '.' }} ${{ matrix.cmake-args }} \
-D MZ_BUILD_TESTS=ON \
-D MZ_BUILD_UNIT_TESTS=ON \
-D BUILD_SHARED_LIBS=OFF \
- -D CMAKE_BUILD_TYPE=Release
+ -D CMAKE_BUILD_TYPE=${{ matrix.build-config || 'Release' }}
env:
CC: ${{ matrix.compiler }}
CXX: ${{ matrix.cxx-compiler }}
CFLAGS: ${{ matrix.cflags }}
LDFLAGS: ${{ matrix.ldflags }}
- name: Compile source code
run: cmake --build ${{ matrix.build-dir || '.' }} --config ${{ matrix.build-config || 'Release' }}
- name: Run test cases
run: ctest --output-on-failure -C ${{ matrix.build-config || 'Release' }}
working-directory: ${{ matrix.build-dir }}
+ env:
+ MSAN_OPTIONS: ${{ matrix.msan-options }}|
@pmqs thanks for your help! I will fix the MSAN issues from here. |
Currently the sanitizer detection code will silently ignore error cases -- like when given an unknown option or when it is asked for a valid sanitizer that isn't available for the platform. This one has stung me a few times.
This change makes it a fatal error to
One thng that dropped out with this change is the use of the Memory Sanitizer in
build.yml, Turns out that it is not available on Ubuntu, so has been adding nothing to our test coverage. I think that may be a limitation of virtualisation. I've just disabled it for now.This is what
build.ymlhad when (not) detecting the memory Sanitizer: