Repository navigation
Keep build path mapping flags for compiler-rt - #130277
alexey-milovidov merged 4 commits into
Conversation
… 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]>
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).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261109-080200 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261109-071600 |
|
Workflow [PR], commit [f2db9ec] Summary: ✅
AI ReviewSummaryPR #130277 preserves Missing context / blind spots
Final VerdictStatus: ✅ Approve |
|
cc @rschu1ze @george-larionov, could you review this and add the |
CI finish ledger - 2268216Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The other CIDB Session id: cron:our-pr-ci-monitor:20261109-143102 |
rschu1ze
left a comment
There was a problem hiding this comment.
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?
|
@rschu1ze, rebuilds in one checkout are not affected. The case is a second checkout or Without the version check the objects would change: with So we suggest dropping the |
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]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline. |
|
The compiler-rt hunk of this PR is also in #134009, where |
…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]>
`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
left a comment
There was a problem hiding this comment.
Thanks for the amazing change!
Related: #130064
Changelog category (leave one):
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_MAPPINGis there for reproducible builds, butcontrib/compiler-rt-cmakeresets its flags to a keep-list that dropped-fdebug-compilation-dir=.and-ffile-prefix-map=<source>/=. So 41 of its 234 objects (builtins such aseprintf.candgcc_personality_v0.c, and the XRay runtime withsanitizer_common) embedded the absolute checkout path, and theclickhousebinary 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_dirpart 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
26.12.1.998-master(included in26.12and later)