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%.
This commit is contained in:
Nikita Popov 2023-06-30 12:27:42 +02:00 committed by nikic
parent cd99de7d35
commit bdb4929ebd
2 changed files with 44 additions and 1 deletions

View File

@ -0,0 +1,39 @@
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

View File

@ -94,6 +94,9 @@ Source6: release-keys.asc
Patch1: 0001-SystemZ-Improve-error-messages-for-unsupported-reloc.patch
# See https://reviews.llvm.org/D137890 for the next two patches
Patch2: 0001-llvm-Add-install-targets-for-gtest.patch
# Backport of https://reviews.llvm.org/D154212 from LLVM 17.
Patch3: 0001-cmake-Add-LLVM_UNITTEST_LINK_FLAGS-option.patch
# RHEL-specific patch to avoid unwanted recommonmark dep
Patch101: 0101-Deactivate-markdown-doc.patch
# Patching third-party dir with a 200 offset in patch number
@ -323,7 +326,8 @@ export ASMFLAGS=$CFLAGS
-DCMAKE_INSTALL_PREFIX=%{install_prefix} \
-DLLVM_INSTALL_SPHINX_HTML_DIR=%{_pkgdocdir}/html \
-DSPHINX_EXECUTABLE=%{_bindir}/sphinx-build-3 \
-DLLVM_INCLUDE_BENCHMARKS=OFF
-DLLVM_INCLUDE_BENCHMARKS=OFF \
-DLLVM_UNITTEST_LINK_FLAGS="-Wl,-plugin-opt=O0"
# Build libLLVM.so first. This ensures that when libLLVM.so is linking, there
# are no other compile jobs running. This will help reduce OOM errors on the