Skip to content

Commit

Permalink
Fix for the Android x86-64 megazord with Android NDK-25
Browse files Browse the repository at this point in the history
The new NDK doesn't link to `libgcc` anymore, which breaks our our NSS
and SQLCipher libraries since they depended on the symbols from
libclang_rt.builtins-x86_64-android` like `__extenddftf2`. See mozilla#5436 for
more details.

The change works around this by manually linking to the
libclang_rt.builtins-x86_64-android library in this case.

Added a doc on how to upgrade the Android NDK which hopefully will help
us in the future.  Extracted some common code from the the
`build-*-android.sh` scripts to make these directions simpler.
  • Loading branch information
bendk committed Mar 27, 2023
1 parent 43a7072 commit dc567d4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 22 deletions.
9 changes: 9 additions & 0 deletions components/support/rc_crypto/nss/nss_build_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ fn link_nss_libs(kind: LinkingKind) {
} else {
println!("cargo:rustc-link-lib=c++");
}
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
if target_arch == "x86_64" && target_os == "android" {
let android_home = env::var("ANDROID_HOME").expect("ANDROID_HOME not set");
const ANDROID_NDK_VERSION: &str = "25.2.9519653";
const LINUX_X86_64_LIB_DIR: &str =
"/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.7/lib/linux/";
println!("cargo:rustc-link-search={android_home}/ndk/{ANDROID_NDK_VERSION}/{LINUX_X86_64_LIB_DIR}");
println!("cargo:rustc-link-lib=static=clang_rt.builtins-x86_64-android");
}
}

fn get_nss_libs(kind: LinkingKind) -> Vec<&'static str> {
Expand Down
14 changes: 14 additions & 0 deletions docs/howtos/upgrades/android-ndk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Here's how to upgrade the Android NDK version:

* Update the version number in:
* `build.gradle` (search for `ndkVersion`)
* `taskcluster/docker/linux/Dockerfile` (search for `ANDROID_NDK_VERSION`)
* `components/support/rc_crypto/nss/nss_build_common/src/lib.rs` (search for `ANDROID_NDK_VERSION`)
* Update these docs by replacing the old version with the new one:
* docs/building.md
* docs/howtos/locally-building-jna.md
* These may need updating if the directory structure changed between this version and the last
* `libs/build-android-common.sh`: ensure the paths to the various binaries are correct.
* `components/support/rc_crypto/nss/nss_build_common/src/lib.rs`: search for
`LINUX_X86_64_LIB_DIR` and ensure this correctly points to the correct lib directory containing
`libclang_rt.builtins-x86_64-android.a`.
17 changes: 17 additions & 0 deletions libs/build-android-common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
# This script is sourced by the `build-*-android.sh` scripts. The shbang above
# is to make shellcheck happy.

export AR="${TOOLCHAIN_PATH}/bin/llvm-ar"
export CC="${TOOLCHAIN_PATH}/bin/${TOOLCHAIN}${ANDROID_NDK_API_VERSION}-clang"
export CXX="${TOOLCHAIN_PATH}/bin/${TOOLCHAIN}${ANDROID_NDK_API_VERSION}-clang++"
# For 32-bit ARM, the compiler is prefixed with armv7a-linux-androideabi
if [[ "${TOOLCHAIN}" == "arm-linux-androideabi" ]]; then
export CC="${TOOLCHAIN_PATH}/bin/armv7a-linux-androideabi${ANDROID_NDK_API_VERSION}-clang"
export CXX="${TOOLCHAIN_PATH}/bin/armv7a-linux-androideabi${ANDROID_NDK_API_VERSION}-clang++"
fi
export LD="${TOOLCHAIN_PATH}/bin/ld"
export NM="${TOOLCHAIN_PATH}/bin/llvm-nm"
export RANLIB="${TOOLCHAIN_PATH}/bin/llvm-ranlib"
export READELF="${TOOLCHAIN_PATH}/bin/llvm-readelf"

14 changes: 2 additions & 12 deletions libs/build-nss-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,8 @@ else
fi
NSPR_64="${NSPR_64:-""}"

export AR="${TOOLCHAIN_PATH}/bin/llvm-ar"
export CC="${TOOLCHAIN_PATH}/bin/${TOOLCHAIN}${ANDROID_NDK_API_VERSION}-clang"
export CXX="${TOOLCHAIN_PATH}/bin/${TOOLCHAIN}${ANDROID_NDK_API_VERSION}-clang++"
# For 32-bit ARM, the compiler is prefixed with armv7a-linux-androideabi
if [[ "${TOOLCHAIN}" == "arm-linux-androideabi" ]]; then
export CC="${TOOLCHAIN_PATH}/bin/armv7a-linux-androideabi${ANDROID_NDK_API_VERSION}-clang"
export CXX="${TOOLCHAIN_PATH}/bin/armv7a-linux-androideabi${ANDROID_NDK_API_VERSION}-clang++"
fi
export LD="${TOOLCHAIN_PATH}/bin/ld"
export NM="${TOOLCHAIN_PATH}/bin/llvm-nm"
export RANLIB="${TOOLCHAIN_PATH}/bin/llvm-ranlib"
export READELF="${TOOLCHAIN_PATH}/bin/llvm-readelf"
# shellcheck source=libs/build-android-common.sh
source ./build-android-common.sh

# Build NSPR
NSPR_BUILD_DIR=$(mktemp -d)
Expand Down
12 changes: 2 additions & 10 deletions libs/build-sqlcipher-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,8 @@ if [[ -d "${DIST_DIR}" ]]; then
exit 0
fi

export AR="${TOOLCHAIN_PATH}/bin/llvm-ar"
export CC="${TOOLCHAIN_PATH}/bin/${TOOLCHAIN}${ANDROID_NDK_API_VERSION}-clang"
export CXX="${TOOLCHAIN_PATH}/bin/${TOOLCHAIN}${ANDROID_NDK_API_VERSION}-clang++"
# For 32-bit ARM, the compiler is prefixed with armv7a-linux-androideabi
if [[ "${TOOLCHAIN}" == "arm-linux-androideabi" ]]; then
export CC="${TOOLCHAIN_PATH}/bin/armv7a-linux-androideabi${ANDROID_NDK_API_VERSION}-clang"
export CXX="${TOOLCHAIN_PATH}/bin/armv7a-linux-androideabi${ANDROID_NDK_API_VERSION}-clang++"
fi
export LD="${TOOLCHAIN_PATH}/bin/ld"
export RANLIB="${TOOLCHAIN_PATH}/bin/llvm-ranlib"
# shellcheck source=libs/build-android-common.sh
source ./build-android-common.sh

if [[ "${TOOLCHAIN}" == "x86_64-linux-android" ]]
then
Expand Down

0 comments on commit dc567d4

Please sign in to comment.