Skip to content

Do not treat the CFI build as a sanitizer build in the test harnesses - #115591

Merged
alexey-milovidov merged 6 commits into
ClickHouse:masterfrom
groeneai:fix-115122-cfi-not-a-sanitizer-build
Aug 21, 2026
Merged

alexey-milovidov merged 6 commits into
ClickHouse:masterfrom
groeneai:fix-115122-cfi-not-a-sanitizer-build

Conversation

@groeneai

@groeneai groeneai commented Aug 20, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Description

Closes: #115122

Two test harnesses decide whether a build is a sanitizer build by testing CXX_FLAGS LIKE '%-fsanitize=%'. The amd_cfi profile adds -fsanitize=cfi-vcall,cfi-derived-cast
(CMakeLists.txt:527), so the substring matches even though -DSANITIZE= is empty:

  • tests/config/install.sh:227 installs config.d/trace_log_no_symbolize.xml, so
    TraceLog.cpp:298-299 inserts a zero-length array into symbols and lines, failing the two
    03150_trace_log_* tests.
  • tests/integration/helpers/cluster.py:5152 is_built_with_sanitizer() makes 50 no-argument call
    sites across 35 integration test files skip themselves, test_trace_log_build_id saying
    "trace_log is disabled with sanitizers", which is not true under CFI.

Both now test -DSANITIZER, which cmake/sanitize.cmake:30 puts into SAN_FLAGS and which reaches
CMAKE_CXX_FLAGS in all 5 branches of if (SANITIZE) and nowhere else. The named address /
thread / memory checks keep testing -fsanitize=<name>.

The reporter's open question is answered, and negatively: official release builds are not
affected.
amd_cfi and amd_release differ by exactly one flag (-DENABLE_CFI=1 versus
-DBUILD_STANDALONE_KEEPER=1), so ThinLTO with split-debug and stripping is already the shipped
configuration.

Validated on the exact binary from the failing job (build ID e3992b92...): with the override
present both 03150_* tests fail; with the patched script both pass. That binary is now classified
as not sanitized while a real ASan binary still is, the regression risk this PR's ASan/TSan/MSan
lanes cover.

No existing check can show the 03150_* tests green: WeeklyCFI on master runs only build,
integration and stress (ci/workflows/weekly_cfi.py:30-34), and the stateless amd_cfi lane arrives
with #115036, still open. Since both consumers react by skipping work, a revert would stay green, so
ci/tests/test_cfi_not_a_sanitizer_build.py pins both predicates against the measured CXX_FLAGS of
nine profiles, running the installer's own function with a stub clickhouse. It runs on every PR,
and both predicate files are now CI Tests digest inputs so a later edit cannot reuse a cached pass.
#113107 edits the same block, so whichever lands second may need a rebase.

CI report.

Other users of an -fsanitize string test, left unchanged (click to expand)

I checked every in-tree consumer of the same "is this a sanitizer build" idea and changed the two
that are reachable under CFI and change test outcomes:

consumer reachable under CFI? why left alone
install.sh:92 is_fast_build no its only call site needs FAST_TEST=1, whose only producer builds with -DENABLE_THINLTO=0 and no CFI, and CFI without ThinLTO is a cmake FATAL_ERROR
tests/clickhouse-test:5135 collect_build_flags yes already correct: it maps sanitizer names, so CFI yields no flag and SANITIZED stays false. It must keep the name map to emit per-sanitizer no-asan/no-tsan tags, which a boolean marker cannot express
tests/docker_scripts/upgrade_runner.sh:171 no there is no amd_cfi upgrade job
tests/integration/test_userspace_page_cache/test.py:31 yes its own local probe, run before the cluster starts so it cannot use the helper. The consequence is one extra container under CFI, not a wrong result
ci/jobs/scripts/functional_tests/setup_log_cluster.sh:102 yes the value is only echoed, never read again anywhere in the tree - a dead diagnostic

Stress test (amd_cfi) also runs install.sh on master, so that predicate is exercised there, but
that suite asserts nothing about symbolized trace_log.

Each remaining one is a separate question with no observed consequence today, so widening this PR
to them would be unmeasured churn.


Workflow [PR]
Sync PR [sync-upstream/pr/115591]

Version info

  • Merged into: 26.8.1.1830 (included in 26.8 and later)

…staller

