[Lldb-commits] [lldb] [lldb][unittests] Add LLDB_UNITTEST_STRIP_DEBUG_INFO to cut unittest link time (PR #203274)
Charles Zablit via lldb-commits
lldb-commits at lists.llvm.org
Thu Jun 11 07:04:42 PDT 2026
https://github.com/charles-zablit created https://github.com/llvm/llvm-project/pull/203274
Add an opt-in cache option (default OFF). When ON, every target declared via `add_lldb_unittest` links without per-target debug info and dead-strips:
- **MSVC**: `/DEBUG:NONE + /INCREMENTAL:NO + /OPT:REF + /OPT:ICF`
- **clang/gcc**: `-g0 + LINKER:--strip-debug` (or `LINKER:-S` on macOS).
This drastically speeds up linking the unittests executable when building with debug info on Windows.
>From 789f60b45ded696d35167229b51a7dcc1a908d37 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Thu, 11 Jun 2026 14:58:12 +0100
Subject: [PATCH] [lldb][unittests] Add LLDB_UNITTEST_STRIP_DEBUG_INFO to cut
unittest link time
---
lldb/unittests/CMakeLists.txt | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/lldb/unittests/CMakeLists.txt b/lldb/unittests/CMakeLists.txt
index 41e1c29c8093b..365f3e76430e2 100644
--- a/lldb/unittests/CMakeLists.txt
+++ b/lldb/unittests/CMakeLists.txt
@@ -10,6 +10,11 @@ if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
add_compile_options("-Wno-suggest-override")
endif()
+option(LLDB_UNITTEST_STRIP_DEBUG_INFO
+ "Strip debug info from lldb unit-test binaries to cut link time and disk \
+usage. On MSVC this also adds /OPT:REF /OPT:ICF /INCREMENTAL:NO. Turn OFF \
+when you need to debug a unittest binary." OFF)
+
function(add_lldb_unittest test_name)
cmake_parse_arguments(ARG
"SBAPITEST"
@@ -41,6 +46,23 @@ function(add_lldb_unittest test_name)
COMMAND "${CMAKE_COMMAND}" -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Inputs)
target_link_libraries(${test_name} PRIVATE ${ARG_LINK_LIBS})
+
+ if (LLDB_UNITTEST_STRIP_DEBUG_INFO)
+ if (MSVC)
+ target_link_options(${test_name} PRIVATE
+ "LINKER:/DEBUG:NONE"
+ "LINKER:/INCREMENTAL:NO"
+ "LINKER:/OPT:REF"
+ "LINKER:/OPT:ICF")
+ else()
+ target_compile_options(${test_name} PRIVATE -g0)
+ if (APPLE)
+ target_link_options(${test_name} PRIVATE "LINKER:-S")
+ else()
+ target_link_options(${test_name} PRIVATE "LINKER:--strip-debug")
+ endif()
+ endif()
+ endif()
endfunction()
function(add_unittest_inputs test_name inputs)
More information about the lldb-commits
mailing list