Skip to content

Keep build path mapping flags for compiler-rt - #130277

Merged
alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:groeneai/ccache-reuse-across-checkouts
Nov 29, 2026
Merged

alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:groeneai/ccache-reuse-across-checkouts

Conversation

@groeneai

@groeneai groeneai commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #130064

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

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

With ENABLE_BUILD_PATH_MAPPING (the default for non-Debug builds), compiler-rt is now compiled with the path mapping flags too, so its __FILE__ strings in the binary no longer contain the absolute source path.

Description

ENABLE_BUILD_PATH_MAPPING is there for reproducible builds, but contrib/compiler-rt-cmake resets its flags to a keep-list that dropped -fdebug-compilation-dir=. and -ffile-prefix-map=<source>/=. So 41 of its 234 objects (builtins such as eprintf.c and gcc_personality_v0.c, and the XRay runtime with sanitizer_common) embedded the absolute checkout path, and the clickhouse binary still named the checkout it was built in. Reported by @ snelheidai in #130064.

This PR keeps the two flags in the keep-list. Validated locally (RelWithDebInfo, clang-22, no compiler cache): with the change 0 of 234 compiler-rt objects contain the checkout path, without it 41. Build-system change, so no test.

An earlier ccache base_dir part of this PR was dropped in review: it only worked with ccache 4.0 to 4.9.


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

Version info

  • Merged into: 26.12.1.998-master (included in 26.12 and later)

groeneai and others added 2 commits November 9, 2026 04:49
… is on

With ENABLE_BUILD_PATH_MAPPING every C/C++ compile carries
-fdebug-compilation-dir=. and -ffile-prefix-map=<source>/=, so the objects
do not depend on the checkout. ccache still hashed the absolute -I, sysroot
and source paths and (with -g) the working directory, so a second checkout
or git worktree missed on every compile.

When ccache >= 4.0 is the launcher, prefix the C/C++ launchers with
CCACHE_BASEDIR=<source dir> and CCACHE_NOHASHDIR=true. In depend mode ccache
invokes the compiler with the original absolute arguments (base_dir only
changes the hash), so -ffile-prefix-map keeps producing the same object as an
uncached compile. Without depend mode (ccache 3.x) ccache would pass the
rewritten relative paths to the compiler and objects would embed ../src/...,
hence the version condition.

Depend mode is silently disabled when run_second_cpp is false (a user's
ccache.conf or CCACHE_NOCPP2), which also turns off the #embed tracking it is
enabled for; force CCACHE_CPP2=true together with CCACHE_DEPEND=true and drop
CCACHE_NOCPP2 from the environment so both negations are never set at once.

compiler-rt resets its flags to a keep-list that dropped the path-mapping
flags, so its objects embedded absolute __FILE__ strings and a cache hit from
another checkout would carry that checkout's paths. Keep both flags; they
change no code generation.

Requested in ClickHouse#130064
(patch and measurement by @ snelheidai). The sccache counterpart is discussed
in ClickHouse#127827.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…HASHDIR