tests/config/install.sh classified a build as a sanitizer build by testing
CXX_FLAGS LIKE '%-fsanitize=%'. The amd_cfi profile adds
-fsanitize=cfi-vcall,cfi-derived-cast (CMakeLists.txt:527), so the substring
matched even though -DSANITIZE= is empty. The harness therefore installed
config.d/trace_log_no_symbolize.xml, TraceLog stored symbolize = false, and
TraceLog.cpp:296-299 inserted a zero-length array into both symbols and lines.
That is why 03150_trace_log_add_build_id and 03150_trace_log_source_lines fail
under amd_cfi. CFI is a link-time vtable check with no runtime interception of
allocation or memory access, so the override's purpose (in-flush symbolization
being too slow under sanitizer instrumentation) does not apply to it.

Test the build system's own marker instead. cmake/sanitize.cmake:30 puts
-DSANITIZER into SAN_FLAGS, which is applied to CMAKE_CXX_FLAGS in all five
branches of the if (SANITIZE) block and nowhere else in the tree, and
sanitize.cmake:150-152 fails configure if a branch loses it. A hardcoded
sanitizer-name list would be a second parser to keep in sync with cmake.

Measured on three real binaries: the ASan snapshot still returns 1, the exact
amd_cfi artifact from the failing job (build ID e3992b92853623fcc8ebea13060c0d
7603f98201) now returns 0, the debug snapshot is unchanged at 0. End to end,
running the real install.sh and the real test files against that artifact: with
the reverted script both tests fail (0 1 0 and 0 0, every trace row carrying
zero-length arrays), with this change both pass (0 1 1 and 0 1) and real frames
appear.

Nothing is wrong with symbolization, ThinLTO, CFI codegen, SPLIT_DEBUG_SYMBOLS
or BUILD_STRIPPED_BINARY. Official release builds are not affected: amd_cfi and
amd_release differ by exactly one flag (ENABLE_CFI versus
BUILD_STANDALONE_KEEPER), both carry ENABLE_THINLTO=1, an empty SANITIZE,
SPLIT_DEBUG_SYMBOLS=ON and BUILD_STRIPPED_BINARY=1, so ThinLTO with split debug
symbols and a stripped binary is the shipped release configuration.

Closes: ClickHouse#115122
The note added in the previous commit called CFI a "link-time-only check".
CFI requires ThinLTO at link time, but it enforces at runtime: CMakeLists.txt:519-520
documents that a violation executes an illegal instruction (SIGILL) and CI's
core-dump handler turns that into a stack trace, and CFI_FLAGS at
CMakeLists.txt:527 carries -fno-sanitize-recover=cfi, which is a runtime
continue-after-violation policy.

The load-bearing invariant is unchanged and is now stated accurately: CFI traps
on a bad vcall or cast without linking a sanitizer runtime, so in-flush
symbolization is not slowed down and the trace_log_no_symbolize.xml override
does not apply.

Comment text only. Stripping full-line comments from tests/config/install.sh at
the previous commit and at this one yields byte-identical files, so no rebuild
or re-validation is required.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Aug 20, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (click to expand)

Reviewed cold before reading the implementation notes, then re-reviewed by an independent model
against the frozen PR body. Verdicts below; every AGREE is fixed in this branch.

# Finding Verdict
❌ The comment added to is_sanitizer_build called CFI a "link-time-only check". CFI requires ThinLTO at link time but enforces at runtime: CMakeLists.txt:519-520 documents that a violation executes an illegal instruction, and CFI_FLAGS carries -fno-sanitize-recover=cfi, a runtime policy. AGREE, fixed. The comment now says CFI's checks trap on a bad vcall or cast without a sanitizer runtime, which is the actual reason symbolization stays fast.
❌ The PR body named Stateless tests (amd_cfi, parallel) in WeeklyCFI as the check that verifies this, and asked for such a run. Master's WeeklyCFI has no stateless job (ci/workflows/weekly_cfi.py:30-34); that lane arrives with #115036, still open. AGREE, fixed. The body and the issue reply now state that no existing check can show these tests green, and ask for nothing that cannot be run.
⚠️ Three line citations in the body were off: clickhouse-test:5150 is an import (the function is :5135), and TraceLog.cpp:296 is #endif (the inserts are :298-299). AGREE, fixed.
⚠️ The body said setup_log_cluster.sh:102 "selects a log-cluster schema". Its value is assigned and echoed, never read again anywhere in the tree. AGREE, fixed: it is described as a dead diagnostic, which is a stronger reason to leave it alone.
💡 #113107 edits the same install.sh block without touching this function, so whichever lands second may need a trivial textual rebase. AGREE, noted in the body.

