llvm/0001-cmake-Add-LLVM_UNITTEST_LINK_FLAGS-option.patch
Nikita Popov bdb4929ebd Use LLVM_UNITTEST_LINK_FLAGS to reduce link times for unit tests
We currently spend a lot of time performing LTO on unit tests,
which is largely wasted effort. We can't disable LTO entirely,
because we don't have fat objects, but at least we can disable
post-link optimization.

For my local build, this reduces time in %build by about 30%.
2023-07-07 07:20:18 +00:00

40 lines
1.5 KiB
Diff

From cf35b4622d31701d0c79e0441931518726f997f2 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov@redhat.com>
Date: Fri, 30 Jun 2023 12:25:09 +0200
Subject: [PATCH] Add LLVM_UNITTEST_LINK_FLAGS option
This allows specifying linker flags that should only be applied
to unit tests, e.g. to disable LTO optimization for them.
---
llvm/cmake/modules/AddLLVM.cmake | 2 ++
llvm/cmake/modules/HandleLLVMOptions.cmake | 3 +++
2 files changed, 5 insertions(+)
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 94fc83db9344..7cf75223ce38 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1592,6 +1592,8 @@ function(add_unittest test_suite test_name)
endif()
endif()
+ target_link_options(${test_name} PRIVATE "${LLVM_UNITTEST_LINK_FLAGS}")
+
set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
set_output_directory(${test_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir})
# libpthreads overrides some standard library symbols, so main
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 6119ecdce0f4..eec98162c2d7 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -1274,3 +1274,6 @@ endif()
set(LLVM_THIRD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../third-party CACHE STRING
"Directory containing third party software used by LLVM (e.g. googletest)")
+
+set(LLVM_UNITTEST_LINK_FLAGS "" CACHE STRING
+ "Additional linker flags for unit tests")
--
2.40.1