[llvm] [BOLT] Fix unit test failures when libLLVM is linked dynamically (PR #152190)
Anatoly Trosinenko via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 5 11:51:07 PDT 2025
https://github.com/atrosinenko created https://github.com/llvm/llvm-project/pull/152190
When LLVM_LINK_LLVM_DYLIB is ON, `check-bolt` target reports unit test failures:
BOLT-Unit :: Core/./CoreTests/failed_to_discover_tests_from_gtest
BOLT-Unit :: Profile/./ProfileTests/failed_to_discover_tests_from_gtest
The reason is that when llvm-lit runs a unit-test executable:
/path/to/CoreTests --gtest_list_tests '--gtest_filter=-*DISABLED_*'
an assertion is triggered with the following message:
LLVM ERROR: Option 'default' already exists!
This assertion triggers when the initializer of defaultListDAGScheduler defined at SelectionDAGISel.cpp:219 is called as a statically-linked function after already being called during the initialization of libLLVM.
The issue can be traced down to LLVMTestingSupport library which depends on libLLVM as neither COMPONENT_LIB nor DISABLE_LLVM_LINK_LLVM_DYLIB is specified in a call to `add_llvm_library(LLVMTestingSupport ...)`.
Specifying DISABLE_LLVM_LINK_LLVM_DYLIB for LLVMTestingSupport makes Clang unit test fail and COMPONENT_LIB is probably inappropriate for a testing-specific library, thus as a workaround, added Error.cpp source from LLVMTestingSupport directly to the list of source files of CoreTests target (as it depends on `llvm::detail::TakeError(llvm::Error)`) and removed LLVMTestingSupport from the list of dependencies of ProfileTests.
>From ca562acbfc9cdd35e0225ca39c65adf03c708308 Mon Sep 17 00:00:00 2001
From: Anatoly Trosinenko <atrosinenko at accesssoftek.com>
Date: Sat, 2 Aug 2025 11:52:09 +0300
Subject: [PATCH] [BOLT] Fix unit test failures when libLLVM is linked
dynamically
When LLVM_LINK_LLVM_DYLIB is ON, `check-bolt` target reports unit test
failures:
BOLT-Unit :: Core/./CoreTests/failed_to_discover_tests_from_gtest
BOLT-Unit :: Profile/./ProfileTests/failed_to_discover_tests_from_gtest
The reason is that when llvm-lit runs a unit-test executable:
/path/to/CoreTests --gtest_list_tests '--gtest_filter=-*DISABLED_*'
an assertion is triggered with the following message:
LLVM ERROR: Option 'default' already exists!
This assertion triggers when the initializer of defaultListDAGScheduler
defined at SelectionDAGISel.cpp:219 is called as a statically-linked
function after already being called during the initialization of libLLVM.
The issue can be traced down to LLVMTestingSupport library which depends
on libLLVM as neither COMPONENT_LIB nor DISABLE_LLVM_LINK_LLVM_DYLIB is
specified in a call to `add_llvm_library(LLVMTestingSupport ...)`.
Specifying DISABLE_LLVM_LINK_LLVM_DYLIB for LLVMTestingSupport makes
Clang unit test fail and COMPONENT_LIB is probably inappropriate for a
testing-specific library, thus as a workaround, added Error.cpp source
from LLVMTestingSupport directly to the list of source files of CoreTests
target (as it depends on `llvm::detail::TakeError(llvm::Error)`) and
removed LLVMTestingSupport from the list of dependencies of ProfileTests.
---
bolt/unittests/Core/CMakeLists.txt | 6 +++++-
bolt/unittests/Profile/CMakeLists.txt | 1 -
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/bolt/unittests/Core/CMakeLists.txt b/bolt/unittests/Core/CMakeLists.txt
index 54e8ea10cda12..f10b0d9472067 100644
--- a/bolt/unittests/Core/CMakeLists.txt
+++ b/bolt/unittests/Core/CMakeLists.txt
@@ -11,6 +11,11 @@ add_bolt_unittest(CoreTests
MemoryMaps.cpp
DynoStats.cpp
+ # FIXME CoreTests uses `llvm::detail::TakeError(llvm::Error)`, but linking
+ # to LLVMTestingSupport introduces a transitive dependency on the
+ # dynamic LLVM library when LLVM_LINK_LLVM_DYLIB is ON.
+ ${LLVM_MAIN_SRC_DIR}/lib/Testing/Support/Error.cpp
+
DISABLE_LLVM_LINK_LLVM_DYLIB
)
@@ -20,7 +25,6 @@ target_link_libraries(CoreTests
LLVMBOLTRewrite
LLVMBOLTProfile
LLVMBOLTUtils
- LLVMTestingSupport
)
foreach (tgt ${BOLT_TARGETS_TO_BUILD})
diff --git a/bolt/unittests/Profile/CMakeLists.txt b/bolt/unittests/Profile/CMakeLists.txt
index ce01c6c4b949e..7b3cbd2cad724 100644
--- a/bolt/unittests/Profile/CMakeLists.txt
+++ b/bolt/unittests/Profile/CMakeLists.txt
@@ -16,7 +16,6 @@ target_link_libraries(ProfileTests
LLVMBOLTCore
LLVMBOLTProfile
LLVMTargetParser
- LLVMTestingSupport
)
foreach (tgt ${BOLT_TARGETS_TO_BUILD})
More information about the llvm-commits
mailing list