Skip to contentSkip to conversation

arm: Make the LTO conditions in arch/arm/config.mk take effect

PATCH Superseded Josef Schlehofer 2 participants 5 messages Oct 13 – Oct 28

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover arm: Make the LTO conditions in arch/arm/config.mk take effect

As requested in the review of the mpc85xx LTO series [1], this sets LTO_ENABLE before the top Makefile reads arch/arm/config.mk, so that U-Boot proper of the ARM LTO boards is no longer built with -ffunction-sections -fdata-sections.

The first patch keeps --gc-sections, which the same change would otherwise drop for LTO with the private libgcc, making most of these images larger.

[1] https://lore.kernel.org/u-boot/20261012190720.GF3722450@bill-the-cat/

Josef Schlehofer (2):
arm: Keep --gc-sections with LTO
Makefile: Set LTO_ENABLE before including config.mk

 Makefile           | 14 +++++++-------
 arch/arm/config.mk |  2 --
 2 files changed, 7 insertions(+), 9 deletions(-)

base-commit: 5e3b01c8466dbe45cd6a06299f8f4c7e8c1c2363

Signature · 1 line
2.54.0 (Apple Git-157)
#1 lore raw

PATCH 1/2 arm: Keep --gc-sections with LTO

Commit 34ccadcd3334 ("ARM: don't use --gc-sections with LTO when using private libgcc") left out --gc-sections for LTO builds that use the private libgcc. Since commit a55014d09b29 ("Makefile: Allow LTO to be disabled for a build"), the condition tests LTO_ENABLE, which the top Makefile sets only after it has read arch/arm/config.mk, so U-Boot proper has been linked with --gc-sections ever since.

Once the next patch sets LTO_ENABLE in time, the condition would take effect again. U-Boot proper would then grow on most of these boards and keep the .discard.addressable section of keep-syms-lto.o in its ELF file. Keep --gc-sections for all builds; this changes no image on main.

Cc Tom Rini <[email protected]>
Cc Marek Behún <[email protected]>
Cc Simon Glass <[email protected]>

---
With Debian's GCC 14.2 and the next patch, but without this one, U-Boot proper grows on 18 of the 25 ARM LTO defconfigs that use the private libgcc, by up to 6728 bytes. With both patches, all 25 shrink by 896 to 4512 bytes.

---
 arch/arm/config.mk | 2 --
 1 file changed, 2 deletions(-)
arch/arm/config.mk +0 -2
index bce9a31e966..a10b2022d4e 100644
@@ -13,9 +13,7 @@ CFLAGS_NON_EFI := -fno-pic $(FIXED_REG) -ffunction-sections -fdata-sections \
 		  -fstack-protector-strong
 CFLAGS_EFI := -fpic -fshort-wchar
 
-ifneq ($(LTO_ENABLE)$(CONFIG_USE_PRIVATE_LIBGCC),yy)
 LDFLAGS_FINAL += --gc-sections
-endif
 
 ifneq ($(LTO_ENABLE),y)
 PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections
Signature · 1 line
2.54.0 (Apple Git-157)
#2 lore raw

PATCH 2/2 Makefile: Set LTO_ENABLE before including config.mk

In reply to Josef Schlehofer

Commit a55014d09b29 ("Makefile: Allow LTO to be disabled for a build") made the condition in arch/arm/config.mk that leaves out -ffunction-sections -fdata-sections with LTO test LTO_ENABLE. The top Makefile, however, sets LTO_ENABLE only after it has included config.mk, which reads arch/$(ARCH)/config.mk, so for U-Boot proper the condition has seen an empty LTO_ENABLE since then. The xPL builds are not affected, as scripts/Makefile.xpl adds these flags for them anyway.

Set LTO_ENABLE before config.mk is included.

Fixes a55014d09b29 ("Makefile: Allow LTO to be disabled for a build")
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Cc Marek Behún <[email protected]>

---
As requested in
https://lore.kernel.org/u-boot/20261012190720.GF3722450@bill-the-cat/

With Debian's GCC 14.2, this changes u-boot-nodtb.bin of the 27 ARM LTO defconfigs that build on main by -7720 to +2144 bytes; the 22 of them that use the private libgcc all shrink. Their SPLs do not change, and neither does sandbox, whose config.mk does not test LTO_ENABLE.

The other three ARM LTO defconfigs, imx6dl_mamoj, phycore-rk3288 and turris_omnia, do not build on main with Debian's GCC 14.2, with or without this patch. "Makefile: Pass -static to the LTO link", sent separately, makes them build; with it, this patch changes their u-boot-nodtb.bin by -4512, -4112 and -3560 bytes, and turris_omnia u-boot-with-spl.kwb goes from 976640 to 973056 bytes, against a limit of 983040 bytes.

---
 Makefile | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
Makefile +7 -7
index 6303a0cca6a..547053d7bab 100644
@@ -819,6 +819,13 @@ u-boot.cfg spl/u-boot.cfg tpl/u-boot.cfg vpl/u-boot.cfg:
 -include include/autoconf.mk
 -include include/autoconf.mk.dep
 
