Skip to content

Commit e5f18ba

Browse files
authored
Change libonnxruntime.so's SONAME: remove the minor and patch version. (microsoft#21339)
### Description Resolve microsoft#21281 and microsoft#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 microsoft#10589
1 parent 9c2b85a commit e5f18ba

File tree

5 files changed

+39
-28
lines changed

5 files changed

+39
-28
lines changed

cmake/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,13 @@ endfunction()
11401140
function(onnxruntime_add_shared_library target_name)
11411141
add_library(${target_name} SHARED ${ARGN})
11421142
onnxruntime_configure_target(${target_name})
1143+
if(WIN32)
1144+
target_compile_definitions(${target_name} PRIVATE VER_MAJOR=${VERSION_MAJOR_PART})
1145+
target_compile_definitions(${target_name} PRIVATE VER_MINOR=${VERSION_MINOR_PART})
1146+
target_compile_definitions(${target_name} PRIVATE VER_BUILD=${VERSION_BUILD_PART})
1147+
target_compile_definitions(${target_name} PRIVATE VER_PRIVATE=${VERSION_PRIVATE_PART})
1148+
target_compile_definitions(${target_name} PRIVATE VER_STRING=\"${VERSION_STRING}\")
1149+
endif()
11431150
endfunction()
11441151

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

11591173
onnxruntime_configure_target(${target_name})
@@ -1636,6 +1650,14 @@ set(VERSION_MINOR_PART 0 CACHE STRING "Second part of numeric file/product ver
16361650
set(VERSION_BUILD_PART 0 CACHE STRING "Third part of numeric file/product version.")
16371651
set(VERSION_PRIVATE_PART 0 CACHE STRING "Fourth part of numeric file/product version.")
16381652
set(VERSION_STRING "Internal Build" CACHE STRING "String representation of file/product version.")
1653+
if(VERSION_MAJOR_PART STREQUAL "0" AND VERSION_MINOR_PART STREQUAL "0" AND VERSION_BUILD_PART STREQUAL "0" AND VERSION_PRIVATE_PART STREQUAL "0")
1654+
string(REPLACE "." ";" ORT_VERSION_STRING_LIST ${ORT_VERSION})
1655+
list(GET ORT_VERSION_STRING_LIST 0 VERSION_MAJOR_PART)
1656+
list(GET ORT_VERSION_STRING_LIST 1 VERSION_MINOR_PART)
1657+
list(GET ORT_VERSION_STRING_LIST 2 VERSION_BUILD_PART)
1658+
set(VERSION_STRING ORT_VERSION)
1659+
endif()
1660+
16391661

16401662
if (WIN32)
16411663
list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${SYS_PATH_LIB})

cmake/onnxruntime.cmake

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ elseif(onnxruntime_BUILD_APPLE_FRAMEWORK)
9595
FRAMEWORK TRUE
9696
FRAMEWORK_VERSION A
9797
MACOSX_FRAMEWORK_INFO_PLIST ${INFO_PLIST_PATH}
98-
SOVERSION ${ORT_VERSION}
9998
# Note: The PUBLIC_HEADER and VERSION properties for the 'onnxruntime' target will be set later in this file.
10099
)
101100
else()
@@ -108,11 +107,7 @@ endif()
108107
add_dependencies(onnxruntime onnxruntime_generate_def ${onnxruntime_EXTERNAL_DEPENDENCIES})
109108
target_include_directories(onnxruntime PRIVATE ${ONNXRUNTIME_ROOT} PUBLIC "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime>")
110109

111-
target_compile_definitions(onnxruntime PRIVATE VER_MAJOR=${VERSION_MAJOR_PART})
112-
target_compile_definitions(onnxruntime PRIVATE VER_MINOR=${VERSION_MINOR_PART})
113-
target_compile_definitions(onnxruntime PRIVATE VER_BUILD=${VERSION_BUILD_PART})
114-
target_compile_definitions(onnxruntime PRIVATE VER_PRIVATE=${VERSION_PRIVATE_PART})
115-
target_compile_definitions(onnxruntime PRIVATE VER_STRING=\"${VERSION_STRING}\")
110+
116111
target_compile_definitions(onnxruntime PRIVATE FILE_NAME=\"onnxruntime.dll\")
117112

118113
if(UNIX)
@@ -130,7 +125,6 @@ if (NOT WIN32)
130125
set(ONNXRUNTIME_SO_LINK_FLAG " -Wl,-exported_symbols_list,${SYMBOL_FILE}")
131126
if (${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
132127
set_target_properties(onnxruntime PROPERTIES
133-
SOVERSION ${ORT_VERSION}
134128
MACOSX_RPATH TRUE
135129
INSTALL_RPATH_USE_LINK_PATH FALSE
136130
BUILD_WITH_INSTALL_NAME_DIR TRUE
@@ -222,13 +216,23 @@ target_link_libraries(onnxruntime PRIVATE
222216
)
223217

224218
set_property(TARGET onnxruntime APPEND_STRING PROPERTY LINK_FLAGS ${ONNXRUNTIME_SO_LINK_FLAG} ${onnxruntime_DELAYLOAD_FLAGS})
225-
set_target_properties(onnxruntime PROPERTIES
226-
PUBLIC_HEADER "${ONNXRUNTIME_PUBLIC_HEADERS}"
227-
LINK_DEPENDS ${SYMBOL_FILE}
228-
VERSION ${ORT_VERSION}
229-
FOLDER "ONNXRuntime"
230-
)
231219

220+
#See: https://cmake.org/cmake/help/latest/prop_tgt/SOVERSION.html
221+
if(NOT APPLE AND NOT WIN32)
222+
set_target_properties(onnxruntime PROPERTIES
223+
PUBLIC_HEADER "${ONNXRUNTIME_PUBLIC_HEADERS}"
224+
LINK_DEPENDS ${SYMBOL_FILE}
225+
VERSION ${ORT_VERSION}
226+
SOVERSION 1
227+
FOLDER "ONNXRuntime")
228+
else()
229+
# Omit the SOVERSION setting in Windows/macOS/iOS/.. build
230+
set_target_properties(onnxruntime PROPERTIES
231+
PUBLIC_HEADER "${ONNXRUNTIME_PUBLIC_HEADERS}"
232+
LINK_DEPENDS ${SYMBOL_FILE}
233+
VERSION ${ORT_VERSION}
234+
FOLDER "ONNXRuntime")
235+
endif()
232236
install(TARGETS onnxruntime
233237
EXPORT ${PROJECT_NAME}Targets
234238
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime

cmake/onnxruntime_providers_cpu.cmake

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,6 @@ if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD
236236
set_target_properties(onnxruntime_providers_shared PROPERTIES FOLDER "ONNXRuntime")
237237
set_target_properties(onnxruntime_providers_shared PROPERTIES LINKER_LANGUAGE CXX)
238238

239-
target_compile_definitions(onnxruntime_providers_shared PRIVATE VER_MAJOR=${VERSION_MAJOR_PART})
240-
target_compile_definitions(onnxruntime_providers_shared PRIVATE VER_MINOR=${VERSION_MINOR_PART})
241-
target_compile_definitions(onnxruntime_providers_shared PRIVATE VER_BUILD=${VERSION_BUILD_PART})
242-
target_compile_definitions(onnxruntime_providers_shared PRIVATE VER_PRIVATE=${VERSION_PRIVATE_PART})
243-
target_compile_definitions(onnxruntime_providers_shared PRIVATE VER_STRING=\"${VERSION_STRING}\")
244239
target_compile_definitions(onnxruntime_providers_shared PRIVATE FILE_NAME=\"onnxruntime_providers_shared.dll\")
245240

246241

cmake/onnxruntime_providers_openvino.cmake

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@
4545
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/)
4646
target_link_libraries(onnxruntime_providers_openvino ${ONNXRUNTIME_PROVIDERS_SHARED} Boost::mp11 ${OPENVINO_LIB_LIST} ${ABSEIL_LIBS})
4747

48-
target_compile_definitions(onnxruntime_providers_openvino PRIVATE VER_MAJOR=${VERSION_MAJOR_PART})
49-
target_compile_definitions(onnxruntime_providers_openvino PRIVATE VER_MINOR=${VERSION_MINOR_PART})
50-
target_compile_definitions(onnxruntime_providers_openvino PRIVATE VER_BUILD=${VERSION_BUILD_PART})
51-
target_compile_definitions(onnxruntime_providers_openvino PRIVATE VER_PRIVATE=${VERSION_PRIVATE_PART})
52-
target_compile_definitions(onnxruntime_providers_openvino PRIVATE VER_STRING=\"${VERSION_STRING}\")
5348
target_compile_definitions(onnxruntime_providers_openvino PRIVATE FILE_NAME=\"onnxruntime_providers_openvino.dll\")
5449

5550
if(MSVC)

cmake/winml.cmake

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -718,11 +718,6 @@ target_compile_definitions(winml_dll PRIVATE ONNX_ML)
718718
target_compile_definitions(winml_dll PRIVATE LOTUS_LOG_THRESHOLD=2)
719719
target_compile_definitions(winml_dll PRIVATE LOTUS_ENABLE_STDERR_LOGGING)
720720
target_compile_definitions(winml_dll PRIVATE PLATFORM_WINDOWS)
721-
target_compile_definitions(winml_dll PRIVATE VER_MAJOR=${VERSION_MAJOR_PART})
722-
target_compile_definitions(winml_dll PRIVATE VER_MINOR=${VERSION_MINOR_PART})
723-
target_compile_definitions(winml_dll PRIVATE VER_BUILD=${VERSION_BUILD_PART})
724-
target_compile_definitions(winml_dll PRIVATE VER_PRIVATE=${VERSION_PRIVATE_PART})
725-
target_compile_definitions(winml_dll PRIVATE VER_STRING=\"${VERSION_STRING}\")
726721
target_compile_definitions(winml_dll PRIVATE BINARY_NAME=\"${BINARY_NAME}\")
727722

728723
if (onnxruntime_WINML_NAMESPACE_OVERRIDE STREQUAL "Windows")

0 commit comments

Comments
 (0)