[PATCH v2] kbuild: Avoid including architecture-specific Makefile twice

Bryan Brattlof bb at ti.com
Fri Jul 11 18:08:10 CEST 2025


On July 11, 2025 thus sayeth Yao Zi:
> Stranges errors are observed when building U-Boot master for almost any
> RISC-V board, the messages are in two types, one is about duplicated
> symbols,
> 
> 	u-boot/arch/riscv/cpu//mtrap.S:32: multiple definition of `trap_entry';
> 	arch/riscv/cpu/mtrap.o: u-boot/arch/riscv/cpu//mtrap.S:32: first defined here
> 
> and the other is fixdep's complaint about missing dependency files,
> 
> 	fixdep: error opening file: arch/riscv/cpu/.mtrap.o.d: No such file or directory
> 	fixdep: error opening file: arch/riscv/cpu//.start.o.d: No such file or directory
> 
> where the latter could only be reproduced when building parallelly.
> 
> Both the two types of errors are about files in arch/riscv/cpu, and
> there's a suspicious slash character in the reported path. Looking
> through RISC-V-specific Makefiles, there's only one place that may
> expand to such a path,
> 
> 	libs-y += arch/riscv/cpu/$(CPU)/
> 
> The right hand expands to "arch/riscv/cpu//" if $(CPU) isn't defined at
> the time of including. With some debug statement added to
> arch/riscv/Makefile, the output proves that arch/riscv/Makefile is
> included twice, once with $(CPU) undefined and once defined correctly
> according to CONFIG_SYS_CPU.
> 
> Futher bisecting shows an extra include statement against
> arch/$(SRCARCH)/Makefile is added in earlier bump of Kbuild system. But
> the statement is evaluated before config.mk is included and definition
> of $(CPU), causing objects in arch/riscv/cpu/ are built and linked twice
> (once as "arch/riscv/cpu/*", and once as "arch/riscv/cpu//*"), resulting
> in the error.
> 
> Let's simply remove the extra include to fix these nasty errors. For
> config targets, bumping Kbuild also introduced a new include to
> arch/$(SRCARCH)/Makefile, which is removed as well for consistency.
> 
> Fixes: 5f520875bdf ("kbuild: Bump the build system to 5.1")
> Signed-off-by: Yao Zi <ziyao at disroot.org>
> Reviewed-by: Ilias Apalodimas <ilias.apalodimas at linaro.org>
> ---
> 
> Changes from v1
> - Don't describe the problem as RISC-V-specific since it may affect ARM
>   builds as well.
> - Prevent config targets from including for architecture-specific
>   Makefile as well for consistency.
> - Add comments to explain the removal.
> - Link to v1: https://lore.kernel.org/u-boot/20250709161418.21287-2-ziyao@disroot.org/
> 
>  Makefile | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)

Works for arch/arm/mach-k3 thanks for fixing this

Tested-by: Bryan Brattlof <bb at ti.com>

~Bryan


More information about the U-Boot mailing list