-
Notifications
You must be signed in to change notification settings - Fork 13k
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
C/C++ code linked to Rust code can't use some clang builtins #109717
Comments
The first step in investigating this issue would be to find out why rustc currently passes -nodefaultlibs. It sounds like if we removed that flag, it would fix this bug? |
See 28fa81a. |
Has anyone else had a chance to look at this issue more? With Rust's standard library only targeting NDK 25 in recent versions, I think that this issue has become more problematic for projects using the same NDK. AFAICT, the symbol has to exist somewhere in clang's |
Adds a temporary workaround for [an issue] with the Rust compiler and Android when compiling for x86_64 devices. The Android NDK used to include `libgcc` for unwind support (which is required by Rust among others). From NDK r23, `libgcc` is removed, replaced by LLVM's `libunwind`. However, `libgcc` was ambiently providing other compiler builtins, one of which we require: `__extenddftf2` for software floating-point emulation. This is used by SQLite (via the `rusqlite` crate), which defines a `LONGDOUBLE_TYPE` type as `long double`. Rust uses a `compiler-builtins` crate that does not provide `__extenddftf2` because [it involves floating-point types that are not supported by Rust][unsupported]. For some reason, they _do_ export this symbol for `aarch64-linux-android`, but they do not for `x86_64-linux-android`. Thus we run into a problem when trying to compile and run the SDK on an x86_64 emulator. The workaround comes from [this Mozilla PR]: we tell Cargo to statically link the builtins from the Clang runtime provided inside the NDK, to provide this symbol. [an issue]: rust-lang/rust#109717 [this Mozilla PR]:mozilla/application-services#5442 [unsupported]: https://github.com/rust-lang/compiler-builtins#unimplemented-functions This fix was copied from: https://github.com/nerdcash/Nerdbank.Cryptocurrencies/pull/262/files#diff-7cc5f1ef7cbfce3114fe631861f19de2c050c13ff71e987100669131bb9ffa25 Fixes rusqlite#1380
Adds a temporary workaround for [an issue] with the Rust compiler and Android when compiling for x86_64 devices. The Android NDK used to include `libgcc` for unwind support (which is required by Rust among others). From NDK r23, `libgcc` is removed, replaced by LLVM's `libunwind`. However, `libgcc` was ambiently providing other compiler builtins, one of which we require: `__extenddftf2` for software floating-point emulation. This is used by SQLite (via the `rusqlite` crate), which defines a `LONGDOUBLE_TYPE` type as `long double`. Rust uses a `compiler-builtins` crate that does not provide `__extenddftf2` because [it involves floating-point types that are not supported by Rust][unsupported]. For some reason, they _do_ export this symbol for `aarch64-linux-android`, but they do not for `x86_64-linux-android`. Thus we run into a problem when trying to compile and run the SDK on an x86_64 emulator. The workaround comes from [this Mozilla PR]: we tell Cargo to statically link the builtins from the Clang runtime provided inside the NDK, to provide this symbol. [an issue]: rust-lang/rust#109717 [this Mozilla PR]:mozilla/application-services#5442 [unsupported]: https://github.com/rust-lang/compiler-builtins#unimplemented-functions This fix was copied from: Electric-Coin-Company/zcash-android-wallet-sdk@1bf2f84 Fixes rusqlite#1380 Co-authored-by: Jack Grigg <jack@electriccoin.co>
Update the workaround for rust-lang/rust#109717 to avoid hardcoding the clang version; instead, run `clang -dumpversion` to figure it out. While we're there, use the `CC_x86_64-linux-android` env var, which should point to clang, rather than relying on `ANDROID_NDK_HOME` to be set.
Update the workaround for rust-lang/rust#109717 to avoid hardcoding the clang version; instead, run `clang -dumpversion` to figure it out. While we're there, use the `CC_x86_64-linux-android` env var, which should point to clang, rather than relying on `ANDROID_NDK_HOME` to be set.
Update the workaround for rust-lang/rust#109717 to avoid hardcoding the clang version; instead, run `clang -dumpversion` to figure it out. While we're there, use the `CC_x86_64-linux-android` env var, which should point to clang, rather than relying on `ANDROID_NDK_HOME` to be set.
Update the workaround for rust-lang/rust#109717 to avoid hardcoding the clang version; instead, run `clang -dumpversion` to figure it out. While we're there, use the `CC_x86_64-linux-android` env var, which should point to clang, rather than relying on `ANDROID_NDK_HOME` to be set.
This is theoretically a problem that applies to all platforms, but in practice, at least on Linux, the rust compiler is saved by the forced linkage of libgcc_s (which, incidentally, is not really desirable when using clang's
--rtlib
argument, but that's another story). It is a problem on x86_64 Android.Here are steps to reproduce the problem:
Download and unpack Android NDK r25c:
Create a test crate:
Compile the crate (with some manual work that presumable cargo-apk would do):
This fails to link with, eventually:
The
__extenddftft2
symbol comes from the compilation of the functionfoo
, for the extension of the 64-bits double to a 128-bits double. It is part of libclang_rt that comes with clang. But because rustc calls the linker (clang) with-nodefaultlibs
, the clang runtime is not compiled in. And because the equivalent compiler-builtins from rustc doesn't contain all the clang builtins, this fails to link.When linking dynamic libraries, the link actually goes through without an error, but yields an error when the library is loaded at runtime because of the missing
__extenddftft2
symbol. You'll find multiple people running into this problem over the years, but somehow I didn't find it reported against the rust compiler (example: mozilla/application-services#5436).Because the
__extenddftft2
symbol exists in rustc's compiler-builtins for aarch64 android, it's not a problem on that platform.The text was updated successfully, but these errors were encountered: