This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-ffi.git
The following commit(s) were added to refs/heads/main by this push:
new 1476960b Hide direct static archive symbols in Darwin shared libraries
(#864)
1476960b is described below
commit 1476960b697300cd0c106253f4c1ee02be6728a9
Author: Tianqi Chen <[email protected]>
AuthorDate: Thu Oct 22 10:41:47 2026 -0400
Hide direct static archive symbols in Darwin shared libraries (#864)
Extend `tvm_ffi_hide_static_linked_lib_symbols` with native Darwin
archive visibility at the final shared-library link. Direct archive
paths and configured static/unknown imported archives use
`-load_hidden`; shared, interface, and object targets retain their
existing behavior. Linux/BSD handling and the helper API are unchanged.
Apply the main shared-library policy after its link dependencies are
added so it includes libbacktrace. The change preserves archive contents
and installation behavior.
---
CMakeLists.txt | 2 +-
cmake/Utils/Library.cmake | 32 +++++++++++++++++++++++++++++++-
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9e24c9fa..becf6201 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -129,7 +129,6 @@ endif ()
tvm_ffi_add_msvc_flags(tvm_ffi_objs)
tvm_ffi_add_target_from_obj(tvm_ffi tvm_ffi_objs)
-tvm_ffi_hide_static_linked_lib_symbols(tvm_ffi_shared)
if (TVM_FFI_USE_THREADS)
find_package(Threads REQUIRED)
@@ -164,6 +163,7 @@ endif ()
target_link_libraries(tvm_ffi_objs PUBLIC tvm_ffi_header)
target_link_libraries(tvm_ffi_shared PUBLIC tvm_ffi_header)
target_link_libraries(tvm_ffi_static PUBLIC tvm_ffi_header)
+tvm_ffi_hide_static_linked_lib_symbols(tvm_ffi_shared)
# ######### Target: `tvm_ffi_testing` ##########
# Build testing utilities as a separate shared library that can be loaded on
demand
diff --git a/cmake/Utils/Library.cmake b/cmake/Utils/Library.cmake
index 6f263b58..0e527d91 100644
--- a/cmake/Utils/Library.cmake
+++ b/cmake/Utils/Library.cmake
@@ -87,7 +87,8 @@ endfunction ()
# exports of libtvm_ffi.so and unexpectedly interpose with symbols from
downstream libraries.
#
# Linux, Android, and BSD targets generally use GNU-compatible linkers that
support this through
-# `--exclude-libs,ALL`. Other platforms are left unchanged.
+# `--exclude-libs,ALL`. Darwin uses -load_hidden for direct archive
dependencies; call this helper
+# after adding the target's link libraries. Other platforms are left unchanged.
#
# Parameters:
# target_name: CMake target to modify
@@ -97,6 +98,35 @@ function (tvm_ffi_hide_static_linked_lib_symbols target_name)
MATCHES "GNU|Clang"
)
target_link_options(${target_name} PRIVATE "-Wl,--exclude-libs,ALL")
+ elseif (APPLE)
+ # CMake evaluates link features in the caller's directory scope, after
this function returns.
+ set(CMAKE_LINK_LIBRARY_USING_tvm_ffi_hidden
+ "LINKER:-load_hidden,<LIBRARY>"
+ PARENT_SCOPE
+ )
+ set(CMAKE_LINK_LIBRARY_USING_tvm_ffi_hidden_SUPPORTED
+ TRUE
+ PARENT_SCOPE
+ )
+ get_target_property(linked_libs ${target_name} LINK_LIBRARIES)
+ foreach (lib IN LISTS linked_libs)
+ if (TARGET ${lib})
+ # Shared, interface and object targets do not provide dependency
archives to hide.
+ get_target_property(lib_type ${lib} TYPE)
+ if (lib_type STREQUAL "STATIC_LIBRARY" OR lib_type STREQUAL
"UNKNOWN_LIBRARY")
+ # UNKNOWN imports may resolve to a shared library; inspect the
selected configuration's
+ # file.
+ set(is_archive
"$<STREQUAL:$<PATH:GET_EXTENSION,LAST_ONLY,$<TARGET_FILE:${lib}>>,.a>")
+ set_property(
+ TARGET ${target_name} PROPERTY LINK_LIBRARY_OVERRIDE_${lib}
+
"$<IF:${is_archive},tvm_ffi_hidden,DEFAULT>"
+ )
+ endif ()
+ elseif (lib MATCHES "[.]a$")
+ # Some dependency finders supply archive paths directly, without
imported CMake targets.
+ set_property(TARGET ${target_name} PROPERTY
LINK_LIBRARY_OVERRIDE_${lib} tvm_ffi_hidden)
+ endif ()
+ endforeach ()
endif ()
endfunction ()