microsoft / microsoft/onnxruntime
[Build] Mlas linking failed on Android x86
@yihonglyu is already working on this.
Since Sep 10, 2022.
- Dominant language
- C++
- Stars
- 21.9k
- Forks
- 4.2k
- Avg merge
- 4d 8h
- Merged PRs (30d)
- 179
Description
Describe the issue
Dear Sir
when I build onnxruntime for Android x86 via CMake it builds fine, but when I link it to my project (compiled with the same toolchain) I get this error
ld: error: relocation R_386_PC32 cannot be used against symbol '__x86.get_pc_thunk.bx'; recompile with -fPIC
>>> defined in libonnxruntime_mlas.a(x86.get_pc_thunk.S.o)
>>> referenced by SgemmKernelAvx.S.o:(.text+0x31F) in archive libonnxruntime_mlas.
My toolchain:
set(ANDROID_NDK_VERSION "r25b")
set(CMAKE_SYSTEM_VERSION "21")
set(ANDROID_ABI "x86")
set(CMAKE_ANDROID_ARCH_ABI ${ANDROID_ABI})
set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION "clang")
set(ANDROID_STL "c++_static") # LLVM libc++ static
set(CMAKE_ANDROID_STL_TYPE ${ANDROID_STL})
include("${CMAKE_CURRENT_LIST_DIR}/utilities/polly_common.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/flags/cxx17.cmake") # before toolchain!
include("${CMAKE_CURRENT_LIST_DIR}/flags/fpic.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/flags/hidden.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/flags/lto.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/os/android.cmake")
fpic.cmake file:
string(COMPARE EQUAL "${ANDROID_NDK_VERSION}" "" _not_android)
if(_not_android)
polly_add_cache_flag(CMAKE_CXX_FLAGS "-fPIC")
polly_add_cache_flag(CMAKE_C_FLAGS "-fPIC")
else()
polly_add_cache_flag(CMAKE_CXX_FLAGS_INIT "-fPIC")
polly_add_cache_flag(CMAKE_C_FLAGS_INIT "-fPIC")
endif()
set(
CMAKE_POSITION_INDEPENDENT_CODE
TRUE
CACHE
BOOL
"Position independent code"
FORCE
)
In onnxruntime_mlas CMake file I found this:
# In r23, NDK remove __x86.get_pc_thunk.* from libatomic. Add our own
# implementation to avoid external dependency.
if(ANDROID)
set(mlas_platform_srcs
${mlas_platform_srcs}
${MLAS_SRC_DIR}/x86/x86.get_pc_thunk.S
)
endif()
I'm using Android NDK r25b on Ubuntu 22.04 x86_64 host. For other OS and 64-bit Android it works fine.
EDIT: with NDK r22 it builds and links fine, so the problem appeared in newer versions of NDK.
Urgency
This error blocks my futher development so I want it to be resolved as soon as possible.
Target platform
Android x86
Build script
cmake -DCMAKE_TOOLCHAIN_FILE=<toolchain> -DCMAKE_BUILD_TYPE=RELEASE -G"Unix Makefiles" -Bbuild -S./
Error / output
ld: error: relocation R_386_PC32 cannot be used against symbol '__x86.get_pc_thunk.bx'; recompile with -fPIC
>>> defined in libonnxruntime_mlas.a(x86.get_pc_thunk.S.o)
>>> referenced by SgemmKernelAvx.S.o:(.text+0x31F) in archive libonnxruntime_mlas.
Visual Studio Version
No response
GCC / Compiler Version
clang-14.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.