This is an automated email from the ASF dual-hosted git repository.

syfeng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new 79f9e577f7 Do not link LLVM libraries into cpptest binary (#15639)
79f9e577f7 is described below

commit 79f9e577f7f34db7827a7bf316446591e17d9f88
Author: Krzysztof Parzyszek <[email protected]>
AuthorDate: Wed Aug 30 03:41:26 2023 -0500

    Do not link LLVM libraries into cpptest binary (#15639)
    
    Do not link LLVM libraries into cpptest binary if they are visible in TVM
    
    They are already linked into libtvm.so, and cpptests links against
    libtvm.so, so if they are visible in the TVM library, they are not
    needed again. On the other hand, linking them twice can lead to the
    following error:
    ```
    CommandLine Error: Option 'print-summary-global-ids' registered more than 
once!
    LLVM ERROR: inconsistency in registered CommandLine options
    ```
---
 CMakeLists.txt | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7b69145806..75f80bfaac 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -713,7 +713,23 @@ if(GTEST_FOUND)
   # include runtime files for unit testing
   target_link_libraries(cpptest PRIVATE ${TVM_TEST_LIBRARY_NAME} GTest::GTest 
GTest::Main GTest::gmock pthread dl)
   if(DEFINED LLVM_LIBS)
-    target_link_libraries(cpptest PRIVATE ${LLVM_LIBS})
+    # The TVM library is linked with LLVM libraries. If the LLVM libraries are
+    # static and the symbols are not hidden, then don't link them again into
+    # cpptest since cpptest is itself linked against the TVM library. If static
+    # LLVM libraries are linked in twice, it can cause issues with global
+    # variable initialization (cl::opt).
+    # If the LLVM libraries are dynamic, we have to link them again, since the
+    # TVM library will not contain any LLVM definitions.
+    unset(LLVM_SO)
+    foreach(L IN LISTS LLVM_LIBS)
+      if(L MATCHES "libLLVM.*\.so")
+        set(LLVM_SO TRUE)
+        break()
+      endif()
+    endforeach()
+    if(DEFINED LLVM_SO OR HIDE_PRIVATE_SYMBOLS)
+      target_link_libraries(cpptest PRIVATE ${LLVM_LIBS})
+    endif()
   endif()
   if(DEFINED ETHOSN_RUNTIME_LIBRARY)
     target_link_libraries(cpptest PRIVATE ${ETHOSN_RUNTIME_LIBRARY})

Reply via email to