Skip to content

Do not index absolute symbols as addresses - #119136

Closed
groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:skip-absolute-elf-symbols-in-symbol-index
Closed

groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:skip-absolute-elf-symbols-in-symbol-index

Conversation

@groeneai

@groeneai groeneai commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #117449

Changelog category (leave one):

  • Improvement

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

system.symbols no longer lists symbols whose value is not an address, such as absolute symbols: their address_begin/address_end were meaningless. On builds compiled with ThinLTO, -fwhole-program-vtables emits the control-flow-integrity type-id globals (__typeid__*) as absolute symbols whose value is a bit mask rather than an address, and those were indexed as if they were offsets into the binary, inflating max(address_end) by a factor of about 1.7 million.

Description

Stateless tests (amd_release, parallel, 1/2) is red on every master commit since #117449 merged, on 05076_error_trace_file_offsets, which prints 1 0 instead of 1 1. It reproduces 45/45 with and without randomized settings. Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=baa509a920113525f109868c2448414d963e5252&name_0=MasterCI

SymbolIndex copies Elf64_Sym::st_value 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 is enabled for every ThinLTO build and emits __typeid__* as absolute symbols holding a bit mask, so on amd_release max(address_end) FROM system.symbols reads 1162219258676258 instead of 685204737 (505 such symbols; amd_debug has none). The test bounds captured stack frames by that value, so the raw runtime addresses it looks for stop exceeding it.

A section-relative definition is now required in all three places that turn a symbol table entry into an offset: the two ELF collectors, and the Mach-O one, which requires N_SECT instead of only rejecting N_UNDF. Each build's bound is again its largest real symbol offset, so 05076 and 03172_error_log_table_not_empty need no change.

Validated by injecting one SHN_ABS symbol into a debug binary: unfixed, 05076 fails 10/10 with exactly the CI diff; fixed, it passes 10/10. 02911_system_symbols and 03565_system_stack_trace_works also pass, and 05076 and 03172 pass 50 randomized runs each.

Stateless tests (amd_release, *) runs only in MasterCI, so this PR's own CI cannot show the failing arm going green; it does so after merge. The Fast test (arm_darwin) red on 05076 is a separate defect, covered by #119145; that build disables ThinLTO, so __typeid__* cannot exist in it.


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

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 ClickHouse#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]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Sep 10, 2026
@groeneai

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

Pre-publication review by an independent model (engine: codex; 1 finding), plus my own cold read of
the diff. No blocker and no major finding; both passes converged on the same single nit.

# Sev Finding Verdict Evidence / action
1 💡 The comment at SymbolIndex.cpp:110-112 says a reserved section index means the value is a constant; SHN_XINDEX (0xffff) is reserved yet its value is an address AGREE, not fixed here The predicate is deliberately an enumeration of SHN_UNDEF/SHN_ABS/SHN_COMMON, not a >= 0xff00 range check, precisely so SHN_XINDEX symbols survive; e_shnum is 57/58 on the affected artefacts, against the 65280 sections needed to reach it. Narrowing the sentence to the three indices is a one-line change if a reviewer prefers it
2 💡 The draft changelog entry put the inflation at "about three orders of magnitude" AGREE, corrected before publishing Measured 1162219258676258 / 685204737 = about 1.7 million; the entry now states that factor

Independently re-measured rather than taken from the implementation notes: readelf -sW on the
amd_release artefact of the failing sha reproduces both bounds, all 505 absolute symbols with a
nonzero size are __typeid*, .dynsym and libc.so.6 have none, and none of the 505 values falls
inside any of the 620540 FUNC ranges, so no code address resolves differently after the change.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-10:20260910-025600

@clickhouse-gh clickhouse-gh Bot closed this Sep 10, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0ff741f]

Summary: ❌

job_name test_name status info comment
Fast test (arm_darwin) FAIL
05076_error_trace_file_offsets FAIL cidb
Stress test (amd_debug) FAIL
Logical error: Input nodes size mismatch in dag: A, expected: [B], [C] (STID: 4752-5ad8) FAIL cidb
Stress test (arm_asan_ubsan) FAIL
Cannot start clickhouse-server FAIL cidb
Logical error: offsets_column has data inconsistent with nested_column. Data size: A, last offset: B (STID: 2632-3cfc) FAIL cidb
Check failed FAIL cidb
Integration tests (amd_msan, 4/8) ERROR
test_storage_nats/test_nats_jet_stream.py::test_nats_jet_stream_returns_buffered_backlog_to_the_broker_when_unsubscribing FAIL cidb
test_storage_nats/test_nats_jet_stream.py::test_nats_jet_stream_does_not_acknowledge_messages_discarded_by_a_view_dropped_mid_cycle FAIL cidb
test_storage_nats/test_nats_jet_stream.py::test_nats_jet_stream_does_not_acknowledge_messages_discarded_by_a_view_detached_mid_cycle FAIL cidb
test_storage_nats/test_nats_jet_stream.py::test_nats_jet_stream_streams_to_a_materialized_view_with_a_null_target FAIL cidb
test_storage_nats/test_nats_jet_stream.py::test_nats_jet_stream_streams_to_a_fan_out_with_a_null_target FAIL cidb
test_storage_nats/test_nats_jet_stream.py::test_nats_jet_stream_hands_back_the_backlog_of_a_consumer_a_direct_select_left_subscribed FAIL cidb
test_storage_nats/test_nats_jet_stream.py::test_nats_jet_stream_resumes_consuming_after_two_broker_restarts FAIL cidb
test_storage_nats/test_nats_jet_stream.py::test_nats_jet_stream_does_not_resubscribe_while_healthy FAIL cidb
test_storage_nats/test_nats_jet_stream.py::test_nats_jet_stream_settles_after_one_broker_restart FAIL cidb
test_storage_nats/test_nats_jet_stream.py::test_nats_jet_stream_resumes_consuming_multiple_subjects_after_broker_restart FAIL cidb
2 more test cases not shown

