Skip to content

Commit 45ffdf4

Browse files
committed
Add bolt
1 parent f62ed2f commit 45ffdf4

File tree

2 files changed

+306
-2
lines changed

2 files changed

+306
-2
lines changed
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
From ee0f56cff40b324bb06e034e247ec85ae9a846bf Mon Sep 17 00:00:00 2001
2+
From: Nikita Popov <[email protected]>
3+
Date: Wed, 8 Jan 2025 08:28:18 +0100
4+
Subject: [PATCH] [PATCH] [Bolt][CMake] Don't export bolt libraries in
5+
LLVMExports.cmake
6+
7+
Bolt makes use of add_llvm_library and as such ends up exporting
8+
its libraries from LLVMExports.cmake, which is not correct.
9+
10+
Bolt doesn't have its own exports file, and I assume that there
11+
is no desire to have one either -- Bolt libraries are not intended
12+
to be consumed as a cmake module, right?
13+
14+
As such, this PR adds a NO_EXPORT option to simplify exclude these
15+
libraries from the exports file.
16+
17+
---
18+
This patch originates from this PR:
19+
20+
https://patch-diff.githubusercontent.com/raw/llvm/llvm-project/pull/121936.
21+
22+
The commit was:
23+
24+
https://github.com/nikic/llvm-project/commit/4333a4dd270b5c046c5469b97846e3dae58fb221.patch
25+
26+
And then it was rebased onto llvmorg-19.1.6.
27+
---
28+
bolt/lib/Core/CMakeLists.txt | 1 +
29+
bolt/lib/Passes/CMakeLists.txt | 1 +
30+
bolt/lib/Profile/CMakeLists.txt | 1 +
31+
bolt/lib/Rewrite/CMakeLists.txt | 1 +
32+
bolt/lib/RuntimeLibs/CMakeLists.txt | 1 +
33+
bolt/lib/Target/AArch64/CMakeLists.txt | 1 +
34+
bolt/lib/Target/RISCV/CMakeLists.txt | 1 +
35+
bolt/lib/Target/X86/CMakeLists.txt | 1 +
36+
bolt/lib/Utils/CMakeLists.txt | 1 +
37+
llvm/cmake/modules/AddLLVM.cmake | 12 +++++++++---
38+
10 files changed, 18 insertions(+), 3 deletions(-)
39+
40+
diff --git a/bolt/lib/Core/CMakeLists.txt b/bolt/lib/Core/CMakeLists.txt
41+
index bb58667066fd..8c1f5d0bb37b 100644
42+
--- a/bolt/lib/Core/CMakeLists.txt
43+
+++ b/bolt/lib/Core/CMakeLists.txt
44+
@@ -35,6 +35,7 @@ add_llvm_library(LLVMBOLTCore
45+
ParallelUtilities.cpp
46+
Relocation.cpp
47+
48+
+ NO_EXPORT
49+
DISABLE_LLVM_LINK_LLVM_DYLIB
50+
LINK_LIBS
51+
${LLVM_PTHREAD_LIB}
52+
diff --git a/bolt/lib/Passes/CMakeLists.txt b/bolt/lib/Passes/CMakeLists.txt
53+
index 407d8b03f739..7367b541545d 100644
54+
--- a/bolt/lib/Passes/CMakeLists.txt
55+
+++ b/bolt/lib/Passes/CMakeLists.txt
56+
@@ -45,6 +45,7 @@ add_llvm_library(LLVMBOLTPasses
57+
VeneerElimination.cpp
58+
RetpolineInsertion.cpp
59+
60+
+ NO_EXPORT
61+
DISABLE_LLVM_LINK_LLVM_DYLIB
62+
63+
LINK_LIBS
64+
diff --git a/bolt/lib/Profile/CMakeLists.txt b/bolt/lib/Profile/CMakeLists.txt
65+
index 9aa4ba0490b0..a2bb4aa074c7 100644
66+
--- a/bolt/lib/Profile/CMakeLists.txt
67+
+++ b/bolt/lib/Profile/CMakeLists.txt
68+
@@ -7,6 +7,7 @@ add_llvm_library(LLVMBOLTProfile
69+
YAMLProfileReader.cpp
70+
YAMLProfileWriter.cpp
71+
72+
+ NO_EXPORT
73+
DISABLE_LLVM_LINK_LLVM_DYLIB
74+
75+
LINK_COMPONENTS
76+
diff --git a/bolt/lib/Rewrite/CMakeLists.txt b/bolt/lib/Rewrite/CMakeLists.txt
77+
index 34993af2623b..6737e89b8451 100644
78+
--- a/bolt/lib/Rewrite/CMakeLists.txt
79+
+++ b/bolt/lib/Rewrite/CMakeLists.txt
80+
@@ -26,6 +26,7 @@ add_llvm_library(LLVMBOLTRewrite
81+
RewriteInstance.cpp
82+
SDTRewriter.cpp
83+
84+
+ NO_EXPORT
85+
DISABLE_LLVM_LINK_LLVM_DYLIB
86+
87+
LINK_LIBS
88+
diff --git a/bolt/lib/RuntimeLibs/CMakeLists.txt b/bolt/lib/RuntimeLibs/CMakeLists.txt
89+
index d3ac71d3e797..b8db7e4a1553 100644
90+
--- a/bolt/lib/RuntimeLibs/CMakeLists.txt
91+
+++ b/bolt/lib/RuntimeLibs/CMakeLists.txt
92+
@@ -11,6 +11,7 @@ add_llvm_library(LLVMBOLTRuntimeLibs
93+
HugifyRuntimeLibrary.cpp
94+
InstrumentationRuntimeLibrary.cpp
95+
96+
+ NO_EXPORT
97+
DISABLE_LLVM_LINK_LLVM_DYLIB
98+
)
99+
100+
diff --git a/bolt/lib/Target/AArch64/CMakeLists.txt b/bolt/lib/Target/AArch64/CMakeLists.txt
101+
index be03e247aa96..526a9645cb54 100644
102+
--- a/bolt/lib/Target/AArch64/CMakeLists.txt
103+
+++ b/bolt/lib/Target/AArch64/CMakeLists.txt
104+
@@ -7,6 +7,7 @@ set(LLVM_LINK_COMPONENTS
105+
add_llvm_library(LLVMBOLTTargetAArch64
106+
AArch64MCPlusBuilder.cpp
107+
108+
+ NO_EXPORT
109+
DISABLE_LLVM_LINK_LLVM_DYLIB
110+
111+
DEPENDS
112+
diff --git a/bolt/lib/Target/RISCV/CMakeLists.txt b/bolt/lib/Target/RISCV/CMakeLists.txt
113+
index 7f9557606320..3955cfc0f089 100644
114+
--- a/bolt/lib/Target/RISCV/CMakeLists.txt
115+
+++ b/bolt/lib/Target/RISCV/CMakeLists.txt
116+
@@ -7,6 +7,7 @@ set(LLVM_LINK_COMPONENTS
117+
add_llvm_library(LLVMBOLTTargetRISCV
118+
RISCVMCPlusBuilder.cpp
119+
120+
+ NO_EXPORT
121+
DISABLE_LLVM_LINK_LLVM_DYLIB
122+
123+
DEPENDS
124+
diff --git a/bolt/lib/Target/X86/CMakeLists.txt b/bolt/lib/Target/X86/CMakeLists.txt
125+
index 2b769bc7e7f5..00100e9b84c9 100644
126+
--- a/bolt/lib/Target/X86/CMakeLists.txt
127+
+++ b/bolt/lib/Target/X86/CMakeLists.txt
128+
@@ -9,6 +9,7 @@ add_llvm_library(LLVMBOLTTargetX86
129+
X86MCPlusBuilder.cpp
130+
X86MCSymbolizer.cpp
131+
132+
+ NO_EXPORT
133+
DISABLE_LLVM_LINK_LLVM_DYLIB
134+
135+
DEPENDS
136+
diff --git a/bolt/lib/Utils/CMakeLists.txt b/bolt/lib/Utils/CMakeLists.txt
137+
index d1403314274b..ceddcfc8f57a 100644
138+
--- a/bolt/lib/Utils/CMakeLists.txt
139+
+++ b/bolt/lib/Utils/CMakeLists.txt
140+
@@ -2,6 +2,7 @@ add_llvm_library(LLVMBOLTUtils
141+
CommandLineOpts.cpp
142+
Utils.cpp
143+
144+
+ NO_EXPORT
145+
DISABLE_LLVM_LINK_LLVM_DYLIB
146+
147+
LINK_LIBS
148+
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
149+
index 03f4e1f190fd..addf083b7c71 100644
150+
--- a/llvm/cmake/modules/AddLLVM.cmake
151+
+++ b/llvm/cmake/modules/AddLLVM.cmake
152+
@@ -897,7 +897,7 @@ endfunction()
153+
154+
macro(add_llvm_library name)
155+
cmake_parse_arguments(ARG
156+
- "SHARED;BUILDTREE_ONLY;MODULE;INSTALL_WITH_TOOLCHAIN"
157+
+ "SHARED;BUILDTREE_ONLY;MODULE;INSTALL_WITH_TOOLCHAIN;NO_EXPORT"
158+
""
159+
""
160+
${ARGN})
161+
@@ -932,7 +932,11 @@ macro(add_llvm_library name)
162+
set(umbrella)
163+
endif()
164+
165+
- get_target_export_arg(${name} LLVM export_to_llvmexports ${umbrella})
166+
+ if(ARG_NO_EXPORT)
167+
+ set(export_to_llvmexports)
168+
+ else()
169+
+ get_target_export_arg(${name} LLVM export_to_llvmexports ${umbrella})
170+
+ endif()
171+
install(TARGETS ${name}
172+
${export_to_llvmexports}
173+
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name}
174+
@@ -945,7 +949,9 @@ macro(add_llvm_library name)
175+
COMPONENT ${name})
176+
endif()
177+
endif()
178+
- set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
179+
+ if(NOT ARG_NO_EXPORT)
180+
+ set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
181+
+ endif()
182+
endif()
183+
184+
get_subproject_title(subproject_title)
185+
--
186+
2.47.1
187+

llvm.spec

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@
6060
%bcond_with libcxx
6161
%endif
6262

63+
# I've called the build condition "build_bolt" to indicate that this does not
64+
# necessarily "use" BOLT in order to build LLVM.
65+
%if %{without compat_build} && 0%{?fedora} >= 41
66+
# BOLT only supports aarch64 and x86_64
67+
%ifarch aarch64 x86_64
68+
%bcond_without build_bolt
69+
%else
70+
%bcond_with build_bolt
71+
%endif
72+
%else
73+
%bcond_with build_bolt
74+
%endif
75+
6376
# Disable LTO on x86 and riscv in order to reduce memory consumption.
6477
%ifarch %ix86 riscv64
6578
%bcond_with lto_build
@@ -205,11 +218,15 @@
205218
%global pkg_name_llvm_libunwind llvm-libunwind
206219
#endregion libcxx globals
207220

221+
#region BOLT globals
222+
%global pkg_name_bolt llvm-bolt%{pkg_suffix}
223+
#endregion BOLT globals
224+
208225
#region packages
209226
#region main package
210227
Name: %{pkg_name_llvm}
211228
Version: %{maj_ver}.%{min_ver}.%{patch_ver}%{?rc_ver:~rc%{rc_ver}}%{?llvm_snapshot_version_suffix:~%{llvm_snapshot_version_suffix}}
212-
Release: 1%{?dist}
229+
Release: 2%{?dist}
213230
Summary: The Low Level Virtual Machine
214231

215232
License: Apache-2.0 WITH LLVM-exception OR NCSA
@@ -293,6 +310,10 @@ Patch1907: 0001-CMake-Use-correct-exports-for-MLIR-tools.patch
293310
Patch1908: cstdint.patch
294311
#endregion MLIR patches
295312

313+
#region BOLT patches
314+
Patch1909: 0001-19-PATCH-Bolt-CMake-Don-t-export-bolt-libraries-in-LLVM.patch
315+
#endregion BOLT patches
316+
296317
#region LLD patches
297318
Patch1800: 0001-18-Always-build-shared-libs-for-LLD.patch
298319
Patch1902: 0001-19-Always-build-shared-libs-for-LLD.patch
@@ -926,6 +947,24 @@ Static library for LLVM libunwind.
926947
%endif
927948
#endregion libcxx packages
928949

950+
#region BOLT packages
951+
%if %{with build_bolt}
952+
%package -n %{pkg_name_bolt}
953+
Summary: A post-link optimizer developed to speed up large applications
954+
License: Apache-2.0 WITH LLVM-exception
955+
URL: https://github.com/llvm/llvm-project/tree/main/bolt
956+
957+
# As hinted by bolt documentation
958+
Recommends: gperftools-devel
959+
960+
%description -n %{pkg_name_bolt}
961+
962+
BOLT is a post-link optimizer developed to speed up large applications.
963+
It achieves the improvements by optimizing application's code layout based on
964+
execution profile gathered by sampling profiler, such as Linux `perf` tool.
965+
%endif
966+
#endregion BOLT packages
967+
929968
#endregion packages
930969

931970
#region prep
@@ -1035,6 +1074,10 @@ Static library for LLVM libunwind.
10351074
%global projects %{projects};mlir
10361075
%endif
10371076

1077+
%if %{with build_bolt}
1078+
%global projects %{projects};bolt
1079+
%endif
1080+
10381081
%if %{with libcxx}
10391082
%global runtimes %{runtimes};libcxx;libcxxabi;libunwind
10401083
%endif
@@ -1657,6 +1700,11 @@ popd
16571700
%endif
16581701
#endregion libcxx installation
16591702

1703+
#region BOLT installation
1704+
# We don't ship libLLVMBOLT*.a
1705+
rm -f %{buildroot}%{_libdir}/libLLVMBOLT*.a
1706+
#endregion BOLT installation
1707+
16601708
%if %{with compat_build}
16611709
# Add version suffix to binaries. Do this at the end so it includes any
16621710
# additional binaries that may be been added by other steps.
@@ -2031,10 +2079,13 @@ reset_test_opts
20312079
%if %{with mlir}
20322080
reset_test_opts
20332081

2082+
%if %{maj_ver} < 20
20342083
# The ml_dtypes python module required by mlir/test/python/execution_engine.py
2035-
# isn't packaged.
2084+
# isn't packaged. But in LLVM 20 the execution_engine.py is modified to only
2085+
# run certain tests if ml_dtypes is present.
20362086
test_list_filter_out+=("MLIR :: python/execution_engine.py")
20372087
test_list_filter_out+=("MLIR :: python/multithreaded_tests.py")
2088+
%endif
20382089

20392090
%ifarch s390x
20402091
# s390x does not support half-float
@@ -2048,6 +2099,51 @@ export PYTHONPATH=%{buildroot}/%{python3_sitearch}
20482099
%endif
20492100
#endregion Test MLIR
20502101

2102+
#region BOLT tests
2103+
%if %{with build_bolt}
2104+
%if %{maj_ver} < 20
2105+
export LIT_XFAIL="$LIT_XFAIL;AArch64/build_id.c"
2106+
export LIT_XFAIL="$LIT_XFAIL;AArch64/plt-call.test"
2107+
export LIT_XFAIL="$LIT_XFAIL;X86/linux-static-keys.s"
2108+
export LIT_XFAIL="$LIT_XFAIL;X86/plt-call.test"
2109+
%endif
2110+
2111+
# Beginning with LLVM 20 this test has the "non-root-user" requirement
2112+
# and then the test should pass. But now it is flaky, hence we can only
2113+
# filter it out.
2114+
test_list_filter_out+=("BOLT :: unreadable-profile.test")
2115+
2116+
%ifarch aarch64
2117+
# Failing test cases on aarch64
2118+
# TODO(kkleine): The following used to fail on aarch64 but passed today.
2119+
#export LIT_XFAIL="$LIT_XFAIL;cache+-deprecated.test"
2120+
#export LIT_XFAIL="$LIT_XFAIL;bolt-icf.test"
2121+
#export LIT_XFAIL="$LIT_XFAIL;R_ABS.pic.lld.cpp"
2122+
2123+
# The following tests require LSE in order to run.
2124+
# More info at: https://github.com/llvm/llvm-project/issues/86485
2125+
if ! grep -q atomics /proc/cpuinfo; then
2126+
test_list_filter_out+=("BOLT :: runtime/AArch64/basic-instrumentation.test")
2127+
test_list_filter_out+=("BOLT :: runtime/AArch64/hook-fini.test")
2128+
test_list_filter_out+=("BOLT :: runtime/AArch64/instrumentation-ind-call.c")
2129+
test_list_filter_out+=("BOLT :: runtime/exceptions-instrumentation.test")
2130+
test_list_filter_out+=("BOLT :: runtime/instrumentation-indirect-2.c")
2131+
test_list_filter_out+=("BOLT :: runtime/pie-exceptions-split.test")
2132+
fi
2133+
%endif
2134+
2135+
%if %{maj_ver} < 20
2136+
%ifarch x86_64
2137+
# BOLT-ERROR: instrumentation of static binary currently does not support profile output on binary
2138+
# finalization, so it requires -instrumentation-sleep-time=N (N>0) usage
2139+
export LIT_XFAIL="$LIT_XFAIL;X86/internal-call-instrument.s"
2140+
%endif
2141+
%endif
2142+
2143+
%cmake_build --target check-bolt
2144+
%endif
2145+
#endregion BOLT tests
2146+
20512147
%endif
20522148

20532149
%if %{with snapshot_build}
@@ -2922,10 +3018,31 @@ fi
29223018
%endif
29233019
#endregion libcxx files
29243020

3021+
#region BOLT files
3022+
%if %{with build_bolt}
3023+
%files -n %{pkg_name_bolt}
3024+
%license bolt/LICENSE.TXT
3025+
%{_bindir}/llvm-bolt
3026+
%if %{maj_ver} >= 20
3027+
%{_bindir}/llvm-bolt-binary-analysis
3028+
%endif
3029+
%{_bindir}/llvm-boltdiff
3030+
%{_bindir}/llvm-bolt-heatmap
3031+
%{_bindir}/merge-fdata
3032+
%{_bindir}/perf2bolt
3033+
3034+
%{_libdir}/libbolt_rt_hugify.a
3035+
%{_libdir}/libbolt_rt_instr.a
3036+
%endif
3037+
#endregion BOLT files
3038+
29253039
#endregion files
29263040

29273041
#region changelog
29283042
%changelog
3043+
* Mon Jan 20 2025 Konrad Kleine <[email protected]> - 19.1.7-2
3044+
- Add bolt
3045+
29293046
* Wed Jan 20 2025 Timm Bäder <[email protected]> - 19.1.7-1
29303047
- Update to 19.1.7
29313048

0 commit comments

Comments
 (0)