-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Description
Inconsistent NEON intrinsics compilation between NDK clang and standalone clang for Android aarch64
When building the same Android aarch64 project, NDK’s bundled clang compiles successfully, but the same version of standalone clang (built from llvm-project) fails with a NEON intrinsics error coming from #include <arm_neon.h>
, even though the compile commands and flags are identical. This suggests a discrepancy in how NEON builtins are handled between the NDK clang toolchain and a self-built clang with the same target.
Steps to Reproduce
0.Patch CMake
Cmake overrides current compiler when system name is set to android, this patch fixes that and will soon be merged upstream
diff --git a/Modules/Platform/Android-Determine-C.cmake b/Modules/Platform/Android-Determine-C.cmake
index c7d1d1512c..1d93cd724b 100644
--- a/Modules/Platform/Android-Determine-C.cmake
+++ b/Modules/Platform/Android-Determine-C.cmake
@@ -1,2 +1,5 @@
+if(CMAKE_C_COMPILER)
+ return()
+endif()
include(Platform/Android/Determine-Compiler)
__android_determine_compiler(C)
diff --git a/Modules/Platform/Android-Determine-CXX.cmake b/Modules/Platform/Android-Determine-CXX.cmake
index 3a3de880a4..e7d96beae2 100644
--- a/Modules/Platform/Android-Determine-CXX.cmake
+++ b/Modules/Platform/Android-Determine-CXX.cmake
@@ -1,2 +1,5 @@
+if(CMAKE_CXX_COMPILER)
+ return()
+endif()
include(Platform/Android/Determine-Compiler)
__android_determine_compiler(CXX)
-
Clone the repro project:
git clone https://github.com/mccakit/cross_compile_fun
cd cross_compile_fun -
Configure and build using standalone clang:
cmake -B build_0 -G Ninja -DCMAKE_TOOLCHAIN_FILE=toolchains/android-arm64.cmake
cmake --build build_0This uses a custom toolchain file pointing to a locally built clang (/home/mccakit/dev/llvm/bin/clang) and NDK sysroot.
-
Observe the error:
[20/77] Building C object extern/sdl_ttf/CMakeFiles/SDL3_ttf-shared.dir/src/SDL_ttf.c.o
FAILED: [code=1] extern/sdl_ttf/CMakeFiles/SDL3_ttf-shared.dir/src/SDL_ttf.c.o
/home/mccakit/dev/llvm/bin/clang --target=aarch64-none-linux-android35 -DBUILD_SDL -DDLL_EXPORT -DPLUTOSVG_BUILD_STATIC -DPLUTOSVG_HAS_FREETYPE -DPLUTOVG_BUILD_STATIC -DSDL_BUILD_MAJOR_VERSION=3 -DSDL_BUILD_MICRO_VERSION=0 -DSDL_BUILD_MINOR_VERSION=3 -DTTF_USE_HARFBUZZ=1 -DTTF_USE_PLUTOSVG=1 -I/home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/include -I/home/mccakit/desktop/projects/cross_compile_fun/build_0/extern/sdl3/include-revision -I/home/mccakit/desktop/projects/cross_compile_fun/extern/sdl3/include -I/home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/external/harfbuzz/src -I/home/mccakit/desktop/projects/cross_compile_fun/build_0/extern/sdl_ttf/external/freetype-build/include -I/home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/external/freetype/include -I/home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/external/plutosvg/source -I/home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/external/plutovg/include -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fexceptions -O3 -DNDEBUG -std=gnu23 -fPIC -fvisibility=hidden --sysroot=/home/mccakit/dev/android-clt/ndk/29.0.13599879/toolchains/llvm/prebuilt/linux-x86_64/sysroot -resource-dir=/home/mccakit/dev/android-clt/ndk/29.0.13599879/toolchains/llvm/prebuilt/linux-x86_64/lib/clang/20 -w -Wall -Wextra -pthread -MD -MT extern/sdl_ttf/CMakeFiles/SDL3_ttf-shared.dir/src/SDL_ttf.c.o -MF extern/sdl_ttf/CMakeFiles/SDL3_ttf-shared.dir/src/SDL_ttf.c.o.d -o extern/sdl_ttf/CMakeFiles/SDL3_ttf-shared.dir/src/SDL_ttf.c.o -c /home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/src/SDL_ttf.c
In file included from /home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/src/SDL_ttf.c:128:
/home/mccakit/dev/android-clt/ndk/29.0.13599879/toolchains/llvm/prebuilt/linux-x86_64/lib/clang/20/include/arm_neon.h:1919:24: error: incompatible constant for this __builtin_neon function
1919 | __ret = (uint16x8_t) __builtin_neon_vceqzq_f16((int8x16_t)__p0, 49);
| ^ ~~
-
Now configure and build using NDK’s own clang:
cmake -B build_1 -G Ninja -DCMAKE_TOOLCHAIN_FILE=toolchains/android-arm64-ndk.cmake
cmake --build build_1This uses the NDK-provided clang binary from
$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/clang.This build succeeds.
Key Observation
compile_commands.json for the failing and succeeding builds are identical:
{ "directory": "/home/mccakit/desktop/projects/cross_compile_fun/build_0", "command": "/home/mccakit/dev/llvm/bin/clang --target=aarch64-none-linux-android35 -DBUILD_SDL -DDLL_EXPORT -DPLUTOSVG_BUILD_STATIC -DPLUTOSVG_HAS_FREETYPE -DPLUTOVG_BUILD_STATIC -DSDL_BUILD_MAJOR_VERSION=3 -DSDL_BUILD_MICRO_VERSION=0 -DSDL_BUILD_MINOR_VERSION=3 -DTTF_USE_HARFBUZZ=1 -DTTF_USE_PLUTOSVG=1 -I/home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/include -I/home/mccakit/desktop/projects/cross_compile_fun/build_0/extern/sdl3/include-revision -I/home/mccakit/desktop/projects/cross_compile_fun/extern/sdl3/include -I/home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/external/harfbuzz/src -I/home/mccakit/desktop/projects/cross_compile_fun/build_0/extern/sdl_ttf/external/freetype-build/include -I/home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/external/freetype/include -I/home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/external/plutosvg/source -I/home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/external/plutovg/include -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fexceptions -O3 -DNDEBUG -std=gnu23 -fPIC -fvisibility=hidden --sysroot=/home/mccakit/dev/android-clt/ndk/29.0.13599879/toolchains/llvm/prebuilt/linux-x86_64/sysroot -resource-dir=/home/mccakit/dev/android-clt/ndk/29.0.13599879/toolchains/llvm/prebuilt/linux-x86_64/lib/clang/20 -w -Wall -Wextra -pthread -o extern/sdl_ttf/CMakeFiles/SDL3_ttf-shared.dir/src/SDL_ttf.c.o -c /home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/src/SDL_ttf.c", "file": "/home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/src/SDL_ttf.c", "output": "/home/mccakit/desktop/projects/cross_compile_fun/build_0/extern/sdl_ttf/CMakeFiles/SDL3_ttf-shared.dir/src/SDL_ttf.c.o" }
{ "directory": "/home/mccakit/desktop/projects/cross_compile_fun/build_1", "command": "/home/mccakit/dev/android-clt/ndk/29.0.13599879/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=aarch64-none-linux-android35 -DBUILD_SDL -DDLL_EXPORT -DPLUTOSVG_BUILD_STATIC -DPLUTOSVG_HAS_FREETYPE -DPLUTOVG_BUILD_STATIC -DSDL_BUILD_MAJOR_VERSION=3 -DSDL_BUILD_MICRO_VERSION=0 -DSDL_BUILD_MINOR_VERSION=3 -DTTF_USE_HARFBUZZ=1 -DTTF_USE_PLUTOSVG=1 -I/home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/include -I/home/mccakit/desktop/projects/cross_compile_fun/build_1/extern/sdl3/include-revision -I/home/mccakit/desktop/projects/cross_compile_fun/extern/sdl3/include -I/home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/external/harfbuzz/src -I/home/mccakit/desktop/projects/cross_compile_fun/build_1/extern/sdl_ttf/external/freetype-build/include -I/home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/external/freetype/include -I/home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/external/plutosvg/source -I/home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/external/plutovg/include -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fexceptions -O3 -DNDEBUG -std=gnu23 -fPIC -fvisibility=hidden -Wall -Wextra -pthread -o extern/sdl_ttf/CMakeFiles/SDL3_ttf-shared.dir/src/SDL_ttf.c.o -c /home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/src/SDL_ttf.c", "file": "/home/mccakit/desktop/projects/cross_compile_fun/extern/sdl_ttf/src/SDL_ttf.c", "output": "/home/mccakit/desktop/projects/cross_compile_fun/build_1/extern/sdl_ttf/CMakeFiles/SDL3_ttf-shared.dir/src/SDL_ttf.c.o" }
Only the compiler binary differs:
- Failing: /home/mccakit/dev/llvm/bin/clang
- Working: $NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
Environment
- Host: Linux Mint 22.2, X64
- NDK version: r29.0.13599879
- Clang version: 22
- Target: aarch64-none-linux-android35
Expected Behavior
Standalone clang with the same flags and sysroot should compile successfully, just like NDK clang.
Actual Behavior
Standalone clang fails with:
error: incompatible constant for this __builtin_neon function
at arm_neon.h:1919.