diff --git a/0005-PATCH-Bolt-CMake-Don-t-export-bolt-libraries-in-LLVM.patch b/0005-PATCH-Bolt-CMake-Don-t-export-bolt-libraries-in-LLVM.patch new file mode 100644 index 0000000000000000000000000000000000000000..086675c714384975420fccf4bff6feb45528c9aa --- /dev/null +++ b/0005-PATCH-Bolt-CMake-Don-t-export-bolt-libraries-in-LLVM.patch @@ -0,0 +1,186 @@ +From ee0f56cff40b324bb06e034e247ec85ae9a846bf Mon Sep 17 00:00:00 2001 +From: Nikita Popov +Date: Wed, 8 Jan 2025 08:28:18 +0100 +Subject: [PATCH] [PATCH] [Bolt][CMake] Don't export bolt libraries in + LLVMExports.cmake + +Bolt makes use of add_llvm_library and as such ends up exporting +its libraries from LLVMExports.cmake, which is not correct. + +Bolt doesn't have its own exports file, and I assume that there +is no desire to have one either -- Bolt libraries are not intended +to be consumed as a cmake module, right? + +As such, this PR adds a NO_EXPORT option to simplify exclude these +libraries from the exports file. + +--- +This patch originates from this PR: + +https://patch-diff.githubusercontent.com/raw/llvm/llvm-project/pull/121936. + +The commit was: + +https://github.com/nikic/llvm-project/commit/4333a4dd270b5c046c5469b97846e3dae58fb221.patch + +And then it was rebased onto llvmorg-19.1.6. +--- + bolt/lib/Core/CMakeLists.txt | 1 + + bolt/lib/Passes/CMakeLists.txt | 1 + + bolt/lib/Profile/CMakeLists.txt | 1 + + bolt/lib/Rewrite/CMakeLists.txt | 1 + + bolt/lib/RuntimeLibs/CMakeLists.txt | 1 + + bolt/lib/Target/AArch64/CMakeLists.txt | 1 + + bolt/lib/Target/RISCV/CMakeLists.txt | 1 + + bolt/lib/Target/X86/CMakeLists.txt | 1 + + bolt/lib/Utils/CMakeLists.txt | 1 + + llvm/cmake/modules/AddLLVM.cmake | 12 +++++++++--- + 10 files changed, 18 insertions(+), 3 deletions(-) + +diff --git a/bolt/lib/Core/CMakeLists.txt b/bolt/lib/Core/CMakeLists.txt +index bb58667066fd..8c1f5d0bb37b 100644 +--- a/bolt/lib/Core/CMakeLists.txt ++++ b/bolt/lib/Core/CMakeLists.txt +@@ -35,6 +35,7 @@ add_llvm_library(LLVMBOLTCore + ParallelUtilities.cpp + Relocation.cpp + ++ NO_EXPORT + DISABLE_LLVM_LINK_LLVM_DYLIB + LINK_LIBS + ${LLVM_PTHREAD_LIB} +diff --git a/bolt/lib/Passes/CMakeLists.txt b/bolt/lib/Passes/CMakeLists.txt +index 407d8b03f739..7367b541545d 100644 +--- a/bolt/lib/Passes/CMakeLists.txt ++++ b/bolt/lib/Passes/CMakeLists.txt +@@ -45,6 +45,7 @@ add_llvm_library(LLVMBOLTPasses + VeneerElimination.cpp + RetpolineInsertion.cpp + ++ NO_EXPORT + DISABLE_LLVM_LINK_LLVM_DYLIB + + LINK_LIBS +diff --git a/bolt/lib/Profile/CMakeLists.txt b/bolt/lib/Profile/CMakeLists.txt +index 9aa4ba0490b0..a2bb4aa074c7 100644 +--- a/bolt/lib/Profile/CMakeLists.txt ++++ b/bolt/lib/Profile/CMakeLists.txt +@@ -7,6 +7,7 @@ add_llvm_library(LLVMBOLTProfile + YAMLProfileReader.cpp + YAMLProfileWriter.cpp + ++ NO_EXPORT + DISABLE_LLVM_LINK_LLVM_DYLIB + + LINK_COMPONENTS +diff --git a/bolt/lib/Rewrite/CMakeLists.txt b/bolt/lib/Rewrite/CMakeLists.txt +index 34993af2623b..6737e89b8451 100644 +--- a/bolt/lib/Rewrite/CMakeLists.txt ++++ b/bolt/lib/Rewrite/CMakeLists.txt +@@ -26,6 +26,7 @@ add_llvm_library(LLVMBOLTRewrite + RewriteInstance.cpp + SDTRewriter.cpp + ++ NO_EXPORT + DISABLE_LLVM_LINK_LLVM_DYLIB + + LINK_LIBS +diff --git a/bolt/lib/RuntimeLibs/CMakeLists.txt b/bolt/lib/RuntimeLibs/CMakeLists.txt +index d3ac71d3e797..b8db7e4a1553 100644 +--- a/bolt/lib/RuntimeLibs/CMakeLists.txt ++++ b/bolt/lib/RuntimeLibs/CMakeLists.txt +@@ -11,6 +11,7 @@ add_llvm_library(LLVMBOLTRuntimeLibs + HugifyRuntimeLibrary.cpp + InstrumentationRuntimeLibrary.cpp + ++ NO_EXPORT + DISABLE_LLVM_LINK_LLVM_DYLIB + ) + +diff --git a/bolt/lib/Target/AArch64/CMakeLists.txt b/bolt/lib/Target/AArch64/CMakeLists.txt +index be03e247aa96..526a9645cb54 100644 +--- a/bolt/lib/Target/AArch64/CMakeLists.txt ++++ b/bolt/lib/Target/AArch64/CMakeLists.txt +@@ -7,6 +7,7 @@ set(LLVM_LINK_COMPONENTS + add_llvm_library(LLVMBOLTTargetAArch64 + AArch64MCPlusBuilder.cpp + ++ NO_EXPORT + DISABLE_LLVM_LINK_LLVM_DYLIB + + DEPENDS +diff --git a/bolt/lib/Target/RISCV/CMakeLists.txt b/bolt/lib/Target/RISCV/CMakeLists.txt +index 7f9557606320..3955cfc0f089 100644 +--- a/bolt/lib/Target/RISCV/CMakeLists.txt ++++ b/bolt/lib/Target/RISCV/CMakeLists.txt +@@ -7,6 +7,7 @@ set(LLVM_LINK_COMPONENTS + add_llvm_library(LLVMBOLTTargetRISCV + RISCVMCPlusBuilder.cpp + ++ NO_EXPORT + DISABLE_LLVM_LINK_LLVM_DYLIB + + DEPENDS +diff --git a/bolt/lib/Target/X86/CMakeLists.txt b/bolt/lib/Target/X86/CMakeLists.txt +index 2b769bc7e7f5..00100e9b84c9 100644 +--- a/bolt/lib/Target/X86/CMakeLists.txt ++++ b/bolt/lib/Target/X86/CMakeLists.txt +@@ -9,6 +9,7 @@ add_llvm_library(LLVMBOLTTargetX86 + X86MCPlusBuilder.cpp + X86MCSymbolizer.cpp + ++ NO_EXPORT + DISABLE_LLVM_LINK_LLVM_DYLIB + + DEPENDS +diff --git a/bolt/lib/Utils/CMakeLists.txt b/bolt/lib/Utils/CMakeLists.txt +index d1403314274b..ceddcfc8f57a 100644 +--- a/bolt/lib/Utils/CMakeLists.txt ++++ b/bolt/lib/Utils/CMakeLists.txt +@@ -2,6 +2,7 @@ add_llvm_library(LLVMBOLTUtils + CommandLineOpts.cpp + Utils.cpp + ++ NO_EXPORT + DISABLE_LLVM_LINK_LLVM_DYLIB + + LINK_LIBS +diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake +index 03f4e1f190fd..addf083b7c71 100644 +--- a/llvm/cmake/modules/AddLLVM.cmake ++++ b/llvm/cmake/modules/AddLLVM.cmake +@@ -897,7 +897,7 @@ endfunction() + + macro(add_llvm_library name) + cmake_parse_arguments(ARG +- "SHARED;BUILDTREE_ONLY;MODULE;INSTALL_WITH_TOOLCHAIN" ++ "SHARED;BUILDTREE_ONLY;MODULE;INSTALL_WITH_TOOLCHAIN;NO_EXPORT" + "" + "" + ${ARGN}) +@@ -932,7 +932,11 @@ macro(add_llvm_library name) + set(umbrella) + endif() + +- get_target_export_arg(${name} LLVM export_to_llvmexports ${umbrella}) ++ if(ARG_NO_EXPORT) ++ set(export_to_llvmexports) ++ else() ++ get_target_export_arg(${name} LLVM export_to_llvmexports ${umbrella}) ++ endif() + install(TARGETS ${name} + ${export_to_llvmexports} + LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} +@@ -945,7 +949,9 @@ macro(add_llvm_library name) + COMPONENT ${name}) + endif() + endif() +- set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) ++ if(NOT ARG_NO_EXPORT) ++ set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) ++ endif() + endif() + + get_subproject_title(subproject_title) +-- +2.47.1 diff --git a/llvm-toolset-19.spec b/llvm-toolset-19.spec index 036bc0c175381c371301f5cd83689ba831671396..50f830412f6ab92e896666b7b3f1e581fe4550d3 100644 --- a/llvm-toolset-19.spec +++ b/llvm-toolset-19.spec @@ -24,6 +24,12 @@ %bcond_without lldb %bcond_without libcxx +%ifarch aarch64 x86_64 +%bcond_without bolt +%else +%bcond_with bolt +%endif + %if %{with toolchain_clang} %global toolchain clang %endif @@ -145,11 +151,15 @@ %global pkg_name_llvm_libunwind %{?scl_prefix}llvm-libunwind #endregion libcxx globals +#region BOLT globals +%global pkg_name_bolt %{?scl_prefix}llvm-bolt +#endregion BOLT globals + #region packages #region main package Name: llvm-toolset-%{maj_ver} Version: %{maj_ver}.%{min_ver}.%{patch_ver} -Release: 7 +Release: 8 Summary: The Low Level Virtual Machine License: NCSA @@ -170,6 +180,7 @@ Patch0003: 0003-Always-build-shared-libs-for-LLD.patch # backport riscv64 support for offload host plugin from llvm 20.1 # https://github.com/llvm/llvm-project/pull/115773 Patch0004: 0004-Offload-Add-support-for-riscv64-to-host-plugin.patch +Patch0005: 0005-PATCH-Bolt-CMake-Don-t-export-bolt-libraries-in-LLVM.patch BuildRequires: gcc BuildRequires: gcc-c++ @@ -720,6 +731,24 @@ Documentation for LLVM libunwind %endif #endregion libcxx packages +#region BOLT packages +%if %{with bolt} +%package -n %{pkg_name_bolt} +Summary: A post-link optimizer developed to speed up large applications +License: Apache-2.0 WITH LLVM-exception +URL: https://github.com/llvm/llvm-project/tree/main/bolt + +# As hinted by bolt documentation +Recommends: gperftools-devel + +%description -n %{pkg_name_bolt} + +BOLT is a post-link optimizer developed to speed up large applications. +It achieves the improvements by optimizing application's code layout based on +execution profile gathered by sampling profiler, such as Linux `perf` tool. +%endif +#endregion BOLT packages + #endregion packages #region prep @@ -763,6 +792,10 @@ Documentation for LLVM libunwind %global projects %{projects};mlir %endif +%if %{with bolt} +%global projects %{projects};bolt +%endif + %global runtimes compiler-rt;openmp %if %{maj_ver} >= 19 @@ -1474,6 +1507,11 @@ popd %endif #endregion libcxx installation +#region BOLT installation +# We don't ship libLLVMBOLT*.a +rm -f %{buildroot}%{_libdir}/libLLVMBOLT*.a +#endregion BOLT installation + %if %{without sys_llvm} # Add version suffix to binaries. Do this at the end so it includes any # additional binaries that may be been added by other steps. @@ -1886,6 +1924,51 @@ export PYTHONPATH=%{buildroot}/%{python3_sitearch} %endif #endregion Test MLIR +#region BOLT tests +%if %{with bolt} +%if %{maj_ver} < 20 +export LIT_XFAIL="$LIT_XFAIL;AArch64/build_id.c" +export LIT_XFAIL="$LIT_XFAIL;AArch64/plt-call.test" +export LIT_XFAIL="$LIT_XFAIL;X86/linux-static-keys.s" +export LIT_XFAIL="$LIT_XFAIL;X86/plt-call.test" +%endif + +# Beginning with LLVM 20 this test has the "non-root-user" requirement +# and then the test should pass. But now it is flaky, hence we can only +# filter it out. +test_list_filter_out+=("BOLT :: unreadable-profile.test") + +%ifarch aarch64 +# Failing test cases on aarch64 +# TODO(kkleine): The following used to fail on aarch64 but passed today. +#export LIT_XFAIL="$LIT_XFAIL;cache+-deprecated.test" +#export LIT_XFAIL="$LIT_XFAIL;bolt-icf.test" +#export LIT_XFAIL="$LIT_XFAIL;R_ABS.pic.lld.cpp" + +# The following tests require LSE in order to run. +# More info at: https://github.com/llvm/llvm-project/issues/86485 +if ! grep -q atomics /proc/cpuinfo; then + test_list_filter_out+=("BOLT :: runtime/AArch64/basic-instrumentation.test") + test_list_filter_out+=("BOLT :: runtime/AArch64/hook-fini.test") + test_list_filter_out+=("BOLT :: runtime/AArch64/instrumentation-ind-call.c") + test_list_filter_out+=("BOLT :: runtime/exceptions-instrumentation.test") + test_list_filter_out+=("BOLT :: runtime/instrumentation-indirect-2.c") + test_list_filter_out+=("BOLT :: runtime/pie-exceptions-split.test") +fi +%endif + +%if %{maj_ver} < 20 +%ifarch x86_64 +# BOLT-ERROR: instrumentation of static binary currently does not support profile output on binary +# finalization, so it requires -instrumentation-sleep-time=N (N>0) usage +export LIT_XFAIL="$LIT_XFAIL;X86/internal-call-instrument.s" +%endif +%endif + +%cmake_build --target check-bolt +%endif +#endregion BOLT tests + %endif #endregion check @@ -2843,9 +2926,41 @@ fi %doc %{_pkgdocdir}/html #endregion libcxx files +#region BOLT files +%if %{with bolt} +%files -n %{pkg_name_bolt} +%license bolt/LICENSE.TXT +%{install_bindir}/llvm-bolt +%if %{maj_ver} >= 20 +%{install_bindir}/llvm-bolt-binary-analysis +%endif +%{install_bindir}/llvm-boltdiff +%{install_bindir}/llvm-bolt-heatmap +%{install_bindir}/merge-fdata +%{install_bindir}/perf2bolt + +%{install_libdir}/libbolt_rt_hugify.a +%{install_libdir}/libbolt_rt_instr.a + +%if %{without sys_llvm} +%{_bindir}/llvm-bolt-%{maj_ver} +%if %{maj_ver} >= 20 +%{_bindir}/llvm-bolt-binary-analysis-%{maj_ver} +%endif +%{_bindir}/llvm-boltdiff-%{maj_ver} +%{_bindir}/llvm-bolt-heatmap-%{maj_ver} +%{_bindir}/merge-fdata-%{maj_ver} +%{_bindir}/perf2bolt-%{maj_ver} +%endif + +%endif +#endregion BOLT files + #endregion files %changelog +* Fri May 16 2025 liyunfei - 19.1.7-8 +- Add bolt * Mon Mar 31 2025 liyunfei - 19.1.7-7 - Bugfixes for 2403 build