Repository navigation
Revert "Revert "Print file offsets in the bare fatal stack traces and build the release binary as PIE"" - #119284
Conversation
… build the release binary as PIE"" This reverts 34421af (pull request #119279), restoring pull request #117449. #119279 reverted the change to get `master` green: the test it added, `05076_error_trace_file_offsets`, was failing on every release run. The Darwin half had already been fixed on `master` by 734d678 (pull request #119145), whose `no-darwin` tag comes back with this re-land, but `amd_release` was still failing and remains undiagnosed. Do not merge this before that is fixed - it re-introduces a known red job. What is known about the remaining failure: - Only `Stateless tests (amd_release, parallel, 1/2)` fails. `arm_release` passes at the same times, and so does every other configuration. - It is deterministic, not flaky: 48 of 48 runs with the randomized settings and 49 of 49 without them. - It is the second column that fails, dropping from 1 to 0: no captured frame lies outside the main executable, so either every frame is being stored as a file offset, or `max(address_end)` from `system.symbols` is above all of them. - Both release builds are configured identically apart from the toolchain file, and both set `ENABLE_THINLTO=1`. Before this change PIE was gated on `NOT ENABLE_THINLTO`, so the release builds are exactly the ones whose PIE status it flips - and only the amd64 one fails. The difference is therefore in architecture-specific link or runtime behaviour, not in the CMake configuration. Related: #117449 Related: #119145 Related: #119279
|
Workflow [PR], commit [047e62c] Summary: ✅
AI ReviewSummaryThis PR re-lands PIE for Linux release builds and updates the crash / error / Findings
Final VerdictRequest changes. LLVM Coverage ReportMeasured on commit 047e62c.
Changed lines: Changed C/C++ lines covered: 100/109 (91.74%) · Uncovered code |
SymbolIndex copied Elf64_Sym::st_value (and + st_size) into Symbol::offset_begin/offset_end without checking that the symbol is defined relative to a section. When st_shndx is a reserved index, the value is a constant rather than an address. -fwhole-program-vtables, enabled for every ThinLTO build, emits LLVM's control-flow-integrity type-id globals (__typeid__*) as absolute symbols whose value is a bit mask. system.symbols published those verbatim, so on amd_release max(address_end) read 1162219258676258 instead of 685204737 (505 such symbols; amd_debug, built with ENABLE_THINLTO=0, has none). An "offset" of 1.16 petabytes into a 4.6 GB binary is impossible on its face. 05076_error_trace_file_offsets bounds captured stack frames by that value, so the raw runtime addresses of frames outside the main executable stopped exceeding it and the test printed "1 0" on every master commit since #117449 merged. The inflated bound also cost the first column its meaning on that flavour, since it counted those same raw addresses as in-range. No test is changed. Once the bound again reflects the largest real symbol offset, both columns of 05076, and the same bound in 03172_error_log_table_not_empty, hold for the reason their comments state. Of the 505 absolute values none lands inside any of the 620643 real FUNC symbol ranges, so no code address resolves differently. The Mach-O collector already skips N_STAB, N_UNDF and n_value == 0; it is left alone because both Darwin recipes disable ThinLTO and no macOS job could validate the change. Co-Authored-By: Claude Opus 5 <[email protected]>
`n_value` is an address only for a symbol defined in a section. `N_ABS` holds a constant such as a bit mask and `N_INDR` holds a string table index, so neither belongs in the offset ranges the symbol index is searched by. The loop skipped `N_STAB`, `N_UNDF` and `n_value == 0`; requiring `N_SECT` instead of rejecting `N_UNDF` covers all four non-section types at once and mirrors `symbolValueIsAddress` on the ELF side. Both Darwin recipes disable ThinLTO, so the `__typeid__*` symbols that motivated the ELF change do not exist there and no macOS job can exercise this. It is the same invariant, enforced in the one remaining place that turns a symbol table entry into an offset. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
| { | ||
| writeChar(' ', bare_stacktrace); | ||
| writePointerHex(stack_trace.getFramePointers()[i], bare_stacktrace); | ||
| writeResolvedAddress(stack_trace.getFramePointers()[i], bare_stacktrace); |
There was a problem hiding this comment.
This Stack trace: line used to be the crash handler's raw fallback, so you still got plain PCs even if symbolization later failed. Calling writeResolvedAddress here makes that fallback depend on StackTrace::resolveAddress -> SymbolIndex::instance(), i.e. the same lazy symbol-index/DWARF machinery the symbolized trace uses. On the server path build_id() comes from daemon->build_id, so a fault during early startup or during lazy SymbolIndex initialization can now skip the only raw-address dump instead of leaving something addr2line-able behind; please keep the first dump raw, or make writeResolvedAddress fall back to writePointerHex(addr) without constructing SymbolIndex.
There was a problem hiding this comment.
🕵 Adopted. The PR was merged before this landed, so the fix is in a follow-up: #120148. It adds SymbolIndex::instanceIfInitialized (an atomic pointer published after the constructor finishes, so it never touches the function-local static's guard) and StackTrace::tryResolveAddress on top of it; writeResolvedAddress uses that and falls back to writePointerHex(addr) when the index is not built yet. The server keeps printing offsets because BaseDaemon builds the index at startup for the build id, which is what test_crash_log checks.
Build profile diff (arm_release)Comparing Binary sizes
|
| Binary | Master | PR | Δ |
|---|---|---|---|
programs/clickhouse-stripped |
718.60 MiB | 746.94 MiB | +28.34 MiB (+3.94%) |
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.
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.
Object file sizes
15515 object files changed (-3.25 MiB total), 0 added.
| Object file | Master | PR | Δ |
|---|---|---|---|
contrib/hive-metastore-cmake/CMakeFiles/_hivemetastore.dir/__/hive-metastore/ThriftHiveMetastore.cp… |
5.81 MiB | 5.68 MiB | -133.43 KiB (-2.24%) |
contrib/google-cloud-cpp-cmake/CMakeFiles/google_cloud_cpp_storage_protos.dir/google/storage/v2/sto… |
1.76 MiB | 1.71 MiB | -46.26 KiB (-2.57%) |
contrib/vectorscan-cmake/CMakeFiles/_vectorscan.dir/__/vectorscan/src/rose/rose_build_program.cpp.o |
732.05 KiB | 698.10 KiB | -33.96 KiB (-4.64%) |
contrib/arrow-cmake/CMakeFiles/_parquet.dir/__/arrow/cpp/src/generated/parquet_types.cpp.o |
1017.44 KiB | 986.57 KiB | -30.87 KiB (-3.03%) |
contrib/google-protobuf-cmake/CMakeFiles/_libprotobuf.dir/__/google-protobuf/src/google/protobuf/co… |
365.34 KiB | 336.43 KiB | -28.90 KiB (-7.91%) |
base/poco/Foundation/CMakeFiles/_poco_foundation.dir/src/Exception.cpp.o |
356.32 KiB | 327.53 KiB | -28.79 KiB (-8.08%) |
contrib/libhdfs3-cmake/CMakeFiles/_hdfs3.dir/ClientNamenodeProtocol.pb.cc.o |
1.07 MiB | 1.04 MiB | -24.19 KiB (-2.22%) |
contrib/icu-cmake/CMakeFiles/_icui18n.dir/__/icu/icu4c/source/i18n/messageformat2_data_model.cpp.o |
192.21 KiB | 168.35 KiB | -23.86 KiB (-12.41%) |
contrib/icu-cmake/CMakeFiles/_icui18n.dir/__/icu/icu4c/source/i18n/number_fluent.cpp.o |
124.48 KiB | 103.95 KiB | -20.53 KiB (-16.49%) |
src/CMakeFiles/dbms.dir/Interpreters/ActionsDAG.cpp.o |
1.26 MiB | 1.24 MiB | -20.34 KiB (-1.57%) |
contrib/llvm-project-cmake/CMakeFiles/LLVMAnalysis.dir/__/llvm-project/llvm/lib/Analysis/ScalarEvol… |
1.32 MiB | 1.30 MiB | -18.73 KiB (-1.39%) |
contrib/llvm-project-cmake/CMakeFiles/LLVMCore.dir/__/llvm-project/llvm/lib/IR/ConstantRange.cpp.o |
273.43 KiB | 256.75 KiB | -16.68 KiB (-6.10%) |
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.
Compile time of recompiled translation units
4087 translation units recompiled, 19113 s compile time in total, 4087 of them have a recent master baseline.
Median compile-time ratio to the baselines is ×1.06 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +1112.4 s (+6%) in total before that adjustment.
Symbol sizes ⚠️
| Binary | Symbol | Master | PR | Δ |
|---|---|---|---|---|
programs/clickhouse |
_ZZN24TopLevelDomainLookupHash7isValidEPKcmE8wordlist |
new | 864.07 KiB | +864.07 KiB |
programs/clickhouse-keeper |
_ZZN24TopLevelDomainLookupHash7isValidEPKcmE8wordlist |
new | 864.07 KiB | +864.07 KiB |
programs/clickhouse-keeper |
wordlist |
new | 242.38 KiB | +242.38 KiB |
programs/clickhouse |
wordlist |
new | 242.38 KiB | +242.38 KiB |
programs/clickhouse |
rd_kafka_properties |
new | 131.25 KiB | +131.25 KiB |
programs/clickhouse |
_ZGRN2DB12_GLOBAL__N_15nounsE_ |
new | 102.33 KiB | +102.33 KiB |
programs/clickhouse-keeper |
_ZGRN2DB12_GLOBAL__N_15nounsE_ |
new | 102.33 KiB | +102.33 KiB |
programs/clickhouse |
a_2 |
new | 82.50 KiB | +82.50 KiB |
programs/clickhouse-keeper |
a_2 |
new | 82.50 KiB | +82.50 KiB |
`system.errors` keeps one mutable row per error code for the whole server, and `FUNCTION_THROW_IF_VALUE_IS_NON_ZERO` is thrown by around 140 stateless tests, so a test running in parallel answered the read with its own trace. A throw trace holds at most 32 frames, so a deeper throw is cut off before the C library frames at the bottom of the thread stack and the second column read 0. Throwing `CANNOT_DLSYM`, which no query reaches, leaves this test as the only writer of the row it reads. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`StorageSystemStackTrace` subtracted the base of whichever object contained a frame, so an offset into a library was stored as a bare number indistinguishable from a main executable offset, and `addressToSymbol` on it answers with the main executable symbol at that offset. `resolveAddressForStorage` keeps only main executable frames as file offsets, which is what `system.trace_log`, `system.crash_log`, `system.error_log` and `system.errors` already store. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The only test reading that column checks that some frame demangles to a `DB::` symbol, which holds whether frames are stored as runtime addresses or as file offsets. This asserts the split itself: frames in the main binary below the largest offset in `system.symbols`, and the frames outside it above that bound. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The value of an `STT_TLS` symbol is an offset into the thread local block of its object, not into the object itself, but `symbolValueIsAddress` only looked at the section index and thread local symbols have a real one. 381 of them were published by `system.symbols` with values between 0 and 46608. Those were the only symbols of the main binary below 2263648, the largest symbol offset of any library loaded into the server. Without them the lowest indexed offset of the main binary is 30880872, so the offsets of the main binary and of the libraries no longer overlap and an offset resolves in the object it belongs to. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`addressToSymbol` does not answer with the main binary's symbol at the offset of a library frame, so that was the wrong reason to keep runtime addresses. The right one is that a runtime address records which object the frame is in and a bare offset does not. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…' into reland-117449-pie-trace-offsets
Algunenano
left a comment
There was a problem hiding this comment.
The test looks stable now. Merging
The `Stack trace:` line in the fatal signal handler is the raw fallback that has to come out even when symbolization later fails, but `writeResolvedAddress` routed it through `StackTrace::resolveAddress`, which calls `SymbolIndex::instance` and so builds the index on demand. `instance` is a function-local static: a fault in the thread that was building it would leave the signal listener blocked on the static's guard before the first dump, and a fault during startup would print nothing until ~25 MiB of ELF parsing had been done inside the handler. Add `SymbolIndex::instanceIfInitialized`, which hands out the index only after the constructor has published it through an atomic pointer and never touches the guard, and `StackTrace::tryResolveAddress` on top of it. The bare dump uses that and falls back to the raw runtime address when the index is not built yet. A daemon builds the index during initialization for its build id, so the server still prints the ASLR-independent offsets that `test_crash_log` checks. Addresses ClickHouse#119284 (comment) Co-Authored-By: Claude Fable 5.1 <[email protected]>
Reverts #119279, restoring #117449 ("Print file offsets in the bare fatal stack traces and build the release binary as PIE").
#119279 reverted that change to get
mastergreen -05076_error_trace_file_offsetswas failing on every release run. The Darwin half had already been fixed onmasterby #119145, and itsno-darwintag comes back with this re-land.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Workflow [PR]
Sync PR [sync-upstream/pr/119284]
Version info
26.9.1.1514(included in26.9and later)