Makefile: Skip undefined symbols in keep-syms-lto.c
PATCH v2 1/1 Makefile: Skip undefined symbols in keep-syms-lto.c
The generated keep-syms-lto.c gets an __ADDRESSABLE() entry for every linker list symbol that nm prints, including symbols that the input objects only reference and nothing defines. keep-syms-lto.c is compiled without LTO, so such an entry becomes a reference that the link cannot resolve unless .discard.addressable is dropped.
Pass --defined-only to nm in the U-Boot and the xPL rule, so that only symbols defined by the scanned objects reach the generator.
---
Changes in v2:
- send it on its own, outside the mpc85xx LTO series
- move the turris_1x example below
With Debian's GCC 14.2 and the mpc85xx LTO series, turris_1x_sdcard shows both cases. _u_boot_list_2_driver_2_atsha204 is defined by the ATSHA204 driver and referenced by board/CZ.NIC/turris_atsha_otp.o in U-Boot proper, where its entry stays. The SPL only references it, as the driver is not part of the SPL, and there its entry goes away. The images do not change. Without this patch and without the /DISCARD/ rule that the series adds, the SPL link fails:
keep-syms-lto.c:5:(.discard.addressable+0xc):
undefined reference to `_u_boot_list_2_driver_2_atsha204'
On main, this changes no image of the ARM LTO defconfigs or of sandbox.
The option goes to the two callers rather than into the script, as the script runs the command it is given, which can start with a wrapper such as the ccache that buildman can put in front of the toolchain.
v1: https://lore.kernel.org/u-boot/[email protected]/
--- Makefile | 2 +- scripts/Makefile.xpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Makefile +1 -1
@@ -2076,7 +2076,7 @@ u-boot-keep-syms-lto_c := $(patsubst %.o,%.c,$(u-boot-keep-syms-lto)) quiet_cmd_keep_syms_lto = KSL $@ cmd_keep_syms_lto = \ - $(srctree)/scripts/gen_ll_addressable_symbols.sh $(NM) $^ > $@ + $(srctree)/scripts/gen_ll_addressable_symbols.sh $(NM) --defined-only $^ > $@ quiet_cmd_keep_syms_lto_cc = KSLCC $@ cmd_keep_syms_lto_cc = \
scripts/Makefile.xpl +1 -1
@@ -491,7 +491,7 @@ u-boot-spl-keep-syms-lto_c := \ quiet_cmd_keep_syms_lto = KSL $@ cmd_keep_syms_lto = \ - $(srctree)/scripts/gen_ll_addressable_symbols.sh $(NM) $^ > $@ + $(srctree)/scripts/gen_ll_addressable_symbols.sh $(NM) --defined-only $^ > $@ quiet_cmd_keep_syms_lto_cc = KSLCC $@ cmd_keep_syms_lto_cc = \
base-commit: 5e3b01c8466dbe45cd6a06299f8f4c7e8c1c2363
Signature · 1 line
2.54.0 (Apple Git-157)
Quoted 10 lines · Josef Schlehofer
The generated
keep-syms-lto.cgets an__ADDRESSABLE()entry for every linker list symbol that nm prints, including symbols that the input objects only reference and nothing defines.keep-syms-lto.cis compiled without LTO, so such an entry becomes a reference that the link cannot resolve unless .discard.addressable is dropped.Pass --defined-only to nm in the U-Boot and the xPL rule, so that only symbols defined by the scanned objects reach the generator.
[...]
Applied to u-boot/main, thanks!
[1/1] Makefile: Skip undefined symbols in keep-syms-lto.c
commit: 5ab784245a445d683709b9bf10dc04f580c13afe
Signature · 1 line
Tom