Skip to content

Commit 239ef9e

Browse files
authored
Use symbol file to export symbols in onnxruntime library on AIX platform as well (#28016)
On AIX platform , the exporting of symbols in libonnxruntime library is handled through `onnxruntime_c_api.cc` and CMake itself. Because of which it exports lot of symbols but misses out `OrtSessionOptionsAppendExecutionProvider_CPU`. This change is to make the symbol exports on AIX platform similar to how it is done for other platforms.
1 parent 72bce1d commit 239ef9e

2 files changed

Lines changed: 20 additions & 31 deletions

File tree

cmake/onnxruntime.cmake

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ if(UNIX)
55
set(SYMBOL_FILE ${CMAKE_CURRENT_BINARY_DIR}/onnxruntime.lds)
66
if(APPLE)
77
set(OUTPUT_STYLE xcode)
8+
elseif(CMAKE_SYSTEM_NAME MATCHES "AIX")
9+
set(OUTPUT_STYLE aix)
810
else()
911
set(OUTPUT_STYLE gcc)
1012
endif()
@@ -66,7 +68,6 @@ if(onnxruntime_BUILD_SHARED_LIB)
6668
list(APPEND SYMBOL_FILES "${ONNXRUNTIME_ROOT}/core/providers/${f}/symbols.txt")
6769
endforeach()
6870

69-
if(NOT CMAKE_SYSTEM_NAME MATCHES "AIX")
7071
add_custom_command(OUTPUT ${SYMBOL_FILE} ${CMAKE_CURRENT_BINARY_DIR}/generated_source.c
7172
COMMAND ${Python_EXECUTABLE} "${REPO_ROOT}/tools/ci_build/gen_def.py"
7273
--version_file "${ONNXRUNTIME_ROOT}/../VERSION_NUMBER" --src_root "${ONNXRUNTIME_ROOT}"
@@ -76,7 +77,6 @@ if(onnxruntime_BUILD_SHARED_LIB)
7677
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
7778

7879
add_custom_target(onnxruntime_generate_def ALL DEPENDS ${SYMBOL_FILE} ${CMAKE_CURRENT_BINARY_DIR}/generated_source.c)
79-
endif()
8080
if(WIN32)
8181
onnxruntime_add_shared_library(onnxruntime
8282
${SYMBOL_FILE}
@@ -122,11 +122,7 @@ if(onnxruntime_BUILD_SHARED_LIB)
122122
# Note: The PUBLIC_HEADER and VERSION properties for the 'onnxruntime' target will be set later in this file.
123123
)
124124
else()
125-
if(CMAKE_SYSTEM_NAME MATCHES "AIX")
126-
onnxruntime_add_shared_library(onnxruntime ${ONNXRUNTIME_ROOT}/core/session/onnxruntime_c_api.cc)
127-
else()
128-
onnxruntime_add_shared_library(onnxruntime ${CMAKE_CURRENT_BINARY_DIR}/generated_source.c )
129-
endif()
125+
onnxruntime_add_shared_library(onnxruntime ${CMAKE_CURRENT_BINARY_DIR}/generated_source.c)
130126
if(NOT APPLE)
131127
include(CheckLinkerFlag)
132128
check_linker_flag(CXX "LINKER:-rpath=\$ORIGIN" LINKER_SUPPORT_RPATH)
@@ -136,11 +132,7 @@ if(onnxruntime_BUILD_SHARED_LIB)
136132
endif()
137133
endif()
138134

139-
if(CMAKE_SYSTEM_NAME MATCHES "AIX")
140-
add_dependencies(onnxruntime ${onnxruntime_EXTERNAL_DEPENDENCIES})
141-
else()
142-
add_dependencies(onnxruntime onnxruntime_generate_def ${onnxruntime_EXTERNAL_DEPENDENCIES})
143-
endif()
135+
add_dependencies(onnxruntime onnxruntime_generate_def ${onnxruntime_EXTERNAL_DEPENDENCIES})
144136
target_include_directories(onnxruntime PRIVATE ${ONNXRUNTIME_ROOT} PUBLIC "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime>")
145137

146138

@@ -149,7 +141,10 @@ if(onnxruntime_BUILD_SHARED_LIB)
149141
if(UNIX)
150142
if (APPLE)
151143
target_link_options(onnxruntime PRIVATE "LINKER:-dead_strip")
152-
elseif(NOT CMAKE_SYSTEM_NAME MATCHES "AIX")
144+
elseif(CMAKE_SYSTEM_NAME MATCHES "AIX")
145+
set_property(TARGET onnxruntime PROPERTY AIX_EXPORT_ALL_SYMBOLS OFF)
146+
target_link_options(onnxruntime PRIVATE "LINKER:-bE:${SYMBOL_FILE}")
147+
else()
153148
target_link_options(onnxruntime PRIVATE "LINKER:--version-script=${SYMBOL_FILE}" "LINKER:--no-undefined" "LINKER:--gc-sections" "LINKER:-z,noexecstack")
154149
endif()
155150
else()
@@ -286,21 +281,13 @@ if(WIN32)
286281
target_link_options(onnxruntime PRIVATE ${onnxruntime_DELAYLOAD_FLAGS})
287282
endif()
288283
#See: https://cmake.org/cmake/help/latest/prop_tgt/SOVERSION.html
289-
if(NOT WIN32)
290-
if(CMAKE_SYSTEM_NAME MATCHES "AIX")
291-
set_target_properties(onnxruntime PROPERTIES
292-
PUBLIC_HEADER "${ONNXRUNTIME_PUBLIC_HEADERS}"
293-
VERSION ${ORT_VERSION}
294-
SOVERSION 1
295-
FOLDER "ONNXRuntime")
296-
else()
297-
set_target_properties(onnxruntime PROPERTIES
298-
PUBLIC_HEADER "${ONNXRUNTIME_PUBLIC_HEADERS}"
299-
LINK_DEPENDS ${SYMBOL_FILE}
300-
VERSION ${ORT_VERSION}
301-
SOVERSION 1
302-
FOLDER "ONNXRuntime")
303-
endif()
284+
if(NOT WIN32)
285+
set_target_properties(onnxruntime PROPERTIES
286+
PUBLIC_HEADER "${ONNXRUNTIME_PUBLIC_HEADERS}"
287+
LINK_DEPENDS ${SYMBOL_FILE}
288+
VERSION ${ORT_VERSION}
289+
SOVERSION 1
290+
FOLDER "ONNXRuntime")
304291
else()
305292
# Omit the SOVERSION setting in Windows build
306293
set_target_properties(onnxruntime PROPERTIES

tools/ci_build/gen_def.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def parse_arguments():
99
parser.add_argument("--output", required=True, help="output file")
1010
parser.add_argument("--output_source", required=True, help="output file")
1111
parser.add_argument("--version_file", required=True, help="VERSION_NUMBER file")
12-
parser.add_argument("--style", required=True, choices=["gcc", "vc", "xcode"])
12+
parser.add_argument("--style", required=True, choices=["gcc", "vc", "xcode", "aix"])
1313
parser.add_argument("--config", required=True, nargs="+")
1414
return parser.parse_args()
1515

@@ -38,8 +38,8 @@ def parse_arguments():
3838
if args.style == "vc":
3939
file.write("LIBRARY\n")
4040
file.write("EXPORTS\n")
41-
elif args.style == "xcode":
42-
pass # xcode compile don't has any header.
41+
elif args.style in ["xcode", "aix"]:
42+
pass # Both xcode and AIX export files don't need a specific header.
4343
else:
4444
file.write(f"VERS_{VERSION_STRING} {{\n")
4545
file.write(" global:\n")
@@ -49,6 +49,8 @@ def parse_arguments():
4949
file.write(f" {symbol} @{symbol_index}\n")
5050
elif args.style == "xcode":
5151
file.write(f"_{symbol}\n")
52+
elif args.style == "aix":
53+
file.write(f"{symbol}\n") # AIX just needs the name
5254
else:
5355
file.write(f" {symbol};\n")
5456
symbol_index += 1

0 commit comments

Comments
 (0)