AI Review

Summary

This PR stops SymbolIndex from treating non-section-defined symbols as address ranges when populating system.symbols: on ELF it skips SHN_UNDEF, SHN_ABS, and SHN_COMMON, and on Mach-O it keeps only N_SECT entries. That matches the failing Linux trace-offset tests the PR cites, and after reviewing the current diff, the touched collectors in src/Common/SymbolIndex.cpp, the existing tests, and the prior PR discussion, I did not find a correctness, compatibility, or evidence gap that warrants a review finding.

Final Verdict

✅ No findings.

LLVM Coverage Report

Measured on commit 0ff741f.

Metric Baseline Current Δ
Lines 88.90% 89.00% +0.10%
Functions 91.80% 91.80% +0.00%
Branches 81.30% 81.30% +0.00%

Changed lines: Changed C/C++ lines covered: 15/16 (93.75%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Sep 10, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @al13n321 @alexey-milovidov, could you review this? SymbolIndex copied Elf64_Sym::st_value into Symbol::offset_begin/offset_end without checking st_shndx, so the SHN_ABS __typeid__* bit masks that -fwhole-program-vtables emits on every ThinLTO build were indexed as offsets and pushed max(address_end) FROM system.symbols to 1162219258676258 instead of 685204737. That bound is what 05076_error_trace_file_offsets compares captured stack frames against, so it reds Stateless tests (amd_release, parallel, 1/2) on every master commit.

@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 0ff741f48 with master 0de7f8fcd (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

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

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - f64cbb9

CI is fully finished at this commit. One check failed, and it has an owner.

Check / test Reason Owner / fixing PR
Fast test (arm_darwin) / 05076_error_trace_file_offsets pre-existing and deterministic on Darwin, and not something this diff can reach: both collectors it patches sit inside #if defined(__ELF__) (src/Common/SymbolIndex.cpp:97, Mach-O path behind #elif defined(OS_DARWIN) at :487), so none of it is compiled on Darwin, where StackTrace::resolveAddress keeps runtime addresses and system.symbols reports absolute addresses of every loaded image. 45 distinct PRs carry this same row in the last 24 h. #119145 (mine, open)

Mergeable Check names that one row and PR is the rollup, so neither carries a defect of its own.

What this PR does fix is green here: 05076_error_trace_file_offsets passes on every Linux flavour that ran it at this commit, 10 OK rows (Fast test plus 9 Stateless tests flavours), 1 skipped, 0 failures.

Finish evidence: 170 check-runs in the live workflow run 34432949799, 0 queued or in progress, with Config Workflow, Style check and Finish Workflow all success and CH Inc sync success. The earlier run 34432942484 on this same commit was cancelled wholesale (169 of its 170 legs), so it is superseded and its Finish Workflow failure row is not a real red.

Session id: cron:our-pr-ci-monitor:20260910-083052

@Algunenano Algunenano self-assigned this Sep 10, 2026
`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]>
@groeneai groeneai changed the title Do not index absolute ELF symbols as addresses Do not index absolute symbols as addresses Sep 10, 2026
pull Bot pushed a commit to Spencerx/ClickHouse that referenced this pull request Sep 10, 2026
The test asserts that frames inside the main binary reach
system.errors.last_error_trace as file offsets, bounded above by
max(address_end) from system.symbols. That storage form is ELF-only.

StackTrace::resolveAddress is compiled under
`#if defined(__ELF__) && !defined(OS_FREEBSD)`. The other arm returns
AddressKind::Unsupported with the address unchanged, which StackTrace.h
documents as "the platform keeps runtime addresses", so on Darwin
resolveAddressForStorage stores a raw runtime address for every frame and
none is ever converted to a file offset. collectSymbolsFromMachOImage in
turn stores absolute addresses (n_value + slide) and extends each image's
last symbol to that image's max_addr, and SymbolIndex::load() runs it for
every loaded dyld image. max(address_end) is therefore a ceiling above
every captured frame, which makes the second column unsatisfiable and
leaves the first no longer measuring the offset form. The test printed
`1 0` for that reason, 23 times out of 23 runs.

Fast test (arm_darwin) had 23 failures and no passes across 23 distinct
pull requests since ClickHouse#117449 added the test, which is every pull request
that reached that arm. The assertion is left untouched on the arms whose
platform implements the contract it checks.

This is a different defect from the one ClickHouse#119136 fixes: unfiltered
absolute Mach-O symbols would only raise a ceiling that is already above
every frame, so filtering them would leave the output at `1 0`.

Related: ClickHouse#119136
Related: ClickHouse#117449

Co-Authored-By: Claude Opus 5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). and removed comp-system-table system.* tables (introspection, system metadata, performance visibility). labels Sep 10, 2026
@Algunenano

Copy link
Copy Markdown
Member

I'll fix this as part of reintroducing the feature: #119268

@Algunenano Algunenano closed this Sep 10, 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-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants