kbuild: Avoid including architecture-specific Makefile twice
PATCH v2 1/1 kbuild: Avoid including architecture-specific Makefile twice
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.
---
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/[email protected]/
Makefile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
Makefile +7 -4
@@ -635,8 +635,9 @@ ifeq ($(config-targets),1) # Read arch specific Makefile to set KBUILD_DEFCONFIG as needed. # KBUILD_DEFCONFIG may point out an alternative default configuration # used for 'make defconfig' -# Modified for U-Boot --include arch/$(SRCARCH)/Makefile +# Modified for U-Boot: we don't include arch/$(SRCARCH)/Makefile for config +# targets, which is useless since U-Boot has no architecture defining its own +# KBUILD_{DEF,K}CONFIG, or CROSS_COMPILE. export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT config: scripts_basic outputmakefile FORCE
@@ -724,8 +725,10 @@ endif ARCH_CPPFLAGS := ARCH_AFLAGS := ARCH_CFLAGS := -# Modified for U-Boot --include arch/$(SRCARCH)/Makefile +# Modified for U-Boot: we put off the include of arch/$(SRCARCH)/Makefile until +# making sure include/config/auto.conf is up-to-date and include of config.mk, +# because the architecture-specific Makefile may make use of variables defined +# in config.mk. See also the comment about autoconf_is_old. ifeq ($(dot-config),1) ifeq ($(may-sync-config),1)
Signature · 1 line
2.50.0
Hi Yao,
Quoted 35 lines · 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 hereand 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 directorywhere 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 thatarch/riscv/Makefileis included twice, once with $(CPU) undefined and once defined correctly according toCONFIG_SYS_CPU.Futher bisecting shows an extra include statement against arch/$(SRCARCH)/Makefile is added in earlier bump of
Kbuildsystem. But the statement is evaluated before config.mk is included and definition of $(CPU), causing objects inarch/riscv/cpu/are built and linked twice (once as "arch/riscv/cpu/*", and once as "arch/riscv/cpu//*"), resulting in the error.
Quoted 7 lines
Let's simply remove the extra include to fix these nasty errors. For config targets, bumping
Kbuildalso 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 <[email protected]>Reviewed-by Ilias Apalodimas <[email protected]>
This fixes the mx6sabresd_defconfig build, thanks:
Quoted 73 lines · 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 hereand 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 directorywhere 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 thatarch/riscv/Makefileis included twice, once with $(CPU) undefined and once defined correctly according toCONFIG_SYS_CPU.Futher bisecting shows an extra include statement against arch/$(SRCARCH)/Makefile is added in earlier bump of
Kbuildsystem. But the statement is evaluated before config.mk is included and definition of $(CPU), causing objects inarch/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
Kbuildalso 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 <[email protected]>Reviewed-by Ilias Apalodimas <[email protected]>---
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-specificMakefileas well for consistency.
- Add comments to explain the removal.
- Link to v1: https://lore.kernel.org/u-boot/[email protected]/Makefile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)Makefile +3
-2@@ -635,8 +635,9 @@ ifeq ($(config-targets),1) # Read arch specific Makefile to set KBUILD_DEFCONFIG as needed. # KBUILD_DEFCONFIG may point out an alternative default configuration # used for 'make defconfig' -# Modified for U-Boot --include arch/$(SRCARCH)/Makefile +# Modified for U-Boot: we don't include arch/$(SRCARCH)/Makefile for config +# targets, which is useless since U-Boot has no architecture defining its own +# KBUILD_{DEF,K}CONFIG, or CROSS_COMPILE. export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT config: scripts_basic outputmakefile FORCE@@ -724,8 +725,10 @@ endif ARCH_CPPFLAGS := ARCH_AFLAGS :=
Makefile endif · line 734
Quoted 10 lines
Makefile +4
-2ARCH_CFLAGS := -# Modified for U-Boot --include arch/$(SRCARCH)/Makefile +# Modified for U-Boot: we put off the include of arch/$(SRCARCH)/Makefile until +# making sure include/config/auto.conf is up-to-date and include of config.mk, +# because the architecture-specific Makefile may make use of variables defined +# in config.mk. See also the comment about autoconf_is_old. ifeq ($(dot-config),1) ifeq ($(may-sync-config),1)
Since Fabio confirmed this fixes his issue, I'd like one or two more tested-by's if I can before the end of the day when I'll apply this. Thanks!
Signature · 1 line
Tom
Michal Simek
Tested-byQuoted 83 lines · Tom Rini
Quoted 81 lines · 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 hereand 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 directorywhere 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 thatarch/riscv/Makefileis included twice, once with $(CPU) undefined and once defined correctly according toCONFIG_SYS_CPU.Futher bisecting shows an extra include statement against arch/$(SRCARCH)/Makefile is added in earlier bump of
Kbuildsystem. But the statement is evaluated before config.mk is included and definition of $(CPU), causing objects inarch/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
Kbuildalso 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 <[email protected]>Reviewed-by Ilias Apalodimas <[email protected]>---
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-specificMakefileas well for consistency.
- Add comments to explain the removal.
- Link to v1: https://lore.kernel.org/u-boot/[email protected]/Makefile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)Makefile +7
-4@@ -635,8 +635,9 @@ ifeq ($(config-targets),1) # Read arch specific Makefile to set KBUILD_DEFCONFIG as needed. # KBUILD_DEFCONFIG may point out an alternative default configuration # used for 'make defconfig' -# Modified for U-Boot --include arch/$(SRCARCH)/Makefile +# Modified for U-Boot: we don't include arch/$(SRCARCH)/Makefile for config +# targets, which is useless since U-Boot has no architecture defining its own +# KBUILD_{DEF,K}CONFIG, or CROSS_COMPILE. export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT config: scripts_basic outputmakefile FORCE@@ -724,8 +725,10 @@ endif ARCH_CPPFLAGS := ARCH_AFLAGS := ARCH_CFLAGS := -# Modified for U-Boot --include arch/$(SRCARCH)/Makefile +# Modified for U-Boot: we put off the include of arch/$(SRCARCH)/Makefile until +# making sure include/config/auto.conf is up-to-date and include of config.mk, +# because the architecture-specific Makefile may make use of variables defined +# in config.mk. See also the comment about autoconf_is_old.
Quoted 7 lines
Makefile endif · line 734
Quoted 2 lines
Makefile +0
-0ifeq ($(dot-config),1) ifeq ($(may-sync-config),1)Since Fabio confirmed this fixes his issue, I'd like one or two more tested-by's if I can before the end of the day when I'll apply this. Thanks!
Thanks,
Michal
On July 11, 2025 thus sayeth Yao Zi:
Quoted 51 lines
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 hereand 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 directorywhere 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 thatarch/riscv/Makefileis included twice, once with $(CPU) undefined and once defined correctly according toCONFIG_SYS_CPU.Futher bisecting shows an extra include statement against arch/$(SRCARCH)/Makefile is added in earlier bump of
Kbuildsystem. But the statement is evaluated before config.mk is included and definition of $(CPU), causing objects inarch/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
Kbuildalso 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 <[email protected]>Reviewed-by Ilias Apalodimas <[email protected]>---
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-specificMakefileas well for consistency.
- Add comments to explain the removal.
- Link to v1: https://lore.kernel.org/u-boot/[email protected]/
Quoted 2 lines
Makefile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
Works for arch/arm/mach-k3 thanks for fixing this
~Bryan
Quoted 8 lines · 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[...]
Applied to u-boot/master, thanks!
[1/1] kbuild: Avoid including architecture-specific Makefile twice
commit: e80998a77b97fa52e9321a56e004d8adfd8125d7
Signature · 1 line
Tom