Skip to content

Conversation

JDevlieghere
Copy link
Member

Enforce that only specific tests can link liblldb. All the other unit tests statically link the private libraries. Linking both the static libraries and liblldb results in duplicated symbols.

Fixes #162378

Enforce that only specific tests can link liblldb. All the other unit
tests statically link the private libraries. Linking both the static
libraries and liblldb results in duplicated symbols.

Fixes llvm#162378
@JDevlieghere JDevlieghere changed the title [lldb] Enforce that only the LLDB API unit tests can link liblldbo [lldb] Enforce that only the LLDB API unit tests can link liblldb Oct 7, 2025
@llvmbot llvmbot added the lldb label Oct 7, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 7, 2025

@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)

Changes

Enforce that only specific tests can link liblldb. All the other unit tests statically link the private libraries. Linking both the static libraries and liblldb results in duplicated symbols.

Fixes #162378


Full diff: https://github.com/llvm/llvm-project/pull/162384.diff

3 Files Affected:

  • (modified) lldb/unittests/API/CMakeLists.txt (+2)
  • (modified) lldb/unittests/CMakeLists.txt (+5-1)
  • (modified) lldb/unittests/DAP/CMakeLists.txt (+2)
diff --git a/lldb/unittests/API/CMakeLists.txt b/lldb/unittests/API/CMakeLists.txt
index 06ac49244176c..ea140a23af605 100644
--- a/lldb/unittests/API/CMakeLists.txt
+++ b/lldb/unittests/API/CMakeLists.txt
@@ -3,6 +3,8 @@ add_lldb_unittest(APITests
   SBLineEntryTest.cpp
   SBMutexTest.cpp
 
+  SBAPITEST
+
   LINK_LIBS
     liblldb
   )
diff --git a/lldb/unittests/CMakeLists.txt b/lldb/unittests/CMakeLists.txt
index 4c5267ae25b74..194dd425430e2 100644
--- a/lldb/unittests/CMakeLists.txt
+++ b/lldb/unittests/CMakeLists.txt
@@ -12,7 +12,7 @@ endif()
 
 function(add_lldb_unittest test_name)
   cmake_parse_arguments(ARG
-    ""
+    "SBAPITEST"
     ""
     "LINK_LIBS;LINK_COMPONENTS"
     ${ARGN})
@@ -21,6 +21,10 @@ function(add_lldb_unittest test_name)
     message(FATAL_ERROR "Unit test name must end with 'Tests' for lit to find it.")
   endif()
 
+  if ("liblldb" IN_LIST ARG_LINK_LIBS AND NOT ARG_SBAPITEST)
+    message(FATAL_ERROR "The ${test_name} are not allowed to link liblldb.")
+  endif()
+
   list(APPEND LLVM_LINK_COMPONENTS ${ARG_LINK_COMPONENTS})
 
   add_unittest(LLDBUnitTests
diff --git a/lldb/unittests/DAP/CMakeLists.txt b/lldb/unittests/DAP/CMakeLists.txt
index 716159b454231..a08414c30e6cd 100644
--- a/lldb/unittests/DAP/CMakeLists.txt
+++ b/lldb/unittests/DAP/CMakeLists.txt
@@ -12,6 +12,8 @@ add_lldb_unittest(DAPTests
   TestBase.cpp
   VariablesTest.cpp
 
+  SBAPITEST
+
   LINK_COMPONENTS
     Support
   LINK_LIBS

Copy link
Member

@bulbazord bulbazord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea. I wish CMake had a mechanism to enforce these kinds of linking constraints.

@JDevlieghere JDevlieghere merged commit 02572c6 into llvm:main Oct 8, 2025
11 checks passed
@JDevlieghere JDevlieghere deleted the issue-162378 branch October 8, 2025 19:55
@ilovepi
Copy link
Contributor

ilovepi commented Oct 8, 2025

We're seeing this after this patch:

- Performing Test CXX_SUPPORTS_NO_DOCUMENTATION_DEPRECATED_SYNC - Success
CMake Error at /b/s/w/ir/x/w/llvm-llvm-project/lldb/unittests/CMakeLists.txt:25 (message):
  The LLDBBreakpointTests are not allowed to link liblldb.
Call Stack (most recent call first):
  /b/s/w/ir/x/w/llvm-llvm-project/lldb/unittests/Breakpoint/CMakeLists.txt:1 (add_lldb_unittest)

Seems related to this change. would you mind taking a look?

Bot: https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci/lldb-linux-x64/b8701546007217978577/overview
Log: https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8701546007217978577/+/u/build_and_install_lldb/configure/stdout

@JDevlieghere
Copy link
Member Author

We're seeing this after this patch:

- Performing Test CXX_SUPPORTS_NO_DOCUMENTATION_DEPRECATED_SYNC - Success
CMake Error at /b/s/w/ir/x/w/llvm-llvm-project/lldb/unittests/CMakeLists.txt:25 (message):
  The LLDBBreakpointTests are not allowed to link liblldb.
Call Stack (most recent call first):
  /b/s/w/ir/x/w/llvm-llvm-project/lldb/unittests/Breakpoint/CMakeLists.txt:1 (add_lldb_unittest)

Looks like Jim forgot to unstage these additions in #162370. I'm removing them.

@vsapsai
Copy link
Collaborator

vsapsai commented Oct 8, 2025

Pre-commit CI is also broken with the same error.

@JDevlieghere
Copy link
Member Author

Fixed by 1395d43

JDevlieghere added a commit to swiftlang/llvm-project that referenced this pull request Oct 9, 2025
…vm#162384)

Enforce that only specific tests can link liblldb. All the other unit
tests statically link the private libraries. Linking both the static
libraries and liblldb results in duplicated symbols.

Fixes llvm#162378

(cherry picked from commit 02572c6)
svkeerthy pushed a commit that referenced this pull request Oct 9, 2025
…62384)

Enforce that only specific tests can link liblldb. All the other unit
tests statically link the private libraries. Linking both the static
libraries and liblldb results in duplicated symbols.

Fixes #162378
clingfei pushed a commit to clingfei/llvm-project that referenced this pull request Oct 10, 2025
…vm#162384)

Enforce that only specific tests can link liblldb. All the other unit
tests statically link the private libraries. Linking both the static
libraries and liblldb results in duplicated symbols.

Fixes llvm#162378
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enforce that only the LLDB API unit tests can link liblldb

5 participants