Repository navigation
DX-128331: Gandiva: normalize Darwin host triple to macosx so exp10 libcall is available - #151
Merged
lriggs merged 4 commits intoNov 11, 2026
Conversation
victor6567758
force-pushed
the
DX-128331-gandiva-fexp10-crash
branch
from
November 9, 2026 20:46
e174967 to
7b71843
Compare
victor6567758
requested review from
a team,
alinaliBQ,
dmitry-chirkov-dremio,
g-zemlianyi,
lriggs,
myk and
tristan-sturgess
November 10, 2026 11:49
…ibcall is available
victor6567758
force-pushed
the
DX-128331-gandiva-fexp10-crash
branch
from
November 10, 2026 12:04
7b71843 to
61a1a4d
Compare
victor6567758
marked this pull request as ready for review
November 10, 2026 14:43
victor6567758
force-pushed
the
DX-128331-gandiva-fexp10-crash
branch
from
November 10, 2026 19:59
ea850ba to
5f4b6df
Compare
dmitry-chirkov-dremio
approved these changes
Nov 11, 2026
lriggs
pushed a commit
that referenced
this pull request
Nov 12, 2026
…ibcall is available (#151) (#157) * DX-128331: Gandiva: normalize Darwin host triple to macosx so exp10 libcall is available * DX-128331: Gandiva: merge 'unchanged' Darwin triple normalization tests * DX-128331: Gandiva: document why round(float64, int32) tests cover the exp10 lowering path * DX-128331: Gandiva: move round(float64, scale) tests to decimal_test.cc (cherry picked from commit 148cb48)
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.
Summary
Fixes DX-128331: on macOS (Apple arm64) with Gandiva IR optimization disabled (we do this past the 2k-expression threshold), expressions such as
round(c0, 1)orround(c0, c1)crash the JVM witherror: no libcall available for fexp10.Root cause
Gandiva builds its JIT target machine from
llvm::sys::getDefaultTargetTriple(), which on macOS is an unversioned/kernel-versionedarm64-apple-darwin<N>. LLVM only enables macOS libcalls such as__exp10for themacosxOS name. With optimization off,pow(10, x)(used byget_scale_multiplierfor scales outside 0..19) islowered to
llvm.exp10, and the backend finds no libcall for it.Fix
Add
NormalizeDarwinTriple()(declared inengine.h, defined inengine.cc) and apply it to the host triple inMakeTargetMachineBuilder.darwin<kernel>becomesmacosx<version>, usingTriple::getMacOSXVersion.macOSfor the architecture:11.0forarm64,10.15forx86_64.macosx11.0, notmacosx11).Why this approach
Same as clang: clang's driver does this rewrite when it targets
macOS. The JIT skips the driver, so we do it ourselves. It means:arm64-apple-darwin27.2.0is whatllvm::sys::getDefaultTargetTriple()returns. The OS part isdarwin, followed by the kernel version.arm64-apple-macosx27.2.0is what clang uses internally. The OS part ismacosx, followed by a macOS version.Fixes the cause for all libcalls: other macOS-only libcalls hit the same wrong-OS-name problem. Rewriting
exp10orpowin precompiled IR would only patch one symptom and would change the IR for every platform.Only "at least macOS 10.9" matters for libcall selection, so the approximate kernel-to-macOS mapping is acceptable.
bool RuntimeLibcallsInfo::darwinHasExp10(const Triple &TT) { switch (TT.getOS()) { case Triple::MacOSX: return !TT.isMacOSXVersionLT(10, 9);Fixing
darwinHasExp10fromLLVMwould require changes in the additional component what is outside of our control: https://github.com/llvm/llvm-project/blob/main/llvm/lib/IR/RuntimeLibcalls.cppTests
engine_llvm_test.cc: unit tests forNormalizeDarwinTriple(darwin to macosx, the floor for unversioned/old, floor boundaries, arch aliases, non-Darwin unchanged, idempotence).projector_test.cc:round(float64, int32)with optimization off. They cover:pow(10, scale)paths that lower toexp10.JarBuild osx-aarch_64 jar, running the round cases withexec.gandiva.optimize_ir=false).SELECT ROUND(c0, 1) AS r FROM $scratch.g1works after the fix.buildJaris OK: https://github.com/dremio/arrow-java/actions/runs/42818876037Why we need the new tests:
decimal_test.cc: this test runs OK BEFORE this fix. It cannot catch the problematic code:tests/decimal_test.cc:408-417:TreeExprBuilder::MakeFunction("round", {field_a, scale_1}, arrow::decimal128(precision, 1))->void round_decimal128_int32 ( precompiled/decimal_wrapper.cc:146)->auto out = gandiva::decimalops::Round(x, out_precision, out_scale, rounding_scale, &overflow) ( precompiled/decimal_ops.cc:662)->RoundWithPositiveScale at 615 and RoundWithNegativeScale at 644 (cpp/src/gandiva/precompiled/decimal_ops.cc)->It does integer arithmetic using
BasicDecimal128::GetScaleMultiplier(scale), which is a table lookup on 128-bit integers.10:11-12:20 /Users/victor.zoubok/work/codebase2/arrow/cpp/cmake-build-debug_homebrew [DX-128331-gandiva-fexp10-crash*] > cd /Users/victor.zoubok/work/codebase2/arrow/cpp/cmake-build-debug_homebrew/debug
for t in $(./gandiva-projector-test --gtest_list_tests --gtest_filter='TestProjector.TestRoundFloat64*' | awk '/^[^ ]/{s=$1} /^ /{print s $1}'); do
./gandiva-projector-test --gtest_filter="$t" >/tmp/pt.out 2>&1; echo "exit $? : $t"; grep -m1 "no libcall" /tmp/pt.out
done
exit 1 : TestProjector.TestRoundFloat64ScaleInLookupTable
error: no libcall available for fexp10
exit 1 : TestProjector.TestRoundFloat64ScaleAtTableBoundary
error: no libcall available for fexp10
exit 1 : TestProjector.TestRoundFloat64LargeScale
error: no libcall available for fexp10
exit 1 : TestProjector.TestRoundFloat64NegativeScale
error: no libcall available for fexp10
exit 1 : TestProjector.TestRoundFloat64MixedScalesInOneBatch
error: no libcall available for fexp10
exit 1 : TestProjector.TestRoundFloat64LargeValuesSkipRounding
error: no libcall available for fexp10
exit 1 : TestProjector.TestRoundFloat64ZeroValue
error: no libcall available for fexp10
cpp/src/gandiva/precompiled/extended_math_ops.cc. Steps 1 to 4 are in the source. Steps 5 and 6 are how LLVM behaves. Note that native unit tests forround_float64_int32are called directly, no Gandiva JIT, that's why the issue is not detected.SQL / expression: round(float64 value, int32 scale)
│
▼
expands to round_float64_int32(number, out_scale)
line 315: scale_multiplier = get_scale_multiplier(out_scale);
|
▼
• scale in [0, 20) → values[scale] table lookup, no math call
• otherwise → power_float64_float64(10.0, scale) line 448
│
▼
power_float64_float64(in1, in2) = powl(in1, in2) line 221
│
▼
embedded as kPrecompiledBitcode) and loaded by the JIT engine
→ the whole function is compiled, including the powl(10, x) branch,
whatever scale the data has
│
▼
│
▼
→ no __exp10 libcall enabled for "darwin"
→ "error: no libcall available for fexp10" → process aborts
Fix: NormalizeDarwinTriple() rewrites the triple to "macosx"
Review comments
#ifdef __APPLE__which assertNormalizeDarwinTriple(llvm::Triple(llvm::sys::getDefaultTargetTriple())).getOS() == llvm::Triple::MacOSXbecause the function is intended to run correctly on any platform, no real value to disable new tests on Windows or Linux.exp10. That is the intent.