From nobody Wed Nov 27 18:07:31 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B35C1474A4; Sun, 10 Nov 2024 01:37:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202621; cv=none; b=rd6qhNXUafIcERF0RUNvywHChny9jLnjmRh/sJhPsrC4PpWwLE4oBKUKr2sSjAn7Qk93RCnHMk8XEvokQcVzEVmLeTo+LpougB2mXQTONCcWKDFF7JI/v1W8CVHMVB6KQLKUWxXGbEm8hPxOFPiuT0xj3HVnpGv38ca+3wOKJxA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202621; c=relaxed/simple; bh=6i1YYERXoeK4NchDSXf7fBlYYK9mmrlTiZyLP0h7vss=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FmPoa18T2Iyla4yj6h9CDtucJFo91+9bWielrK4j4LbAsCk1UgU43Hj8e9mXwo1Uw8REyFgW/faE2C4rcUNxPpXQXFMunMIv3vNF4Mxvpx4pVcqexPiYzuyJ0KvcSbt3TYTU3BYULjLy1QzfDEZc1fuLzOp+UAvZRKSzNcjNz9c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iEh8VqkP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iEh8VqkP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1433C4CED4; Sun, 10 Nov 2024 01:36:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731202621; bh=6i1YYERXoeK4NchDSXf7fBlYYK9mmrlTiZyLP0h7vss=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iEh8VqkPzPuEgZNPH3JpYX1chq5w5yux7r0655wlb4LVkns8l8XFiXqVR5weZZ1v0 eMPSlFtK3Aq4//BKzP0+CHMzMoQUZLP2N5t2rry5sU237lkRIbIc+WsDDofMaGIYV0 haVd1X1MrizC+md/6FGJTuuwsbD9tx7d0f7pHwnnLbgE1CBQZkARbuvOpwWzg7K9jz QEo1zLsNmSJvg0NsqbMhXOXAy/YThw6WwQ58t/CqE8Y9BhZQri+alX87/9SQxBvsDs eLO0+qEMooWkS3o1ygYLpB0DJ2oJJRs792MCzfby3F/Bj1dFGdo9ahnZlwbBspUkru fGUjf/+t+/bFw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, cocci@inria.fr, Masahiro Yamada , Nicolas Schier Subject: [PATCH v2 02/11] kbuild: add $(objtree)/ prefix to some in-kernel build artifacts Date: Sun, 10 Nov 2024 10:34:30 +0900 Message-ID: <20241110013649.34903-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241110013649.34903-1-masahiroy@kernel.org> References: <20241110013649.34903-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" $(objtree) refers to the top of the output directory of kernel builds. This commit adds the explicit $(objtree)/ prefix to build artifacts needed for building external modules. This change has no immediate impact, as the top-level Makefile currently defines: objtree :=3D . This commit prepares for supporting the building of external modules in a different directory. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Changes in v2: - Add more $(objtree)/ to arch/*/Makefile Makefile | 10 +++++----- arch/arm/Makefile | 4 ++-- arch/arm64/Makefile | 2 +- arch/powerpc/Makefile | 4 ++-- arch/riscv/Makefile | 2 +- scripts/Kbuild.include | 2 +- scripts/Makefile.build | 4 ++-- scripts/Makefile.modfinal | 14 +++++++------- scripts/Makefile.modinst | 2 +- scripts/Makefile.modpost | 12 ++++++------ scripts/depmod.sh | 4 ++-- 11 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index 891d28e54791..9b8f4f4cb01b 100644 --- a/Makefile +++ b/Makefile @@ -354,7 +354,7 @@ else # !mixed-build include $(srctree)/scripts/Kbuild.include =20 # Read KERNELRELEASE from include/config/kernel.release (if it exists) -KERNELRELEASE =3D $(call read-file, include/config/kernel.release) +KERNELRELEASE =3D $(call read-file, $(objtree)/include/config/kernel.relea= se) KERNELVERSION =3D $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEV= EL),.$(SUBLEVEL)))$(EXTRAVERSION) export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION =20 @@ -720,7 +720,7 @@ endif export KBUILD_MODULES KBUILD_BUILTIN =20 ifdef need-config -include include/config/auto.conf +include $(objtree)/include/config/auto.conf endif =20 ifeq ($(KBUILD_EXTMOD),) @@ -783,13 +783,13 @@ else # !may-sync-config # and include/config/auto.conf but do not care if they are up-to-date. # Use auto.conf to show the error message =20 -checked-configs :=3D include/generated/autoconf.h include/generated/rustc_= cfg include/config/auto.conf +checked-configs :=3D $(addprefix $(objtree)/, include/generated/autoconf.h= include/generated/rustc_cfg include/config/auto.conf) missing-configs :=3D $(filter-out $(wildcard $(checked-configs)), $(checke= d-configs)) =20 ifdef missing-configs -PHONY +=3D include/config/auto.conf +PHONY +=3D $(objtree)/include/config/auto.conf =20 -include/config/auto.conf: +$(objtree)/include/config/auto.conf: @echo >&2 '***' @echo >&2 '*** ERROR: Kernel configuration is invalid. The following f= iles are missing:' @printf >&2 '*** - %s\n' $(missing-configs) diff --git a/arch/arm/Makefile b/arch/arm/Makefile index aafebf145738..00ca7886b18e 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -264,13 +264,13 @@ stack_protector_prepare: prepare0 -mstack-protector-guard=3Dtls \ -mstack-protector-guard-offset=3D$(shell \ awk '{if ($$2 =3D=3D "TSK_STACK_CANARY") print $$3;}'\ - include/generated/asm-offsets.h)) + $(objtree)/include/generated/asm-offsets.h)) else stack_protector_prepare: prepare0 $(eval SSP_PLUGIN_CFLAGS :=3D \ -fplugin-arg-arm_ssp_per_task_plugin-offset=3D$(shell \ awk '{if ($$2 =3D=3D "TSK_STACK_CANARY") print $$3;}'\ - include/generated/asm-offsets.h)) + $(objtree)/include/generated/asm-offsets.h)) $(eval KBUILD_CFLAGS +=3D $(SSP_PLUGIN_CFLAGS)) $(eval GCC_PLUGINS_CFLAGS +=3D $(SSP_PLUGIN_CFLAGS)) endif diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 9efd3f37c2fd..358c68565bfd 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -71,7 +71,7 @@ stack_protector_prepare: prepare0 -mstack-protector-guard-reg=3Dsp_el0 \ -mstack-protector-guard-offset=3D$(shell \ awk '{if ($$2 =3D=3D "TSK_STACK_CANARY") print $$3;}' \ - include/generated/asm-offsets.h)) + $(objtree)/include/generated/asm-offsets.h)) endif =20 ifeq ($(CONFIG_ARM64_BTI_KERNEL),y) diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile index bbfe4a1f06ef..321b596d2550 100644 --- a/arch/powerpc/Makefile +++ b/arch/powerpc/Makefile @@ -402,9 +402,9 @@ prepare: stack_protector_prepare PHONY +=3D stack_protector_prepare stack_protector_prepare: prepare0 ifdef CONFIG_PPC64 - $(eval KBUILD_CFLAGS +=3D -mstack-protector-guard-offset=3D$(shell awk '{= if ($$2 =3D=3D "PACA_CANARY") print $$3;}' include/generated/asm-offsets.h)) + $(eval KBUILD_CFLAGS +=3D -mstack-protector-guard-offset=3D$(shell awk '{= if ($$2 =3D=3D "PACA_CANARY") print $$3;}' $(objtree)/include/generated/asm= -offsets.h)) else - $(eval KBUILD_CFLAGS +=3D -mstack-protector-guard-offset=3D$(shell awk '{= if ($$2 =3D=3D "TASK_CANARY") print $$3;}' include/generated/asm-offsets.h)) + $(eval KBUILD_CFLAGS +=3D -mstack-protector-guard-offset=3D$(shell awk '{= if ($$2 =3D=3D "TASK_CANARY") print $$3;}' $(objtree)/include/generated/asm= -offsets.h)) endif endif =20 diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index d469db9f46f4..a08cfeb6cbf9 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -129,7 +129,7 @@ stack_protector_prepare: prepare0 -mstack-protector-guard-reg=3Dtp \ -mstack-protector-guard-offset=3D$(shell \ awk '{if ($$2 =3D=3D "TSK_STACK_CANARY") print $$3;}' \ - include/generated/asm-offsets.h)) + $(objtree)/include/generated/asm-offsets.h)) endif =20 # arch specific predefines for sparse diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index ed8a7493524b..8c311b997e24 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -205,7 +205,7 @@ if_changed_dep =3D $(if $(if-changed-cond),$(cmd_and_fi= xdep),@:) =20 cmd_and_fixdep =3D = \ $(cmd); \ - scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\ + $(objtree)/scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-targe= t).cmd;\ rm -f $(depfile) =20 # Usage: $(call if_changed_rule,foo) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 8f423a1faf50..64cd046f8fd8 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -34,7 +34,7 @@ subdir-asflags-y :=3D subdir-ccflags-y :=3D =20 # Read auto.conf if it exists, otherwise ignore --include include/config/auto.conf +-include $(objtree)/include/config/auto.conf =20 include $(srctree)/scripts/Kbuild.include include $(srctree)/scripts/Makefile.compiler @@ -107,7 +107,7 @@ cmd_cpp_i_c =3D $(CPP) $(c_flags) -o $@ $< $(obj)/%.i: $(obj)/%.c FORCE $(call if_changed_dep,cpp_i_c) =20 -genksyms =3D scripts/genksyms/genksyms \ +genksyms =3D $(objtree)/scripts/genksyms/genksyms \ $(if $(1), -T $(2)) \ $(if $(KBUILD_PRESERVE), -p) \ -r $(or $(wildcard $(2:.symtypes=3D.symref)), /dev/null) diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index 1482884ec3ca..6d8aa3059ee2 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -6,7 +6,7 @@ PHONY :=3D __modfinal __modfinal: =20 -include include/config/auto.conf +include $(objtree)/include/config/auto.conf include $(srctree)/scripts/Kbuild.include =20 # for c_flags @@ -37,15 +37,15 @@ quiet_cmd_ld_ko_o =3D LD [M] $@ cmd_ld_ko_o =3D \ $(LD) -r $(KBUILD_LDFLAGS) \ $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ - -T scripts/module.lds -o $@ $(filter %.o, $^) + -T $(objtree)/scripts/module.lds -o $@ $(filter %.o, $^) =20 quiet_cmd_btf_ko =3D BTF [M] $@ cmd_btf_ko =3D \ - if [ ! -f vmlinux ]; then \ + if [ ! -f $(objtree)/vmlinux ]; then \ printf "Skipping BTF generation for %s due to unavailability of vmlinux\= n" $@ 1>&2; \ else \ - LLVM_OBJCOPY=3D"$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) $(MODULE_PAHOLE= _FLAGS) --btf_base vmlinux $@; \ - $(RESOLVE_BTFIDS) -b vmlinux $@; \ + LLVM_OBJCOPY=3D"$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) $(MODULE_PAHOLE= _FLAGS) --btf_base $(objtree)/vmlinux $@; \ + $(RESOLVE_BTFIDS) -b $(objtree)/vmlinux $@; \ fi; =20 # Same as newer-prereqs, but allows to exclude specified extra dependencies @@ -57,8 +57,8 @@ if_changed_except =3D $(if $(call newer_prereqs_except,$(= 2))$(cmd-check), \ printf '%s\n' 'savedcmd_$@ :=3D $(make-cmd)' > $(dot-target).cmd, @:) =20 # Re-generate module BTFs if either module's .ko or vmlinux changed -%.ko: %.o %.mod.o $(extmod_prefix).module-common.o scripts/module.lds $(an= d $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),vmlinux) FORCE - +$(call if_changed_except,ld_ko_o,vmlinux) +%.ko: %.o %.mod.o $(extmod_prefix).module-common.o $(objtree)/scripts/modu= le.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),$(objtree)/= vmlinux) FORCE + +$(call if_changed_except,ld_ko_o,$(objtree)/vmlinux) ifdef CONFIG_DEBUG_INFO_BTF_MODULES +$(if $(newer-prereqs),$(call cmd,btf_ko)) endif diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index d97720943189..6fa9af4a25b4 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -6,7 +6,7 @@ PHONY :=3D __modinst __modinst: =20 -include include/config/auto.conf +include $(objtree)/include/config/auto.conf include $(srctree)/scripts/Kbuild.include =20 install-y :=3D diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 44936ebad161..12e7c15d099c 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -35,10 +35,10 @@ PHONY :=3D __modpost __modpost: =20 -include include/config/auto.conf +include $(objtree)/include/config/auto.conf include $(srctree)/scripts/Kbuild.include =20 -MODPOST =3D scripts/mod/modpost +MODPOST =3D $(objtree)/scripts/mod/modpost =20 modpost-args =3D \ $(if $(CONFIG_MODULES),-M) \ @@ -119,11 +119,11 @@ include $(kbuild-file) =20 output-symdump :=3D $(KBUILD_EXTMOD)/Module.symvers =20 -ifeq ($(wildcard Module.symvers),) -missing-input :=3D Module.symvers +ifeq ($(wildcard $(objtree)/Module.symvers),) +missing-input :=3D $(objtree)/Module.symvers else -modpost-args +=3D -i Module.symvers -modpost-deps +=3D Module.symvers +modpost-args +=3D -i $(objtree)/Module.symvers +modpost-deps +=3D $(objtree)/Module.symvers endif =20 modpost-args +=3D -e $(addprefix -i , $(KBUILD_EXTRA_SYMBOLS)) diff --git a/scripts/depmod.sh b/scripts/depmod.sh index e22da27fe13e..3c34fecacbc8 100755 --- a/scripts/depmod.sh +++ b/scripts/depmod.sh @@ -12,7 +12,7 @@ KERNELRELEASE=3D$1 =20 : ${DEPMOD:=3Ddepmod} =20 -if ! test -r System.map ; then +if ! test -r "${objtree}/System.map" ; then echo "Warning: modules_install: missing 'System.map' file. Skipping depmo= d." >&2 exit 0 fi @@ -25,7 +25,7 @@ if [ -z $(command -v $DEPMOD) ]; then exit 0 fi =20 -set -- -ae -F System.map +set -- -ae -F "${objtree}/System.map" if test -n "$INSTALL_MOD_PATH"; then set -- "$@" -b "$INSTALL_MOD_PATH" fi --=20 2.43.0