Repository navigation
DOC: Describe the CMake build and how to run the memory checks - #119
hjmjohnson wants to merge 2 commits into
Conversation
6ca9685 to
7af234f
Compare
gdevenyi
left a comment
There was a problem hiding this comment.
Review by Google Carbon
Verdict: Request Changes
Updating README.md with modern CMake, offline testing, ASan+UBSan, and Valgrind/Docker instructions is very helpful! However, testing the exact commands in README.md against current master surfaced one broken workflow and two sanitizer/valgrind flag gaps:
- Offline workflow (
-DDOWNLOAD_TEST_DATA=OFF+ctest -LE NEEDS_DATA) currently fails onmaster(README.md:97-98): Onmaster(50a9216),nifti2/CMakeLists.txt:165(${TEST_PREFIX}_dsets_test) is missingPROPERTIES LABELS NEEDS_DATA, so running the documentedcmake -S . -B build -DDOWNLOAD_TEST_DATA=OFF && cmake --build build -j && ctest --test-dir build -LE NEEDS_DATAfails onnifti2_dsets_test! Either include that 1-lineset_tests_properties(${TEST_PREFIX}_dsets_test PROPERTIES LABELS NEEDS_DATA)fix here or merge PR#89first. - Missing
-DCMAKE_SHARED_LINKER_FLAGSin the ASan/UBSan snippet (README.md:108-110): Right above at line 96,-DBUILD_SHARED_LIBS=ONis recommended; combining-DBUILD_SHARED_LIBS=ONwith the ASan snippet fails to linklibznz.so/libniftiio.soon Linux GCC unless-DCMAKE_SHARED_LINKER_FLAGS="-fsanitize=address,undefined"is also passed (or-DCMAKE_C_FLAGSis used for both compile & link viaCMAKE_SHARED_LINKER_FLAGS). - Valgrind snippet (
README.md:117) reusesReleasebuildfrom line 91: Runningctest --test-dir build -T memcheckagainst the-DCMAKE_BUILD_TYPE=Releasedirectory omits debug line numbers (-g) in Valgrind backtraces, andctest -T memcheckrequiresMEMORYCHECK_COMMAND(valgrind) to have been present whencmakeconfiguredDartConfiguration.tcl(configuring a dedicated-B build-memcheck -DCMAKE_BUILD_TYPE=Debugas done in the Docker snippet on line 142 avoids both traps).
| ```sh | ||
| cmake -S . -B build-asan -DCMAKE_BUILD_TYPE=Debug \ | ||
| -DCMAKE_C_FLAGS="-fsanitize=address,undefined -fno-sanitize-recover=all" \ | ||
| -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address,undefined" |
There was a problem hiding this comment.
[Google Carbon] Please also include -DCMAKE_SHARED_LINKER_FLAGS="-fsanitize=address,undefined" here so users who add -DBUILD_SHARED_LIBS=ON (from line 96) don't hit undefined __asan_* / __ubsan_* symbols when linking the shared libraries on Linux GCC.
There was a problem hiding this comment.
I could not reproduce this: CMake puts CMAKE_C_FLAGS on the link line of C shared libraries as well as executables, so -fsanitize=address,undefined already reaches libznz.so. The documented snippet with -DBUILD_SHARED_LIBS=ON built and passed its tests with GCC 14 on Debian and with Apple clang, where the dylib link line shows the flag, so I left it unchanged.
nifti_dsets_test reads nifti_regress_data like its neighbors, but was the one test in that block without the NEEDS_DATA label. A build with -DDOWNLOAD_TEST_DATA=OFF therefore failed it under "ctest -LE NEEDS_DATA", the documented way to test without network access.
The build instructions in README.md were two lines about 'make all',
which builds a subset of the tree with a Makefile nothing else in the
project uses. They now describe the CMake build the CI and the install
rules actually use, and note that the Makefile is unmaintained and does
not cover nifti2 or cifti.
A new section records how to run the sanitizers and valgrind, including
three things that each cost an afternoon to work out:
* valgrind's memcheck needs --trace-children=yes here, because most of
the tests are shell scripts that exec the tools. Without it valgrind
inspects the shell, sees nothing and reports a clean run;
* ctest -T memcheck exits 0 even when valgrind reports defects, so the
logs have to be read;
* valgrind refuses to start without the C library's debug symbols, and
on distributions that ship a stripped ld.so with no debuginfo package
-- Arch and its derivatives -- it cannot be run at all, DEBUGINFOD_URLS
included, because those builds are not on any debuginfod server. A
container recipe is given.
Every command in the new sections was run against this tree.
7af234f to
c43e4d2
Compare
Re-submission of #58, reverted from
masteron 2026-09-24 so it can bereviewed before merging. After review it also labels
nifti_dsets_testas
NEEDS_DATA(the same line #89 adds), so the documented offline testrun passes.
Base:
master. Independent: nothing has to land before it.Commits
Ordering for all the re-submitted work is tracked in #84.