Independently re-derived and confirmed: -DSANITIZER is emitted only by cmake/sanitize.cmake:30
and reaches CMAKE_CXX_FLAGS in all five if (SANITIZE) branches and nowhere else; no
CMAKE_CXX_FLAGS write between sanitize.cmake and print_flags.cmake is a reset, so the marker
survives into the system.build_options row; contrib's own copy of the flag cannot leak into that
row; the two 03150_* tests do fail if the change is reverted, by contract rather than by
inference; and a real ASan binary still answers 1 to the new predicate (measured, not read).

@clickhouse-gh clickhouse-gh Bot closed this Aug 20, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Aug 20, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. On the exact binary from the failing job (build ID e3992b92...), the symbolize=false arm returns 0/0 for the two assertions with 65 of 65 trace rows carrying zero-length symbols and lines, on every run. CI reports 49/49 and 52/52.
b Root cause explained? Yes. install.sh:227 tests CXX_FLAGS LIKE '%-fsanitize=%'; CMakeLists.txt:527 adds -fsanitize=cfi-vcall,cfi-derived-cast to the CFI build, so the substring matches with -DSANITIZE= empty; the harness installs trace_log_no_symbolize.xml; SystemLog.cpp:285 sets symbolize_traces=false; TraceLog.cpp:296-299 inserts a zero-length array. Confirmed at each link, including the failing job's own job.log:323-326 installing the symlink, and the artifact's arrays being zero-length rather than empty strings (a failed lookup would emit empty strings at TraceLog.cpp:287-288).
c Fix matches root cause? Yes. The build classifier is wrong, so the classifier is corrected. Not a second config override fighting the first, not a test skip, not a weakened assertion. no-cfi-style skipping was already tried and reverted by the profile's author.
d Test intent preserved / new tests added? Yes. Both 03150_* tests are untouched and now pass under amd_cfi rather than being skipped or relaxed. No new test file: the regression is a shell predicate with no SQL surface, and these two tests are exactly its oracle.
e Both directions demonstrated? Yes, twice. Config-level A/B on one binary with only <symbolize> differing: false gives 0/0, true gives 1/1 with real frames. End-to-end through the real install.sh and the real .sql files against the committed .reference: patched script both pass (0 1 1, 0 1), reverted script both fail (0 1 0, 0 0).
f Fix is general across code paths? Yes for the reachable carrier. All seven in-tree consumers of an -fsanitize string test were enumerated; only install.sh:227 is reachable under CFI and corrupts output, and it is fixed. is_fast_build is unreachable (its call site needs FAST_TEST=1, whose only producer disables ThinLTO, and CFI without ThinLTO is a cmake FATAL_ERROR); collect_build_flags is already correct; the rest are in other suites where the consequence is lost coverage, not wrong output. Tabled in the PR description.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A for type wrappers (a shell test over a build-flag string). The real input space is the set of build profiles and it was enumerated: -DSANITIZER is emitted by SAN_FLAGS in all 5 branches of if (SANITIZE) and nowhere else in the tree; measured on three real binaries (ASan 1, CFI 0, debug 0); the per-target -fsanitize=fuzzer-no-link never reaches CXX_FLAGS, and -fsanitize-coverage= does not contain the -fsanitize= substring, so coverage builds are unaffected either way.
h Backward compatible? Yes, nothing to migrate. Test-harness shell only: no setting, no serialization format, no SettingsChangesHistory.cpp entry.
i Invariants and contracts preserved? Yes. The invariant is that a build counts as sanitized exactly when it carries a runtime sanitizer. CFI violated it before this change and all three measured binaries satisfy it after. The function has a single call site tree-wide (install.sh:232) controlling one symlink, so nothing else keys off it. sanitize.cmake:150-152 fails configure if a sanitizer branch loses SAN_FLAGS, so the marker cannot silently disappear.

Session id: cron:clickhouse-impl-slot-4:20260820-090002

@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2f1e5f8]

Summary: ✅


AI Review

Summary

This PR fixes the amd_cfi misclassification in both behavior-changing test harness consumers: tests/config/install.sh now keys the trace-log symbolization override on -DSANITIZER, and tests/integration/helpers/cluster.py does the same for the generic integration-test skip path while keeping the named sanitizer checks on -fsanitize=<name>. The new ci/tests/test_cfi_not_a_sanitizer_build.py coverage plus the CI Tests digest updates make the regression hard to reintroduce silently. I did not find any remaining correctness or evidence gaps in the current diff.

Final Verdict

✅ No new findings.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @Algunenano, could you review this? The test harness classified the CFI build as a sanitizer build because it tested CXX_FLAGS for '-fsanitize=', which also matches CFI's cfi-vcall and cfi-derived-cast, so it installed the no-symbolize trace_log override and system.trace_log came back with empty symbols and lines. It now tests for the -DSANITIZER marker that cmake/sanitize.cmake adds only in real sanitizer builds.

