Android NDK 編譯和 Crash 問題集合

error: undefined reference to ‘pthread_spin_XX’

問題:

error: undefined reference to 'pthread_spin_lock'
error: undefined reference to 'pthread_spin_unlock'
error: undefined reference to 'pthread_spin_init'
error: undefined reference to 'pthread_spin_destroy'

解決:
APP_PLATFORM 需要改成 android-24 或以上版本才支持 pthread 自旋鎖。
使用 Application.mk 時,做一下修改(使用 Cmake 時也需做對應修改):

...
APP_PLATFORM := android-24
...

error: undefined reference to ‘cv::imwrite’

問題:
NDK(ndkr20) 使用 OpenCV (3.4.2) 出現的編譯問題

error: undefined reference to 'cv::imwrite(cv::String const&, cv::_InputArray const&, std::__ndk1::vector<int, std::__ndk1::allocator<int> > const&)'

解決:
App 目錄下的 build.gradle 文件作如下修改:

        externalNativeBuild {
            cmake {
                cppFlags '-std=c++11 -fopenmp'
                arguments '-DANDROID_PLATFORM=android-24',
                '-DANDROID_TOOLCHAIN=clang++',
                '-DANDROID_STL=c++_static',
                "-DANDROID_ARM_NEON=TRUE",
                "-DANDROID_ALLOW_UNDEFINED_SYMBOLS=TRUE"
            }
        }

error: undefined reference to 'std::__ndk1::__fs::filesystem::

問題:

error: undefined reference to 'std::__ndk1::__fs::filesystem::directory_iterator::__dereference() const'
error: undefined reference to 'std::__ndk1::__fs::filesystem::directory_iterator::directory_iterator(std::__ndk1::__fs::filesystem::path const&, std::__ndk1::error_code*, std::__ndk1::__fs::filesystem::directory_options)'
error: undefined reference to 'std::__ndk1::__fs::filesystem::directory_iterator::__increment(std::__ndk1::error_code*)'
error: undefined reference to 'std::__ndk1::__fs::filesystem::directory_iterator::__dereference() 

解決:
低版本 NDK 不支持 filesystem ,修改 NDK 版本,如 NDK r20 。

stack corruption detected

問題:

06-17 08:54:08.226 10713 10713 F libc    : stack corruption detected (-fstack-protector)
06-17 08:54:08.226 10713 10713 F libc    : Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 10713 (low.learnffmpeg), pid 10713 (low.learnffmpeg)
06-17 08:54:08.295 10762 10762 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-17 08:54:08.296 10762 10762 F DEBUG   : Build fingerprint: 'samsung/beyond2qltesq/beyond2q:9/PPR1.180610.011/G975USQU1ASC6:userdebug/test-keys'
06-17 08:54:08.296 10762 10762 F DEBUG   : Revision: '13'
06-17 08:54:08.296 10762 10762 F DEBUG   : ABI: 'arm64'
06-17 08:54:08.296 10762 10762 F DEBUG   : pid: 10713, tid: 10713, name: low.learnffmpeg  >>> com.byteflow.learnffmpeg <<<
06-17 08:54:08.296 10762 10762 F DEBUG   : signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
06-17 08:54:08.296 10762 10762 F DEBUG   : Abort message: 'stack corruption detected (-fstack-protector)'
06-17 08:54:08.296 10762 10762 F DEBUG   :     x0  0000000000000000  x1  00000000000029d9  x2  0000000000000006  x3  0000000000000008
06-17 08:54:08.296 10762 10762 F DEBUG   :     x4  0000000000000000  x5  0000000000000000  x6  0000000000000000  x7  0000000000000030
06-17 08:54:08.296 10762 10762 F DEBUG   :     x8  0000000000000083  x9  522dc3403fd55b7d  x10 0000000000000000  x11 fffffffc7ffffbdf
06-17 08:54:08.296 10762 10762 F DEBUG   :     x12 0000000000000001  x13 000000005ee969b0  x14 000c8768dead0062  x15 0000f7bd6d6914c5
06-17 08:54:08.296 10762 10762 F DEBUG   :     x16 000000777ac5c2a8  x17 000000777ab7ced0  x18 0000000000000010  x19 00000000000029d9
06-17 08:54:08.296 10762 10762 F DEBUG   :     x20 00000000000029d9  x21 00000076f9c14c00  x22 0000007fc4ac3430  x23 00000076f5882504
06-17 08:54:08.296 10762 10762 F DEBUG   :     x24 0000000000000000  x25 0000007780b7b5f8  x26 00000076f9c14ca0  x27 0000000000000000
06-17 08:54:08.296 10762 10762 F DEBUG   :     x28 0000007fc4ac3170  x29 0000007fc4ac2c30
06-17 08:54:08.296 10762 10762 F DEBUG   :     sp  0000007fc4ac2bf0  lr  000000777ab6f33c  pc  000000777ab6f364
06-17 08:54:08.296 10762 10762 F DEBUG   : backtrace:
06-17 08:54:08.296 10762 10762 F DEBUG   :     #00 pc 0000000000022364  /system/lib64/libc.so (abort+116)
06-17 08:54:08.296 10762 10762 F DEBUG   :     #01 pc 000000000007c140  /system/lib64/libc.so (__stack_chk_fail+20)

解決:問題原因是棧內存被破壞,一般是數組越界導致,檢查棧內存數組是否分配過小了。

Fatal signal 7 (SIGBUS), code 1 (BUS_ADRALN), ReferenceQueueD

問題:

06-29 13:10:15.134  4232  4242 F libc    : Fatal signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr 0x5f626d75687415 in tid 4242 (ReferenceQueueD), pid 4232 (low.learnffmpeg)
06-29 13:10:15.237  4867  4867 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-29 13:10:15.237  4867  4867 F DEBUG   : Build fingerprint: 'samsung/beyond2qltesq/beyond2q:9/PPR1.180610.011/G975USQU1ASC6:userdebug/test-keys'
06-29 13:10:15.237  4867  4867 F DEBUG   : Revision: '13'
06-29 13:10:15.237  4867  4867 F DEBUG   : ABI: 'arm64'
06-29 13:10:15.237  4867  4867 F DEBUG   : pid: 4232, tid: 4242, name: ReferenceQueueD  >>> com.byteflow.learnffmpeg <<<
06-29 13:10:15.238  4867  4867 F DEBUG   : signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr 0x5f626d75687415
06-29 13:10:15.238  4867  4867 F DEBUG   :     x0  305f626d7568740d  x1  00000076e5586544  x2  000000777eb6c064  x3  00000076f0758b20
06-29 13:10:15.238  4867  4867 F DEBUG   :     x4  00000076e5586990  x5  0000000072debce8  x6  712e666d606b2e60  x7  0000000000000000
06-29 13:10:15.238  4867  4867 F DEBUG   :     x8  000000007568740d  x9  00000076f0758b28  x10 00000076f1506d48  x11 0000000000000000
06-29 13:10:15.238  4867  4867 F DEBUG   :     x12 00000000f1506cf7  x13 305f626d75687415  x14 00000076f99981e4  x15 0000000000000000
06-29 13:10:15.238  4867  4867 F DEBUG   :     x16 000000777fc5a1b8  x17 000000777f6aa804  x18 0000000000000000  x19 00000076f0758b20
06-29 13:10:15.238  4867  4867 F DEBUG   :     x20 00000076f57ffe74  x21 00000076f9cb9000  x22 00000076e55867e0  x23 0000000072debce8
06-29 13:10:15.238  4867  4867 F DEBUG   :     x24 0000000000000010  x25 00000076e5588588  x26 00000076f9cb90a0  x27 0000000000000004
06-29 13:10:15.238  4867  4867 F DEBUG   :     x28 0000000000000000  x29 00000076e5586500
06-29 13:10:15.238  4867  4867 F DEBUG   :     sp  00000076e55864f0  lr  000000777eb6c080  pc  000000777f6aa94c
06-29 13:10:15.271  4867  4867 F DEBUG   : 
06-29 13:10:15.271  4867  4867 F DEBUG   : backtrace:
06-29 13:10:15.271  4867  4867 F DEBUG   :     #00 pc 000000000032e94c  /system/lib64/libhwui.so (SkPaint::~SkPaint()+328)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #01 pc 000000000016207c  /system/lib64/libandroid_runtime.so (android::PaintGlue::deletePaint(android::Paint*)+24)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #02 pc 000000000016207c  /system/lib64/libandroid_runtime.so (android::PaintGlue::deletePaint(android::Paint*)+24)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #03 pc 000000000007dc20  /system/framework/arm64/boot-core-libart.oat (offset 0x7a000) (java.math.NativeBN.BN_copy [DEDUPED]+160)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #04 pc 000000000055824c  /system/lib64/libart.so (art_quick_invoke_static_stub+604)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #05 pc 00000000000cfce8  /system/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+232)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #06 pc 0000000000280438  /system/lib64/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+344)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #07 pc 000000000027a440  /system/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+968)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #08 pc 0000000000528408  /system/lib64/libart.so (MterpInvokeStatic+204)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #09 pc 000000000054a714  /system/lib64/libart.so (ExecuteMterpImpl+14612)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #10 pc 00000000000b9420  /system/framework/boot-core-libart.vdex (libcore.util.NativeAllocationRegistry$CleanerThunk.run+32)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #11 pc 0000000000254144  /system/lib64/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEb.llvm.2978999722+488)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #12 pc 0000000000259c38  /system/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+216)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #13 pc 000000000027a424  /system/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+940)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #14 pc 0000000000527e80  /system/lib64/libart.so (MterpInvokeInterface+1392)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #15 pc 000000000054a794  /system/lib64/libart.so (ExecuteMterpImpl+14740)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #16 pc 00000000001266e2  /system/framework/boot.vdex (sun.misc.Cleaner.clean+18)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #17 pc 0000000000254144  /system/lib64/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEb.llvm.2978999722+488)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #18 pc 0000000000259c38  /system/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+216)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #19 pc 000000000027a424  /system/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+940)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #20 pc 0000000000526f04  /system/lib64/libart.so (MterpInvokeVirtual+588)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #21 pc 000000000054a594  /system/lib64/libart.so (ExecuteMterpImpl+14228)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #22 pc 00000000000cba90  /system/framework/boot.vdex (java.lang.ref.ReferenceQueue.enqueueLocked+28)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #23 pc 0000000000254144  /system/lib64/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEb.llvm.2978999722+488)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #24 pc 0000000000259c38  /system/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+216)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #25 pc 000000000027a424  /system/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+940)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #26 pc 0000000000528244  /system/lib64/libart.so (MterpInvokeDirect+296)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #27 pc 000000000054a694  /system/lib64/libart.so (ExecuteMterpImpl+14484)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #28 pc 00000000000cbc74  /system/framework/boot.vdex (java.lang.ref.ReferenceQueue.enqueuePending+36)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #29 pc 0000000000254144  /system/lib64/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEb.llvm.2978999722+488)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #30 pc 0000000000259c38  /system/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+216)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #31 pc 000000000027a424  /system/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+940)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #32 pc 0000000000528408  /system/lib64/libart.so (MterpInvokeStatic+204)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #33 pc 000000000054a714  /system/lib64/libart.so (ExecuteMterpImpl+14612)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #34 pc 00000000000af1f6  /system/framework/boot-core-libart.vdex (java.lang.Daemons$ReferenceQueueDaemon.runInternal+54)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #35 pc 0000000000254144  /system/lib64/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEb.llvm.2978999722+488)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #36 pc 0000000000259c38  /system/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+216)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #37 pc 000000000027a424  /system/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+940)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #38 pc 0000000000526f04  /system/lib64/libart.so (MterpInvokeVirtual+588)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #39 pc 000000000054a594  /system/lib64/libart.so (ExecuteMterpImpl+14228)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #40 pc 00000000000aecf0  /system/framework/boot-core-libart.vdex (java.lang.Daemons$Daemon.run+20)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #41 pc 0000000000254144  /system/lib64/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEb.llvm.2978999722+488)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #42 pc 0000000000259c38  /system/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+216)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #43 pc 000000000027a424  /system/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+940)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #44 pc 0000000000527e80  /system/lib64/libart.so (MterpInvokeInterface+1392)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #45 pc 000000000054a794  /system/lib64/libart.so (ExecuteMterpImpl+14740)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #46 pc 00000000000ca97a  /system/framework/boot.vdex (java.lang.Thread.run+12)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #47 pc 0000000000254144  /system/lib64/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEb.llvm.2978999722+488)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #48 pc 0000000000517798  /system/lib64/libart.so (artQuickToInterpreterBridge+1020)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #49 pc 00000000005610fc  /system/lib64/libart.so (art_quick_to_interpreter_bridge+92)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #50 pc 0000000000557f88  /system/lib64/libart.so (art_quick_invoke_stub+584)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #51 pc 00000000000cfcc8  /system/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+200)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #52 pc 000000000045e444  /system/lib64/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+104)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #53 pc 000000000045f500  /system/lib64/libart.so (art::InvokeVirtualOrInterfaceWithJValues(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, jvalue*)+424)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #54 pc 000000000048a920  /system/lib64/libart.so (art::Thread::CreateCallback(void*)+1120)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #55 pc 00000000000919c0  /system/lib64/libc.so (__pthread_start(void*)+36)
06-29 13:10:15.271  4867  4867 F DEBUG   :     #56 pc 0000000000023fb0  /system/lib64/libc.so (__start_thread+68)

解決:
這個問題一般是某個對象的指針 Double Free 所致,檢查下某個指針所指向的內存是否被重複釋放了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章