You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/10/01 05:28:20 UTC

[GitHub] [tvm] lhez opened a new issue #9173: [Bug] [CMake] libtvm_runtime and cpp rpc won't build with NDK 23

lhez opened a new issue #9173:
URL: https://github.com/apache/tvm/issues/9173


   NDK 23 seems to make some major changes from previous releases - it removes all gcc related components and `ld.gold`. This causes two issues when building with NDK 23.
   
   First, `libgcc` is added in the root [`CMakeLists.txt`](https://github.com/apache/tvm/blob/main/CMakeLists.txt#L228),
   
   ```
   if(BUILD_FOR_ANDROID)
     # EmuTLS on Android is in libgcc. Without it linked in, libtvm_runtime.so
     # won't load on Android due to missing __emutls_XXX symbols.
     list(APPEND TVM_RUNTIME_LINKER_LIBS "gcc")
   endif()
   ```
   This will result in following linker error because `libgcc` has been removed from NDK 23 (instead `libclang_rt.builtins-aarch64-android.a` is used)
   
   ```
   ld: error: unable to find library -lgcc
   ```
   
   This can be reproduced with the following commands,
   
   ```
   cmake -DCMAKE_TOOLCHAIN_FILE=/ndk/23.0.7599858/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=28 -DANDROID_STL=c++_static -DUSE_CPP_RPC=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -G Ninja ..
   ninja tvm_rpc
   ```
   
   Linker will fail with `libtvm_runtime.so`. This can be fixed by disabling `libgcc` for NDK is 23. I am not sure about the TLS functions - but `tvm_rpc` runs fine with NDK 23 for me when `libgcc` is removed.
   
   Second, when OpenCL is enabled, `tvm_rpc` (the cpp rpc) will use `ld.gold` as the linker. This is specified in `tvm_rpc`'s [`CMakeLists.txt`](https://github.com/apache/tvm/blob/main/apps/cpp_rpc/CMakeLists.txt#L35),
   
   ```
   if(USE_OPENCL)
     if (ANDROID_ABI)
       set_property(TARGET tvm_rpc PROPERTY LINK_FLAGS -fuse-ld=gold)
     endif()
   endif()
   ```
   
   Since `ld.gold` is removed from NDK 23, Clang seems to call host `ld.gold`, resulting in failure
   
   ```
   /usr/bin/ld.gold: --no-rosegment: unknown option
   /usr/bin/ld.gold: use the --help option for usage information
   ```
   
   This can be reproduced by adding OpenCL,
   
   ```
   cmake -DCMAKE_TOOLCHAIN_FILE=/ndk/23.0.7599858/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -D
   ANDROID_PLATFORM=28 -DANDROID_STL=c++_static -DUSE_CPP_RPC=ON -DUSE_OPENCL=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -G Ninja ..
   ninja tvm_rpc
   ```
   
   Similarly, this can be fixed by disabling `ld.gold` for NDK 23.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org