Skip to content

Commit

Permalink
Hack to make x86-64 work with Android NDK-25
Browse files Browse the repository at this point in the history
The new NDK doesn't link to `libgcc`, 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 hack works around this by taking object files from the built
libraries and `libclang_rt.builtins-x86_64-android.a`, and combining
them together to get the final static library.
  • Loading branch information
bendk committed Mar 24, 2023
1 parent 22a3e33 commit 82a533e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions libs/build-all-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,23 @@ for i in "${!TARGET_ARCHS[@]}"; do
./build-sqlcipher-android.sh "${SQLCIPHER_SRC_PATH}" "${DIST_DIR}" "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${NDK_HOST_TAG}" "${TARGET_ARCHS_TOOLCHAINS[${i}]}" "${ANDROID_NDK_API_VERSION}" "${NSS_DIR}" || exit 1
fi
done

echo "# Adding missing X86-64 compiler builtins"
add_missing_x86_64_symbols() {
LIBRARY=$1
shift
# after shift, the extra libraries are in $@
AR="${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${NDK_HOST_TAG}/bin/llvm-ar"
WORKDIR=$(mktemp -d)
pushd $WORKDIR
# Extract all object files from the library
$AR x $LIBRARY
# Extract the object files we need from libclang_rt.builtins-x86_64-android.a
$AR x "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${NDK_HOST_TAG}/lib64/clang/14.0.7/lib/linux/libclang_rt.builtins-x86_64-android.a" "$@"
# Create a new static lib with each extracted object file and use it
$AR cr fixed-lib.a *.o
mv fixed-lib.a $LIBRARY
popd
}
add_missing_x86_64_symbols $(abspath "android/x86_64/nss/lib/libnspr4.a") extenddftf2.c.o
add_missing_x86_64_symbols $(abspath "android/x86_64/sqlcipher/lib/libsqlcipher.a") extenddftf2.c.o trunctfdf2.c.o multf3.c.o addtf3.c.o divtf3.c.o fixtfsi.c.o fp_mode.c.o floatditf.c.o floatsitf.c.o subtf3.c.o comparetf2.c.o

0 comments on commit 82a533e

Please sign in to comment.