ccache 4.10 removed the depend-mode branch that ran the compiler with the
original arguments (ccache commit 204933e7ce, "Remove unnecessary
depend_extra_args"); since then the compiler always gets the base_dir-rewritten
relative -I and source paths, so with ccache 4.10+ every object would embed
../src/... instead of the -ffile-prefix-map result. Gate the prefix on
4.0 <= version < 4.10 (measured: ccache 4.12.1 executes `-I../src ...
../src/hello.cpp` and the served object differs from an uncached compile;
4.9.1 executes the absolute paths and the object is identical).

CCACHE_NOHASHDIR is not needed: with -g, ccache >= 4.0 hashes the working
directory relocated through -ffile-prefix-map, so <checkout>/build hashes as
"build" in every checkout. Setting it also let differently named build
directories share results, although a TU that includes a build-dir-generated
header through an absolute -I embeds build/... vs build2/... in its DWARF.

ENABLE_CHECK_HEAVY_BUILDS saves the C++ launcher before the prefix is added,
and contrib/CMakeLists.txt restores that saved copy, so every contrib C++
compile lost CCACHE_BASEDIR (8,378 of 18,172 launchers). Prefix the saved
launcher too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

groeneai commented Nov 9, 2026

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

Pre-publication review by an independent model (engine: codex; 5 findings; bounded: 1 full pass + 1 fix round + 1 delta recheck).

# Sev Finding Verdict Evidence / action
1 ❌ The >= 4.0 condition admitted ccache 4.10+, whose depend mode passes the base_dir-rewritten paths to the compiler (ccache/ccache@204933e), so objects would embed ../src/... AGREE, fixed @ 2268216 Range is now 4.0 to 4.9. Probe: ccache 4.12.1 runs -I../src ... ../src/hello.cpp and serves a differing object; 4.9.1 runs the absolute paths and serves an identical one
2 ⚠️ CCACHE_NOHASHDIR was unnecessary (ccache relocates the hashed working directory through -ffile-prefix-map) and let differently named build dirs share objects that name the other dir AGREE, fixed @ 2268216 Dropped. Same-layout reuse unchanged: 16,612 of 16,737 hits; build vs build2 now miss
3 ⚠️ ENABLE_CHECK_HEAVY_BUILDS restores a launcher saved before the prefix, so contrib C++ missed AGREE, fixed @ 2268216 The saved launcher is prefixed too; all 18,172 launchers carry CCACHE_BASEDIR once
4 💡 A user-supplied CMAKE_<LANG>_COMPILER_LAUNCHER is not wrapped DISAGREE Used as given by design (cmake/ccache.cmake:15-20); its ccache version is unknown there, and ccache 3.x or 4.10+ would rewrite the objects
5 💡 With clang-tidy dummy launchers, the launchers saved before the prefix (cmake/clang_tidy.cmake:38) are restored for the real compiles (contrib, code generators), which still miss across checkouts AGREE, not changed Misses only, the objects do not change; noted, not blocking

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding. Findings on hunks unchanged by the fix round are auto-dropped.

Session id: cron:clickhouse-review-slot-8:20261109-080200

@groeneai

groeneai commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. A second checkout built with the cache filled by the first: 12 of 16,737 compiles hit without this PR, 16,612 with it, on every run.
b Root cause explained? Path mapping makes the objects path-independent, but ccache keys still hold the absolute -I and source paths.
c Fix matches root cause? Yes. ccache keys paths relative to the source dir only where depend mode keeps the compiler on its original arguments (ccache 4.0 to 4.9; 4.10+ passes rewritten paths, measured on 4.12.1).
d Test intent preserved / new tests added? Build-system change: no build-system test; validated by local measurement.
e Both directions demonstrated? Yes. Second checkout 1,389 s / 12 hits without, 331 s / 16,612 hits with; probes: ccache 4.12.1 would serve a differing object (gated off), 4.9.1 serves an identical one; CCACHE_NOCPP2: old launcher differs, new one identical.
f Fix is general across code paths? All C/C++ launchers checked (RelWithDebInfo, ASan, native sub-build, heavy-build check); ASM has no launcher; compiler-rt keep-list fixed too.
g Fix generalizes across inputs (params/datatypes/wrappers)? Configure controls: Debug, path mapping off, COMPILER_CACHE=disabled, ccache 3.x and 4.12.1, sccache get no prefix; with the heavy-build check all 18,172 launchers get it once; build dirs with other names do not share results.
h Backward compatible? (maintainer-approved exception only) Yes. No setting or format; outside ccache 4.0 to 4.9 with path mapping, only compiler-rt's __FILE__ strings become relative.
i Invariants and contracts preserved? 17,101 of 17,103 served objects byte-identical to an uncached build; the 2 others differ only in 6 DWARF names (stripped objects identical); the working directory stays in the key, so differently named build dirs never share an object.

Session id: cron:clickhouse-impl-slot-5:20261109-071600

@clickhouse-gh

clickhouse-gh Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f2db9ec]

Summary: ✅


AI Review

Summary

PR #130277 preserves -fdebug-compilation-dir and -ffile-prefix-map when filtering compiler-rt flags, extending ENABLE_BUILD_PATH_MAPPING to its objects. No actionable findings in head f2db9ec892c9137e60ae6fecbc0c058d0bdf2592; approve. The affected source-path consumers are builtins’ __compilerrt_abort_impl (ignores the path on Linux/FreeBSD) and sanitizer/XRay CheckFailed (formats it as diagnostic text).

Missing context / blind spots
  • ⚠️ The broader build/test matrix is still running. Fast test passed (15,384 passed, 4,592 skipped), as did all four ARM tidy shards; completed reports show no failures. Completed build and downstream test results would close this remaining validation gap. Current CI report.
Final Verdict

Status: ✅ Approve

@groeneai

groeneai commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

cc @rschu1ze @george-larionov, could you review this and add the can be tested label so CI runs? With build path mapping on, CMake now passes CCACHE_BASEDIR=<source dir> to ccache 4.0 to 4.9 (their depend mode still compiles with the original paths, so objects do not change), and a second checkout or worktree reuses the cache (331 s vs 1,389 s locally); CI uses sccache, so there only the compiler-rt __FILE__ strings become relative.

@clickhouse-gh clickhouse-gh Bot added pr-build Pull request with build/testing/packaging improvement submodule changed At least one submodule changed in this PR. labels Nov 9, 2026
@clickhouse-gh clickhouse-gh Bot added can be tested Allows running workflows for external contributors manual approve Manual approve required to run CI comp-build-system Build system (CMake, compilation, platform builds). labels Nov 9, 2026
@groeneai

groeneai commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 2268216

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
AST fuzzer (amd_release, oracle) / AST fuzzer oracle mismatch wrong results, not from this PR (it changes only CMake files): the TLP WHERE oracle on ts NOT IN (SELECT toDate32OrDefault(1675195200) GROUP BY ALL) drops rows because index analysis skips granules for an IN set whose type is coarser than the key; reproduces on master #112890 (mine, open)
Build profile diff infra, not from this PR (no ci/ file in the diff): all readiness probes to the CI logs cluster hit Read timed out. (read timeout=3), so has_pr_data raised LogClusterNotReady: the endpoint never became ready. The same job ended with LogClusterNotReady on 35 runs today #129675 (mine, open)
Mergeable Check, PR praktika rollups of the rows above #112890 (mine, open), #129675 (mine, open)

The other CIDB FAIL row on this head is Config Workflow / Pre Hooks of the run before the can be tested label.

Session id: cron:our-pr-ci-monitor:20261109-143102

Comment thread CMakeLists.txt Resolved

@rschu1ze rschu1ze left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The build path mapping is on in Release builds. I am using ccache locally and I never had a problem with caching object files in Release builds. What problem is this PR solving?

@snelheidai

Copy link
Copy Markdown

@rschu1ze, rebuilds in one checkout are not affected. The case is a second checkout or git worktree of the same code at another path: path mapping makes the objects independent of the checkout path, but ccache's key still contains the absolute -I and source paths, so the new worktree recompiles nearly everything. CCACHE_BASEDIR=<source dir> makes ccache hash them as relative paths.

Without the version check the objects would change: with base_dir, ccache also passes the rewritten relative paths (../src/Foo.cpp) to the compiler, as its manual describes, so -ffile-prefix-map=<source>/= no longer matches and __FILE__ strings and debug info contain ../src/.... Only depend mode in ccache 4.0 to 4.9 compiles with the original paths, and Ubuntu 26.04 (ccache 4.12.3) and Homebrew (4.14.3) are already past that range.

So we suggest dropping the CCACHE_BASEDIR part rather than moving it; whoever builds in several worktrees can set base_dir in their own ccache config. The compiler-rt change is independent of ccache: without it, compiler-rt's __FILE__ strings contain the checkout path despite path mapping.

Review feedback: the version-gated CCACHE_BASEDIR prefix is unwanted.
It only helps a second checkout or worktree of the same code, and only
with ccache 4.0 to 4.9: since 4.10 ccache hands the base_dir-rewritten
relative paths to the compiler, so -ffile-prefix-map stops matching and
the objects change. Users who build in several worktrees can set
base_dir in their own ccache config. The CCACHE_CPP2 change only kept
depend mode on for that prefix, so it goes too.

What remains is independent of ccache: compiler-rt resets its flags to
a keep-list that dropped -fdebug-compilation-dir and -ffile-prefix-map,
so with ENABLE_BUILD_PATH_MAPPING 41 of its 234 objects (builtins and
the XRay runtime with sanitizer_common) still embedded the absolute
source path in __FILE__ strings; with the flags kept, none do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai changed the title Let ccache reuse its results across checkouts when build path mapping is on Keep build path mapping flags for compiler-rt Nov 10, 2026
@clickhouse-gh clickhouse-gh Bot added comp-external-dependencies Third-party deps updates in contrib/, vendored code, and platform base libraries. and removed comp-build-system Build system (CMake, compilation, platform builds). labels Nov 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f2db9ec89 with master 81560e6e5 (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

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

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

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

The compiler-rt hunk of this PR is also in #134009, where SCCACHE_BASEDIRS needs it. Without -ffile-prefix-map, 41 of the 234 compiler-rt objects embed the absolute source path. With basedirs that path is stripped from the cache key, so sccache would serve those objects with the path of the checkout that filled the cache.

…se-across-checkouts

Resolve the conflict in contrib/compiler-rt-cmake/CMakeLists.txt: master
added -mbranch-protection= to the compiler-rt keep-list, this branch adds
-fdebug-compilation-dir= / -ffile-prefix-map=. Keep both. The list comment
now uses the same single line as ClickHouse#134009, which carries the same hunk, so
whichever of the two merges first leaves the other without a conflict.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Nov 29, 2026
`contrib/compiler-rt-cmake` resets its flags to a keep-list, which dropped
`-fdebug-compilation-dir=.` and `-ffile-prefix-map=<source>/=`, so the
`__FILE__` strings of the sanitizer and XRay runtimes in the binary contained
the absolute path of the checkout (24 strings in `clickhouse-stripped`).
Same change as #130277.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov alexey-milovidov self-assigned this Nov 29, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the amazing change!

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 29, 2026
Merged via the queue into ClickHouse:master with commit 5c86d06 Nov 29, 2026
194 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 29, 2026
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 comp-external-dependencies Third-party deps updates in contrib/, vendored code, and platform base libraries. manual approve Manual approve required to run CI pr-build Pull request with build/testing/packaging improvement pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants