You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "tqchen (via GitHub)" <gi...@apache.org> on 2026/06/17 15:25:06 UTC
[PR] Hide symbols from linked static libraries [tvm-ffi]
tqchen opened a new pull request, #627:
URL: https://github.com/apache/tvm-ffi/pull/627
To avoid downstream mistakenly picking up symbols from static libstdc++_nonshared, always hide symbols from static libraries linked into tvm-ffi shared objects.
This adds a CMake helper for the policy and applies it to tvm_ffi_shared, tvm_ffi_testing, and the optional tvm_ffi_cython target on ELF platforms.
Local validation:
- Configured and built tvm_ffi_shared and tvm_ffi_testing with TVM_FFI_USE_LIBBACKTRACE=OFF.
- Verified generated Ninja link flags include -Wl,--exclude-libs,ALL for libtvm_ffi.so and libtvm_ffi_testing.so.
- Static-runtime before/after probe: upstream without the flag exported 1122 defined C++ runtime symbols under -static-libstdc++ -static-libgcc; patched build exported 0 matching defined C++ runtime symbols.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [BUILD] Hide symbols from linked static libraries [tvm-ffi]
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on code in PR #627:
URL: https://github.com/apache/tvm-ffi/pull/627#discussion_r3429419913
##########
cmake/Utils/Library.cmake:
##########
@@ -77,6 +77,30 @@ function (tvm_ffi_add_msvc_flags target_name)
endif ()
endfunction ()
+# ~~~
+# tvm_ffi_hide_static_linked_lib_symbols(target_name)
+# Prevent symbols from static archives linked into a shared library from being exported by that
+# shared library.
+#
+# This matters when a toolchain links helper archives into a shared target, for example
+# libstdc++_nonshared.a. Without this guard, symbols pulled from those archives can become dynamic
+# exports of libtvm_ffi.so and unexpectedly interpose with symbols from downstream libraries.
+#
+# On ELF targets, GNU-compatible linkers support this through `--exclude-libs,ALL`. Non-ELF
+# platforms are left unchanged.
+#
+# Parameters:
+# target_name: CMake target to modify
+# ~~~
+function (tvm_ffi_hide_static_linked_lib_symbols target_name)
+ if (UNIX
+ AND NOT APPLE
+ AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang"
+ )
+ target_link_options(${target_name} PRIVATE "-Wl,--exclude-libs,ALL")
+ endif ()
Review Comment:
Updated to restrict the flag to Linux, Android, and BSD targets via CMAKE_SYSTEM_NAME while retaining the GNU/Clang compiler guard. Reconfigured locally on Linux and verified the generated Ninja link rules still apply -Wl,--exclude-libs,ALL to libtvm_ffi.so and libtvm_ffi_testing.so.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [BUILD] Hide symbols from linked static libraries [tvm-ffi]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #627:
URL: https://github.com/apache/tvm-ffi/pull/627#discussion_r3429380048
##########
cmake/Utils/Library.cmake:
##########
@@ -77,6 +77,30 @@ function (tvm_ffi_add_msvc_flags target_name)
endif ()
endfunction ()
+# ~~~
+# tvm_ffi_hide_static_linked_lib_symbols(target_name)
+# Prevent symbols from static archives linked into a shared library from being exported by that
+# shared library.
+#
+# This matters when a toolchain links helper archives into a shared target, for example
+# libstdc++_nonshared.a. Without this guard, symbols pulled from those archives can become dynamic
+# exports of libtvm_ffi.so and unexpectedly interpose with symbols from downstream libraries.
+#
+# On ELF targets, GNU-compatible linkers support this through `--exclude-libs,ALL`. Non-ELF
+# platforms are left unchanged.
+#
+# Parameters:
+# target_name: CMake target to modify
+# ~~~
+function (tvm_ffi_hide_static_linked_lib_symbols target_name)
+ if (UNIX
+ AND NOT APPLE
+ AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang"
+ )
+ target_link_options(${target_name} PRIVATE "-Wl,--exclude-libs,ALL")
+ endif ()
Review Comment:

On non-ELF UNIX platforms (such as Solaris or AIX) where GCC or Clang might be used with the native system linker, the `-Wl,--exclude-libs,ALL` option is not supported and will cause build failures. To prevent this, restrict this option to operating systems that use GNU-compatible linkers (like Linux, Android, and the BSDs) by checking `CMAKE_SYSTEM_NAME`.
```
if (CMAKE_SYSTEM_NAME MATCHES "Linux|Android|FreeBSD|NetBSD|OpenBSD"
AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang"
)
target_link_options(${target_name} PRIVATE "-Wl,--exclude-libs,ALL")
endif ()
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [BUILD] Hide symbols from linked static libraries [tvm-ffi]
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen merged PR #627:
URL: https://github.com/apache/tvm-ffi/pull/627
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org