Comments (17)
I have tested with stock LLVM/Clang in the following way:
➜ /opt/homebrew/opt/llvm/bin/clang++ -target armv7a-unknown-linux-android21 -I `<path_to_boost_include_dir>` -c -o sample.o sample.cpp -v -Wno-deprecated-builtins -fsanitize=address --sysroot ~/Downloads/r26d/toolchains/llvm/prebuilt/darwin-x86_64/sysroot
Homebrew clang version 18.1.7
Target: armv7a-unknown-linux-android21
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin
(in-process)
"/opt/homebrew/Cellar/llvm/18.1.7/bin/clang-18" -cc1 -triple armv7-unknown-linux-android21 -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name sample.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu generic -target-feature +soft-float-abi -target-feature +vfp2 -target-feature +vfp2sp -target-feature +vfp3 -target-feature +vfp3d16 -target-feature +vfp3d16sp -target-feature +vfp3sp -target-feature -fp16 -target-feature -vfp4 -target-feature -vfp4d16 -target-feature -vfp4d16sp -target-feature -vfp4sp -target-feature -fp-armv8 -target-feature -fp-armv8d16 -target-feature -fp-armv8d16sp -target-feature -fp-armv8sp -target-feature -fullfp16 -target-feature +fp64 -target-feature +d32 -target-feature +neon -target-feature -sha2 -target-feature -aes -target-feature -fp16fml -target-abi aapcs-linux -mfloat-abi soft -debugger-tuning=gdb -fdebug-compilation-dir=/Users/kellerms/pocs/android-ndk-compiler-issue -target-linker-version 1053.12 -v -fcoverage-compilation-dir=/Users/kellerms/pocs/android-ndk-compiler-issue -resource-dir /opt/homebrew/Cellar/llvm/18.1.7/lib/clang/18 -I /Users/kellerms/pocs/android-ndk-compiler-issue -isysroot /Users/kellerms/Downloads/r26d/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -internal-isystem /Users/kellerms/Downloads/r26d/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1 -internal-isystem /opt/homebrew/Cellar/llvm/18.1.7/lib/clang/18/include -internal-isystem /Users/kellerms/Downloads/r26d/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/local/include -internal-externc-isystem /Users/kellerms/Downloads/r26d/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/arm-linux-androideabi -internal-externc-isystem /Users/kellerms/Downloads/r26d/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/include -internal-externc-isystem /Users/kellerms/Downloads/r26d/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include -Wno-deprecated-builtins -fdeprecated-macro -ferror-limit 19 -femulated-tls -fsanitize=address -fsanitize-system-ignorelist=/opt/homebrew/Cellar/llvm/18.1.7/lib/clang/18/share/asan_ignorelist.txt -fno-sanitize-memory-param-retval -fsanitize-address-use-after-scope -fsanitize-address-globals-dead-stripping -fno-assume-sane-operator-new -fno-signed-char -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o sample.o -x c++ sample.cpp
clang -cc1 version 18.1.7 based upon LLVM 18.1.7 default target arm64-apple-darwin23.5.0
ignoring nonexistent directory "/Users/kellerms/Downloads/r26d/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/local/include"
ignoring nonexistent directory "/Users/kellerms/Downloads/r26d/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/include"
#include "..." search starts here:
#include <...> search starts here:
/Users/kellerms/pocs/android-ndk-compiler-issue
/Users/kellerms/Downloads/r26d/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1
/opt/homebrew/Cellar/llvm/18.1.7/lib/clang/18/include
/Users/kellerms/Downloads/r26d/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/arm-linux-androideabi
/Users/kellerms/Downloads/r26d/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include
End of search list.
And it's able to compile the sample program without issue. This makes me thing is something with Android flavor of Clang.
from ndk.
To clarify: there is no android flavor of Clang. We built it, but it's the upstream source. The reason for the behavior difference is that it's a different version of Clang, which does mean that this bug might be fixed in r28, which has a newer Clang than either r26 or r27.
It's not likely that we'll have a backport for r26 at this point, as it doesn't sound like this is a regression from r25 (though we'll need to confirm that). r27 is a possibility though.
from ndk.
Can you add --save-temps
and share the sample.ii
(with r27, like danalbert mentioned)? To make sure we are looking at the same failure as yours.
from ndk.
Hello, output running with --save-temps
:
➜ android-ndk-compiler-issue ./r27/bin/armv7a-linux-androideabi21-clang++ -I `pwd` -c -o sample.o sample.cpp -v -Wno-deprecated-builtins -fsanitize=address --save-temps
Android (11889484, +pgo, -bolt, +lto, -mlgo, based on r522817) clang version 18.0.1 (https://android.googlesource.com/toolchain/llvm-project d8003a456d14a3deb8054cdaa529ffbf02d9b262)
Target: armv7a-unknown-linux-android21
Thread model: posix
InstalledDir: /Users/kellerms/pocs/android-ndk-compiler-issue/./r27/bin
"/Users/kellerms/pocs/android-ndk-compiler-issue/r27/bin/clang180++" -cc1 -triple armv7-unknown-linux-android21 -E -save-temps=cwd -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name sample.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu generic -target-feature +soft-float-abi -target-feature +vfp2 -target-feature +vfp2sp -target-feature +vfp3 -target-feature +vfp3d16 -target-feature +vfp3d16sp -target-feature +vfp3sp -target-feature -fp16 -target-feature -vfp4 -target-feature -vfp4d16 -target-feature -vfp4d16sp -target-feature -vfp4sp -target-feature -fp-armv8 -target-feature -fp-armv8d16 -target-feature -fp-armv8d16sp -target-feature -fp-armv8sp -target-feature -fullfp16 -target-feature +fp64 -target-feature +d32 -target-feature +neon -target-feature -sha2 -target-feature -aes -target-feature -fp16fml -target-abi aapcs-linux -mfloat-abi soft -debugger-tuning=gdb -fdebug-compilation-dir=/Users/kellerms/pocs/android-ndk-compiler-issue -v -fcoverage-compilation-dir=/Users/kellerms/pocs/android-ndk-compiler-issue -resource-dir /Users/kellerms/pocs/android-ndk-compiler-issue/r27/lib/clang/18 -I /Users/kellerms/pocs/android-ndk-compiler-issue -internal-isystem /Users/kellerms/pocs/android-ndk-compiler-issue/./r27/bin/../sysroot/usr/include/c++/v1 -internal-isystem /Users/kellerms/pocs/android-ndk-compiler-issue/r27/lib/clang/18/include -internal-isystem /Users/kellerms/pocs/android-ndk-compiler-issue/./r27/bin/../sysroot/usr/local/include -internal-externc-isystem /Users/kellerms/pocs/android-ndk-compiler-issue/./r27/bin/../sysroot/usr/include/arm-linux-androideabi -internal-externc-isystem /Users/kellerms/pocs/android-ndk-compiler-issue/./r27/bin/../sysroot/include -internal-externc-isystem /Users/kellerms/pocs/android-ndk-compiler-issue/./r27/bin/../sysroot/usr/include -Wno-deprecated-builtins -fdeprecated-macro -ferror-limit 19 -femulated-tls -fsanitize=address -fsanitize-system-ignorelist=/Users/kellerms/pocs/android-ndk-compiler-issue/r27/lib/clang/18/share/asan_ignorelist.txt -fno-sanitize-memory-param-retval -fsanitize-address-use-after-scope -fsanitize-address-globals-dead-stripping -fno-assume-sane-operator-new -fno-signed-char -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o sample.ii -x c++ sample.cpp
clang -cc1 version 18.0.1 based upon LLVM 18.0.1 default target x86_64-apple-darwin23.5.0
ignoring nonexistent directory "/Users/kellerms/pocs/android-ndk-compiler-issue/./r27/bin/../sysroot/usr/local/include"
ignoring nonexistent directory "/Users/kellerms/pocs/android-ndk-compiler-issue/./r27/bin/../sysroot/include"
#include "..." search starts here:
#include <...> search starts here:
/Users/kellerms/pocs/android-ndk-compiler-issue
/Users/kellerms/pocs/android-ndk-compiler-issue/./r27/bin/../sysroot/usr/include/c++/v1
/Users/kellerms/pocs/android-ndk-compiler-issue/r27/lib/clang/18/include
/Users/kellerms/pocs/android-ndk-compiler-issue/./r27/bin/../sysroot/usr/include/arm-linux-androideabi
/Users/kellerms/pocs/android-ndk-compiler-issue/./r27/bin/../sysroot/usr/include
End of search list.
"/Users/kellerms/pocs/android-ndk-compiler-issue/r27/bin/clang180++" -cc1 -triple armv7-unknown-linux-android21 -emit-llvm-bc -emit-llvm-uselists -save-temps=cwd -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name sample.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu generic -target-feature +soft-float-abi -target-feature +vfp2 -target-feature +vfp2sp -target-feature +vfp3 -target-feature +vfp3d16 -target-feature +vfp3d16sp -target-feature +vfp3sp -target-feature -fp16 -target-feature -vfp4 -target-feature -vfp4d16 -target-feature -vfp4d16sp -target-feature -vfp4sp -target-feature -fp-armv8 -target-feature -fp-armv8d16 -target-feature -fp-armv8d16sp -target-feature -fp-armv8sp -target-feature -fullfp16 -target-feature +fp64 -target-feature +d32 -target-feature +neon -target-feature -sha2 -target-feature -aes -target-feature -fp16fml -target-abi aapcs-linux -mfloat-abi soft -debugger-tuning=gdb -fdebug-compilation-dir=/Users/kellerms/pocs/android-ndk-compiler-issue -v -fcoverage-compilation-dir=/Users/kellerms/pocs/android-ndk-compiler-issue -resource-dir /Users/kellerms/pocs/android-ndk-compiler-issue/r27/lib/clang/18 -Wno-deprecated-builtins -fdeprecated-macro -ferror-limit 19 -femulated-tls -fsanitize=address -fsanitize-system-ignorelist=/Users/kellerms/pocs/android-ndk-compiler-issue/r27/lib/clang/18/share/asan_ignorelist.txt -fno-sanitize-memory-param-retval -fsanitize-address-use-after-scope -fsanitize-address-globals-dead-stripping -fno-assume-sane-operator-new -fno-signed-char -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -disable-llvm-passes -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o sample.bc -x c++-cpp-output sample.ii
clang -cc1 version 18.0.1 based upon LLVM 18.0.1 default target x86_64-apple-darwin23.5.0
#include "..." search starts here:
End of search list.
"/Users/kellerms/pocs/android-ndk-compiler-issue/r27/bin/clang180++" -cc1 -triple armv7-unknown-linux-android21 -S -save-temps=cwd -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name sample.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu generic -target-feature +soft-float-abi -target-feature +vfp2 -target-feature +vfp2sp -target-feature +vfp3 -target-feature +vfp3d16 -target-feature +vfp3d16sp -target-feature +vfp3sp -target-feature -fp16 -target-feature -vfp4 -target-feature -vfp4d16 -target-feature -vfp4d16sp -target-feature -vfp4sp -target-feature -fp-armv8 -target-feature -fp-armv8d16 -target-feature -fp-armv8d16sp -target-feature -fp-armv8sp -target-feature -fullfp16 -target-feature +fp64 -target-feature +d32 -target-feature +neon -target-feature -sha2 -target-feature -aes -target-feature -fp16fml -target-abi aapcs-linux -mfloat-abi soft -debugger-tuning=gdb -fdebug-compilation-dir=/Users/kellerms/pocs/android-ndk-compiler-issue -v -fcoverage-compilation-dir=/Users/kellerms/pocs/android-ndk-compiler-issue -resource-dir /Users/kellerms/pocs/android-ndk-compiler-issue/r27/lib/clang/18 -Wno-deprecated-builtins -ferror-limit 19 -femulated-tls -fsanitize=address -fsanitize-system-ignorelist=/Users/kellerms/pocs/android-ndk-compiler-issue/r27/lib/clang/18/share/asan_ignorelist.txt -fno-sanitize-memory-param-retval -fsanitize-address-use-after-scope -fsanitize-address-globals-dead-stripping -fno-assume-sane-operator-new -fno-signed-char -fgnuc-version=4.2.1 -fcolor-diagnostics -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o sample.s -x ir sample.bc
clang -cc1 version 18.0.1 based upon LLVM 18.0.1 default target x86_64-apple-darwin23.5.0
error: ran out of registers during register allocation
error: ran out of registers during register allocation
error: ran out of registers during register allocation
error: ran out of registers during register allocation
error: ran out of registers during register allocation
error: ran out of registers during register allocation
Here is a zip file with temp files:
temps.zip
from ndk.
To clarify: there is no android flavor of Clang. We built it, but it's the upstream source. The reason for the behavior difference is that it's a different version of Clang, which does mean that this bug might be fixed in r28, which has a newer Clang than either r26 or r27.
It's not likely that we'll have a backport for r26 at this point, as it doesn't sound like this is a regression from r25 (though we'll need to confirm that). r27 is a possibility though.
Thanks for the clarification. Our stack was previously being built with R18 (I know... a little bit old) and we only found this issue once we tried to move to R26. I have tested R22 & R23 and both seems to compile fine this piece of code. So definitely something introduced in R24.
I dive deep into why boost lockfree queue triggers this behavior and it seems to be because the heavy use of templates to deduce compile/runtime size of the queue type. I tried to isolate an smaller program without use of boost library without success. Adding this context just in case is somehow helpful (I hope so).
from ndk.
We'll see what we can do, but we do give priority to regressions from the previous release over bugs that have been broken for a long time (if they've been broken a long time and this is the first report, they probably aren't as wide spread). We're almost entirely dependent on upstream actually providing the fixes, but since it's working with LLVM 18 (and I think r27 is ever so slightly behind LLVM 18?), the odds are pretty good that there's already a fix we can cherry-pick.
from ndk.
clang-18.0.0(r510928) doesn't crash but 18.0.1(r522817) does.
from ndk.
Simpler command line to repro with the provided sample.ii file.
$CC -cc1 -triple armv7-unknown-linux-android21 -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name sample.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu generic -target-feature +soft-float-abi -target-feature +vfp2 -target-feature +vfp2sp -target-feature +vfp3 -target-feature +vfp3d16 -target-feature +vfp3d16sp -target-feature +vfp3sp -target-feature -fp16 -target-feature -vfp4 -target-feature -vfp4d16 -target-feature -vfp4d16sp -target-feature -vfp4sp -target-feature -fp-armv8 -target-feature -fp-armv8d16 -target-feature -fp-armv8d16sp -target-feature -fp-armv8sp -target-feature -fullfp16 -target-feature +fp64 -target-feature +d32 -target-feature +neon -target-feature -sha2 -target-feature -aes -target-feature -fp16fml -target-abi aapcs-linux -mfloat-abi soft -fdeprecated-macro -ferror-limit 19 -femulated-tls -fsanitize=address -fno-sanitize-memory-param-retval -fsanitize-address-use-after-scope -fsanitize-address-globals-dead-stripping -fno-assume-sane-operator-new -fno-signed-char -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o sample.o -x c++ sample.ii
from ndk.
Using -mllvm -asan-use-stack-safety=1
fixes the error. I feel the problem is still latent in llvm but after llvm/llvm-project#77210 the error went away.
Either cherry-picking this patch to ndk or maybe adding this flag as default cc flags should be fine.
from ndk.
Yeah so even with trunk compiler and with -mllvm -asan-use-stack-safety=0
we get this error. The error only occurs for Android targets though. https://godbolt.org/z/5ocv7Wsa9
from ndk.
I hadn't read closely enough before (evidently I really needed that vacation) and missed that this was ASan related. @kellermanrivero, have you tried HWASan? ASan isn't actually supported for Android by upstream any more because there are so few reasons why it should be used over HWASan. See https://developer.android.com/ndk/guides/memory-debug for an overview of the tools available. ASan says "only as a last resort". HWASan was historically a pain to use, but as of U (which I know is extremely new) it's easier to use than ASan is.
Clang shouldn't crash in any case and it'd be good to pick up the fix for this, but if you've got a better alternative you may not actually care :)
from ndk.
@appujee great job! thanks for the dive deep here. It's extremely valuable. I feel I have somehow contributed to the project by reporting this error.
@DanAlbert my team is moving away from a really old NDK r18 into latest one so I guess maybe ASAN was the recommended option for R18. I will try out HWASan and report the results back.
Thanks both for the hard work here!
from ndk.
@DanAlbert my team is moving away from a really old NDK r18 into latest one so I guess maybe ASAN was the recommended option for R18. I will try out HWASan and report the results back.
r18 is old enough that I don't remember whether hwasan would work there or not, but I suspect you're right. Even if it did, I think you probably need an NDK that is aware of android U (which I think means r26+) to use the easy mode?
from ndk.
Tentatively adding this for r27b so we remember to check, but due to the lack of upstream support for ASan, there may never be a fix for us to pick up.
from ndk.
@DanAlbert I just realized that this issue specifically happens on Armv7 target so HWASan won't work since it only supports 64-bit architecture.
from ndk.
Maybe. If the bug is present but asymptomatic on arm64, hwasan should still be able to catch it. If it's in arm32-specific code though, yeah, hwasan won't help you :(
from ndk.
The reported bug in llvm-upstream has a reduced testcase, maybe that can give you some insight on a workaround in the mean time? llvm/llvm-project#98222
from ndk.
Related Issues (20)
- [DOC] `system_fonts.h` HOT 7
- [Bug]: Lambda segfaults in Clang HOT 11
- [FR] Official NDK release for Linux arm64 HOT 1
- [Bug]: fatal error: error in backend: Cannot select: 0x10ba8ace0: nxv4f32 = BUILD_VECTOR 0x133163a90, 0x1330f4800, 0x133108d20, 0x1248b9e60 HOT 6
- [BUG] Compilation Error with std::execution in C++17 HOT 3
- [BUG] CLEAR_VARS does not clear LOCAL_STRIP_MODE variable HOT 2
- [Bug]: Android NDK r27 rc2 miscompiles code with inderect gotos HOT 13
- [Bug] NDK's openmp test crashing on x86 with latest LLVM update HOT 4
- Please provide maintainable list of NDK codename-revision pairs HOT 3
- [Bug]: clang compile with -D_FORTIFY_SOURCE=2 -Dstatic= cause undefined symbol: snprintf HOT 7
- [BUG] android-ndk-r26c use -pg ld.lld: error: undefined symbol: _mcount HOT 7
- [Bug]: Compiler Crash HOT 5
- [FR] support libclang? HOT 1
- [BUG] investigate odd find_package behavior HOT 3
- [BUG] NDK 27 no longer supports passing in `CMAKE_SYSTEM_PROCESSOR` to CMake to set the arch HOT 8
- [Bug]: Unable to disable a builtin with -fno-builtin-wmemchr HOT 17
- [BUG] sysroot wrongly includes tflite_support_libz.a? HOT 3
- [BUG] Build error of ncnn for Android 'x86_64' ABI with NDK r27 HOT 4
- [BUG]Building Library\Bee\artifacts\Android\d8kzr\d29di98gygw8.o failed HOT 2
- [BUG] Clang error: unsupported option '-frecord-command-line' for target 'x86_64-w64-windows-gnu' HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ndk.