Skip to content

Commit e2f8b09

Browse files
authored
Optimize mold-git
- use LTO+PGO+BOLT
1 parent 7c6600d commit e2f8b09

File tree

1 file changed

+84
-17
lines changed

1 file changed

+84
-17
lines changed

packages/mold-git/PKGBUILD

Lines changed: 84 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
# Maintainer: Peter Jung ptr1337 <[email protected]>
2-
31
pkgname=mold-git
4-
pkgver=v2.31.0_32_g08be7ff2
2+
pkgver=v2.36.0_2_gbe087071
53
pkgrel=1
64
pkgdesc="A Modern Linker"
75
arch=(x86_64)
86
url="https://github.com/rui314/mold"
97
license=("AGPL3")
108
# xxhash is bundled
119
depends=('gcc-libs' 'mimalloc' 'openssl' 'zlib' 'onetbb')
12-
makedepends=('git' 'python' 'cmake' 'mold')
10+
makedepends=('git' 'python' 'cmake' 'mold' 'llvm')
1311
checkdepends=('clang' 'libdwarf')
1412
source=("mold::git+https://github.com/rui314/mold")
1513
sha256sums=('SKIP')
1614
provides=("mold=$pkgver")
15+
options=(!lto !strip)
1716
conflicts=("mold")
1817
reponame="mold"
1918

@@ -22,24 +21,92 @@ pkgver() {
2221
git describe --long --tags | sed "s/-/_/g"
2322
}
2423

25-
2624
build() {
25+
# First build - Generate profile data
2726
cmake \
28-
-S "$reponame" \
29-
-B build \
30-
-DCMAKE_BUILD_TYPE='Release' \
31-
-DCMAKE_INSTALL_PREFIX='/usr' \
32-
-DCMAKE_INSTALL_LIBEXECDIR='lib' \
33-
-DMOLD_USE_SYSTEM_MIMALLOC=OFF \
34-
-DMOLD_USE_SYSTEM_TBB=OFF \
35-
-DCMAKE_C_STANDARD=23 \
36-
-DCMAKE_CXX_STANDARD=23 \
37-
-DMOLD_USE_MOLD=ON \
38-
-DMOLD_LTO=ON
27+
-S "$reponame" \
28+
-B build-pgo \
29+
-DCMAKE_BUILD_TYPE='Debug' \
30+
-DCMAKE_INSTALL_PREFIX='/usr' \
31+
-DCMAKE_INSTALL_LIBEXECDIR='lib' \
32+
-DMOLD_USE_SYSTEM_MIMALLOC=OFF \
33+
-DMOLD_USE_SYSTEM_TBB=OFF \
34+
-DCMAKE_C_STANDARD=23 \
35+
-DCMAKE_CXX_STANDARD=23 \
36+
-DMOLD_USE_MOLD=OFF \
37+
-DMOLD_LTO=OFF \
38+
-DCMAKE_C_FLAGS="-fprofile-generate -fno-omit-frame-pointer -g3 -mllvm -vp-counters-per-site=6" \
39+
-DCMAKE_CXX_FLAGS="-fprofile-generate -fno-omit-frame-pointer -g3 -mllvm -vp-counters-per-site=6"
40+
41+
cmake --build build-pgo
42+
43+
# Run tests to generate profile data
44+
cd build-pgo
45+
ctest --output-on-failure
46+
cd ..
47+
48+
# Merge profile data
49+
llvm-profdata merge -output=build-pgo/default.profdata build-pgo/default*.profraw
50+
51+
# Second build - Use profile data with debug info for BOLT
52+
cmake \
53+
-S "$reponame" \
54+
-B build \
55+
-DCMAKE_BUILD_TYPE='Release' \
56+
-DCMAKE_INSTALL_PREFIX='/usr' \
57+
-DCMAKE_INSTALL_LIBEXECDIR='lib' \
58+
-DMOLD_USE_SYSTEM_MIMALLOC=OFF \
59+
-DMOLD_USE_SYSTEM_TBB=OFF \
60+
-DCMAKE_C_STANDARD=23 \
61+
-DCMAKE_CXX_STANDARD=23 \
62+
-DMOLD_USE_MOLD=OFF \
63+
-DMOLD_LTO=ON \
64+
-DCMAKE_C_FLAGS="-fprofile-use=/tmp/makepkg/mold-git/src/build-pgo/default.profdata" \
65+
-DCMAKE_CXX_FLAGS="-fprofile-use=/tmp/makepkg/mold-git/src/build-pgo/default.profdata" \
66+
-DCMAKE_EXE_LINKER_FLAGS="-Wl,--emit-relocs" \
67+
-DCMAKE_MODULE_LINKER_FLAGS="-Wl,--emit-relocs" \
68+
-DCMAKE_SHARED_LINKER_FLAGS="-Wl,--emit-relocs"
3969

4070
cmake --build build
41-
}
4271

72+
# Create perf data for BOLT
73+
cd build
74+
perf record -e cycles:u -j any,u -o perf.data -- ctest --output-on-failure
75+
cd ..
76+
77+
# Process with BOLT
78+
llvm-bolt build/mold \
79+
--data=build/perf.data \
80+
--dyno-stats \
81+
--cu-processing-batch-size=64 \
82+
--eliminate-unreachable\
83+
--frame-opt=all \
84+
--icf=all \
85+
--jump-tables=aggressive \
86+
--min-branch-clusters \
87+
--stoke \
88+
--sctc-mode=always \
89+
--plt=all \
90+
--hot-data \
91+
--hot-text \
92+
--frame-opt-rm-stores \
93+
--peepholes=all \
94+
--infer-stale-profile=1 \
95+
--x86-strip-redundant-address-size \
96+
--indirect-call-promotion=all \
97+
--reg-reassign \
98+
--use-aggr-reg-reassign \
99+
--reorder-blocks=ext-tsp \
100+
--reorder-functions=cdsort \
101+
--split-all-cold \
102+
--split-eh \
103+
--split-functions \
104+
--split-strategy=cdsplit \
105+
-o build/mold.bolt
106+
107+
# Replace original binary with BOLTed one
108+
mv build/mold.bolt build/mold
109+
}
43110

44111
check() {
45112
ctest --test-dir build --output-on-failure

0 commit comments

Comments
 (0)