Skip to content

[Android] Robust fix for missing C++ ABI symbols (__gxx_personality_v0) during static linking #480

@lparam

Description

@lparam

Problem

When building for Android targets using the NDK toolchain, i encountered persistent linker errors (e.g., undefined reference to '__gxx_personality_v0') when attempting to produce fully static binaries.

The root cause is that the NDK's sysroot prioritizes .so stubs over the required static libraries (libc++_static.a, libc++abi.a, libunwind.a). Additionally, the path to libunwind.a is deeply nested within a versioned Clang resource directory, making it difficult to locate
across different NDK versions.

Proposed Solution

I have implemented a robust fix in build.rs that automates the static linking process for Android:

  • Dynamic Detection: Automatically detects the Host OS and the NDK's internal Clang version.
  • Architecture Mapping: Correctly maps Rust target triples to NDK architectures (e.g., mapping armv7 to arm and i686 to i386).
  • Shadow Directory: Creates a temporary directory in OUT_DIR to isolate the correct .a files, ensuring they take precedence during linking.
  • Comprehensive Coverage: Supports all major Android architectures: aarch64, armv7, i686, and x86_64.

Impact

This enables boring to produce fully static, portable Android binaries out-of-the-box, without external dependencies on libc++_shared.so.

I have already verified this implementation across all architectures and confirmed it passes CI on multiple host OSes. Let me know if you would like me to submit a PR.

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