Skip to content

Android build fails to link: undefined symbol std::__ndk1::__libcpp_verbose_abort #8

Open

Description

@xvrh

Hi, I was interested in this package for the webcrypto integration (prebuilt & treeshaked). But we hit some error when trying it. My AI wrote me all this bellow, hope that help :-)

The Android build of libbssl_dart.so fails at the link step.

  • On main (2d2d11d) it fails for every ABI.
  • On 0.4.1 it fails for armeabi-v7a only.

We hit it through google/webcrypto.dart#417: flutter build aar fails, because Flutter builds armeabi-v7a by default.

Steps to reproduce

With the Android NDK (r28.2 locally, r29.0.14206865 on GitHub's ubuntu-latest), from the repository root:

ABI=arm64-v8a   # same with armeabi-v7a, x86_64, riscv64
cmake -S src -B "build/android-$ABI" -G Ninja \
  -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \
  -DANDROID_ABI="$ABI" \
  -DANDROID_PLATFORM=android-24 \
  -DCMAKE_BUILD_TYPE=Release
cmake --build "build/android-$ABI"

Expected

libbssl_dart.so links.

Actual

On main, arm64-v8a, NDK r29:

ld.lld: error: undefined symbol: std::__ndk1::__libcpp_verbose_abort(char const*, ...)
>>> referenced by stdexcept:253 (.../sysroot/usr/include/c++/v1/stdexcept:253)
>>>               .../crypto/x509/by_dir.cc.o:(std::__ndk1::__throw_out_of_range[abi:nn210000](char const*))
clang: error: linker command failed with exit code 1 (use -v to see invocation)

On armeabi-v7a the same symbol is referenced from crypto/cpu_arm_linux.cc. On 0.4.1, this is the only failure.

Cause

The library is linked as C, without the C++ runtime. BoringSSL's C++ code is built with -fno-exceptions, but it still calls into libc++ when a bounds check fails. The NDK linker refuses undefined symbols.

Linux shows the same gap without an error. With GCC 13, main leaves std::__throw_out_of_range_fmt undefined in the .so. The library loads with lazy binding, but LD_BIND_NOW=1 makes it fail to load.

A possible fix

Upstream BoringSSL now expects libcrypto to have the C++ runtime. So we tried linking the runtime rather than avoiding it.

  • The runtime is linked statically, and its symbols stay hidden.
  • An Android job in CI covers four ABIs.

Branch and green CI: xvrh#3

The Android CI job alone, on main, fails on this error: xvrh#1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions