Skip to contentSkip to conversation

lto.inc: introduce LTO_DEFAULT variable to support per-package overrides with Clang

PATCH New [email protected] 1 participant 1 message Jan 30

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lto.inc: introduce LTO_DEFAULT variable to support per-package overrides with Clang

From: "mark.yang" <[email protected]>

Currently, LTO variable is set with a toolchain-clang override directly.

This causes priority issues where package-specific overrides (e.g., LTO:pn-perl = "") are ignored when the Clang toolchain is active, making it difficult to disable LTO for specific failing recipes.

This patch refactors the logic by introducing an intermediate LTO_DEFAULT variable.
- LTO_DEFAULT handles the toolchain-specific flags (GCC vs Clang).
- LTO is assigned LTO_DEFAULT as a default value.

This structure allows LTO to be cleanly overridden by recipe-specific overrides (like pn-${PN}) regardless of the active toolchain.

Added a toolchain-gcc override for alsa-lib because -flto-partition=none is not supported by Clang.

---
 meta/conf/distro/include/lto.inc | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
meta/conf/distro/include/lto.inc +5 -3
index 227f0c5c2a1..8752249685a 100644
@@ -28,7 +28,7 @@ LTO:pn-grub-efi = ""
 # Custom LTO flags
 # disable partitioning/streaming algorithm since its uses ASM
 # constructs not compatible with lto
-LTOEXTRA:pn-alsa-lib = "-flto-partition=none"
+LTOEXTRA:pn-alsa-lib:toolchain-gcc = "-flto-partition=none"
 
 LTOEXTRA ?= ""
 
@@ -43,9 +43,11 @@ LTOEXTRA ?= ""
 # -fuse-linker-plugin
 # ensures that libraries participate in LTO by supplying intermediate
 # code from .a files to linker
-LTO ?= "-flto -ffat-lto-objects -fuse-linker-plugin ${LTOEXTRA}"
+LTO_DEFAULT = "-flto -ffat-lto-objects -fuse-linker-plugin ${LTOEXTRA}"
 
-LTO:toolchain-clang = "${@bb.utils.contains('DISTRO_FEATURES', 'thin-lto', '-flto=thin ${LTOEXTRA}', '-flto ${LTOEXTRA}', d)}"
+LTO_DEFAULT:toolchain-clang = "${@bb.utils.contains('DISTRO_FEATURES', 'thin-lto', '-flto=thin ${LTOEXTRA}', '-flto ${LTOEXTRA}', d)}"
+
+LTO ?= "${LTO_DEFAULT}"
 
 SELECTED_OPTIMIZATION:append = "${@bb.utils.contains('DISTRO_FEATURES', 'lto', ' ${LTO}', '', d)}"
 TARGET_LDFLAGS:append:class-target = "${@bb.utils.contains('DISTRO_FEATURES', 'lto', ' ${LTO}', '', d)}"