Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Build Crash With Asan On, clang++: error: clang frontend command failed with exit code 139 #1978

Closed
WangYisi225 opened this issue Dec 19, 2023 · 6 comments
Labels

Comments

@WangYisi225
Copy link

WangYisi225 commented Dec 19, 2023

Description

In a complex C/C++ image processing project involving opencl and dsp, using CMakeLists+Linux, when I turned on the Asan detection compilation option(add_definitions("-fsanitize=address")), the NDK reported the following error. When I close Asan option, it compiles smoothly. I tried from r19c to 26b version, it doesn't work anyway.
The error log points to a function called "FastLoopCl", which is a host cpp function of an opencl that is written the same way as hundreds of other opencl host functions in my project, which runs stably and correctly when the asan compilation option is not enabled.
I tried to annotate this function, and it works and succeed in compiling.
I also tried to annotate a part of this function, but it dosen't work. It cant point to a specific part of codes which leads to the crash. It seems to trigger randomly.
The most obvious error log is: clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation).
So have any friends encountered the same problem? How can I fix it?
Sorry I can't provide a simple test case. I cant reproduce this error in a simple test case anyway.
The error log is as below:
//=====================================================================================================

Stack dump:
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module '/data/branch_opencl.cpp'.
4.      Running pass 'Greedy Register Allocator' on function '@FastLoopCl'
 #0 0x000055c0850c7445 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x4a37445)
 #1 0x000055c0850c64b0 llvm::sys::RunSignalHandlers() (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x4a364b0)
 #2 0x000055c085091bae (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x4a01bae)
 #3 0x000055c085091d16 (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x4a01d16)
 #4 0x00007fade2d7f980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #5 0x000055c08750f118 (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x6e7f118)
 #6 0x000055c08722ef53 (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x6b9ef53)
 #7 0x000055c086f5fdf3 (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x68cfdf3)
 #8 0x000055c086f5f65c (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x68cf65c)
 #9 0x000055c086e816d3 llvm::RegAllocBase::allocatePhysRegs() (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x67f16d3)
#10 0x000055c0872dcc45 (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x6c4cc45)
#11 0x000055c086e20853 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x6790853)
#12 0x000055c086dff2d3 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x676f2d3)
#13 0x000055c086dfee2f llvm::FPPassManager::runOnModule(llvm::Module&) (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x676ee2f)
#14 0x000055c087752e09 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x70c2e09)
#15 0x000055c0877001f5 (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x70701f5)
#16 0x000055c0876fdabf clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream>>) (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x706dabf)
#17 0x000055c086d89005 (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x66f9005)
#18 0x000055c086d19d07 clang::ParseAST(clang::Sema&, bool, bool) (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x6689d07)
#19 0x000055c0876bca70 clang::FrontendAction::Execute() (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x702ca70)
#20 0x000055c0876bc8f3 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x702c8f3)
#21 0x000055c0876b5792 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x7025792)
#22 0x000055c0876b4bf6 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x7024bf6)
#23 0x000055c08771c174 (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x708c174)
#24 0x000055c087473ce6 (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x6de3ce6)
#25 0x000055c08769e61c llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x700e61c)
#26 0x000055c08769e504 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__1::optional<llvm::StringRef>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, bool*) const (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x700e504)
#27 0x000055c08741a747 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x6d8a747)
#28 0x000055c08741a8ff clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*>>&) (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x6d8a8ff)
#29 0x000055c087418ead clang_main(int, char**) (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x6d88ead)
#30 0x00007fade1dbec87 __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:344:0
#31 0x000055c0874e22a9 _start (/home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x6e522a9)
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Android (10552028, +pgo, +bolt, +lto, -mlgo, based on r487747d) clang version 17.0.2 (https://android.googlesource.com/toolchain/llvm-project d9f89f4d16663d5012e5c09495f3b30ece3d2362)
Target: aarch64-none-linux-android23
Thread model: posix
InstalledDir: /home/yisiwang/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin
clang++: note: diagnostic msg: 
********************


Upstream bug

No response

Commit to cherry-pick

No response

Affected versions

r26

Canary version

No response

Host OS

Linux

Host OS version

Ubuntu18.04

Affected ABIs

arm64-v8a

@pirama-arumuga-nainar
Copy link
Collaborator

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++: note: diagnostic msg: /tmp/rawhdr_merge_evx_tone_branch_opencl-ccfa7f.cpp
clang++: note: diagnostic msg: /tmp/rawhdr_merge_evx_tone_branch_opencl-ccfa7f.sh
clang++: note: diagnostic msg:

We need these files to investigate further.

@pirama-arumuga-nainar
Copy link
Collaborator

A workaround is to use __attribute__((no_sanitize("address"))) to disable asan for that particular function: https://clang.llvm.org/docs/AddressSanitizer.html#:~:text=Some%20code%20should,__has_feature(address_sanitizer)..

@DanAlbert
Copy link
Member

Also note that upstream no longer supports ASan for Android (HWASan is better in pretty much every way for API 34+). It's not likely that this bug is Android specific so upstream may still want to fix the crash, but if you have an API 34 device available, you're probably better off just switching to HWASan?

@WangYisi225
Copy link
Author

attribute((no_sanitize("address")))

Hello, I tried use attribute((no_sanitize("address"))) to disable asan check for this function, but NDK still crashes during the compiling. I tried this attribute in a helloworld Demo, when this demo compling works fine, I can actually disable the particular function asan check. However, it doesn't work in the particular function in my project .

@appujee
Copy link
Collaborator

appujee commented Dec 26, 2023

The crash is in the llvm's register allocator. Can you provide preprocessed file that resulted in the error? See https://releases.llvm.org/8.0.0/docs/HowToSubmitABug.html#front-end-bugs on how to provide a preprocessed file. TLDR: add --save-temps to compiler flag and the compiler will output a .ii file.

@pirama-arumuga-nainar
Copy link
Collaborator

If this fails with r26b, uploading the files in PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: would also help investigation. Please re-open with relevant reproducer.

@DanAlbert DanAlbert closed this as not planned Won't fix, can't repro, duplicate, stale Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants