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

std::bad_cast errors from oboe-sys #64

Open
EDLLT opened this issue Sep 19, 2024 · 0 comments
Open

std::bad_cast errors from oboe-sys #64

EDLLT opened this issue Sep 19, 2024 · 0 comments

Comments

@EDLLT
Copy link

EDLLT commented Sep 19, 2024

Android Version: Android 13
NDK Version: r27

It took me a long time to narrow down the source of the issue
When compiling the project rnote, which relies on rodio which in turn uses oboe-sys, it gives me symbol issues

  = note: ld.lld: error: undefined symbol: operator delete(void*)
          >>> referenced by SourceFloatCaller.h:31 (oboe/src/common/SourceFloatCaller.h:31)
          >>>               083f6a9c839ae21c-SourceFloatCaller.o:(oboe::SourceFloatCaller::~SourceFloatCaller()) in archive /home/builder/.termux-build/rnote-nuke/src/target/x86_64-linux-android/debug/deps/liboboe_sys-57071089cfae7174.rlib
          >>> referenced by locale.cpp
          >>>               locale.cpp.o:(std::__ndk1::collate<char>::~collate()) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by ios.instantiations.cpp
          >>>               ios.instantiations.cpp.o:(std::__ndk1::basic_ios<char, std::__ndk1::char_traits<char>>::~basic_ios()) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced 393 more times
          
          ld.lld: error: undefined symbol: operator new(unsigned long)
          >>> referenced by locale.cpp
          >>>               locale.cpp.o:(std::__ndk1::collate<char>::do_transform(char const*, char const*) const) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by ios.cpp
          >>>               ios.cpp.o:(std::__ndk1::__iostream_category::message(int) const) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by locale.cpp
          >>>               locale.cpp.o:(std::__ndk1::collate<wchar_t>::do_transform(wchar_t const*, wchar_t const*) const) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced 87 more times
          
          ld.lld: error: undefined symbol: __cxa_allocate_exception
          >>> referenced by new_helpers.cpp
          >>>               new_helpers.cpp.o:(std::__throw_bad_alloc()) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by ios.cpp
          >>>               ios.cpp.o:(std::__ndk1::__throw_failure[abi:ne180000](char const*)) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by hash.cpp
          >>>               hash.cpp.o:(std::__ndk1::__throw_overflow_error[abi:ne180000](char const*)) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced 8 more times
          
          ld.lld: error: undefined symbol: std::bad_alloc::bad_alloc()
          >>> referenced by new_helpers.cpp
          >>>               new_helpers.cpp.o:(std::__throw_bad_alloc()) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          
          ld.lld: error: undefined symbol: typeinfo for std::bad_alloc
          >>> referenced by new_helpers.cpp
          >>>               new_helpers.cpp.o:(std::__throw_bad_alloc()) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          
          ld.lld: error: undefined symbol: std::bad_alloc::~bad_alloc()
          >>> referenced by new_helpers.cpp
          >>>               new_helpers.cpp.o:(std::__throw_bad_alloc()) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          
          ld.lld: error: undefined symbol: __cxa_throw
          >>> referenced by new_helpers.cpp
          >>>               new_helpers.cpp.o:(std::__throw_bad_alloc()) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by ios.cpp
          >>>               ios.cpp.o:(std::__ndk1::__throw_failure[abi:ne180000](char const*)) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by hash.cpp
          >>>               hash.cpp.o:(std::__ndk1::__throw_overflow_error[abi:ne180000](char const*)) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced 8 more times
          
          ld.lld: error: undefined symbol: std::terminate()
          >>> referenced by thread.cpp
          >>>               thread.cpp.o:(std::__ndk1::thread::~thread()) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by call_once.cpp
          >>>               call_once.cpp.o:(__clang_call_terminate) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by exception.cpp
          >>>               exception.cpp.o:(std::rethrow_exception(std::exception_ptr)) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          
          ld.lld: error: undefined symbol: __cxa_guard_acquire
          >>> referenced by thread.cpp
          >>>               thread.cpp.o:(std::__ndk1::__thread_local_data()) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by ios.cpp
          >>>               ios.cpp.o:(std::__ndk1::__throw_failure[abi:ne180000](char const*)) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by system_error.cpp
          >>>               system_error.cpp.o:(std::__ndk1::__system_error_category::default_error_condition(int) const) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced 86 more times
          
          ld.lld: error: undefined symbol: vtable for __cxxabiv1::__class_type_info
          >>> referenced by error_category.cpp
          >>>               error_category.cpp.o:(typeinfo for std::__ndk1::error_category) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by memory.cpp
          >>>               memory.cpp.o:(typeinfo for std::__ndk1::__shared_count) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by ios.cpp
          >>>               ios.cpp.o:(typeinfo for std::__ndk1::ios_base) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced 15 more times
          >>> the vtable symbol may be undefined because the class is missing its key function (see https://lld.llvm.org/missingkeyfunction)
          
          ld.lld: error: undefined symbol: __cxa_guard_release
          >>> referenced by thread.cpp
          >>>               thread.cpp.o:(std::__ndk1::__thread_local_data()) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by ios.cpp
          >>>               ios.cpp.o:(std::__ndk1::__throw_failure[abi:ne180000](char const*)) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by system_error.cpp
          >>>               system_error.cpp.o:(std::__ndk1::__system_error_category::default_error_condition(int) const) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced 85 more times
          
          ld.lld: error: undefined symbol: __cxa_guard_abort
          >>> referenced by thread.cpp
          >>>               thread.cpp.o:(std::__ndk1::__thread_local_data()) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by locale.cpp
          >>>               locale.cpp.o:(std::__ndk1::num_get<char, std::__ndk1::istreambuf_iterator<char, std::__ndk1::char_traits<char>>>::do_get(std::__ndk1::istreambuf_iterator<char, std::__ndk1::char_traits<char>>, std::__ndk1::istreambuf_iterator<char, std::__ndk1::char_traits<char>>, std::__ndk1::ios_base&, unsigned int&, void*&) const) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by locale.cpp
          >>>               locale.cpp.o:(std::__ndk1::num_get<wchar_t, std::__ndk1::istreambuf_iterator<wchar_t, std::__ndk1::char_traits<wchar_t>>>::do_get(std::__ndk1::istreambuf_iterator<wchar_t, std::__ndk1::char_traits<wchar_t>>, std::__ndk1::istreambuf_iterator<wchar_t, std::__ndk1::char_traits<wchar_t>>, std::__ndk1::ios_base&, unsigned int&, void*&) const) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced 48 more times
          
          ld.lld: error: undefined symbol: __cxa_begin_catch
          >>> referenced by ios.instantiations.cpp
          >>>               ios.instantiations.cpp.o:(std::__ndk1::basic_ostream<char, std::__ndk1::char_traits<char>>::flush()) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by call_once.cpp
          >>>               call_once.cpp.o:(__clang_call_terminate) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by ios.instantiations.cpp
          >>>               ios.instantiations.cpp.o:(std::__ndk1::basic_ostream<char, std::__ndk1::char_traits<char>>::sentry::~sentry()) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced 4 more times
          
          ld.lld: error: undefined symbol: __cxa_end_catch
          >>> referenced by ios.instantiations.cpp
          >>>               ios.instantiations.cpp.o:(std::__ndk1::basic_ostream<char, std::__ndk1::char_traits<char>>::flush()) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by ios.instantiations.cpp
          >>>               ios.instantiations.cpp.o:(std::__ndk1::basic_ostream<char, std::__ndk1::char_traits<char>>::flush()) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by ios.instantiations.cpp
          >>>               ios.instantiations.cpp.o:(std::__ndk1::basic_ostream<char, std::__ndk1::char_traits<char>>::sentry::~sentry()) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced 6 more times
          
          ld.lld: error: undefined symbol: vtable for std::logic_error
          >>> referenced by stdexcept.cpp
          >>>               stdexcept.cpp.o:(std::logic_error::logic_error(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&)) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by stdexcept.cpp
          >>>               stdexcept.cpp.o:(std::logic_error::logic_error(char const*)) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> the vtable symbol may be undefined because the class is missing its key function (see https://lld.llvm.org/missingkeyfunction)
          
          ld.lld: error: undefined symbol: vtable for __cxxabiv1::__vmi_class_type_info
          >>> referenced by memory.cpp
          >>>               memory.cpp.o:(typeinfo for std::__ndk1::__shared_weak_count) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by ios.instantiations.cpp
          >>>               ios.instantiations.cpp.o:(typeinfo for std::__ndk1::basic_istream<char, std::__ndk1::char_traits<char>>) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by ios.instantiations.cpp
          >>>               ios.instantiations.cpp.o:(typeinfo for std::__ndk1::basic_ostream<char, std::__ndk1::char_traits<char>>) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced 31 more times
          >>> the vtable symbol may be undefined because the class is missing its key function (see https://lld.llvm.org/missingkeyfunction)
          
          ld.lld: error: undefined symbol: std::exception::~exception()
          >>> referenced by stdexcept.cpp
          >>>               stdexcept.cpp.o:(std::logic_error::logic_error(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&)) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by stdexcept.cpp
          >>>               stdexcept.cpp.o:(std::logic_error::logic_error(char const*)) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by stdexcept.cpp
          >>>               stdexcept.cpp.o:(std::runtime_error::runtime_error(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&)) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced 1 more times
          
          ld.lld: error: undefined symbol: __cxa_uncaught_exceptions
          >>> referenced by exception.cpp
          >>>               exception.cpp.o:(std::uncaught_exception()) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          
          ld.lld: error: undefined symbol: __cxa_decrement_exception_refcount
          >>> referenced by exception.cpp
          >>>               exception.cpp.o:(std::exception_ptr::~exception_ptr()) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          
          ld.lld: error: undefined symbol: __cxa_free_exception
          >>> referenced by ios.cpp
          >>>               ios.cpp.o:(std::__ndk1::__throw_failure[abi:ne180000](char const*)) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by hash.cpp
          >>>               hash.cpp.o:(std::__ndk1::__throw_overflow_error[abi:ne180000](char const*)) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced by stdexcept.cpp
          >>>               stdexcept.cpp.o:(std::__ndk1::__throw_runtime_error(char const*)) in archive /home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/../sysroot/usr/lib/x86_64-linux-android/libc++_static.a
          >>> referenced 5 more times
          
          ld.lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

I managed to resolve these symbol issues by compiling with
export RUSTFLAGS='-C link-args=-lc++abi -C link-arg=-L/data/data/com.termux/files/usr/lib -C link-args=-liconv'

But when I ran my application, it kept on giving me an std badcast error

~/.../target/release $ ./rnote
libc++abi: terminating due to uncaught exception of type std::bad_cast: std::bad_cast

Then I learned about the existence of gdb and used it to find the source of the issue

rust-gdb ./rnote

(gdb) catch throw
(gdb) run
Starting program: /data/data/com.termux/files/home/rnote/rnote_unoptimized_debug 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/data/data/com.termux/files/usr/lib/libthread_db.so".

Catchpoint 1.1 (exception thrown), 0x0000555558646800 in __cxa_throw ()
(gdb) bt full
#0  0x0000555558646800 in __cxa_throw ()
No symbol table info available.
#1  0x00005555586099bc in std::__ndk1::__throw_bad_cast[abi:ne180000]() ()
No symbol table info available.
#2  0x0000555558623553 in std::__ndk1::locale::use_facet(std::__ndk1::locale::id&) const () <-- THIS specifically
No symbol table info available.
#3  0x00007ffff6ba42b6 in ?? () from /data/data/com.termux/files/usr/lib/libc++_shared.so

Then I narrowed down which crate was responsible through looking for symbols in all my objects
find . -name "*.o" -print0 | xargs -0 nm -A | grep -i locale

./target/x86_64-linux-android/debug/build/oboe-sys-f9d3f4424b593fc5/out/library/083f6a9c839ae21c-Utilities.o:                 U _ZNKSt6__ndk16locale9use_facetERNS0_2idE <-- use facet

./target/x86_64-linux-android/debug/build/oboe-sys-f9d3f4424b593fc5/out/library/083f6a9c839ae21c-Utilities.o:0000000000000000 W _ZNSt6__ndk19use_facetB8nn180000INS_5ctypeIcEEEERKT_RKNS_6localeE <-- use facet

Dependency tree from rodio(for sound)

cargo tree

rodio v0.19.0
|   |   |-- cpal v0.15.3
|   |   |   |-- dasp_sample v0.11.0
|   |   |   |-- jni v0.21.1
|   |   |   |   |-- cesu8 v1.1.0
|   |   |   |   |-- cfg-if v1.0.0
|   |   |   |   |-- combine v4.6.7
|   |   |   |   |   |-- bytes v1.6.1
|   |   |   |   |   `-- memchr v2.7.4
|   |   |   |   |-- jni-sys v0.3.0
|   |   |   |   |-- log v0.4.22
|   |   |   |   `-- thiserror v1.0.63 (*)
|   |   |   |   [build-dependencies]
|   |   |   |   `-- walkdir v2.5.0 (*)
|   |   |   |-- ndk v0.8.0
|   |   |   |   |-- bitflags v2.6.0 (*)
|   |   |   |   |-- jni-sys v0.3.0
|   |   |   |   |-- log v0.4.22
|   |   |   |   |-- ndk-sys v0.5.0+25.2.9519653
|   |   |   |   |   `-- jni-sys v0.3.0
|   |   |   |   |-- num_enum v0.7.2
|   |   |   |   |   `-- num_enum_derive v0.7.2 (proc-macro)
|   |   |   |   |       |-- proc-macro-crate v3.1.0 (*)
|   |   |   |   |       |-- proc-macro2 v1.0.86 (*)
|   |   |   |   |       |-- quote v1.0.36 (*)
|   |   |   |   |       `-- syn v2.0.72 (*)
|   |   |   |   `-- thiserror v1.0.63 (*)
|   |   |   |-- ndk-context v0.1.1
|   |   |   `-- oboe v0.6.1
|   |   |       |-- jni v0.21.1 (*)
|   |   |       |-- ndk v0.8.0 (*)
|   |   |       |-- ndk-context v0.1.1
|   |   |       |-- num-derive v0.4.2 (proc-macro) (*)
|   |   |       |-- num-traits v0.2.19 (*)
|   |   |       `-- oboe-sys v0.6.1
|   |   |           [build-dependencies]
|   |   |           `-- cc v1.1.6
|   |   |               |-- jobserver v0.1.32
|   |   |               |   `-- libc v0.2.155
|   |   |               `-- libc v0.2.155

oboe sys is for some reason attempting to call use facet which is failing.
For now, I will abandon using rodio altogether but this was a real headache to figure out ngl. Hopefully this helps out someone who faces a similar issue in the future

Also, may I ask what the issue actually is and how to fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant