Skip to content

Cherry pick #104946 to 26.5: Fix JIT symbol lookup on macOS - #107600

Merged
robot-ch-test-poll2 merged 9 commits into
backport/26.5/104946from
cherrypick/26.5/104946
Jun 16, 2026
Merged

robot-ch-test-poll2 merged 9 commits into
backport/26.5/104946from
cherrypick/26.5/104946

Conversation

@robot-ch-test-poll2

Copy link
Copy Markdown
Contributor

Original pull-request #104946

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

leshikus and others added 9 commits May 13, 2026 12:45
llvm::Mangler::getNameWithPrefix prepends '_' to C symbol names on macOS,
but registerSymbol() in CHJIT stores them unmangled. The lookup in
JITSymbolResolver::findSymbol misses, surfacing as:

  Could not find symbol _memcmpSmallCharsAllowOverflow15
  (CANNOT_COMPILE_CODE)

Any query that JIT-compiles a comparator over a String column hits this
in the macOS arm_darwin Fast test job — for example, a sort description
that includes a String key with compile_sort_description=1.

Retry the lookup without the leading underscore as a fallback. Linux is
unaffected because LLVM doesn't add the '_' prefix there. macOS now finds
the symbol on the second try and JIT compilation succeeds.

Issue: #103235
Exercises the sort-description JIT path on a String column with
`compile_sort_description=1` and `min_count_to_compile_sort_description=0`.
Before the parent commit on macOS this query failed with
`CANNOT_COMPILE_CODE: Could not find symbol _memcmpSmallCharsAllowOverflow15`.

Issue: #103235
Per review on #104946 (review),
replace the macOS-specific fallback in JITSymbolResolver::findSymbol with
target-mangling at registration time. registerSymbol now runs the symbol
name through llvm::Mangler::getNameWithPrefix using the JIT's DataLayout,
so the map keys match exactly the names LLVM produces inside the generated
object code. findSymbol becomes a single map lookup with no platform-specific
fallback path.

The behavior on Linux is unchanged because the mangler does not add a prefix
on ELF targets - the mangled form is identical to the input. On macOS the
mangler adds the leading underscore that the previous code stripped on a miss.
The previous version of the test used `count()` over an inner ORDER BY,
which the optimizer drops because count is order-independent. The sort
step was eliminated before any JIT decision was made, so
`compileSortDescriptionIfNeeded` never ran and the test passed whether
or not the JIT symbol-mangling fix was present. Confirmed empirically
on `Fast test (arm_darwin)`: the test passed against the unfixed
master binary and the server log contained no `Compile sort description`
or `Could not find symbol` entries.

The new query uses a top-level ORDER BY with `FORMAT Null` so the
optimizer cannot drop the sort. A follow-up SELECT against
`system.query_log` asserts that `ProfileEvents['CompileFunction']`
is non-zero, so a future regression that bypasses the JIT path (e.g.
optimizer drops the sort again, or a setting default changes) fails
loudly instead of silently passing.
Address review feedback on the regression test:
- `SYSTEM FLUSH LOGS` without an argument fails the repository checks
  and flushes more than the test needs; narrow it to `query_log`.
- Tag the JIT query with a unique `log_comment` and filter the
  assertion `SELECT` by that comment, so concurrent or pre-existing
  entries in the shared `system.query_log` cannot influence the result.
CI on https://github.com/ClickHouse/ClickHouse/actions/runs/25888833167/job/76087238926?pr=104946
flagged two issues against the rewritten test:

1. Style check rejects queries against `system.query_log` that lack a
   `current_database = currentDatabase()` clause. Add it - it composes
   with the `log_comment` filter and tightens isolation further.

2. Linux Fast test failed `expected 1, got 0`. The compiled-expression
   cache is server-wide, so an earlier test with the same sort-description
   hash had already populated it. Our SELECT hit the cache,
   `compileSortDescription` did not run, and `ProfileEvents['CompileFunction']`
   stayed at zero. Run `SYSTEM DROP COMPILED EXPRESSION CACHE` before the
   JIT query to force a fresh compilation.
@robot-ch-test-poll2 robot-ch-test-poll2 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Jun 16, 2026
@robot-ch-test-poll2
robot-ch-test-poll2 merged commit f0a182d into backport/26.5/104946 Jun 16, 2026
@robot-ch-test-poll2
robot-ch-test-poll2 deleted the cherrypick/26.5/104946 branch June 16, 2026 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants