kbuild: Avoid including architecture-specific Makefile twice
PATCH 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. Note though this therotically affects all architectures, ones except RISC-V may not reproduce similar errors since there are no source files directly under arch/*/cpu, thus the extra include doesn't hurt.
---
I was surprised to see this morning's CI passed[1] even for these RISC-V boards. Builds for SiFive unleashed, QEMU S-Mode virt and Sipeed Lichee Pi 4A always fail on my machine with the latest master branch, thus maybe I missed some points when digging the issue, please correct me if so.
Makefile | 2 -- 1 file changed, 2 deletions(-)
Makefile +0 -2
@@ -724,8 +724,6 @@ endif ARCH_CPPFLAGS := ARCH_AFLAGS := ARCH_CFLAGS := -# Modified for U-Boot --include arch/$(SRCARCH)/Makefile 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 4 lines
Let's simply remove the extra include to fix these nasty errors. Note though this therotically affects all architectures, ones except RISC-V may not reproduce similar errors since there are no source files directly under
arch/*/cpu, thus the extra include doesn't hurt.
There's another unconditional include under ifeq ($(config-targets),1). Should we remove that as well?
The patch it self seems correct, but can you try removing the pre-existing include instead and add the config.mk inclusion? Something like
Makefile +2 -4
@@ -636,6 +636,7 @@ ifeq ($(config-targets),1) # KBUILD_DEFCONFIG may point out an alternative default configuration # used for 'make defconfig' # Modified for U-Boot +include config.mk -include arch/$(SRCARCH)/Makefile export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT
@@ -725,6 +726,7 @@ ARCH_CPPFLAGS := ARCH_AFLAGS := ARCH_CFLAGS := # Modified for U-Boot +include config.mk -include arch/$(SRCARCH)/Makefile ifeq ($(dot-config),1)
@@ -773,10 +775,6 @@ ifneq ($(wildcard $(KCONFIG_CONFIG)),) ifneq ($(wildcard include/config/auto.conf),) autoconf_is_old := $(shell find . -path ./$(KCONFIG_CONFIG) -newer \ include/config/auto.conf) -ifeq ($(autoconf_is_old),) -include config.mk -include arch/$(ARCH)/Makefile -endif endif endif
I prefer keeping the makefile closer to the kernel so we can sync it up easier in the future
Thanks for looking at this
/Ilias
Quoted 32 lines
Fixes 5f520875bdf ("kbuild: Bump the build system to 5.1")Signed-off-by Yao Zi <[email protected]>---
I was surprised to see this morning's CI passed[1] even for these RISC-V boards. Builds for SiFive unleashed, QEMU S-Mode virt and Sipeed Lichee Pi 4A always fail on my machine with the latest master branch, thus maybe I missed some points when digging the issue, please correct me if so.
Makefile | 2 -- 1 file changed, 2 deletions(-)Makefile +0
-3@@ -724,8 +724,6 @@ endif ARCH_CPPFLAGS := ARCH_AFLAGS := ARCH_CFLAGS := -# Modified for U-Boot --include arch/$(SRCARCH)/Makefile ifeq ($(dot-config),1) ifeq ($(may-sync-config),1) --2.50.0
Quoted 39 lines · Ilias Apalodimas
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
Quoted 4 lines
Let's simply remove the extra include to fix these nasty errors. Note though this therotically affects all architectures, ones except RISC-V may not reproduce similar errors since there are no source files directly under
arch/*/cpu, thus the extra include doesn't hurt.There's another unconditional include under ifeq ($(config-targets),1). Should we remove that as well?
I don't think it really matters. This include is only for config targets that don't actually run the build, but only descent into scripts/kconfig and generate a configuration. The include of arch/$(SRCARCH)/Makefile seems only for getting an appropriate name of defconfig (KBUILD_DEFCONFIG), as explained by the comment. It seems even okay to remove the include, as U-Boot has no architecture defining its own KBUILD_DEFCONFIG.
Quoted 16 lines
The patch it self seems correct, but can you try removing the pre-existing include instead and add the config.mk inclusion? Something like
Makefile +1
-0@@ -636,6 +636,7 @@ ifeq ($(config-targets),1) # KBUILD_DEFCONFIG may point out an alternative default configuration # used for 'make defconfig' # Modified for U-Boot +include config.mk -include arch/$(SRCARCH)/Makefile export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT
Makefile ARCH_CPPFLAGS := · line 729
Quoted 4 lines
Makefile +1
-0@@ -725,6 +726,7 @@ ARCH_CPPFLAGS := ARCH_AFLAGS := ARCH_CFLAGS := # Modified for U-Boot +include config.mk
I don't think config.mk could be included without making sure include/autoconf.mk is update to date, just as pointed out by the comment at line 768
> 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 > gimmick, wrong config.mk would be included leading nasty > warnings/errors.
And this change does cause errors if I use a defconfig, build U-Boot, then switch to another defconfig and build again, for example,
$ make ARCH=arm CROSS_COMPILE=arm-none-eabi- mx6sabresd_defconfig $ make ARCH=arm CROSS_COMPILE=arm-none-eabi- $ make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-musl- \ sifive_unleashed_defconfig $ make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-musl-
results in errors like
drivers/gpio/sifive-gpio.c:9:10: fatal error: asm/arch/gpio.h: No such file or directory 9 | #include <asm/arch/gpio.h> | ^~~~~~~~~~~~~~~~~ compilation terminated.
and ls -l arch/riscv/include/asm/arch shows the symlink points to a non-existing directory,
$ ls -l arch/riscv/include/asm/arch lrwxrwxrwx 1 ziyao ziyao 8 Jul 11 07:11 arch/riscv/include/asm/arch -> arch-mx6
it's really likely that the old auto.conf is evaluated, since arch-mx6 isn't a RISC-V thing.
Quoted 17 lines
Makefile +0
-4-include arch/$(SRCARCH)/Makefile ifeq ($(dot-config),1)@@ -773,10 +775,6 @@ ifneq ($(wildcard $(KCONFIG_CONFIG)),) ifneq ($(wildcard include/config/auto.conf),) autoconf_is_old := $(shell find . -path ./$(KCONFIG_CONFIG) -newer \ include/config/auto.conf) -ifeq ($(autoconf_is_old),) -include config.mk -include arch/$(ARCH)/Makefile -endif endif endifI prefer keeping the makefile closer to the kernel so we can sync it up easier in the future
Quoted 3 lines
Thanks for looking at this
/IliasQuoted 1 line
Regards,
Yao Zi
Ilias Apalodimas
Reviewed-byHi Yao,
Quoted 46 lines · Yao Zi
Quoted 44 lines · Ilias Apalodimas
Hi Yao,
Quoted 39 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. Note though this therotically affects all architectures, ones except RISC-V may not reproduce similar errors since there are no source files directly under
arch/*/cpu, thus the extra include doesn't hurt.
Quoted 4 lines
Quoted 2 lines
There's another unconditional include under ifeq ($(config-targets),1). Should we remove that as well?
I don't think it really matters.
It doesn't indeed. It's just for consistency
Quoted 23 lines
This include is only for config targets
that don't actually run the build, but only descent intoscripts/kconfigand generate a configuration. The include of arch/$(SRCARCH)/Makefile seems only for getting an appropriate name of defconfig (KBUILD_DEFCONFIG), as explained by the comment. It seems even okay to remove the include, as U-Boot has no architecture defining its ownKBUILD_DEFCONFIG.Quoted 15 lines
The patch it self seems correct, but can you try removing the pre-existing include instead and add the config.mk inclusion? Something like
Makefile +1
-0@@ -636,6 +636,7 @@ ifeq ($(config-targets),1) # KBUILD_DEFCONFIG may point out an alternative default configuration # used for 'make defconfig' # Modified for U-Boot +include config.mk -include arch/$(SRCARCH)/Makefile export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT
Quoted 10 lines
Makefile ARCH_CPPFLAGS := · line 729
Quoted 5 lines
Makefile +1
-0@@ -725,6 +726,7 @@ ARCH_CPPFLAGS := ARCH_AFLAGS := ARCH_CFLAGS := # Modified for U-Boot +include config.mkI don't think config.mk could be included without making sure
include/autoconf.mkis update to date, just as pointed out by the comment at line 768
Ok thanks for testing.
Can you send a v2 removing both of the erroneous -includes and add a comment, that we define it elsewhere for all the reasons you mentioned?
With that feel free to add
Thanks!
Quoted 55 lines
> We want to include arch/$(ARCH)/config.mk only when >
include/config/auto.confis up-to-date. When we switch to a > different board configuration, old CONFIG macros are still > remaining ininclude/config/auto.conf. Without the following > gimmick, wrong config.mk would be included leading nasty > warnings/errors.And this change does cause errors if I use a defconfig, build U-Boot, then switch to another defconfig and build again, for example,
$ make ARCH=arm CROSS_COMPILE=arm-none-eabi- mx6sabresd_defconfig $ make ARCH=arm CROSS_COMPILE=arm-none-eabi- $ make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-musl- \ sifive_unleashed_defconfig $ make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-musl-results in errors like
drivers/gpio/sifive-gpio.c:9:10: fatal error: asm/arch/gpio.h: No such file or directory 9 | #include <asm/arch/gpio.h> | ^~~~~~~~~~~~~~~~~ compilation terminated.and ls -l
arch/riscv/include/asm/archshows the symlink points to a non-existing directory,$ ls -l arch/riscv/include/asm/arch lrwxrwxrwx 1 ziyao ziyao 8 Jul 11 07:11 arch/riscv/include/asm/arch -> arch-mx6it's really likely that the old auto.conf is evaluated, since arch-mx6 isn't a RISC-V thing.
Quoted 17 lines
Makefile +0
-4-include arch/$(SRCARCH)/Makefile ifeq ($(dot-config),1)@@ -773,10 +775,6 @@ ifneq ($(wildcard $(KCONFIG_CONFIG)),) ifneq ($(wildcard include/config/auto.conf),) autoconf_is_old := $(shell find . -path ./$(KCONFIG_CONFIG) -newer \ include/config/auto.conf) -ifeq ($(autoconf_is_old),) -include config.mk -include arch/$(ARCH)/Makefile -endif endif endifI prefer keeping the makefile closer to the kernel so we can sync it up easier in the future
Quoted 3 lines
Thanks for looking at this
/IliasQuoted 1 line
Regards,
Yao Zi