Comment thread tests/config/install.sh Resolved
…rness

The same misclassification the previous commit fixed in tests/config/install.sh
is also present in the integration test harness. is_built_with_sanitizer() with
no argument tested for the bare substring "-fsanitize=", which the amd_cfi
profile matches: cmake/sanitize.cmake leaves CFI's own -fsanitize=cfi-vcall,
cfi-derived-cast in CMAKE_CXX_FLAGS_RELWITHDEBINFO, and cmake/print_flags.cmake
concatenates that into the CXX_FLAGS row of system.build_options that this
predicate reads.

CFI is not a runtime sanitizer. It requires ThinLTO at link time but enforces at
runtime by trapping (CMakeLists.txt:519-520, :527), with no sanitizer runtime
attached, so an amd_cfi build has release-build performance. The generic check
now tests for -DSANITIZER, which cmake/sanitize.cmake:30 puts in SAN_FLAGS and
which reaches CMAKE_CXX_FLAGS in all five branches of the if (SANITIZE) block
(:35, :107, :115, :131, :141); :145 fails configure for an unknown sanitizer, so
there is no sixth branch. cmake/sanitize.cmake:220-224 makes ENABLE_CFI and
SANITIZE mutually exclusive, so the two markers cannot co-occur.

The named checks keep testing -fsanitize=<name>: is_built_with_address_sanitizer,
is_built_with_thread_sanitizer and is_built_with_memory_sanitizer distinguish
between sanitizers, which -DSANITIZER cannot, and test_crash_log/test.py:152-155
passes the names through directly. Verified those three are the only non-bare
callers, and that their results are unchanged for every build profile.

Measured on the real amd_cfi binary from the failing job (build ID
e3992b92853623fcc8ebea13060c0d7603f98201) and on an ASan binary as a positive
control: the old predicate returned true for both, the new one returns true only
for ASan. Exercised the new method body against the CXX_FLAGS rows of nine build
profiles (amd_cfi, asan, tsan, msan, ubsan, asan_ubsan, debug, release,
coverage); only amd_cfi changes verdict.

The visible effect is that under amd_cfi the 50 bare call sites across 35
integration test files no longer skip themselves, which is the point: those
guards exist for sanitizer slowness that a CFI build does not have. The one this
issue is about is test_trace_log_build_id, which skipped with the reason
"trace_log is disabled with sanitizers" even though trace_log is fully enabled
under CFI. This cannot be shown green before merge: WeeklyCFI is a scheduled
workflow (Mondays 03:00 UTC) and no pull request can run it.

Related: ClickHouse#115122
Only WeeklyCFI builds the amd_cfi profile and it is a scheduled workflow, so no
pull request can run either of the two predicates this pull request fixes against
a real CFI binary. Both consumers react to the misclassification by skipping work
(the functional-test installer disables symbolization, integration tests skip
themselves), so a revert would stay green and silently restore the bug.

The test runs the real is_built_with_sanitizer against the measured CXX_FLAGS
rows of nine build profiles, so it fails if the classification regresses. It also
asserts that the named address/thread/memory checks stay on -fsanitize=<name>,
which -DSANITIZER cannot express, and that CFI's flags do match a bare
-fsanitize= test, which is what makes this a live oracle rather than a
tautology. The installer assertion is scoped to is_sanitizer_build, since
is_fast_build tests the same substring but runs only in the Fast test job, which
builds without CFI.

Verified it is not vacuous: reverting the helper fails
test_non_sanitizer_builds_are_not_detected[amd_cfi], and reverting the installer
fails test_installer_gates_symbolization_on_the_same_invariant.

It lives in ci/tests because that suite runs on every pull request, while the
integration suite requires a running cluster and collects only test_*/test*.py.

Related: ClickHouse#115122
Two gaps meant a revert of either predicate could still pass CI.

The installer assertion only searched the script's source text, so it also passed
for a function that ignores the build flags entirely: a body of
`: "'%-DSANITIZER%'"; return 0` contains the new literal and not the old one,
while installing the symbolization override for every build. It now runs the
installer's own is_sanitizer_build with a stub clickhouse on PATH answering the
build_options query, and asserts the exit status that decides whether
trace_log_no_symbolize.xml is installed, for all nine build profiles.

The CI Tests job's cache digest covered ./ci plus two test-harness files, but
neither predicate's file, so a later change touching only tests/config/install.sh
or tests/integration/helpers/cluster.py could reuse a green cached result and
never run these guards. Both are now digest inputs, the same way clickhouse-test
and shell_config.sh already are for the expect-trace guards.

