From 4c6a985432779fcb209bb610eab3520e3266601a Mon Sep 17 00:00:00 2001 From: adrianlizarraga Date: Sun, 22 Dec 2024 01:59:51 -0800 Subject: [PATCH] Try linking shared.so with qnn.so for android --- cmake/onnxruntime_providers_cpu.cmake | 10 +++++++++- cmake/onnxruntime_providers_qnn.cmake | 18 ++++-------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/cmake/onnxruntime_providers_cpu.cmake b/cmake/onnxruntime_providers_cpu.cmake index 79e430763da93..b4b4e7659d05a 100644 --- a/cmake/onnxruntime_providers_cpu.cmake +++ b/cmake/onnxruntime_providers_cpu.cmake @@ -238,7 +238,15 @@ if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD set_property(TARGET onnxruntime_providers_shared APPEND_STRING PROPERTY LINK_FLAGS "-Xlinker -exported_symbols_list ${ONNXRUNTIME_ROOT}/core/providers/shared/exported_symbols.lst") elseif(UNIX) if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX") - set_property(TARGET onnxruntime_providers_shared APPEND_STRING PROPERTY LINK_FLAGS "-Xlinker --version-script=${ONNXRUNTIME_ROOT}/core/providers/shared/version_script.lds -Xlinker --gc-sections") + target_link_options(onnxruntime_providers_shared PRIVATE + "LINKER:--version-script=${ONNXRUNTIME_ROOT}/core/providers/shared/version_script.lds" + "LINKER:--gc-sections") + if(CMAKE_SYSTEM_NAME STREQUAL "Android") + # Need to link libonnxruntime_providers_.so with libonnxruntime_providers_shared.so on Android + # because dlopen with RTLD_GLOBAL does not bring all symbols to global scope. + # See: https://github.com/android/ndk/issues/201 + set(ONNXRUNTIME_PROVIDERS_SHARED onnxruntime_providers_shared) + endif() endif() elseif(WIN32) set_property(TARGET onnxruntime_providers_shared APPEND_STRING PROPERTY LINK_FLAGS "-DEF:${ONNXRUNTIME_ROOT}/core/providers/shared/symbols.def") diff --git a/cmake/onnxruntime_providers_qnn.cmake b/cmake/onnxruntime_providers_qnn.cmake index 505c357d516d0..4f97c968ebf56 100644 --- a/cmake/onnxruntime_providers_qnn.cmake +++ b/cmake/onnxruntime_providers_qnn.cmake @@ -29,20 +29,10 @@ # Set linker flags for function(s) exported by EP DLL if(UNIX) - if(CMAKE_SYSTEM_NAME STREQUAL "Android") - target_link_options(onnxruntime_providers_qnn PRIVATE - "LINKER:--version-script=${ONNXRUNTIME_ROOT}/core/providers/qnn/version_script.lds" - "LINKER:--gc-sections" - "LINKER:-rpath=\$ORIGIN" - "LINKER:-z,undefs" - ) - else() - target_link_options(onnxruntime_providers_qnn PRIVATE - "LINKER:--version-script=${ONNXRUNTIME_ROOT}/core/providers/qnn/version_script.lds" - "LINKER:--gc-sections" - "LINKER:-rpath=\$ORIGIN" - ) - endif() + target_link_options(onnxruntime_providers_qnn PRIVATE + "LINKER:--version-script=${ONNXRUNTIME_ROOT}/core/providers/qnn/version_script.lds" + "LINKER:--gc-sections" + "LINKER:-rpath=\$ORIGIN") elseif(WIN32) set_property(TARGET onnxruntime_providers_qnn APPEND_STRING PROPERTY LINK_FLAGS "-DEF:${ONNXRUNTIME_ROOT}/core/providers/qnn/symbols.def") else()