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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]