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: [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]

Reply via email to