[Lldb-commits] [lldb] [lldb] Enforce that only the LLDB API unit tests can link liblldbo (PR #162384)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 7 15:12:56 PDT 2025


https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/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 #162378

>From c112c637d601707023f19686d35427433c3dd31b Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jonas at devlieghere.com>
Date: Tue, 7 Oct 2025 15:09:53 -0700
Subject: [PATCH] [lldb] Enforce that only the LLDB API unit tests can link
 liblldbo

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
---
 lldb/unittests/API/CMakeLists.txt | 2 ++
 lldb/unittests/CMakeLists.txt     | 6 +++++-
 lldb/unittests/DAP/CMakeLists.txt | 2 ++
 3 files changed, 9 insertions(+), 1 deletion(-)

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



More information about the lldb-commits mailing list