Skip to content

Commit

Permalink
Change libonnxruntime.so's SONAME: remove the minor and patch version. (
Browse files Browse the repository at this point in the history
#21339)

### Description
Resolve #21281 and #10589 .

1. Change libonnxruntime.so's SONAME: remove the minor and patch
version.

By default when creating an ELF shared object, linker will set the
file's internal DT_SONAME field to the specified name which is the file
name plus SOVERSION . For example, the file name for our library is
libonnxruntime.so. And by default SOVERSION is the lib's VERSION number,
which is something like 1.19.0. So the DT_SONAME field in
libonnxruntime.so is something like libonnxruntime.so.1.18.0. You can
use readelf tool to examine it.

```
readelf -d libonnxruntime.so | grep SONAME
 0x000000000000000e (SONAME)             Library soname: [libonnxruntime.so.1.18.0]
```

When an executable is linked with a shared object which has a DT_SONAME
field, then when the executable is run the dynamic linker will attempt
to load the shared object specified by the DT_SONAME field rather than
using the file name(which is libonnxruntime.so) given to the linker.

After this change, the SONAME will be shorten to "libonnxruntime.so.1"
instead.

2. Set default version strings for Windows DLLs, to resolve #10589
  • Loading branch information
snnn authored Jul 15, 2024
1 parent 9c2b85a commit e5f18ba
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 28 deletions.
22 changes: 22 additions & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,13 @@ endfunction()
function(onnxruntime_add_shared_library target_name)
add_library(${target_name} SHARED ${ARGN})
onnxruntime_configure_target(${target_name})
if(WIN32)
target_compile_definitions(${target_name} PRIVATE VER_MAJOR=${VERSION_MAJOR_PART})
target_compile_definitions(${target_name} PRIVATE VER_MINOR=${VERSION_MINOR_PART})
target_compile_definitions(${target_name} PRIVATE VER_BUILD=${VERSION_BUILD_PART})
target_compile_definitions(${target_name} PRIVATE VER_PRIVATE=${VERSION_PRIVATE_PART})
target_compile_definitions(${target_name} PRIVATE VER_STRING=\"${VERSION_STRING}\")
endif()
endfunction()

function(onnxruntime_add_static_library target_name)
Expand All @@ -1154,6 +1161,13 @@ function(onnxruntime_add_shared_library_module target_name)
else()
#On Windows, this target shouldn't generate an import lib, but I don't know how to disable it.
add_library(${target_name} MODULE ${ARGN})
if(WIN32)
target_compile_definitions(${target_name} PRIVATE VER_MAJOR=${VERSION_MAJOR_PART})
target_compile_definitions(${target_name} PRIVATE VER_MINOR=${VERSION_MINOR_PART})
target_compile_definitions(${target_name} PRIVATE VER_BUILD=${VERSION_BUILD_PART})
target_compile_definitions(${target_name} PRIVATE VER_PRIVATE=${VERSION_PRIVATE_PART})
target_compile_definitions(${target_name} PRIVATE VER_STRING=\"${VERSION_STRING}\")
endif()
endif()

onnxruntime_configure_target(${target_name})
Expand Down Expand Up @@ -1636,6 +1650,14 @@ set(VERSION_MINOR_PART 0 CACHE STRING "Second part of numeric file/product ver
set(VERSION_BUILD_PART 0 CACHE STRING "Third part of numeric file/product version.")
set(VERSION_PRIVATE_PART 0 CACHE STRING "Fourth part of numeric file/product version.")
set(VERSION_STRING "Internal Build" CACHE STRING "String representation of file/product version.")
if(VERSION_MAJOR_PART STREQUAL "0" AND VERSION_MINOR_PART STREQUAL "0" AND VERSION_BUILD_PART STREQUAL "0" AND VERSION_PRIVATE_PART STREQUAL "0")
string(REPLACE "." ";" ORT_VERSION_STRING_LIST ${ORT_VERSION})
list(GET ORT_VERSION_STRING_LIST 0 VERSION_MAJOR_PART)
list(GET ORT_VERSION_STRING_LIST 1 VERSION_MINOR_PART)
list(GET ORT_VERSION_STRING_LIST 2 VERSION_BUILD_PART)
set(VERSION_STRING ORT_VERSION)
endif()


if (WIN32)
list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${SYS_PATH_LIB})
Expand Down
30 changes: 17 additions & 13 deletions cmake/onnxruntime.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ elseif(onnxruntime_BUILD_APPLE_FRAMEWORK)
FRAMEWORK TRUE
FRAMEWORK_VERSION A
MACOSX_FRAMEWORK_INFO_PLIST ${INFO_PLIST_PATH}
SOVERSION ${ORT_VERSION}
# Note: The PUBLIC_HEADER and VERSION properties for the 'onnxruntime' target will be set later in this file.
)
else()
Expand All @@ -108,11 +107,7 @@ endif()
add_dependencies(onnxruntime onnxruntime_generate_def ${onnxruntime_EXTERNAL_DEPENDENCIES})
target_include_directories(onnxruntime PRIVATE ${ONNXRUNTIME_ROOT} PUBLIC "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime>")

target_compile_definitions(onnxruntime PRIVATE VER_MAJOR=${VERSION_MAJOR_PART})
target_compile_definitions(onnxruntime PRIVATE VER_MINOR=${VERSION_MINOR_PART})
target_compile_definitions(onnxruntime PRIVATE VER_BUILD=${VERSION_BUILD_PART})
target_compile_definitions(onnxruntime PRIVATE VER_PRIVATE=${VERSION_PRIVATE_PART})
target_compile_definitions(onnxruntime PRIVATE VER_STRING=\"${VERSION_STRING}\")

target_compile_definitions(onnxruntime PRIVATE FILE_NAME=\"onnxruntime.dll\")

if(UNIX)
Expand All @@ -130,7 +125,6 @@ if (NOT WIN32)
set(ONNXRUNTIME_SO_LINK_FLAG " -Wl,-exported_symbols_list,${SYMBOL_FILE}")
if (${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
set_target_properties(onnxruntime PROPERTIES
SOVERSION ${ORT_VERSION}
MACOSX_RPATH TRUE
INSTALL_RPATH_USE_LINK_PATH FALSE
BUILD_WITH_INSTALL_NAME_DIR TRUE
Expand Down Expand Up @@ -222,13 +216,23 @@ target_link_libraries(onnxruntime PRIVATE
)

set_property(TARGET onnxruntime APPEND_STRING PROPERTY LINK_FLAGS ${ONNXRUNTIME_SO_LINK_FLAG} ${onnxruntime_DELAYLOAD_FLAGS})
set_target_properties(onnxruntime PROPERTIES
PUBLIC_HEADER "${ONNXRUNTIME_PUBLIC_HEADERS}"
LINK_DEPENDS ${SYMBOL_FILE}
VERSION ${ORT_VERSION}
FOLDER "ONNXRuntime"
)

#See: https://cmake.org/cmake/help/latest/prop_tgt/SOVERSION.html
if(NOT APPLE AND NOT WIN32)
set_target_properties(onnxruntime PROPERTIES
PUBLIC_HEADER "${ONNXRUNTIME_PUBLIC_HEADERS}"
LINK_DEPENDS ${SYMBOL_FILE}
VERSION ${ORT_VERSION}
SOVERSION 1
FOLDER "ONNXRuntime")
else()
# Omit the SOVERSION setting in Windows/macOS/iOS/.. build
set_target_properties(onnxruntime PROPERTIES
PUBLIC_HEADER "${ONNXRUNTIME_PUBLIC_HEADERS}"
LINK_DEPENDS ${SYMBOL_FILE}
VERSION ${ORT_VERSION}
FOLDER "ONNXRuntime")
endif()
install(TARGETS onnxruntime
EXPORT ${PROJECT_NAME}Targets
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime
Expand Down
5 changes: 0 additions & 5 deletions cmake/onnxruntime_providers_cpu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,6 @@ if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD
set_target_properties(onnxruntime_providers_shared PROPERTIES FOLDER "ONNXRuntime")
set_target_properties(onnxruntime_providers_shared PROPERTIES LINKER_LANGUAGE CXX)

target_compile_definitions(onnxruntime_providers_shared PRIVATE VER_MAJOR=${VERSION_MAJOR_PART})
target_compile_definitions(onnxruntime_providers_shared PRIVATE VER_MINOR=${VERSION_MINOR_PART})
target_compile_definitions(onnxruntime_providers_shared PRIVATE VER_BUILD=${VERSION_BUILD_PART})
target_compile_definitions(onnxruntime_providers_shared PRIVATE VER_PRIVATE=${VERSION_PRIVATE_PART})
target_compile_definitions(onnxruntime_providers_shared PRIVATE VER_STRING=\"${VERSION_STRING}\")
target_compile_definitions(onnxruntime_providers_shared PRIVATE FILE_NAME=\"onnxruntime_providers_shared.dll\")


Expand Down
5 changes: 0 additions & 5 deletions cmake/onnxruntime_providers_openvino.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@
target_include_directories(onnxruntime_providers_openvino SYSTEM PUBLIC ${ONNXRUNTIME_ROOT} ${CMAKE_CURRENT_BINARY_DIR} ${eigen_INCLUDE_DIRS} ${OpenVINO_INCLUDE_DIR} ${OPENVINO_INCLUDE_DIR_LIST} ${PYTHON_INCLUDE_DIRS} $ENV{OPENCL_INCS} $ENV{OPENCL_INCS}/../../cl_headers/)
target_link_libraries(onnxruntime_providers_openvino ${ONNXRUNTIME_PROVIDERS_SHARED} Boost::mp11 ${OPENVINO_LIB_LIST} ${ABSEIL_LIBS})

target_compile_definitions(onnxruntime_providers_openvino PRIVATE VER_MAJOR=${VERSION_MAJOR_PART})
target_compile_definitions(onnxruntime_providers_openvino PRIVATE VER_MINOR=${VERSION_MINOR_PART})
target_compile_definitions(onnxruntime_providers_openvino PRIVATE VER_BUILD=${VERSION_BUILD_PART})
target_compile_definitions(onnxruntime_providers_openvino PRIVATE VER_PRIVATE=${VERSION_PRIVATE_PART})
target_compile_definitions(onnxruntime_providers_openvino PRIVATE VER_STRING=\"${VERSION_STRING}\")
target_compile_definitions(onnxruntime_providers_openvino PRIVATE FILE_NAME=\"onnxruntime_providers_openvino.dll\")

if(MSVC)
Expand Down
5 changes: 0 additions & 5 deletions cmake/winml.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -718,11 +718,6 @@ target_compile_definitions(winml_dll PRIVATE ONNX_ML)
target_compile_definitions(winml_dll PRIVATE LOTUS_LOG_THRESHOLD=2)
target_compile_definitions(winml_dll PRIVATE LOTUS_ENABLE_STDERR_LOGGING)
target_compile_definitions(winml_dll PRIVATE PLATFORM_WINDOWS)
target_compile_definitions(winml_dll PRIVATE VER_MAJOR=${VERSION_MAJOR_PART})
target_compile_definitions(winml_dll PRIVATE VER_MINOR=${VERSION_MINOR_PART})
target_compile_definitions(winml_dll PRIVATE VER_BUILD=${VERSION_BUILD_PART})
target_compile_definitions(winml_dll PRIVATE VER_PRIVATE=${VERSION_PRIVATE_PART})
target_compile_definitions(winml_dll PRIVATE VER_STRING=\"${VERSION_STRING}\")
target_compile_definitions(winml_dll PRIVATE BINARY_NAME=\"${BINARY_NAME}\")

if (onnxruntime_WINML_NAMESPACE_OVERRIDE STREQUAL "Windows")
Expand Down

0 comments on commit e5f18ba

Please sign in to comment.