Repository navigation
Compile with -fPIE instead of -fPIC - #125488
Conversation
ClickHouse#125094 moved `-fPIC` into CMAKE_C/CXX_FLAGS before cmake/linux/default_libs.cmake creates the `cxx`, `cxxabi` and `unwind` targets, so they are compiled with `-fPIC` instead of the CI compiler's default `-fPIE` (CLANG_DEFAULT_PIE_ON_LINUX=ON). That is the only codegen change of ClickHouse#125094 in CI. Since it reached master (2026-10-11 20:38Z), iceberg_suite_{local,s3}_tpch ClickHouse#7, ClickHouse#8 and ClickHouse#12 (TPC-H Q8, Q9, Q13) are ~25% slower on arm: 251/251 master runs and 220/225 PR builds are slow (p50 1.29x of the previous level), against 616/735 fast runs before. All other arm perf queries are unchanged (median ratio 1.00 over 5670). A slow ClickHouse#125094 arm binary and a fast same-base binary differ in 122 functions, all in these three libraries: TLSDESC sequences relaxed by lld instead of local-exec accesses, and GOT loads instead of direct addresses (std::uncaught_exceptions, __cxa_*, std::mutex, std::shared_mutex, ...). glibc-compatibility and harmful are identical in both binaries. The hot loop of the slowed hash join (RowRefList::insert) is byte-identical; how the runtime-library change slows it on Graviton is not identified, and the arm perf run of this change is the A/B. The three targets now get `-fPIE` as a PRIVATE C/C++ compile option. It comes after CMAKE_<LANG>_FLAGS, so it wins over `-fPIC`; with the CI compiler `-fPIC ... -fPIE` is identical to the default. `-fPIE` objects stay relocatable, so ClickHouse#125094's fix for compilers that do not default to PIE is kept. Measured locally: - aarch64 arm_binary objects and arm_release ThinLTO bitcode of the three libraries: 83/83 identical to master with ClickHouse#125094 reverted (31/83 and 81/83 differ from current master). - compile_commands.json vs master (arm_release, arm_binary): only the 81 C/C++ TUs of the three targets differ, each by one `-fPIE`; assembly sources and all other TUs are unchanged. - With a clang wrapper defaulting to `-fno-pic`, llvm-min-tblgen fails to link with ClickHouse#125094 reverted (relocation R_X86_64_32 ... recompile with -fPIC) and links as a PIE with this change, as on master. - amd64 debug build, MSan configure, FreeBSD configure and build of the three targets: OK. 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; 1 finding) plus my own review (0 blocker, 0 major).
Checked in my own review: Session id: cron:clickhouse-review-slot-48:20261012-192400 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261012-184800 |
|
Workflow [PR], commit [9415dcb] Summary: ❌
AI ReviewSummaryPR #125488 replaces the global Missing context / blind spots
Tests
Final Verdict |
CI finish ledger - b9fbfb1Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261013-070008 |
|
🤖 Instead of patching Please rework this PR in that direction:
Validation: Also, the release binary must stay PIE, so #125278 is not a direction we want to take. |
|
Thanks, I'm reworking it in that direction. One thing I need: the amd |
|
Added |
Everything we build is linked into the position-independent executable, so -fPIE is the right code model: -fPIC only adds symbol interposition (GOT loads, TLS descriptor sequences) that an executable never uses. Instead of putting -fPIE back on the three C++ runtime targets, the global flag is now -fPIE, set where ClickHouse#125094 put it, before the default_libs include. The objects stay relocatable, so builds with compilers that do not default to PIE keep working. Also drop the per-target PIC that would override it: POSITION_INDEPENDENT_CODE on _cld2, the cuDF fragments and the GPU island targets, -Xcompiler -fPIC in CMAKE_CUDA_FLAGS (now -Xcompiler -fPIE), -fPIC on xgboost and dmlc-core, and the MSan "-fPIC -fpie" (now -fPIE). -fPIC stays where it is needed or mirrors upstream: compiler-rt (builtins, and the sanitizer and XRay runtimes through SANITIZER_COMMON_FLAGS), glibc-compatibility with ENABLE_OPENSSL_DYNAMIC, and the shared crypto/ssl libraries of that option, which CMake compiles as PIC by itself. musl's rcrt1.c keeps -fPIC on master. Measured locally (compile_commands.json, effective last PIC/PIE flag per TU): - amd64 debug, release; aarch64 binary, release; asan, msan, tsan: every C/C++ TU is -fPIE except clang_rt_builtins and the compiler-rt sanitizer / XRay runtimes; with ENABLE_OPENSSL_DYNAMIC also crypto, ssl and glibc-compatibility. - amd64 debug clickhouse: ELF type DYN, FLAGS_1 NOW PIE; clickhouse local queries with threads and exceptions work. - aarch64 flatc, msan and asan llvm-min-tblgen: DYN + PIE, the sanitizer builds run. - With a clang wrapper defaulting to -fno-pic, llvm-min-tblgen still links as PIE. The GPU island (ENABLE_GPU) is not built by CI and I have no CUDA toolkit, so the cmake/cuda.cmake and contrib/cudf-cmake changes are not built. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Done in 9415dcb:
Checked locally: in |
CI finish ledger - 9415dcbEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Perf evaluation of this head:
Session id: cron:clickhouse-maint-slot-14:20261014-233400 |
Algunenano
left a comment
There was a problem hiding this comment.
LGTM. The performance changes are irrelevant and this is the correct way forward
17a0ca3
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Compile all code with
-fPIEinstead of-fPIC. Everything is linked into the position-independentclickhouseexecutable, so the GOT loads and TLS descriptor sequences that-fPICgenerates for symbol interposition were never needed.Description
Related: #125094, #124818
Everything is linked into the position-independent executable, so
-fPIEis the right code model;-fPIConly adds symbol interposition (GOT loads, TLS descriptor sequences) that an executable never uses. #125094 moved the global-fPICbeforecmake/linux/default_libs.cmake, which also putlibcxx,libcxxabiandlibunwindon-fPICand madeiceberg_suite_{local,s3}_tpch#7, #8 and #12 about 25% slower on arm. The first version of this PR put-fPIEback on those three targets (its arm perf run: 0.78x, 0.87x, 0.90x); this version fixes the root instead:-fPIE, where Set-fPICbefore the C++ runtime libraries from contrib are added #125094 put it;POSITION_INDEPENDENT_CODEon_cld2, the cuDF fragments and the GPU island targets,-Xcompiler -fPICinCMAKE_CUDA_FLAGS(now-fPIE),-fPIConxgboostanddmlc-core, and MSan's-fPIC -fpie(now-fPIE);-fPICstays in compiler-rt (the builtins, and the sanitizer and XRay runtimes throughSANITIZER_COMMON_FLAGS, as upstream), inglibc-compatibilityand the sharedcrypto/sslwithENABLE_OPENSSL_DYNAMIC, and in musl'srcrt1.c.Validation, locally:
compile_commands.json, last PIC/PIE flag per TU, for amd64 debug and release, aarch64 binary and release, ASan, MSan, TSan: every C/C++ TU is-fPIEexcept the compiler-rt targets above (withENABLE_OPENSSL_DYNAMIC, alsocrypto,ssl,glibc-compatibility).clickhouse:DYNwithFLAGS_1: NOW PIE; aarch64, ASan and MSan test executables too, and the sanitizer ones run.-fno-pic, executables still link as PIE.ENABLE_GPU): no CI job enables it and I have no CUDA toolkit.Workflow [PR]
Sync PR [sync-upstream/pr/125488]
Version info
26.10.1.2460-master(included in26.10and later)