Repository navigation
Cherry pick #104946 to 26.5: Fix JIT symbol lookup on macOS - #107600
Merged
robot-ch-test-poll2 merged 9 commits intoJun 16, 2026
Merged
Conversation
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.
Fix JIT symbol lookup on macOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-picklocally.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:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job