From: Charlie Jenkins <charlie@rivosinc.com>
To: Masahiro Yamada <masahiroy@kernel.org>
Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
rust-for-linux@vger.kernel.org, cocci@inria.fr
Subject: Re: [PATCH v2 05/11] kbuild: change working directory to external module directory with M=
Date: Wed, 4 Dec 2024 22:27:34 -0800 [thread overview]
Message-ID: <Z1FH1qIc7nErHVZ2@ghost> (raw)
In-Reply-To: <CAK7LNAR0jmafdi7GAxq58AU-=tuWdVas02q=sQXC4zaOg4JcEA@mail.gmail.com>
On Thu, Dec 05, 2024 at 11:48:08AM +0900, Masahiro Yamada wrote:
> On Thu, Dec 5, 2024 at 8:35 AM Charlie Jenkins <charlie@rivosinc.com> wrote:
> >
> > On Sun, Nov 10, 2024 at 10:34:33AM +0900, Masahiro Yamada wrote:
> > > Currently, Kbuild always operates in the output directory of the kernel,
> > > even when building external modules. This increases the risk of external
> > > module Makefiles attempting to write to the kernel directory.
> > >
> > > This commit switches the working directory to the external module
> > > directory, allowing the removal of the $(KBUILD_EXTMOD)/ prefix from
> > > some build artifacts.
> > >
> > > The command for building external modules maintains backward
> > > compatibility, but Makefiles that rely on working in the kernel
> > > directory may break. In such cases, $(objtree) and $(srctree) should
> > > be used to refer to the output and source directories of the kernel.
> > >
> > > The appearance of the build log will change as follows:
> > >
> > > [Before]
> > >
> > > $ make -C /path/to/my/linux M=/path/to/my/externel/module
> > > make: Entering directory '/path/to/my/linux'
> > > CC [M] /path/to/my/externel/module/helloworld.o
> > > MODPOST /path/to/my/externel/module/Module.symvers
> > > CC [M] /path/to/my/externel/module/helloworld.mod.o
> > > CC [M] /path/to/my/externel/module/.module-common.o
> > > LD [M] /path/to/my/externel/module/helloworld.ko
> > > make: Leaving directory '/path/to/my/linux'
> > >
> > > [After]
> > >
> > > $ make -C /path/to/my/linux M=/path/to/my/externel/module
> > > make: Entering directory '/path/to/my/linux'
> > > make[1]: Entering directory '/path/to/my/externel/module'
> > > CC [M] helloworld.o
> > > MODPOST Module.symvers
> > > CC [M] helloworld.mod.o
> > > CC [M] .module-common.o
> > > LD [M] helloworld.ko
> > > make[1]: Leaving directory '/path/to/my/externel/module'
> > > make: Leaving directory '/path/to/my/linux'
> > >
> > > Printing "Entering directory" twice is cumbersome. This will be
> > > addressed later.
> >
> > This change has caused O=<relative directory> to fail.
> >
> > For example:
> >
> > make O=build defconfig
> > make -j$(nproc) V=1 O=build bindeb-pkg
> >
> > outputs:
> >
> > make ARCH=x86 KERNELRELEASE=6.13.0-rc1 KBUILD_BUILD_VERSION=3 run-command KBUILD_RUN_COMMAND='+$(srctree)/scripts/package/builddeb linux-libc-dev'
> > dh_installchangelogs -plinux-image-6.13.0-rc1
> > ../scripts/package/builddeb linux-headers-6.13.0-rc1
> > dh_compress -plinux-image-6.13.0-rc1
> > dh_fixperms -plinux-image-6.13.0-rc1
> > dh_gencontrol -plinux-image-6.13.0-rc1 -- -fdebian/image.files
> > Rebuilding host programs with x86_64-linux-gnu-gcc...
> > make[6]: Entering directory '/scratch/kernels/linux/build'
> > /scratch/kernels/linux/Makefile:190: *** specified kernel directory "build" does not exist. Stop.
> >
> > It is stepping into this directory and then trying to find the directory
> > it just stepped into so $(realpath $(KBUILD_OUTPUT)) returns an empty
> > string.
> >
> > Using an absolute directory resolves this problem, but I believe it
> > shouldn't be necessary.
>
>
> Agree.
>
> I will apply the following fixup unless I have a better idea.
>
>
>
>
> diff --git a/scripts/package/install-extmod-build
> b/scripts/package/install-extmod-build
> index 64d958ee45f3..85af1573db31 100755
> --- a/scripts/package/install-extmod-build
> +++ b/scripts/package/install-extmod-build
> @@ -69,7 +69,7 @@ if [ "${CC}" != "${HOSTCC}" ]; then
> #
> # Use the single-target build to avoid the modpost invocation, which
> # would overwrite Module.symvers.
> - "${MAKE}" HOSTCC="${CC}" KBUILD_EXTMOD="${destdir}" scripts/
> + "${MAKE}" O=. HOSTCC="${CC}" KBUILD_EXTMOD="${destdir}" scripts/
>
> cat <<-'EOF' > "${destdir}/scripts/Kbuild"
> subdir-y := basic
> @@ -78,7 +78,7 @@ if [ "${CC}" != "${HOSTCC}" ]; then
> EOF
>
> # Run once again to rebuild scripts/basic/ and scripts/mod/modpost.
> - "${MAKE}" HOSTCC="${CC}" KBUILD_EXTMOD="${destdir}" scripts/
> + "${MAKE}" O=. HOSTCC="${CC}" KBUILD_EXTMOD="${destdir}" scripts/
>
> rm -f "${destdir}/Kbuild" "${destdir}/scripts/Kbuild"
> fi
>
Looks fine to me :)
If this is what you decide on, feel free to add my tags.
Tested-by: Charlie Jenkins <charlie@rivosinc.com>
Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>
>
>
> --
> Best Regards
> Masahiro Yamada
next prev parent reply other threads:[~2024-12-05 6:27 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-10 1:34 [PATCH v2 00/11] kbuild: support building external modules in a separate build directory Masahiro Yamada
2024-11-10 1:34 ` [PATCH v2 01/11] kbuild: replace two $(abs_objtree) with $(CURDIR) in top Makefile Masahiro Yamada
2024-11-10 1:34 ` [PATCH v2 02/11] kbuild: add $(objtree)/ prefix to some in-kernel build artifacts Masahiro Yamada
2024-11-10 1:34 ` [PATCH v2 03/11] kbuild: rename abs_objtree to abs_output Masahiro Yamada
2024-11-10 1:34 ` [PATCH v2 04/11] kbuild: use 'output' variable to create the output directory Masahiro Yamada
2024-11-10 1:34 ` [PATCH v2 05/11] kbuild: change working directory to external module directory with M= Masahiro Yamada
2024-11-18 14:47 ` Nicolas Schier
2024-11-18 17:02 ` Masahiro Yamada
2024-11-27 15:29 ` Nicolas Schier
2024-11-27 23:15 ` Masahiro Yamada
2024-12-04 20:51 ` Alison Schofield
2024-12-05 2:33 ` Masahiro Yamada
2024-12-04 23:35 ` Charlie Jenkins
2024-12-05 2:48 ` Masahiro Yamada
2024-12-05 6:27 ` Charlie Jenkins [this message]
2024-12-09 13:46 ` Thorsten Blum
2024-12-09 13:55 ` Thorsten Blum
2024-12-10 10:47 ` Masahiro Yamada
2024-12-10 11:06 ` Thorsten Blum
2024-12-11 2:36 ` Masahiro Yamada
2024-12-10 15:34 ` Jon Hunter
2024-12-11 2:39 ` Masahiro Yamada
2024-12-11 12:21 ` Jon Hunter
2024-12-12 2:08 ` Masahiro Yamada
2024-12-12 6:00 ` Jon Hunter
2024-12-12 15:49 ` Masahiro Yamada
2025-01-27 23:08 ` Qu Wenruo
2024-11-10 1:34 ` [PATCH v2 06/11] kbuild: remove extmod_prefix, MODORDER, MODULES_NSDEPS variables Masahiro Yamada
2024-11-10 1:34 ` [PATCH v2 07/11] kbuild: support building external modules in a separate build directory Masahiro Yamada
2024-11-10 1:34 ` [PATCH v2 08/11] kbuild: support -fmacro-prefix-map for external modules Masahiro Yamada
2024-11-10 1:34 ` [PATCH v2 09/11] kbuild: use absolute path in the generated wrapper Makefile Masahiro Yamada
2024-11-10 1:34 ` [PATCH v2 10/11] kbuild: make wrapper Makefile more convenient for external modules Masahiro Yamada
2024-11-10 1:34 ` [PATCH v2 11/11] kbuild: allow to start building external modules in any directory Masahiro Yamada
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z1FH1qIc7nErHVZ2@ghost \
--to=charlie@rivosinc.com \
--cc=cocci@inria.fr \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masahiroy@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).