From patchwork Thu Sep 19 17:37:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13807910 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 0DAC51A0718; Thu, 19 Sep 2024 17:37:46 +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=1726767467; cv=none; b=nugDieHbyiPbzLtUoSJiunewWO/zWa3jcdbszZ4LSBobwWbSqqImwDI5lP3xO9qMqru4g+n2KbkhUspG68zfZnyIOcvF/870jJJsjFrkHBB3tb/8jw8yt4HquFLf0OSBZf/iky46lnmyfhr+wI0hQ+zwqm1toXhDRUS/Ji6W5jM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726767467; c=relaxed/simple; bh=N/mW8g5kxumYZHOlcz6gF4FNUJq76OQN7SMb5YzXnqM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=goYwz6NrxQmTNUksICyndJ75PZ0vKAFx/eOX9V0Zm2MsiyF2+d+AMEhd7eG2hxvCKByQvR7FE4todt64XUiEGKtM9XVaVk3lSOwhKKrMWXiFehVwx40bNwiIm9ffd35s75mv+PAorAPPSnEs8hcNzBb1SB0i9iiU4a5YcG/paY4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GuKHmjjT; 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="GuKHmjjT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A89AC4CEC4; Thu, 19 Sep 2024 17:37:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726767466; bh=N/mW8g5kxumYZHOlcz6gF4FNUJq76OQN7SMb5YzXnqM=; h=From:To:Cc:Subject:Date:From; b=GuKHmjjTyXcFV+kqH+WKansOjxhaagaXJUFfSEjH8BkU6etRnXvZpNsa4nvsut/1H EOdTJe7Z7d9JubwK7L4+c4Rk3AEky3X7t8Y6AdVVzmmm9mN0Uk9o047hqpOEg1DrW3 aE3mKSZQVlN5FDzjc1wyiuAO7K+UFNaHMpUev7i3eV5zqEtyRM2Zwf5oit75qJcdxM 68lkZNpsr8NTmXaFVyrQFzfPw1aNE5S2uDOV0dWN+Q9apC/hnYJ5KKgLzb9/65cd6r ATiYnlRVAI2lFJo+WUiiW0nj+GuiA2TJXEl5AZIiPugebASIUEK9l9qqD05TfruAih WTD2xNkfMMGOw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Jonathan Corbet , Nathan Chancellor , Nicolas Schier , linux-doc@vger.kernel.org Subject: [PATCH v2 1/5] kbuild: doc: throw out the local table of contents in modules.rst Date: Fri, 20 Sep 2024 02:37:14 +0900 Message-ID: <20240919173740.1080501-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Do similar to commit 5e8f0ba38a4d ("docs/kbuild/makefiles: throw out the local table of contents"). Signed-off-by: Masahiro Yamada --- Changes in v2: - New patch Documentation/kbuild/modules.rst | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/Documentation/kbuild/modules.rst b/Documentation/kbuild/modules.rst index 7eceb9a65e9c..4f67e6a27afe 100644 --- a/Documentation/kbuild/modules.rst +++ b/Documentation/kbuild/modules.rst @@ -4,35 +4,6 @@ Building External Modules This document describes how to build an out-of-tree kernel module. -.. Table of Contents - - === 1 Introduction - === 2 How to Build External Modules - --- 2.1 Command Syntax - --- 2.2 Options - --- 2.3 Targets - --- 2.4 Building Separate Files - === 3. Creating a Kbuild File for an External Module - --- 3.1 Shared Makefile - --- 3.2 Separate Kbuild file and Makefile - --- 3.3 Binary Blobs - --- 3.4 Building Multiple Modules - === 4. Include Files - --- 4.1 Kernel Includes - --- 4.2 Single Subdirectory - --- 4.3 Several Subdirectories - === 5. Module Installation - --- 5.1 INSTALL_MOD_PATH - --- 5.2 INSTALL_MOD_DIR - === 6. Module Versioning - --- 6.1 Symbols From the Kernel (vmlinux + modules) - --- 6.2 Symbols and External Modules - --- 6.3 Symbols From Another External Module - === 7. Tips & Tricks - --- 7.1 Testing for CONFIG_FOO_BAR - - - 1. Introduction =============== From patchwork Thu Sep 19 17:37:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13807911 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 222671A287C; Thu, 19 Sep 2024 17:37:48 +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=1726767469; cv=none; b=iZ8IPHI6/Hn7g7qm0Ylt6k0PZ9nxZORcecHKvAd3D96xNSsCRiexAI8GE31AeyCEMRyqsUH4MtyK5QiCTNt/ecJtgAISBfXfOW4EA99F8tWmzxlasF8G6qlTUWYh5HSqyGx33f38XKwNzsyoTcfraSfK9XQDr0wnkd2JTOMRgPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726767469; c=relaxed/simple; bh=I5cwRWTXa4jyJfEbVmnWyX/hYKFsekUA+7vxG+tn8Wc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mAJyRCFZwnAKB9BIaDVx5WWffJ/vqCSLTt6l6/sO+y789kIhKGfhs4EY8FRCvnDTUaLRB+oM63eTcP12RoSYY9LSrobiQLHav22Y8H5A9klcfm6YCEkMdmsiid1w7dLi7ar1mzlPK5UGrCY79/Nq+9xTGq1dEwVaD9K86i1GOX4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nX2dcIoW; 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="nX2dcIoW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EF09C4CEC5; Thu, 19 Sep 2024 17:37:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726767468; bh=I5cwRWTXa4jyJfEbVmnWyX/hYKFsekUA+7vxG+tn8Wc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nX2dcIoW3boOEqx6F2EfW1dGUyBHlVOSp4Y76kfWpeU8S2H5uRW0aClTdB6dgU36K JBquApPcB20SKNyNn16RKoiacJaaWrfff9/Zuu7Cto3Q9cmUQbZXiKd43CCiya6N+x qWXWaJFoPdtEvldpwZz6ZSfdrHZxSAXizciQ9zPRbztjdGOi++tPXpyXoJjtLmajQg A8Iz+1sZ8c9T+god4rxrnhFAfev+HrldsKGXOFCxD5E3g8sbXCAkqSGolpBPcrKYc4 idKOyesYxKVeWCNJO/ezFv1BAoKZW0sWQUak/IPHFeUFdzLzJI9cDs8Wibv8Kky26F /8/nY+tg93alg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Jonathan Corbet , Nathan Chancellor , Nicolas Schier , linux-doc@vger.kernel.org Subject: [PATCH v2 2/5] kbuild: doc: drop section numbering, use references in modules.rst Date: Fri, 20 Sep 2024 02:37:15 +0900 Message-ID: <20240919173740.1080501-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240919173740.1080501-1-masahiroy@kernel.org> References: <20240919173740.1080501-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Do similar to commit 1a4c1c9df72e ("docs/kbuild/makefiles: drop section numbering, use references"). Signed-off-by: Masahiro Yamada --- Changes in v2: - New patch Documentation/kbuild/modules.rst | 101 ++++++++++++++++--------------- 1 file changed, 51 insertions(+), 50 deletions(-) diff --git a/Documentation/kbuild/modules.rst b/Documentation/kbuild/modules.rst index 4f67e6a27afe..c4a0598aa276 100644 --- a/Documentation/kbuild/modules.rst +++ b/Documentation/kbuild/modules.rst @@ -4,8 +4,8 @@ Building External Modules This document describes how to build an out-of-tree kernel module. -1. Introduction -=============== +Introduction +============ "kbuild" is the build system used by the Linux kernel. Modules must use kbuild to stay compatible with changes in the build infrastructure and @@ -19,11 +19,11 @@ in building out-of-tree (or "external") modules. The author of an external module should supply a makefile that hides most of the complexity, so one only has to type "make" to build the module. This is easily accomplished, and a complete example will be presented in -section 3. +section `Creating a Kbuild File for an External Module`_. -2. How to Build External Modules -================================ +How to Build External Modules +============================= To build external modules, you must have a prebuilt kernel available that contains the configuration and header files used in the build. @@ -40,8 +40,8 @@ NOTE: "modules_prepare" will not build Module.symvers even if CONFIG_MODVERSIONS is set; therefore, a full kernel build needs to be executed to make module versioning work. -2.1 Command Syntax -================== +Command Syntax +-------------- The command to build an external module is:: @@ -59,8 +59,8 @@ executed to make module versioning work. $ make -C /lib/modules/`uname -r`/build M=$PWD modules_install -2.2 Options -=========== +Options +------- ($KDIR refers to the path of the kernel source directory.) @@ -77,8 +77,8 @@ executed to make module versioning work. directory where the external module (kbuild file) is located. -2.3 Targets -=========== +Targets +------- When building an external module, only a subset of the "make" targets are available. @@ -100,7 +100,8 @@ executed to make module versioning work. modules_install Install the external module(s). The default location is /lib/modules//updates/, but a prefix may - be added with INSTALL_MOD_PATH (discussed in section 5). + be added with INSTALL_MOD_PATH (discussed in section + `Module Installation`_). clean Remove all generated files in the module directory only. @@ -108,8 +109,8 @@ executed to make module versioning work. help List the available targets for external modules. -2.4 Building Separate Files -=========================== +Building Separate Files +----------------------- It is possible to build single files that are part of a module. This works equally well for the kernel, a module, and even for @@ -123,8 +124,8 @@ executed to make module versioning work. make -C $KDIR M=$PWD ./ -3. Creating a Kbuild File for an External Module -================================================ +Creating a Kbuild File for an External Module +============================================= In the last section we saw the command to build a module for the running kernel. The module is not actually built, however, because a @@ -153,8 +154,8 @@ module 8123.ko, which is built from the following files:: 8123_pci.c 8123_bin.o_shipped <= Binary blob -3.1 Shared Makefile -------------------- +Shared Makefile +--------------- An external module always includes a wrapper makefile that supports building the module using "make" with no arguments. @@ -192,8 +193,8 @@ module 8123.ko, which is built from the following files:: line; the second pass is by the kbuild system, which is initiated by the parameterized "make" in the default target. -3.2 Separate Kbuild File and Makefile -------------------------------------- +Separate Kbuild File and Makefile +--------------------------------- Kbuild will first look for a file named "Kbuild", and if it is not found, it will then look for "Makefile". Utilizing a "Kbuild" file @@ -220,8 +221,8 @@ module 8123.ko, which is built from the following files:: consisting of several hundred lines, and here it really pays off to separate the kbuild part from the rest. -3.3 Binary Blobs ----------------- +Binary Blobs +------------ Some external modules need to include an object file as a blob. kbuild has support for this, but requires the blob file to be @@ -240,8 +241,8 @@ module 8123.ko, which is built from the following files:: files and the binary file, kbuild will pick up different rules when creating the object file for the module. -3.4 Building Multiple Modules -============================= +Building Multiple Modules +------------------------- kbuild supports building multiple modules with a single build file. For example, if you wanted to build two modules, foo.ko @@ -254,8 +255,8 @@ module 8123.ko, which is built from the following files:: It is that simple! -4. Include Files -================ +Include Files +============= Within the kernel, header files are kept in standard locations according to the following rule: @@ -273,8 +274,8 @@ according to the following rule: include/scsi; and architecture specific headers are located under arch/$(SRCARCH)/include/. -4.1 Kernel Includes -------------------- +Kernel Includes +--------------- To include a header file located under include/linux/, simply use:: @@ -284,8 +285,8 @@ according to the following rule: kbuild will add options to "gcc" so the relevant directories are searched. -4.2 Single Subdirectory ------------------------ +Single Subdirectory +------------------- External modules tend to place header files in a separate include/ directory where their source is located, although this @@ -302,8 +303,8 @@ according to the following rule: ccflags-y := -I $(src)/include 8123-y := 8123_if.o 8123_pci.o 8123_bin.o -4.3 Several Subdirectories --------------------------- +Several Subdirectories +---------------------- kbuild can handle files that are spread over several directories. Consider the following example:: @@ -342,8 +343,8 @@ according to the following rule: file is located. -5. Module Installation -====================== +Module Installation +=================== Modules which are included in the kernel are installed in the directory: @@ -354,8 +355,8 @@ And external modules are installed in: /lib/modules/$(KERNELRELEASE)/updates/ -5.1 INSTALL_MOD_PATH --------------------- +INSTALL_MOD_PATH +---------------- Above are the default directories but as always some level of customization is possible. A prefix can be added to the @@ -369,8 +370,8 @@ And external modules are installed in: calling "make." This has effect when installing both in-tree and out-of-tree modules. -5.2 INSTALL_MOD_DIR -------------------- +INSTALL_MOD_DIR +--------------- External modules are by default installed to a directory under /lib/modules/$(KERNELRELEASE)/updates/, but you may wish to @@ -383,8 +384,8 @@ And external modules are installed in: => Install dir: /lib/modules/$(KERNELRELEASE)/gandalf/ -6. Module Versioning -==================== +Module Versioning +================= Module versioning is enabled by the CONFIG_MODVERSIONS tag, and is used as a simple ABI consistency check. A CRC value of the full prototype @@ -396,8 +397,8 @@ module. Module.symvers contains a list of all exported symbols from a kernel build. -6.1 Symbols From the Kernel (vmlinux + modules) ------------------------------------------------ +Symbols From the Kernel (vmlinux + modules) +------------------------------------------- During a kernel build, a file named Module.symvers will be generated. Module.symvers contains all exported symbols from @@ -421,8 +422,8 @@ build. 1) It lists all exported symbols from vmlinux and all modules. 2) It lists the CRC if CONFIG_MODVERSIONS is enabled. -6.2 Symbols and External Modules --------------------------------- +Symbols and External Modules +---------------------------- When building an external module, the build system needs access to the symbols from the kernel to check if all external symbols @@ -431,8 +432,8 @@ build. tree. During the MODPOST step, a new Module.symvers file will be written containing all exported symbols from that external module. -6.3 Symbols From Another External Module ----------------------------------------- +Symbols From Another External Module +------------------------------------ Sometimes, an external module uses exported symbols from another external module. Kbuild needs to have full knowledge of @@ -472,11 +473,11 @@ build. initialization of its symbol tables. -7. Tips & Tricks -================ +Tips & Tricks +============= -7.1 Testing for CONFIG_FOO_BAR ------------------------------- +Testing for CONFIG_FOO_BAR +-------------------------- Modules often need to check for certain `CONFIG_` options to decide if a specific feature is included in the module. In From patchwork Thu Sep 19 17:37:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13807912 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 12C991A2C35; Thu, 19 Sep 2024 17:37:50 +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=1726767471; cv=none; b=JOW+1UYbNO62/wyo+6hp0M/HsDhU/g3CCxCApijp/m5pGhtl6x+eSe5vA+tHC8a1yEI1imKZLXFMq+Dc3sdbbkUI4Hci9tbW9aDaebokk3gOAPk/Woibk8rddcWAc38Ec6qP8Tn6F95yaPsYszWPLPIPFC4L6J4te63PXltqTEw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726767471; c=relaxed/simple; bh=dAgeAUB+fMnBXcv/96LKcW7XGV9i/ZJLpRzgncAtrz4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p9zrJfzpn2VsvA3q5exdRYu3qglngsorcbBEaEACpDy6RvV9u05C0zFGeK7B5h12YMkidjWbZ/gJEFS3NmnA1XGm98tQATiFt6D0qpVGbgNxJEo01MNpkCc6JxN+W6D8Pt8+0Qlo7bmPBN/5ItPzfC9ebkNMSVcYXqSieeheTtU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JI/uxqtI; 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="JI/uxqtI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D54BC4CECF; Thu, 19 Sep 2024 17:37:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726767470; bh=dAgeAUB+fMnBXcv/96LKcW7XGV9i/ZJLpRzgncAtrz4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JI/uxqtInochdeiZHeqEAUAvfAdKQXjJBm4RHDtd+sdeTwfOkt3Xsirb7BWiZciUV /dIYxpy85kkFF5QR23mjSQ73eBeXs3yrFczKGAGiwcBuCUAg5Wchht7ML1+b1EF0v4 uCKMiWJU3mzvgnfBvFCJkFPVBYb78huCeA0FUrXPLVnNjfb3b1HUWHz07tbqFOCbVv fkHgdjo+1iywDZuwtOZstaiT+wP7kD7O+uwx+iUKCFrA9vc0PzptUOs+cg3BVKZ1n8 q9HubGSPjvYK+3ITVxTbd2OZjfBe7cGLpA2x5MczdISq0MgMDAI5yCq449lj2PG6ib AcpVLYVqMnubw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Nicolas Schier , Jonathan Corbet , Nathan Chancellor , Nicolas Schier , linux-doc@vger.kernel.org Subject: [PATCH v2 3/5] kbuild: doc: remove the description about shipped files Date: Fri, 20 Sep 2024 02:37:16 +0900 Message-ID: <20240919173740.1080501-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240919173740.1080501-1-masahiroy@kernel.org> References: <20240919173740.1080501-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The use of shipped files is discouraged in the upstream kernel these days. [1] Downstream Makefiles have the freedom to use shipped files or other options to handle binaries, but this should not be advertised in the upstream document. [1]: https://lore.kernel.org/all/CAHk-=wgSEi_ZrHdqr=20xv+d6dr5G895CbOAi8ok+7-CQUN=fQ@mail.gmail.com/ Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Changes in v2: - Remove TODO item in makefiles.rst Documentation/kbuild/makefiles.rst | 1 - Documentation/kbuild/modules.rst | 35 +++--------------------------- 2 files changed, 3 insertions(+), 33 deletions(-) diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst index be43990f1e7f..7964e0c245ae 100644 --- a/Documentation/kbuild/makefiles.rst +++ b/Documentation/kbuild/makefiles.rst @@ -1665,6 +1665,5 @@ Credits TODO ==== -- Describe how kbuild supports shipped files with _shipped. - Generating offset header files. - Add more variables to chapters 7 or 9? diff --git a/Documentation/kbuild/modules.rst b/Documentation/kbuild/modules.rst index c4a0598aa276..080e11372351 100644 --- a/Documentation/kbuild/modules.rst +++ b/Documentation/kbuild/modules.rst @@ -152,7 +152,6 @@ module 8123.ko, which is built from the following files:: 8123_if.c 8123_if.h 8123_pci.c - 8123_bin.o_shipped <= Binary blob Shared Makefile --------------- @@ -170,7 +169,7 @@ Shared Makefile ifneq ($(KERNELRELEASE),) # kbuild part of makefile obj-m := 8123.o - 8123-y := 8123_if.o 8123_pci.o 8123_bin.o + 8123-y := 8123_if.o 8123_pci.o else # normal makefile @@ -179,10 +178,6 @@ Shared Makefile default: $(MAKE) -C $(KDIR) M=$$PWD - # Module specific targets - genbin: - echo "X" > 8123_bin.o_shipped - endif The check for KERNELRELEASE is used to separate the two parts @@ -204,7 +199,7 @@ Separate Kbuild File and Makefile --> filename: Kbuild obj-m := 8123.o - 8123-y := 8123_if.o 8123_pci.o 8123_bin.o + 8123-y := 8123_if.o 8123_pci.o --> filename: Makefile KDIR ?= /lib/modules/`uname -r`/build @@ -212,35 +207,11 @@ Separate Kbuild File and Makefile default: $(MAKE) -C $(KDIR) M=$$PWD - # Module specific targets - genbin: - echo "X" > 8123_bin.o_shipped - The split in example 2 is questionable due to the simplicity of each file; however, some external modules use makefiles consisting of several hundred lines, and here it really pays off to separate the kbuild part from the rest. -Binary Blobs ------------- - - Some external modules need to include an object file as a blob. - kbuild has support for this, but requires the blob file to be - named _shipped. When the kbuild rules kick in, a copy - of _shipped is created with _shipped stripped off, - giving us . This shortened filename can be used in - the assignment to the module. - - Throughout this section, 8123_bin.o_shipped has been used to - build the kernel module 8123.ko; it has been included as - 8123_bin.o:: - - 8123-y := 8123_if.o 8123_pci.o 8123_bin.o - - Although there is no distinction between the ordinary source - files and the binary file, kbuild will pick up different rules - when creating the object file for the module. - Building Multiple Modules ------------------------- @@ -301,7 +272,7 @@ Single Subdirectory obj-m := 8123.o ccflags-y := -I $(src)/include - 8123-y := 8123_if.o 8123_pci.o 8123_bin.o + 8123-y := 8123_if.o 8123_pci.o Several Subdirectories ---------------------- From patchwork Thu Sep 19 17:37:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13807913 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 2AF071A38D7; Thu, 19 Sep 2024 17:37:52 +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=1726767473; cv=none; b=dRpJvLbYg1vzrzSbszxIP+Pdjc2iDO25KB9+iSgLtoENmNG4HXrCP6O6Yzift/GoNR+EHhJGiplohrKZoaEmu84+gpZW4eCpN/DbCUN4cCnT14oCvgqqoYUABfdDaoloBkp3vpfwpfFm5+hiF/H2bheP10Rw0UdskOnrlIYuWFo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726767473; c=relaxed/simple; bh=J7RNRqMFxFwXcjhPaEMvrPABns9MkYP8IYj+AKIiTZk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WxJInSbNJNFPS+TDzmjK8fjpfpngEP3YUBsJxb3/zs4VS+4PYLU2xqhWXEZLTIjOsIAQpnaZ6wGYvM1IjdUnqTO9k3ia32kM+in2Y99VcwPTh+Hkw3SFgDOks7HhgQ+HNPZTyMG55QAGO4Ibp9I8Y1/cIO/MBkoHm822LETbTrw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oXcsiT6H; 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="oXcsiT6H" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38FC9C4CEC7; Thu, 19 Sep 2024 17:37:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726767472; bh=J7RNRqMFxFwXcjhPaEMvrPABns9MkYP8IYj+AKIiTZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oXcsiT6HpMytKDPHfpQqyRarfme5p4c4nazWTU9w5gd2XVCqXMATnFkTaCIMiKqIU 2QGUGsF485cbaJGSILANi0JlHZXgXxrP6h5U3VK6zeZsB47WreaWd2RfxAjGu9X6Dm DmLD2ORIkZGZvNdlgX4juPSvtXhRfR+zQ2YpE6ypwPxBr6PjJI/AX5OMrM3vwP533a JA4kJxIUX0BU2xqFScFq1uRx/t6XmtIxEDhJauHg91sfF4ofHluA4ftmaO25qSdra6 zNHdJj+y5Hgk/Sv3wAD41ZK5bx17XwntuU7y8H3GXfx9W5cxIFJAyUNwbN9JIwQ+6U 2nhcocf836LZg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Nicolas Schier , Jonathan Corbet , Nathan Chancellor , Nicolas Schier , linux-doc@vger.kernel.org Subject: [PATCH v2 4/5] kbuild: doc: describe the -C option precisely for external module builds Date: Fri, 20 Sep 2024 02:37:17 +0900 Message-ID: <20240919173740.1080501-4-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240919173740.1080501-1-masahiroy@kernel.org> References: <20240919173740.1080501-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Building external modules is typically done using this command: $ make -C M= Here, refers to the output directory where the kernel was built, not the kernel source directory. When the kernel is built in the source tree, there is no ambiguity, as the output directory and the source directory are the same. If the kernel was built in a separate build directory, should be the kernel output directory. Otherwise, Kbuild cannot locate necessary build artifacts such as the .config file, etc. This has been the method for building external modules against a pre-built kernel in a separate directory for over 20 years. [1] If you pass the kernel source directory to the -C option, you must also specify the kernel build directory using the O= option. This approach works as well, though it results in a slightly longer command: $ make -C O= M= Some people mistakenly believe that O= should point to a build directory for external modules when used together with M=. This commit adds more clarification to Documentation/kbuild/kbuild.rst. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/commit/?id=e321b2ec2eb2993b3d0116e5163c78ad923e3c54 Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Changes in v2: - Rebase Documentation/kbuild/kbuild.rst | 5 +++++ Documentation/kbuild/modules.rst | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Documentation/kbuild/kbuild.rst b/Documentation/kbuild/kbuild.rst index 9c8d1d046ea5..716f6fb70829 100644 --- a/Documentation/kbuild/kbuild.rst +++ b/Documentation/kbuild/kbuild.rst @@ -129,6 +129,11 @@ KBUILD_OUTPUT ------------- Specify the output directory when building the kernel. +This variable can also be used to point to the kernel output directory when +building external modules using kernel build artifacts in a separate build +directory. Please note that this does NOT specify the output directory for the +external modules themselves. + The output directory can also be specified using "O=...". Setting "O=..." takes precedence over KBUILD_OUTPUT. diff --git a/Documentation/kbuild/modules.rst b/Documentation/kbuild/modules.rst index 080e11372351..b24448f789b3 100644 --- a/Documentation/kbuild/modules.rst +++ b/Documentation/kbuild/modules.rst @@ -45,7 +45,7 @@ Command Syntax The command to build an external module is:: - $ make -C M=$PWD + $ make -C M=$PWD The kbuild system knows that an external module is being built due to the "M=" option given in the command. @@ -62,12 +62,15 @@ Command Syntax Options ------- - ($KDIR refers to the path of the kernel source directory.) + ($KDIR refers to the path of the kernel source directory, or the path + of the kernel output directory if the kernel was built in a separate + build directory.) make -C $KDIR M=$PWD -C $KDIR - The directory where the kernel source is located. + The directory that contains the kernel and relevant build + artifacts used for building an external module. "make" will actually change to the specified directory when executing and will change back when finished. From patchwork Thu Sep 19 17:37:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13807914 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 449141A3AA3; Thu, 19 Sep 2024 17:37:54 +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=1726767475; cv=none; b=jkIB3yvYlH3gfhkCulooJPV003Z380ghhme9Bi+d3Nq5bGmAMYtAtSeKLKtM3m2H52o7xPs7b3xMSsQ4NBAPnUdQWi9wDB/DvLrXlfdW4f0vJyvzlHo2SML4bBL5woaTRf6QyYSCXyTthOhxFUsDNDpEg0x+OFRO8aPI52ucvrQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726767475; c=relaxed/simple; bh=aNCBzgHOJ/KRb04CY4zo8gpoJ0YQtB/gZx6KyEZ19SY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KI23Tm65SiAHEEF8I4wrDs3RphPiEldpgCrTx0EyFwRfP2V8Ju76cB24OfcwpMr5DUXyRfJL9qHtUUCJraXTPG1pt5ipR4TOnCri4mHrxTqc2ZZAzz/tK8Qg9CiZuRbWzezG3KvLTyHDUz3SuWiauvIxpuea41Out9HH+H+SpJo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XWZUJCW6; 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="XWZUJCW6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CEB2C4CED1; Thu, 19 Sep 2024 17:37:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726767474; bh=aNCBzgHOJ/KRb04CY4zo8gpoJ0YQtB/gZx6KyEZ19SY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XWZUJCW6AVPRqXm3V8mVHTe4BY/tmbZx8Mggpu7paaqgSULxCgTYKEMtBx4cvJbao x8bSIyieqUQgB5AdnI5OKTzoKEi1Mhwl5Og5dmGDp54wWHOj6GC+W5CxzdFHSgH2zd od3Sgfjkd0/YGCW8a1D3U34W8Fi7NFaeY0amEahPKhyD2F4kz8ixOWCCR99OYAyjpT LBEmEsh9oL48KrXX00hJPRxDIRqszE/Nh/EHySqZ1l/eU3hEO59R+JrYArKfEtMIWQ JA25cm55zRNzy/jbNMvRwrPyNlm8Dk2az67IjRFeMwzmOnqXOT6zfkclMPA/drXw8v iqHlFoi0FSOJw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Nicolas Schier , Jonathan Corbet , Nathan Chancellor , Nicolas Schier , linux-doc@vger.kernel.org Subject: [PATCH v2 5/5] kbuild: doc: replace "gcc" in external module description Date: Fri, 20 Sep 2024 02:37:18 +0900 Message-ID: <20240919173740.1080501-5-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240919173740.1080501-1-masahiroy@kernel.org> References: <20240919173740.1080501-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Avoid "gcc" since it is not the only compiler supported by Kbuild. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Changes in v2: - Rebase Documentation/kbuild/modules.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/kbuild/modules.rst b/Documentation/kbuild/modules.rst index b24448f789b3..cd5a54d91e6d 100644 --- a/Documentation/kbuild/modules.rst +++ b/Documentation/kbuild/modules.rst @@ -9,7 +9,7 @@ Introduction "kbuild" is the build system used by the Linux kernel. Modules must use kbuild to stay compatible with changes in the build infrastructure and -to pick up the right flags to "gcc." Functionality for building modules +to pick up the right flags to the compiler. Functionality for building modules both in-tree and out-of-tree is provided. The method for building either is similar, and all modules are initially developed and built out-of-tree. @@ -256,7 +256,7 @@ Kernel Includes #include - kbuild will add options to "gcc" so the relevant directories + kbuild will add options to the compiler so the relevant directories are searched. Single Subdirectory