Skip to content

Commit 596a93d

Browse files
committed
PKGBUILD: add "clang" mode and rename _use_llvm_lto to _use_llvm
Add a new "clang" option to _use_llvm (formerly _use_llvm_lto) that uses Clang as the compiler with LTO disabled. This is useful for AutoFDO/Propeller profiling workflows and testing without the overhead of LTO linking. Signed-off-by: Peter Jung <admin@ptr1337.dev>
1 parent 4a36345 commit 596a93d

1 file changed

Lines changed: 25 additions & 17 deletions

File tree

linux-cachyos/PKGBUILD

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,14 @@
8181
# - "generic" (kernel's default - to share the package between machines with different CPU µarch as long as they are x86-64)
8282
: "${_processor_opt:=}"
8383

84-
# Clang LTO mode, only available with the "llvm" compiler - options are "none", "full" or "thin".
85-
# ATTENTION - one of three predefined values should be selected!
86-
# "full: uses 1 thread for Linking, slow and uses more memory, theoretically with the highest performance gains."
87-
# "thin: uses multiple threads, faster and uses less memory, may have a lower runtime performance than Full."
88-
# "thin-dist: Similar to thin, but uses a distributed model rather than in-process: https://discourse.llvm.org/t/rfc-distributed-thinlto-build-for-kernel/85934"
89-
# "none: disable LTO
90-
: "${_use_llvm_lto:=thin}"
84+
# Compiler and LTO selection - options are "none", "clang", "thin", "thin-dist" or "full".
85+
# ATTENTION - one of the predefined values should be selected!
86+
# "none": use GCC with LTO disabled.
87+
# "clang": use Clang as compiler but with LTO disabled.
88+
# "thin": use Clang with ThinLTO - multiple threads, faster and uses less memory, may have a lower runtime performance than Full.
89+
# "thin-dist": use Clang with distributed ThinLTO - https://discourse.llvm.org/t/rfc-distributed-thinlto-build-for-kernel/85934
90+
# "full": use Clang with Full LTO - 1 thread for Linking, slow and uses more memory, theoretically with the highest performance gains.
91+
: "${_use_llvm:=thin}"
9192

9293
# Use suffix -lto only when requested by the user
9394
# yes - enable -lto suffix
@@ -151,7 +152,12 @@
151152

152153
# ATTENTION: Do not modify after this line
153154
_is_lto_kernel() {
154-
[[ "$_use_llvm_lto" = "thin" || "$_use_llvm_lto" = "full" || "$_use_llvm_lto" = "thin-dist" ]]
155+
[[ "$_use_llvm" = "thin" || "$_use_llvm" = "full" || "$_use_llvm" = "thin-dist" ]]
156+
return $?
157+
}
158+
159+
_is_clang_build() {
160+
_is_lto_kernel || [[ "$_use_llvm" = "clang" ]]
155161
return $?
156162
}
157163

@@ -162,7 +168,7 @@ _is_ci_build() {
162168

163169
if _is_lto_kernel && [ "$_use_lto_suffix" = "yes" ]; then
164170
_pkgsuffix=cachyos-lto
165-
elif ! _is_lto_kernel && [ "$_use_gcc_suffix" = "yes" ]; then
171+
elif ! _is_clang_build && [ "$_use_gcc_suffix" = "yes" ]; then
166172
_pkgsuffix=cachyos-gcc
167173
else
168174
_pkgsuffix=cachyos
@@ -213,7 +219,7 @@ source=(
213219
"config")
214220

215221
# LLVM makedepends
216-
if _is_lto_kernel; then
222+
if _is_clang_build; then
217223
makedepends+=(clang llvm lld)
218224
source+=("${_patchsource}/misc/dkms-clang.patch")
219225
BUILD_FLAGS=(
@@ -341,18 +347,18 @@ prepare() {
341347
fi
342348

343349
### Select LLVM level
344-
case "$_use_llvm_lto" in
350+
case "$_use_llvm" in
345351
thin) scripts/config -e LTO_CLANG_THIN;;
346352
thin-dist) scripts/config -e LTO_CLANG_THIN_DIST;;
347353
full) scripts/config -e LTO_CLANG_FULL;;
348-
none) scripts/config -e LTO_NONE;;
349-
*) _die "The value '$_use_llvm_lto' is invalid. Choose the correct one again.";;
354+
clang|none) scripts/config -e LTO_NONE;;
355+
*) _die "The value '$_use_llvm' is invalid. Choose the correct one again.";;
350356
esac
351357

352-
echo "Selecting '$_use_llvm_lto' LLVM level..."
358+
echo "Selecting '$_use_llvm' LLVM level..."
353359

354360
if ! _is_lto_kernel; then
355-
echo "Enabling QR Code Panic for GCC Kernels"
361+
echo "Enabling QR Code Panic for non-LTO Kernels"
356362
scripts/config --set-str DRM_PANIC_SCREEN qr_code -e DRM_PANIC_SCREEN_QR_CODE \
357363
--set-str DRM_PANIC_SCREEN_QR_CODE_URL https://panic.archlinux.org/panic_report# \
358364
--set-val CONFIG_DRM_PANIC_SCREEN_QR_VERSION 40
@@ -531,7 +537,7 @@ _sign_modules() {
531537
local sign_cert="${srcdir}/${_srcname}/certs/signing_key.x509"
532538
local hash_algo="$(grep -Po 'CONFIG_MODULE_SIG_HASH="\K[^"]*' "${srcdir}/${_srcname}/.config")"
533539

534-
if [ "$_use_llvm_lto" != "none" ]; then
540+
if [ "$_use_llvm" != "none" ]; then
535541
local strip_bin="llvm-strip"
536542
else
537543
local strip_bin="strip"
@@ -567,7 +573,7 @@ build() {
567573
cd ${srcdir}/"zfs"
568574

569575
local CONFIGURE_FLAGS=()
570-
[ "$_use_llvm_lto" != "none" ] && CONFIGURE_FLAGS+=("KERNEL_LLVM=1")
576+
[ "$_use_llvm" != "none" ] && CONFIGURE_FLAGS+=("KERNEL_LLVM=1")
571577

572578
./autogen.sh
573579
sed -i "s|\$(uname -r)|${_kernuname}|g" configure
@@ -626,6 +632,8 @@ _package-headers() {
626632
if _is_lto_kernel; then
627633
provides+=(linux-cachyos-lto-headers=$_kernver)
628634
replaces=(linux-cachyos-lto-headers)
635+
fi
636+
if _is_clang_build; then
629637
depends+=(clang llvm lld)
630638
fi
631639

0 commit comments

Comments
 (0)