Verified against four mutations: reverting the installer to the bare -fsanitize=
test fails the amd_cfi arm; making the function unconditionally true fails all
four non-sanitizer arms; unconditionally false fails all five sanitizer arms; and
reverting the integration helper fails the amd_cfi classification arm. The first
of those is the only one the previous text-matching assertion could catch.

Related: ClickHouse#115122
The installer guard executed is_sanitizer_build and asserted its exit status, so
it covered the classification but not the wiring to the symlink it controls.
Rewriting the conditional as `if false && is_sanitizer_build` left every
assertion green while no longer disabling symbolization for any sanitizer build.

The guard now extracts the function together with the `if` that consumes it, runs
that block against a temporary destination directory, and asserts whether
trace_log_no_symbolize.xml was linked. That is the state the server actually
reads, so it also covers the conditional and the symlink target.

Six mutations now redden it: the bare -fsanitize= revert, an unconditionally true
predicate, an unconditionally false one, a short-circuited conditional, a symlink
pointing at the wrong file, and the integration helper revert.

Related: ClickHouse#115122
@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 2f1e5f8ba with master bddae8d72 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 704.40 MiB 701.35 MiB -3.05 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

21 translation units recompiled, 220 s compile time in total, 21 of them have a recent master baseline.

Job report

@groeneai groeneai changed the title Do not treat the CFI build as a sanitizer build in the test config installer Do not treat the CFI build as a sanitizer build in the test harnesses Aug 20, 2026
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Aug 20, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 2f1e5f8

No check failed at this head: 173 unique checks, 100 success and 73 skipped, 0 failures. The
praktika aggregator (Finish Workflow) completed successfully.

Check / test Reason Owner / fixing PR

On coverage, since the skipped count is high: CI Tests is green, and that is the job which
runs ci/tests/test_cfi_not_a_sanitizer_build.py, the oracle added in this PR. So the change
does have live coverage here. The two 03150_trace_log_* stateless tests that motivated the
fix cannot run in this PR's CI, because master's WeeklyCFI workflow has no stateless job
(ci/workflows/weekly_cfi.py runs build, integration and stress only, and says stateless is
deliberately excluded); that lane exists only on the branch of the still-open PR #115036.
That is expected non-coverage of the motivating tests, not a gap in this PR's validation.

Session id: cron:our-pr-ci-monitor:20260820-210000

@alexey-milovidov alexey-milovidov self-assigned this Aug 21, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 21, 2026
Merged via the queue into ClickHouse:master with commit 272408f Aug 21, 2026
178 checks passed
zlareb1 added a commit to zlareb1/ClickHouse that referenced this pull request Aug 21, 2026
ClickHouse#115591 fixed ClickHouse#115122:
the empty symbols/lines were not a ThinLTO/CFI symbolization problem
but the test harness misclassifying the CFI build as a sanitizer build
(CXX_FLAGS LIKE '%-fsanitize=%' matches -fsanitize=cfi-vcall,...) and
installing trace_log_no_symbolize.xml. Both tests are expected to pass
in the WeeklyCFI stateless lanes now, so the comments are obsolete.

Co-Authored-By: Claude Fable 5 <[email protected]>
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 21, 2026
zlareb1 added a commit to zlareb1/ClickHouse that referenced this pull request Aug 21, 2026
Review comment: the module's private _is_sanitizer_build probed for the
bare -fsanitize= substring, which also matches the CFI build's
-fsanitize=cfi-vcall,cfi-derived-cast, so started_cluster never created
node_smol and test_size_adjustment silently skipped in every
Integration tests (amd_cfi, *) run. Use the -DSANITIZER predicate, the
same one ClickHouseInstance.is_built_with_sanitizer and
tests/config/install.sh use since ClickHouse#115591. The check runs before the
cluster starts, so it cannot reuse the ClickHouseInstance method
directly.

Co-Authored-By: Claude Fable 5 <[email protected]>
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-ClickHouse__ClickHouse that referenced this pull request Nov 21, 2026
With a UBSan check in trap mode, `CXX_FLAGS` of a build without the `SANITIZE` option contains `-fsanitize=`. Fast
test would then not install `limits_fast.yaml`, the upgrade check would skip its settings comparison and
`test_userspace_page_cache` would skip `test_size_adjustment`. Test `-DSANITIZER`, as `install.sh` and `cluster.py`
already do since ClickHouse#115591.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai manual approve Manual approve required to run CI pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty symbols and lines in system.trace_log in the amd_cfi build profile

3 participants