+export LTO_ENABLE
+
+# This is y if LTO is enabled for this build. See NO_LTO=1 to disable LTO
+ifeq ($(NO_LTO),)
+LTO_ENABLE=$(if $(CONFIG_LTO),y)
+endif
+
 # We want to include arch/$(ARCH)/config.mk only when include/config/auto.conf
 # is up-to-date. When we switch to a different board configuration, old CONFIG
 # macros are still remaining in include/config/auto.conf. Without the following
@@ -858,13 +865,6 @@ export CFLAGS_EFI	# Compiler flags to add when building EFI app
 export CFLAGS_NON_EFI	# Compiler flags to remove when building EFI app
 export EFI_TARGET	# binutils target if EFI is natively supported
 
-export LTO_ENABLE
-
-# This is y if LTO is enabled for this build. See NO_LTO=1 to disable LTO
-ifeq ($(NO_LTO),)
-LTO_ENABLE=$(if $(CONFIG_LTO),y)
-endif
-
 # If board code explicitly specified LDSCRIPT or CONFIG_SYS_LDSCRIPT, use
 # that (or fail if absent).  Otherwise, search for a linker script in a
 # standard location.
Signature · 1 line
2.54.0 (Apple Git-157)
#3 lore raw

Re: [PATCH 2/2] Makefile: Set LTO_ENABLE before including config.mk

Quoted 8 lines · Josef Schlehofer

Commit a55014d09b29 ("Makefile: Allow LTO to be disabled for a build") made the condition in arch/arm/config.mk that leaves out -ffunction-sections -fdata-sections with LTO test LTO_ENABLE. The top Makefile, however, sets LTO_ENABLE only after it has included config.mk, which reads arch/$(ARCH)/config.mk, so for U-Boot proper the condition has seen an empty LTO_ENABLE since then. The xPL builds are not affected, as scripts/Makefile.xpl adds these flags for them anyway.

Quoted 7 lines

Set LTO_ENABLE before config.mk is included.

Fixes a55014d09b29 ("Makefile: Allow LTO to be disabled for a build")
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Cc Marek Behún <[email protected]>

This breaks, among other platforms, am64x_evm_r5
+(am64x_evm_r5) /home/trini/.buildman-toolchains/gcc-14.2.0-nolibc/arm-linux-gnueabi/bin/../lib/gcc/arm-linux-gnueabi/14.2.0/../../../../arm-linux-gnueabi/bin/ld: arch/arm/lib/cache-cp15.o: in function `mmu_set_region_dcache_behaviour':
+(am64x_evm_r5) arch/arm/lib/cache-cp15.c:331:(.text+0x8c): undefined reference to `mmu_set_region_dcache_behaviour_phys'
+(am64x_evm_r5) collect2: error: ld returned 1 exit status
+(am64x_evm_r5) make[1]: *** [Makefile:2131: u-boot] Error 1
+(am64x_evm_r5) make: *** [Makefile:189: __sub-make] Error 2

Signature · 1 line
Tom
#4 lore raw

Re: [PATCH 2/2] Makefile: Set LTO_ENABLE before including config.mk

Oops! That should not have happen. So sorry and thanks for spotting this.

I fixed it in v2 (patch 1/5) and checked that all 208 ARM LTO boards build, am64x_evm_r5 included:
https://lore.kernel.org/u-boot/[email protected]/

Hopefully, this time it is alright.

~ Josef

út 20. 10. 2026 v 23:28 odesílatel Tom Rini <[email protected]> napsal:

Quoted 28 lines · Josef Schlehofer
Quoted 9 lines

Commit a55014d09b29 ("Makefile: Allow LTO to be disabled for a build") made the condition in arch/arm/config.mk that leaves out -ffunction-sections -fdata-sections with LTO test LTO_ENABLE. The top Makefile, however, sets LTO_ENABLE only after it has included config.mk, which reads arch/$(ARCH)/config.mk, so for U-Boot proper the condition has seen an empty LTO_ENABLE since then. The xPL builds are not affected, as scripts/Makefile.xpl adds these flags for them anyway.

Quoted 7 lines

Set LTO_ENABLE before config.mk is included.

Fixes a55014d09b29 ("Makefile: Allow LTO to be disabled for a build")
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Cc Marek Behún <[email protected]>

This breaks, among other platforms, am64x_evm_r5

(quoted diff) +5 -1
+(am64x_evm_r5) /home/trini/.buildman-toolchains/gcc-14.2.0-nolibc/arm-linux-gnueabi/bin/../lib/gcc/arm-linux-gnueabi/14.2.0/../../../../arm-linux-gnueabi/bin/ld: arch/arm/lib/cache-cp15.o: in function `mmu_set_region_dcache_behaviour':
+(am64x_evm_r5) arch/arm/lib/cache-cp15.c:331:(.text+0x8c): undefined reference to `mmu_set_region_dcache_behaviour_phys'
+(am64x_evm_r5) collect2: error: ld returned 1 exit status
+(am64x_evm_r5) make[1]: *** [Makefile:2131: u-boot] Error 1
+(am64x_evm_r5) make: *** [Makefile:189: __sub-make] Error 2
 
--

Tom