Skip to content

Commit

Permalink
Link necessary libraries when building runtime for Android (#5496)
Browse files Browse the repository at this point in the history
- Link libgcc to enable use of thread-local storage (ThreadLocalStore
  requires emutls).
- Link liblog when building with Hexagon support.
  • Loading branch information
Krzysztof Parzyszek authored May 1, 2020
1 parent 9c1e74c commit 360027d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
26 changes: 25 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,35 @@ else(MSVC)
if(BUILD_FOR_HEXAGON)
message(STATUS "Building for Hexagon")
endif()

# Detect if we're compiling for Android.
set(TEST_FOR_ANDROID_CXX
"#ifndef __ANDROID__"
"#error"
"#endif"
"int main() {}")
set(TEST_FOR_ANDROID_DIR
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp")
set(TEST_FOR_ANDROID_FILE "${TEST_FOR_ANDROID_DIR}/test_for_android.cc")
string(REPLACE ";" "\n" TEST_FOR_ANDROID_CXX_TEXT "${TEST_FOR_ANDROID_CXX}")
file(WRITE "${TEST_FOR_ANDROID_FILE}" "${TEST_FOR_ANDROID_CXX_TEXT}")
try_compile(BUILD_FOR_ANDROID "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}"
"${TEST_FOR_ANDROID_FILE}")
file(REMOVE "${TEST_FOR_ANDROID_FILE}")
if(BUILD_FOR_ANDROID)
message(STATUS "Building for Android")
endif()
endif(MSVC)

# Hexagon has dlopen built into QuRT (no need for static library).
if(NOT BUILD_FOR_HEXAGON)
string(APPEND TVM_RUNTIME_LINKER_LIBS ${CMAKE_DL_LIBS})
list(APPEND TVM_RUNTIME_LINKER_LIBS ${CMAKE_DL_LIBS})
endif()

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()

# add source group
Expand Down
6 changes: 5 additions & 1 deletion cmake/modules/Hexagon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ elseif(USE_HEXAGON_DEVICE STREQUAL "${PICK_HW}")
include_directories(
"${HEXAGON_SDK_ROOT}/libs/common/remote/ship/android_Release_aarch64")
include_directories("${HEXAGON_TOOLCHAIN}/include/iss")
list(APPEND TVM_RUNTIME_LINKER_LIBS "-ldl")
list(APPEND TVM_RUNTIME_LINKER_LIBS "dl")
if(BUILD_FOR_ANDROID)
# Hexagon runtime uses __android_log_print, which is in liblog.
list(APPEND TVM_RUNTIME_LINKER_LIBS "log")
endif()
endif()

file(GLOB RUNTIME_HEXAGON_SRCS src/runtime/hexagon/*.cc)
Expand Down

0 comments on commit 360027d

Please sign in to comment.