Skip to contentSkip to conversation

kbuild: rpm-pkg: fix build error when _arch is undefined

PATCH In review Masahiro Yamada 2 participants 8 messages Jul 14, 2022 – Jul 16, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 kbuild: rpm-pkg: fix build error when _arch is undefined

Cross-building (bin)rpm-pkg fails on several architectures.

For example, 'make ARCH=arm binrpm-pkg' fails like follows:

sh ./scripts/package/mkspec prebuilt > ./binkernel.spec
rpmbuild --define "_builddir ." --target \
arm -bb ./binkernel.spec
Building target platforms: arm
Building for target arm
warning: line 19: It's not recommended to have unversioned Obsoletes: Obsoletes: kernel-headers
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.0S8t2F
+ umask 022
+ cd .
+ mkdir -p /home/masahiro/rpmbuild/BUILDROOT/kernel-5.19.0_rc6-19.%{_arch}/boot
+ make -f ./Makefile image_name
+ cp arch/arm/boot/zImage /home/masahiro/rpmbuild/BUILDROOT/kernel-5.19.0_rc6-19.%{_arch}/boot/vmlinuz-5.19.0-rc6
+ make -f ./Makefile INSTALL_MOD_PATH=/home/masahiro/rpmbuild/BUILDROOT/kernel-5.19.0_rc6-19.%{_arch} modules_install
make[3]: *** No rule to make target '/home/masahiro/rpmbuild/BUILDROOT/kernel-5.19.0_rc6-19.arch/arm/crypto/aes-arm-bs.ko{_arch}/lib/modules/5.19.0-rc6/kernel/%', needed by '__modinst'. Stop. make[2]: *** [Makefile:1768: modules_install] Error 2
error: Bad exit status from /var/tmp/rpm-tmp.0S8t2F (%install)

By default, 'buildroot' contains %{_arch} (see /usr/lib/rpm/macros).

_arch is generally defined in /usr/lib/rpm/platforms/*/macros, where the platform sub-directory is specified by --target= option for cross builds.

If the given arch does not exist, %{_arch} is not expanded. In the example above, --target=arm is passed to rpmbuild, but /usr/lib/rpm/platforms/arm-linux/ does not exist.

The '%' character in the path confuses GNU make and rpmbuild.

The same occurs for such architectures as csky, microblaze, nios2, etc.

Define _arch if it has not been defined.

---

 scripts/package/mkspec | 3 +++
 1 file changed, 3 insertions(+)
scripts/package/mkspec +3 -0
index 7c477ca7dc98..8fa7c5b8a1a1 100755
@@ -49,6 +49,9 @@ sed -e '/^DEL/d' -e 's/^\t*//' <<EOF
 	URL: https://www.kernel.org
 $S	Source: kernel-$__KERNELRELEASE.tar.gz
 	Provides: $PROVIDES
+	# $UTS_MACHINE as a fallback of _arch in case
+	# /usr/lib/rpm/platform/*/macros was not included.
+	%define _arch %{?_arch:$UTS_MACHINE}
 	%define __spec_install_post /usr/lib/rpm/brp-compress || :
 	%define debug_package %{nil}
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/4 kbuild: rpm-pkg: pass 'linux' to --target option of rpmbuild

Presumably, _target_os is defined even if the --target flag does not specify it, but it is better to make it explicit.

---

 scripts/Makefile.package | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/Makefile.package +2 -2
index 77b612183c08..5017f6b2da80 100644
@@ -56,7 +56,7 @@ rpm-pkg:
 	$(MAKE) clean
 	$(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
 	$(call cmd,src_tar,$(KERNELPATH),kernel.spec)
-	+rpmbuild $(RPMOPTS) --target $(UTS_MACHINE) -ta $(KERNELPATH).tar.gz \
+	+rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -ta $(KERNELPATH).tar.gz \
 	--define='_smp_mflags %{nil}'
 
 # binrpm-pkg
@@ -66,7 +66,7 @@ binrpm-pkg:
 	$(MAKE) -f $(srctree)/Makefile
 	$(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
 	+rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
-		$(UTS_MACHINE) -bb $(objtree)/binkernel.spec
+		$(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec
 
 PHONY += deb-pkg
 deb-pkg:
Signature · 1 line
2.34.1
#2 lore raw

PATCH 3/4 kbuild: error out if $(KBUILD_EXTMOD) contains % or :

In reply to Masahiro Yamada

If the directory pass given to KBUILD_EXTMOD (or M=) contains % or :, the module fails to build.

% is used in pattern rules, and : as the separator of dependencies.

Bail out with a clearer error message.

---

 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Makefile +3 -0
index faa4880f25f7..ecda62e27553 100644
@@ -129,6 +129,9 @@ endif
 $(if $(word 2, $(KBUILD_EXTMOD)), \
 	$(error building multiple external modules is not supported))
 
+$(foreach x, % :, $(if $(findstring $x, $(KBUILD_EXTMOD)), \
+	$(error module directory path cannot contain '$x')))
+
 # Remove trailing slashes
 ifneq ($(filter %/, $(KBUILD_EXTMOD)),)
 KBUILD_EXTMOD := $(shell dirname $(KBUILD_EXTMOD).)
Signature · 1 line
2.34.1
Reviewed-by on v1 3/4
#3 lore raw

Re: [PATCH 3/4] kbuild: error out if $(KBUILD_EXTMOD) contains % or :

Quoted 9 lines · Masahiro Yamada

If the directory pass given to KBUILD_EXTMOD (or M=) contains % or :, the module fails to build.

% is used in pattern rules, and : as the separator of dependencies.

Bail out with a clearer error message.

---

#4 lore raw

Re: [PATCH 3/4] kbuild: error out if $(KBUILD_EXTMOD) contains % or :

In reply to Masahiro Yamada
Quoted 2 lines · Masahiro Yamada

If the directory pass given to KBUILD_EXTMOD (or M=) contains % or :,

This is a typo.

directory pass -> directory path

Quoted 29 lines

the module fails to build.

% is used in pattern rules, and : as the separator of dependencies.

Bail out with a clearer error message.

---

 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Makefile +3 -1
index faa4880f25f7..ecda62e27553 100644
@@ -129,6 +129,9 @@ endif
 $(if $(word 2, $(KBUILD_EXTMOD)), \
        $(error building multiple external modules is not supported))
 
+$(foreach x, % :, $(if $(findstring $x, $(KBUILD_EXTMOD)), \
+       $(error module directory path cannot contain '$x')))
+
 # Remove trailing slashes
 ifneq ($(filter %/, $(KBUILD_EXTMOD)),)
 KBUILD_EXTMOD := $(shell dirname $(KBUILD_EXTMOD).)
--

2.34.1

Signature · 2 lines
Best Regards
Masahiro Yamada
#5 lore raw

PATCH 4/4 kbuild: error out if $(INSTALL_MOD_PATH) contains % or :

In reply to Masahiro Yamada

If the directory pass given to INSTALL_MOD_PATH contains % or :, the module_install fails.

% is used in pattern rules, and : as the separator of dependencies.

Bail out with a clearer error message.

---

 scripts/Makefile.modinst | 3 +++
 1 file changed, 3 insertions(+)
scripts/Makefile.modinst +3 -0
index 16a02e9237d3..a4c987c23750 100644
@@ -18,6 +18,9 @@ INSTALL_MOD_DIR ?= extra
 dst := $(MODLIB)/$(INSTALL_MOD_DIR)
 endif
 
+$(foreach x, % :, $(if $(findstring $x, $(dst)), \
+	$(error module installation path cannot contain '$x')))
+
 suffix-y				:=
 suffix-$(CONFIG_MODULE_COMPRESS_GZIP)	:= .gz
 suffix-$(CONFIG_MODULE_COMPRESS_XZ)	:= .xz
Signature · 1 line
2.34.1
Reviewed-by on v1 4/4
#6 lore raw

Re: [PATCH 4/4] kbuild: error out if $(INSTALL_MOD_PATH) contains % or :

Quoted 9 lines · Masahiro Yamada

If the directory pass given to INSTALL_MOD_PATH contains % or :, the module_install fails.

% is used in pattern rules, and : as the separator of dependencies.

Bail out with a clearer error message.

---

#7 lore raw

Re: [PATCH 4/4] kbuild: error out if $(INSTALL_MOD_PATH) contains % or :

In reply to Masahiro Yamada
Quoted 2 lines · Masahiro Yamada

If the directory pass given to INSTALL_MOD_PATH contains % or :,

A typo.

directory pass -> directory path

Quoted 29 lines

the module_install fails.

% is used in pattern rules, and : as the separator of dependencies.

Bail out with a clearer error message.

---

 scripts/Makefile.modinst | 3 +++
 1 file changed, 3 insertions(+)
scripts/Makefile.modinst +3 -1
index 16a02e9237d3..a4c987c23750 100644
@@ -18,6 +18,9 @@ INSTALL_MOD_DIR ?= extra
 dst := $(MODLIB)/$(INSTALL_MOD_DIR)
 endif
 
+$(foreach x, % :, $(if $(findstring $x, $(dst)), \
+       $(error module installation path cannot contain '$x')))
+
 suffix-y                               :=
 suffix-$(CONFIG_MODULE_COMPRESS_GZIP)  := .gz
 suffix-$(CONFIG_MODULE_COMPRESS_XZ)    := .xz
--

2.34.1

Signature · 2 lines
Best Regards
Masahiro Yamada