Hi,
I'm facing an issue with the NDK r10c and the ARM64 toolchain.
I'm working on a C++ project made of a library and its associated unit tests using Google Tests.
The project build and execution works like a charm with any architecture but not with the ARM 64 one.
I've extracted a little toy project reproducing the issue in an isolated context for convenience. You'll can find it on bitbucket:
The project uses CMake and has Google Test as a submodule.
The project builds a shared library TestNDK10 and a TestNDK10_test executable linking against TestNDK10, gtest and gtest_main.
There is a shell script available (build/android.sh) to build the project for armeabi-v7a and arm64-v8a. The former works and the latter doesn't.
To build in debug using the script, you can set the cpu_architecture environment variable to Debug.
cpu_architecture=Debug ./build/android.sh
Linking CXX executable ../TestNDK10_test
cd path/to/work/src/testbuild_ndk10c-arm/_android_arm64-v8a/test && /Applications/CMake.app/Contents/bin/cmake -E cmake_link_script CMakeFiles/TestNDK10_test.dir/link.txt --verbose=1
path/to/android-ndk-r10c/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-gcc -fexceptions -frtti -Wno-psabi --sysroot=path/to/android-ndk-r10c/platforms/android-21/arch-arm64 -fsigned-char -no-canonical-prefixes -march=armv8-a -fdata-sections -ffunction-sections -Wa,--noexecstack -O3 -DNDEBUG -Wl,--no-undefined -Wl,-allow-shlib-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,-z,nocopyreloc CMakeFiles/TestNDK10_test.dir/MyTest_test.cpp.o -o ../TestNDK10_test -Lpath/to/android-ndk-r10c/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/user/libs/arm64-v8a -rdynamic ../../libs/arm64-v8a/libTestNDK10.so ../../libs/arm64-v8a/libgtest.a ../../libs/arm64-v8a/libgtest_main.a -ldl -llog ../../libs/arm64-v8a/libgtest.a "path/to/android-ndk-r10c/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a/libgnustl_static.a" "path/to/android-ndk-r10c/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a/libsupc++.a" -lm
path/to/android-ndk-r10c/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9/../../../../aarch64-linux-android/bin/ld: ../../libs/arm64-v8a/libgtest.a(gtest-all.cc.o)(.data.rel.ro._ZTIN7testing8internal26ThreadLocalValueHolderBaseE[_ZTIN7testing8internal26ThreadLocalValueHolderBaseE]+0x0): unresolvable R_AARCH64_ABS64 relocation against symbol `_ZTVN10__cxxabiv117__class_type_infoE'
path/to/android-ndk-r10c/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9/../../../../aarch64-linux-android/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
The detailed error:
/libgtest.a(gtest-all.cc.o)(.data.rel.ro._ZTIN7testing8internal26ThreadLocalValueHolderBaseE[_ZTIN7testing8internal26ThreadLocalValueHolderBaseE]+0x0): unresolvable R_AARCH64_ABS64 relocation against symbol `_ZTVN10__cxxabiv117__class_type_infoE'
I didn't think the problem comes from Google Test since on the project where I found this, the relocation error was on my own library binary.
I think the issue comes from the NDK and in particular the ARM64 toolchain since there is no problem with other architectures.
Thanks in advance.