sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget"/translations/zh_CN/kbuild/modulesmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/zh_TW/kbuild/modulesmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/it_IT/kbuild/modulesmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/ja_JP/kbuild/modulesmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/ko_KR/kbuild/modulesmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/sp_SP/kbuild/modulesmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhsection)}(hhh](htitle)}(hBuilding External Modulesh]hBuilding External Modules}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhh M=$PWD The kbuild system knows that an external module is being built due to the "M=" option given in the command. To build against the running kernel use:: $ make -C /lib/modules/`uname -r`/build M=$PWD Then to install the module(s) just built, add the target "modules_install" to the command:: $ make -C /lib/modules/`uname -r`/build M=$PWD modules_install Starting from Linux 6.13, you can use the -f option instead of -C. This will avoid unnecessary change of the working directory. The external module will be output to the directory where you invoke make. $ make -f /lib/modules/`uname -r`/build/Makefile M=$PWD h](h)}(h,The command to build an external module is::h]h+The command to build an external module is:}(hjghhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK.hjcubh literal_block)}(h%$ make -C M=$PWDh]h%$ make -C M=$PWD}hjwsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1juhhhK0hjcubh)}(hpThe kbuild system knows that an external module is being built due to the "M=" option given in the command.h]htThe kbuild system knows that an external module is being built due to the “M=” option given in the command.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK2hjcubh)}(h)To build against the running kernel use::h]h(To build against the running kernel use:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK5hjcubjv)}(h.$ make -C /lib/modules/`uname -r`/build M=$PWDh]h.$ make -C /lib/modules/`uname -r`/build M=$PWD}hjsbah}(h]h ]h"]h$]h&]jjuh1juhhhK7hjcubh)}(h[Then to install the module(s) just built, add the target "modules_install" to the command::h]h^Then to install the module(s) just built, add the target “modules_install” to the command:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK9hjcubjv)}(h>$ make -C /lib/modules/`uname -r`/build M=$PWD modules_installh]h>$ make -C /lib/modules/`uname -r`/build M=$PWD modules_install}hjsbah}(h]h ]h"]h$]h&]jjuh1juhhhKhjcubjb)}(h8$ make -f /lib/modules/`uname -r`/build/Makefile M=$PWD h]h)}(h7$ make -f /lib/modules/`uname -r`/build/Makefile M=$PWDh](h$ make -f /lib/modules/}(hjhhhNhNubhtitle_reference)}(h `uname -r`h]huname -r}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh/build/Makefile M=$PWD}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKBhjubah}(h]h ]h"]h$]h&]uh1jahhhKBhjcubeh}(h]h ]h"]h$]h&]uh1jahhhK.hjPhhubeh}(h]command-syntaxah ]h"]command syntaxah$]h&]uh1hhjhhhhhK,ubh)}(hhh](h)}(hOptionsh]hOptions}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKEubjb)}(hXE($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.) You can optionally pass MO= option if you want to build the modules in a separate directory. make -C $KDIR M=$PWD [MO=$BUILD_DIR] -C $KDIR 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. M=$PWD Informs kbuild that an external module is being built. The value given to "M" is the absolute path of the directory where the external module (kbuild file) is located. MO=$BUILD_DIR Specifies a separate output directory for the external module. h](h)}(h($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.)h]h($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.)}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKGhj&ubh)}(h\You can optionally pass MO= option if you want to build the modules in a separate directory.h]h\You can optionally pass MO= option if you want to build the modules in a separate directory.}(hj8hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKKhj&ubh)}(h$make -C $KDIR M=$PWD [MO=$BUILD_DIR]h]h$make -C $KDIR M=$PWD [MO=$BUILD_DIR]}(hjFhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKNhj&ubhdefinition_list)}(hhh](hdefinition_list_item)}(h-C $KDIR 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. h](hterm)}(h-C $KDIRh]h-C $KDIR}(hjahhhNhNubah}(h]h ]h"]h$]h&]uh1j_hhhKThj[ubh definition)}(hhh]h)}(hThe 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.h]hThe 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.}(hjthhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKQhjqubah}(h]h ]h"]h$]h&]uh1johj[ubeh}(h]h ]h"]h$]h&]uh1jYhhhKThjVubjZ)}(hM=$PWD Informs kbuild that an external module is being built. The value given to "M" is the absolute path of the directory where the external module (kbuild file) is located. h](j`)}(hM=$PWDh]hM=$PWD}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j_hhhKZhjubjp)}(hhh]h)}(hInforms kbuild that an external module is being built. The value given to "M" is the absolute path of the directory where the external module (kbuild file) is located.h]hInforms kbuild that an external module is being built. The value given to “M” is the absolute path of the directory where the external module (kbuild file) is located.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKWhjubah}(h]h ]h"]h$]h&]uh1johjubeh}(h]h ]h"]h$]h&]uh1jYhhhKZhjVubjZ)}(hMMO=$BUILD_DIR Specifies a separate output directory for the external module. h](j`)}(h MO=$BUILD_DIRh]h MO=$BUILD_DIR}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j_hhhK]hjubjp)}(hhh]h)}(h>Specifies a separate output directory for the external module.h]h>Specifies a separate output directory for the external module.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK]hjubah}(h]h ]h"]h$]h&]uh1johjubeh}(h]h ]h"]h$]h&]uh1jYhhhK]hjVubeh}(h]h ]h"]h$]h&]uh1jThj&ubeh}(h]h ]h"]h$]h&]uh1jahhhKGhjhhubeh}(h]optionsah ]h"]optionsah$]h&]uh1hhjhhhhhKEubh)}(hhh](h)}(hTargetsh]hTargets}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK`ubjb)}(hXWhen building an external module, only a subset of the "make" targets are available. make -C $KDIR M=$PWD [target] The default will build the module(s) located in the current directory, so a target does not need to be specified. All output files will also be generated in this directory. No attempts are made to update the kernel source, and it is a precondition that a successful "make" has been executed for the kernel. modules The default target for external modules. It has the same functionality as if no target was specified. See description above. 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 `Module Installation`_). clean Remove all generated files in the module directory only. help List the available targets for external modules. h](h)}(hTWhen building an external module, only a subset of the "make" targets are available.h]hXWhen building an external module, only a subset of the “make” targets are available.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKbhjubh)}(hmake -C $KDIR M=$PWD [target]h]hmake -C $KDIR M=$PWD [target]}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKehjubh)}(hX2The default will build the module(s) located in the current directory, so a target does not need to be specified. All output files will also be generated in this directory. No attempts are made to update the kernel source, and it is a precondition that a successful "make" has been executed for the kernel.h]hX6The default will build the module(s) located in the current directory, so a target does not need to be specified. All output files will also be generated in this directory. No attempts are made to update the kernel source, and it is a precondition that a successful “make” has been executed for the kernel.}(hj1hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKghjubjU)}(hhh](jZ)}(hmodules The default target for external modules. It has the same functionality as if no target was specified. See description above. h](j`)}(hmodulesh]hmodules}(hjFhhhNhNubah}(h]h ]h"]h$]h&]uh1j_hhhKqhjBubjp)}(hhh]h)}(h|The default target for external modules. It has the same functionality as if no target was specified. See description above.h]h|The default target for external modules. It has the same functionality as if no target was specified. See description above.}(hjWhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKohjTubah}(h]h ]h"]h$]h&]uh1johjBubeh}(h]h ]h"]h$]h&]uh1jYhhhKqhj?ubjZ)}(hmodules_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 `Module Installation`_). h](j`)}(hmodules_installh]hmodules_install}(hjuhhhNhNubah}(h]h ]h"]h$]h&]uh1j_hhhKwhjqubjp)}(hhh]h)}(hInstall the external module(s). The default location is /lib/modules//updates/, but a prefix may be added with INSTALL_MOD_PATH (discussed in section `Module Installation`_).h](hInstall the external module(s). The default location is /lib/modules//updates/, but a prefix may be added with INSTALL_MOD_PATH (discussed in section }(hjhhhNhNubh)}(h`Module Installation`_h]hModule Installation}(hjhhhNhNubah}(h]h ]h"]h$]h&]nameModule Installationjmodule-installationuh1hhjjKubh).}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKthjubah}(h]h ]h"]h$]h&]uh1johjqubeh}(h]h ]h"]h$]h&]uh1jYhhhKwhj?ubjZ)}(h?clean Remove all generated files in the module directory only. h](j`)}(hcleanh]hclean}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j_hhhKzhjubjp)}(hhh]h)}(h8Remove all generated files in the module directory only.h]h8Remove all generated files in the module directory only.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKzhjubah}(h]h ]h"]h$]h&]uh1johjubeh}(h]h ]h"]h$]h&]uh1jYhhhKzhj?ubjZ)}(h6help List the available targets for external modules. h](j`)}(hhelph]hhelp}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j_hhhK}hjubjp)}(hhh]h)}(h0List the available targets for external modules.h]h0List the available targets for external modules.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK}hjubah}(h]h ]h"]h$]h&]uh1johjubeh}(h]h ]h"]h$]h&]uh1jYhhhK}hj?ubeh}(h]h ]h"]h$]h&]uh1jThjubeh}(h]h ]h"]h$]h&]uh1jahhhKbhjhhubeh}(h]targetsah ]h"]targetsah$]h&]uh1hhjhhhhhK`ubh)}(hhh](h)}(hBuilding Separate Filesh]hBuilding Separate Files}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj'hhhhhKubjb)}(hXZIt is possible to build single files that are part of a module. This works equally well for the kernel, a module, and even for external modules. Example (The module foo.ko, consist of bar.o and baz.o):: make -C $KDIR M=$PWD bar.lst make -C $KDIR M=$PWD baz.o make -C $KDIR M=$PWD foo.ko make -C $KDIR M=$PWD ./ h](h)}(hIt is possible to build single files that are part of a module. This works equally well for the kernel, a module, and even for external modules.h]hIt is possible to build single files that are part of a module. This works equally well for the kernel, a module, and even for external modules.}(hj<hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj8ubh)}(h9Example (The module foo.ko, consist of bar.o and baz.o)::h]h8Example (The module foo.ko, consist of bar.o and baz.o):}(hjJhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj8ubjv)}(hkmake -C $KDIR M=$PWD bar.lst make -C $KDIR M=$PWD baz.o make -C $KDIR M=$PWD foo.ko make -C $KDIR M=$PWD ./h]hkmake -C $KDIR M=$PWD bar.lst make -C $KDIR M=$PWD baz.o make -C $KDIR M=$PWD foo.ko make -C $KDIR M=$PWD ./}hjXsbah}(h]h ]h"]h$]h&]jjuh1juhhhKhj8ubeh}(h]h ]h"]h$]h&]uh1jahhhKhj'hhubeh}(h]building-separate-filesah ]h"]building separate filesah$]h&]uh1hhjhhhhhKubeh}(h]how-to-build-external-modulesah ]h"]how to build external modulesah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h-Creating a Kbuild File for an External Moduleh]h-Creating a Kbuild File for an External Module}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj|hhhhhKubh)}(hX?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 build file is required. Contained in this file will be the name of the module(s) being built, along with the list of requisite source files. The file may be as simple as a single line::h]hX>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 build file is required. Contained in this file will be the name of the module(s) being built, along with the list of requisite source files. The file may be as simple as a single line:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj|hhubjv)}(hobj-m := .oh]hobj-m := .o}hjsbah}(h]h ]h"]h$]h&]jjuh1juhhhKhj|hhubh)}(hX/The kbuild system will build .o from .c, and, after linking, will result in the kernel module .ko. The above line can be put in either a "Kbuild" file or a "Makefile." When the module is built from multiple sources, an additional line is needed listing the files::h]hX6The kbuild system will build .o from .c, and, after linking, will result in the kernel module .ko. The above line can be put in either a “Kbuild” file or a “Makefile.” When the module is built from multiple sources, an additional line is needed listing the files:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj|hhubjv)}(h(-y := .o .o ...h]h(-y := .o .o ...}hjsbah}(h]h ]h"]h$]h&]jjuh1juhhhKhj|hhubh)}(hrNOTE: Further documentation describing the syntax used by kbuild is located in Documentation/kbuild/makefiles.rst.h]hrNOTE: Further documentation describing the syntax used by kbuild is located in Documentation/kbuild/makefiles.rst.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj|hhubh)}(h{The examples below demonstrate how to create a build file for the module 8123.ko, which is built from the following files::h]hzThe examples below demonstrate how to create a build file for the module 8123.ko, which is built from the following files:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj|hhubjv)}(h8123_if.c 8123_if.h 8123_pci.ch]h8123_if.c 8123_if.h 8123_pci.c}hjsbah}(h]h ]h"]h$]h&]jjuh1juhhhKhj|hhubh)}(hhh](h)}(hShared Makefileh]hShared Makefile}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubjb)}(hX7An external module always includes a wrapper makefile that supports building the module using "make" with no arguments. This target is not used by kbuild; it is only for convenience. Additional functionality, such as test targets, can be included but should be filtered out from kbuild due to possible name clashes. Example 1:: --> filename: Makefile ifneq ($(KERNELRELEASE),) # kbuild part of makefile obj-m := 8123.o 8123-y := 8123_if.o 8123_pci.o else # normal makefile KDIR ?= /lib/modules/`uname -r`/build default: $(MAKE) -C $(KDIR) M=$$PWD endif The check for KERNELRELEASE is used to separate the two parts of the makefile. In the example, kbuild will only see the two assignments, whereas "make" will see everything except these two assignments. This is due to two passes made on the file: the first pass is by the "make" instance run on the command line; the second pass is by the kbuild system, which is initiated by the parameterized "make" in the default target. h](h)}(hX;An external module always includes a wrapper makefile that supports building the module using "make" with no arguments. This target is not used by kbuild; it is only for convenience. Additional functionality, such as test targets, can be included but should be filtered out from kbuild due to possible name clashes.h]hX?An external module always includes a wrapper makefile that supports building the module using “make” with no arguments. This target is not used by kbuild; it is only for convenience. Additional functionality, such as test targets, can be included but should be filtered out from kbuild due to possible name clashes.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubh)}(h Example 1::h]h Example 1:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubjv)}(h--> filename: Makefile ifneq ($(KERNELRELEASE),) # kbuild part of makefile obj-m := 8123.o 8123-y := 8123_if.o 8123_pci.o else # normal makefile KDIR ?= /lib/modules/`uname -r`/build default: $(MAKE) -C $(KDIR) M=$$PWD endifh]h--> filename: Makefile ifneq ($(KERNELRELEASE),) # kbuild part of makefile obj-m := 8123.o 8123-y := 8123_if.o 8123_pci.o else # normal makefile KDIR ?= /lib/modules/`uname -r`/build default: $(MAKE) -C $(KDIR) M=$$PWD endif}hj sbah}(h]h ]h"]h$]h&]jjuh1juhhhKhjubh)}(hXThe check for KERNELRELEASE is used to separate the two parts of the makefile. In the example, kbuild will only see the two assignments, whereas "make" will see everything except these two assignments. This is due to two passes made on the file: the first pass is by the "make" instance run on the command line; the second pass is by the kbuild system, which is initiated by the parameterized "make" in the default target.h]hXThe check for KERNELRELEASE is used to separate the two parts of the makefile. In the example, kbuild will only see the two assignments, whereas “make” will see everything except these two assignments. This is due to two passes made on the file: the first pass is by the “make” instance run on the command line; the second pass is by the kbuild system, which is initiated by the parameterized “make” in the default target.}(hj.hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubeh}(h]h ]h"]h$]h&]uh1jahhhKhjhhubeh}(h]shared-makefileah ]h"]shared makefileah$]h&]uh1hhj|hhhhhKubh)}(hhh](h)}(h!Separate Kbuild File and Makefileh]h!Separate Kbuild File and Makefile}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjJhhhhhKubjb)}(hXhKbuild will first look for a file named "Kbuild", and if it is not found, it will then look for "Makefile". Utilizing a "Kbuild" file allows us to split up the "Makefile" from example 1 into two files: Example 2:: --> filename: Kbuild obj-m := 8123.o 8123-y := 8123_if.o 8123_pci.o --> filename: Makefile KDIR ?= /lib/modules/`uname -r`/build default: $(MAKE) -C $(KDIR) M=$$PWD 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. Linux 6.13 and later support another way. The external module Makefile can include the kernel Makefile directly, rather than invoking sub Make. Example 3:: --> filename: Kbuild obj-m := 8123.o 8123-y := 8123_if.o 8123_pci.o --> filename: Makefile KDIR ?= /lib/modules/$(shell uname -r)/build export KBUILD_EXTMOD := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) include $(KDIR)/Makefile h](h)}(hKbuild will first look for a file named "Kbuild", and if it is not found, it will then look for "Makefile". Utilizing a "Kbuild" file allows us to split up the "Makefile" from example 1 into two files:h]hKbuild will first look for a file named “Kbuild”, and if it is not found, it will then look for “Makefile”. Utilizing a “Kbuild” file allows us to split up the “Makefile” from example 1 into two files:}(hj_hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj[ubh)}(h Example 2::h]h Example 2:}(hjmhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj[ubjv)}(h--> filename: Kbuild obj-m := 8123.o 8123-y := 8123_if.o 8123_pci.o --> filename: Makefile KDIR ?= /lib/modules/`uname -r`/build default: $(MAKE) -C $(KDIR) M=$$PWDh]h--> filename: Kbuild obj-m := 8123.o 8123-y := 8123_if.o 8123_pci.o --> filename: Makefile KDIR ?= /lib/modules/`uname -r`/build default: $(MAKE) -C $(KDIR) M=$$PWD}hj{sbah}(h]h ]h"]h$]h&]jjuh1juhhhKhj[ubh)}(hThe 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.h]hThe 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.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj[ubh)}(hLinux 6.13 and later support another way. The external module Makefile can include the kernel Makefile directly, rather than invoking sub Make.h]hLinux 6.13 and later support another way. The external module Makefile can include the kernel Makefile directly, rather than invoking sub Make.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj[ubh)}(h Example 3::h]h Example 3:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj[ubjv)}(h--> filename: Kbuild obj-m := 8123.o 8123-y := 8123_if.o 8123_pci.o --> filename: Makefile KDIR ?= /lib/modules/$(shell uname -r)/build export KBUILD_EXTMOD := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) include $(KDIR)/Makefileh]h--> filename: Kbuild obj-m := 8123.o 8123-y := 8123_if.o 8123_pci.o --> filename: Makefile KDIR ?= /lib/modules/$(shell uname -r)/build export KBUILD_EXTMOD := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) include $(KDIR)/Makefile}hjsbah}(h]h ]h"]h$]h&]jjuh1juhhhKhj[ubeh}(h]h ]h"]h$]h&]uh1jahhhKhjJhhubeh}(h]!separate-kbuild-file-and-makefileah ]h"]!separate kbuild file and makefileah$]h&]uh1hhj|hhhhhKubh)}(hhh](h)}(hBuilding Multiple Modulesh]hBuilding Multiple Modules}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubjb)}(hXkbuild supports building multiple modules with a single build file. For example, if you wanted to build two modules, foo.ko and bar.ko, the kbuild lines would be:: obj-m := foo.o bar.o foo-y := bar-y := It is that simple! h](h)}(hkbuild supports building multiple modules with a single build file. For example, if you wanted to build two modules, foo.ko and bar.ko, the kbuild lines would be::h]hkbuild supports building multiple modules with a single build file. For example, if you wanted to build two modules, foo.ko and bar.ko, the kbuild lines would be:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubjv)}(h bar-y := h]h bar-y := }hjsbah}(h]h ]h"]h$]h&]jjuh1juhhhKhjubh)}(hIt is that simple!h]hIt is that simple!}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubeh}(h]h ]h"]h$]h&]uh1jahhhKhjhhubeh}(h]building-multiple-modulesah ]h"]building multiple modulesah$]h&]uh1hhj|hhhhhKubeh}(h]jah ]h"]-creating a kbuild file for an external moduleah$]h&]uh1hhhhhhhhK referencedKubh)}(hhh](h)}(h Include Filesh]h Include Files}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj$hhhhhMubh)}(h_Within the kernel, header files are kept in standard locations according to the following rule:h]h_Within the kernel, header files are kept in standard locations according to the following rule:}(hj5hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj$hhubjb)}(hX&* If the header file only describes the internal interface of a module, then the file is placed in the same directory as the source files. * If the header file describes an interface used by other parts of the kernel that are located in different directories, then the file is placed in include/linux/. NOTE: There are two notable exceptions to this rule: larger subsystems have their own directory under include/, such as include/scsi; and architecture specific headers are located under arch/$(SRCARCH)/include/. h]h bullet_list)}(hhh](h list_item)}(hIf the header file only describes the internal interface of a module, then the file is placed in the same directory as the source files.h]h)}(hIf the header file only describes the internal interface of a module, then the file is placed in the same directory as the source files.h]hIf the header file only describes the internal interface of a module, then the file is placed in the same directory as the source files.}(hjRhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hjNubah}(h]h ]h"]h$]h&]uh1jLhjIubjM)}(hXIf the header file describes an interface used by other parts of the kernel that are located in different directories, then the file is placed in include/linux/. NOTE: There are two notable exceptions to this rule: larger subsystems have their own directory under include/, such as include/scsi; and architecture specific headers are located under arch/$(SRCARCH)/include/. h](h)}(hIf the header file describes an interface used by other parts of the kernel that are located in different directories, then the file is placed in include/linux/.h]hIf the header file describes an interface used by other parts of the kernel that are located in different directories, then the file is placed in include/linux/.}(hjjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hjfubjU)}(hhh]jZ)}(hNOTE: There are two notable exceptions to this rule: larger subsystems have their own directory under include/, such as include/scsi; and architecture specific headers are located under arch/$(SRCARCH)/include/. h](j`)}(hNOTE:h]hNOTE:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j_hhhMhj{ubjp)}(hhh]h)}(hThere are two notable exceptions to this rule: larger subsystems have their own directory under include/, such as include/scsi; and architecture specific headers are located under arch/$(SRCARCH)/include/.h]hThere are two notable exceptions to this rule: larger subsystems have their own directory under include/, such as include/scsi; and architecture specific headers are located under arch/$(SRCARCH)/include/.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1johj{ubeh}(h]h ]h"]h$]h&]uh1jYhhhMhjxubah}(h]h ]h"]h$]h&]uh1jThjfubeh}(h]h ]h"]h$]h&]uh1jLhjIubeh}(h]h ]h"]h$]h&]bullet*uh1jGhhhM hjCubah}(h]h ]h"]h$]h&]uh1jahhhM hj$hhubh)}(hhh](h)}(hKernel Includesh]hKernel Includes}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubjb)}(hTo include a header file located under include/linux/, simply use:: #include kbuild will add options to the compiler so the relevant directories are searched. h](h)}(hCTo include a header file located under include/linux/, simply use::h]hBTo include a header file located under include/linux/, simply use:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubjv)}(h#include h]h#include }hjsbah}(h]h ]h"]h$]h&]jjuh1juhhhMhjubh)}(hQkbuild will add options to the compiler so the relevant directories are searched.h]hQkbuild will add options to the compiler so the relevant directories are searched.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubeh}(h]h ]h"]h$]h&]uh1jahhhMhjhhubeh}(h]kernel-includesah ]h"]kernel includesah$]h&]uh1hhj$hhhhhMubh)}(hhh](h)}(hSingle Subdirectoryh]hSingle Subdirectory}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhM"ubjb)}(hXExternal modules tend to place header files in a separate include/ directory where their source is located, although this is not the usual kernel style. To inform kbuild of the directory, use either ccflags-y or CFLAGS_.o. Using the example from section 3, if we moved 8123_if.h to a subdirectory named include, the resulting kbuild file would look like:: --> filename: Kbuild obj-m := 8123.o ccflags-y := -I $(src)/include 8123-y := 8123_if.o 8123_pci.o h](h)}(hExternal modules tend to place header files in a separate include/ directory where their source is located, although this is not the usual kernel style. To inform kbuild of the directory, use either ccflags-y or CFLAGS_.o.h]hExternal modules tend to place header files in a separate include/ directory where their source is located, although this is not the usual kernel style. To inform kbuild of the directory, use either ccflags-y or CFLAGS_.o.}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM$hj"ubh)}(hUsing the example from section 3, if we moved 8123_if.h to a subdirectory named include, the resulting kbuild file would look like::h]hUsing the example from section 3, if we moved 8123_if.h to a subdirectory named include, the resulting kbuild file would look like:}(hj4hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM)hj"ubjv)}(hc--> filename: Kbuild obj-m := 8123.o ccflags-y := -I $(src)/include 8123-y := 8123_if.o 8123_pci.oh]hc--> filename: Kbuild obj-m := 8123.o ccflags-y := -I $(src)/include 8123-y := 8123_if.o 8123_pci.o}hjBsbah}(h]h ]h"]h$]h&]jjuh1juhhhM-hj"ubeh}(h]h ]h"]h$]h&]uh1jahhhM$hjhhubeh}(h]single-subdirectoryah ]h"]single subdirectoryah$]h&]uh1hhj$hhhhhM"ubh)}(hhh](h)}(hSeveral Subdirectoriesh]hSeveral Subdirectories}(hjahhhNhNubah}(h]h ]h"]h$]h&]uh1hhj^hhhhhM4ubjb)}(hXkbuild can handle files that are spread over several directories. Consider the following example:: . |__ src | |__ complex_main.c | |__ hal | |__ hardwareif.c | |__ include | |__ hardwareif.h |__ include |__ complex.h To build the module complex.ko, we then need the following kbuild file:: --> filename: Kbuild obj-m := complex.o complex-y := src/complex_main.o complex-y += src/hal/hardwareif.o ccflags-y := -I$(src)/include ccflags-y += -I$(src)/src/hal/include As you can see, kbuild knows how to handle object files located in other directories. The trick is to specify the directory relative to the kbuild file's location. That being said, this is NOT recommended practice. For the header files, kbuild must be explicitly told where to look. When kbuild executes, the current directory is always the root of the kernel tree (the argument to "-C") and therefore an absolute path is needed. $(src) provides the absolute path by pointing to the directory where the currently executing kbuild file is located. h](h)}(hbkbuild can handle files that are spread over several directories. Consider the following example::h]hakbuild can handle files that are spread over several directories. Consider the following example:}(hjshhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM6hjoubjv)}(h. |__ src | |__ complex_main.c | |__ hal | |__ hardwareif.c | |__ include | |__ hardwareif.h |__ include |__ complex.hh]h. |__ src | |__ complex_main.c | |__ hal | |__ hardwareif.c | |__ include | |__ hardwareif.h |__ include |__ complex.h}hjsbah}(h]h ]h"]h$]h&]jjuh1juhhhM9hjoubh)}(hHTo build the module complex.ko, we then need the following kbuild file::h]hGTo build the module complex.ko, we then need the following kbuild file:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMChjoubjv)}(h--> filename: Kbuild obj-m := complex.o complex-y := src/complex_main.o complex-y += src/hal/hardwareif.o ccflags-y := -I$(src)/include ccflags-y += -I$(src)/src/hal/includeh]h--> filename: Kbuild obj-m := complex.o complex-y := src/complex_main.o complex-y += src/hal/hardwareif.o ccflags-y := -I$(src)/include ccflags-y += -I$(src)/src/hal/include}hjsbah}(h]h ]h"]h$]h&]jjuh1juhhhMFhjoubh)}(hAs you can see, kbuild knows how to handle object files located in other directories. The trick is to specify the directory relative to the kbuild file's location. That being said, this is NOT recommended practice.h]hAs you can see, kbuild knows how to handle object files located in other directories. The trick is to specify the directory relative to the kbuild file’s location. That being said, this is NOT recommended practice.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMNhjoubh)}(hXKFor the header files, kbuild must be explicitly told where to look. When kbuild executes, the current directory is always the root of the kernel tree (the argument to "-C") and therefore an absolute path is needed. $(src) provides the absolute path by pointing to the directory where the currently executing kbuild file is located.h]hXOFor the header files, kbuild must be explicitly told where to look. When kbuild executes, the current directory is always the root of the kernel tree (the argument to “-C”) and therefore an absolute path is needed. $(src) provides the absolute path by pointing to the directory where the currently executing kbuild file is located.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMShjoubeh}(h]h ]h"]h$]h&]uh1jahhhM6hj^hhubeh}(h]several-subdirectoriesah ]h"]several subdirectoriesah$]h&]uh1hhj$hhhhhM4ubeh}(h] include-filesah ]h"] include filesah$]h&]uh1hhhhhhhhMubh)}(hhh](h)}(hModule Installationh]hModule Installation}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhM\ubh)}(hHModules which are included in the kernel are installed in the directory:h]hHModules which are included in the kernel are installed in the directory:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM^hjhhubjb)}(h&/lib/modules/$(KERNELRELEASE)/kernel/ h]h)}(h%/lib/modules/$(KERNELRELEASE)/kernel/h]h%/lib/modules/$(KERNELRELEASE)/kernel/}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMahjubah}(h]h ]h"]h$]h&]uh1jahhhMahjhhubh)}(h&And external modules are installed in:h]h&And external modules are installed in:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMchjhhubjb)}(h'/lib/modules/$(KERNELRELEASE)/updates/ h]h)}(h&/lib/modules/$(KERNELRELEASE)/updates/h]h&/lib/modules/$(KERNELRELEASE)/updates/}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMehj"ubah}(h]h ]h"]h$]h&]uh1jahhhMehjhhubh)}(hhh](h)}(hINSTALL_MOD_PATHh]hINSTALL_MOD_PATH}(hj=hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj:hhhhhMhubjb)}(hXAbove are the default directories but as always some level of customization is possible. A prefix can be added to the installation path using the variable INSTALL_MOD_PATH:: $ make INSTALL_MOD_PATH=/frodo modules_install => Install dir: /frodo/lib/modules/$(KERNELRELEASE)/kernel/ INSTALL_MOD_PATH may be set as an ordinary shell variable or, as shown above, can be specified on the command line when calling "make." This has effect when installing both in-tree and out-of-tree modules. h](h)}(hAbove are the default directories but as always some level of customization is possible. A prefix can be added to the installation path using the variable INSTALL_MOD_PATH::h]hAbove are the default directories but as always some level of customization is possible. A prefix can be added to the installation path using the variable INSTALL_MOD_PATH:}(hjOhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMjhjKubjv)}(hj$ make INSTALL_MOD_PATH=/frodo modules_install => Install dir: /frodo/lib/modules/$(KERNELRELEASE)/kernel/h]hj$ make INSTALL_MOD_PATH=/frodo modules_install => Install dir: /frodo/lib/modules/$(KERNELRELEASE)/kernel/}hj]sbah}(h]h ]h"]h$]h&]jjuh1juhhhMnhjKubh)}(hINSTALL_MOD_PATH may be set as an ordinary shell variable or, as shown above, can be specified on the command line when calling "make." This has effect when installing both in-tree and out-of-tree modules.h]hINSTALL_MOD_PATH may be set as an ordinary shell variable or, as shown above, can be specified on the command line when calling “make.” This has effect when installing both in-tree and out-of-tree modules.}(hjkhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMqhjKubeh}(h]h ]h"]h$]h&]uh1jahhhMjhj:hhubeh}(h]install-mod-pathah ]h"]install_mod_pathah$]h&]uh1hhjhhhhhMhubh)}(hhh](h)}(hINSTALL_MOD_DIRh]hINSTALL_MOD_DIR}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMwubjb)}(hXExternal modules are by default installed to a directory under /lib/modules/$(KERNELRELEASE)/updates/, but you may wish to locate modules for a specific functionality in a separate directory. For this purpose, use INSTALL_MOD_DIR to specify an alternative name to "updates.":: $ make INSTALL_MOD_DIR=gandalf -C $KDIR \ M=$PWD modules_install => Install dir: /lib/modules/$(KERNELRELEASE)/gandalf/ h](h)}(hXExternal modules are by default installed to a directory under /lib/modules/$(KERNELRELEASE)/updates/, but you may wish to locate modules for a specific functionality in a separate directory. For this purpose, use INSTALL_MOD_DIR to specify an alternative name to "updates."::h]hXExternal modules are by default installed to a directory under /lib/modules/$(KERNELRELEASE)/updates/, but you may wish to locate modules for a specific functionality in a separate directory. For this purpose, use INSTALL_MOD_DIR to specify an alternative name to “updates.”:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMyhjubjv)}(h~$ make INSTALL_MOD_DIR=gandalf -C $KDIR \ M=$PWD modules_install => Install dir: /lib/modules/$(KERNELRELEASE)/gandalf/h]h~$ make INSTALL_MOD_DIR=gandalf -C $KDIR \ M=$PWD modules_install => Install dir: /lib/modules/$(KERNELRELEASE)/gandalf/}hjsbah}(h]h ]h"]h$]h&]jjuh1juhhhMhjubeh}(h]h ]h"]h$]h&]uh1jahhhMyhjhhubeh}(h]install-mod-dirah ]h"]install_mod_dirah$]h&]uh1hhjhhhhhMwubeh}(h]jah ]h"]module installationah$]h&]uh1hhhhhhhhM\j#Kubh)}(hhh](h)}(hModule Versioningh]hModule Versioning}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hXbModule versioning is enabled by the CONFIG_MODVERSIONS tag, and is used as a simple ABI consistency check. A CRC value of the full prototype for an exported symbol is created. When a module is loaded/used, the CRC values contained in the kernel are compared with similar values in the module; if they are not equal, the kernel refuses to load the module.h]hXbModule versioning is enabled by the CONFIG_MODVERSIONS tag, and is used as a simple ABI consistency check. A CRC value of the full prototype for an exported symbol is created. When a module is loaded/used, the CRC values contained in the kernel are compared with similar values in the module; if they are not equal, the kernel refuses to load the module.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hKModule.symvers contains a list of all exported symbols from a kernel build.h]hKModule.symvers contains a list of all exported symbols from a kernel build.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hhh](h)}(h+Symbols From the Kernel (vmlinux + modules)h]h+Symbols From the Kernel (vmlinux + modules)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubjb)}(hX2During a kernel build, a file named Module.symvers will be generated. Module.symvers contains all exported symbols from the kernel and compiled modules. For each symbol, the corresponding CRC value is also stored. The syntax of the Module.symvers file is:: 0xe1cc2a05 usb_stor_suspend drivers/usb/storage/usb-storage EXPORT_SYMBOL_GPL USB_STORAGE The fields are separated by tabs and values may be empty (e.g. if no namespace is defined for an exported symbol). For a kernel build without CONFIG_MODVERSIONS enabled, the CRC would read 0x00000000. Module.symvers serves two purposes: 1) It lists all exported symbols from vmlinux and all modules. 2) It lists the CRC if CONFIG_MODVERSIONS is enabled. h](h)}(hDuring a kernel build, a file named Module.symvers will be generated. Module.symvers contains all exported symbols from the kernel and compiled modules. For each symbol, the corresponding CRC value is also stored.h]hDuring a kernel build, a file named Module.symvers will be generated. Module.symvers contains all exported symbols from the kernel and compiled modules. For each symbol, the corresponding CRC value is also stored.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubh)}(h*The syntax of the Module.symvers file is::h]h)The syntax of the Module.symvers file is:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubjv)}(h 0xe1cc2a05 usb_stor_suspend drivers/usb/storage/usb-storage EXPORT_SYMBOL_GPL USB_STORAGEh]h 0xe1cc2a05 usb_stor_suspend drivers/usb/storage/usb-storage EXPORT_SYMBOL_GPL USB_STORAGE}hj+ sbah}(h]h ]h"]h$]h&]jjuh1juhhhMhj ubh)}(hrThe fields are separated by tabs and values may be empty (e.g. if no namespace is defined for an exported symbol).h]hrThe fields are separated by tabs and values may be empty (e.g. if no namespace is defined for an exported symbol).}(hj9 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubh)}(hUFor a kernel build without CONFIG_MODVERSIONS enabled, the CRC would read 0x00000000.h]hUFor a kernel build without CONFIG_MODVERSIONS enabled, the CRC would read 0x00000000.}(hjG hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubh)}(h#Module.symvers serves two purposes:h]h#Module.symvers serves two purposes:}(hjU hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubhenumerated_list)}(hhh](jM)}(h;It lists all exported symbols from vmlinux and all modules.h]h)}(hjj h]h;It lists all exported symbols from vmlinux and all modules.}(hjl hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjh ubah}(h]h ]h"]h$]h&]uh1jLhje ubjM)}(h3It lists the CRC if CONFIG_MODVERSIONS is enabled. h]h)}(h2It lists the CRC if CONFIG_MODVERSIONS is enabled.h]h2It lists the CRC if CONFIG_MODVERSIONS is enabled.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1jLhje ubeh}(h]h ]h"]h$]h&]enumtypearabicprefixhsuffix)uh1jc hj ubeh}(h]h ]h"]h$]h&]uh1jahhhMhjhhubeh}(h]'symbols-from-the-kernel-vmlinux-modulesah ]h"]+symbols from the kernel (vmlinux + modules)ah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(hVersion Information Formatsh]hVersion Information Formats}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhMubjb)}(hXExported symbols have information stored in __ksymtab or __ksymtab_gpl sections. Symbol names and namespaces are stored in __ksymtab_strings, using a format similar to the string table used for ELF. If CONFIG_MODVERSIONS is enabled, the CRCs corresponding to exported symbols will be added to the __kcrctab or __kcrctab_gpl. If CONFIG_BASIC_MODVERSIONS is enabled (default with CONFIG_MODVERSIONS), imported symbols will have their symbol name and CRC stored in the __versions section of the importing module. This mode only supports symbols of length up to 64 bytes. If CONFIG_EXTENDED_MODVERSIONS is enabled (required to enable both CONFIG_MODVERSIONS and CONFIG_RUST at the same time), imported symbols will have their symbol name recorded in the __version_ext_names section as a series of concatenated, null-terminated strings. CRCs for these symbols will be recorded in the __version_ext_crcs section. h](h)}(hXDExported symbols have information stored in __ksymtab or __ksymtab_gpl sections. Symbol names and namespaces are stored in __ksymtab_strings, using a format similar to the string table used for ELF. If CONFIG_MODVERSIONS is enabled, the CRCs corresponding to exported symbols will be added to the __kcrctab or __kcrctab_gpl.h]hXDExported symbols have information stored in __ksymtab or __ksymtab_gpl sections. Symbol names and namespaces are stored in __ksymtab_strings, using a format similar to the string table used for ELF. If CONFIG_MODVERSIONS is enabled, the CRCs corresponding to exported symbols will be added to the __kcrctab or __kcrctab_gpl.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubh)}(hIf CONFIG_BASIC_MODVERSIONS is enabled (default with CONFIG_MODVERSIONS), imported symbols will have their symbol name and CRC stored in the __versions section of the importing module. This mode only supports symbols of length up to 64 bytes.h]hIf CONFIG_BASIC_MODVERSIONS is enabled (default with CONFIG_MODVERSIONS), imported symbols will have their symbol name and CRC stored in the __versions section of the importing module. This mode only supports symbols of length up to 64 bytes.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubh)}(hXRIf CONFIG_EXTENDED_MODVERSIONS is enabled (required to enable both CONFIG_MODVERSIONS and CONFIG_RUST at the same time), imported symbols will have their symbol name recorded in the __version_ext_names section as a series of concatenated, null-terminated strings. CRCs for these symbols will be recorded in the __version_ext_crcs section.h]hXRIf CONFIG_EXTENDED_MODVERSIONS is enabled (required to enable both CONFIG_MODVERSIONS and CONFIG_RUST at the same time), imported symbols will have their symbol name recorded in the __version_ext_names section as a series of concatenated, null-terminated strings. CRCs for these symbols will be recorded in the __version_ext_crcs section.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubeh}(h]h ]h"]h$]h&]uh1jahhhMhj hhubeh}(h]version-information-formatsah ]h"]version information formatsah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(hSymbols and External Modulesh]hSymbols and External Modules}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhMubjb)}(hXWhen building an external module, the build system needs access to the symbols from the kernel to check if all external symbols are defined. This is done in the MODPOST step. modpost obtains the symbols by reading Module.symvers from the kernel source tree. During the MODPOST step, a new Module.symvers file will be written containing all exported symbols from that external module. h]h)}(hXWhen building an external module, the build system needs access to the symbols from the kernel to check if all external symbols are defined. This is done in the MODPOST step. modpost obtains the symbols by reading Module.symvers from the kernel source tree. During the MODPOST step, a new Module.symvers file will be written containing all exported symbols from that external module.h]hXWhen building an external module, the build system needs access to the symbols from the kernel to check if all external symbols are defined. This is done in the MODPOST step. modpost obtains the symbols by reading Module.symvers from the kernel source tree. During the MODPOST step, a new Module.symvers file will be written containing all exported symbols from that external module.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1jahhhMhj hhubeh}(h]symbols-and-external-modulesah ]h"]symbols and external modulesah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(h$Symbols From Another External Moduleh]h$Symbols From Another External Module}(hj1 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj. hhhhhMubjb)}(hXFSometimes, an external module uses exported symbols from another external module. Kbuild needs to have full knowledge of all symbols to avoid spitting out warnings about undefined symbols. Two solutions exist for this situation. NOTE: The method with a top-level kbuild file is recommended but may be impractical in certain situations. Use a top-level kbuild file If you have two modules, foo.ko and bar.ko, where foo.ko needs symbols from bar.ko, you can use a common top-level kbuild file so both modules are compiled in the same build. Consider the following directory layout:: ./foo/ <= contains foo.ko ./bar/ <= contains bar.ko The top-level kbuild file would then look like:: #./Kbuild (or ./Makefile): obj-m := foo/ bar/ And executing:: $ make -C $KDIR M=$PWD will then do the expected and compile both modules with full knowledge of symbols from either module. Use "make" variable KBUILD_EXTRA_SYMBOLS If it is impractical to add a top-level kbuild file, you can assign a space separated list of files to KBUILD_EXTRA_SYMBOLS in your build file. These files will be loaded by modpost during the initialization of its symbol tables. h](h)}(hSometimes, an external module uses exported symbols from another external module. Kbuild needs to have full knowledge of all symbols to avoid spitting out warnings about undefined symbols. Two solutions exist for this situation.h]hSometimes, an external module uses exported symbols from another external module. Kbuild needs to have full knowledge of all symbols to avoid spitting out warnings about undefined symbols. Two solutions exist for this situation.}(hjC hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj? ubh)}(hjNOTE: The method with a top-level kbuild file is recommended but may be impractical in certain situations.h]hjNOTE: The method with a top-level kbuild file is recommended but may be impractical in certain situations.}(hjQ hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj? ubjU)}(hhh](jZ)}(hXKUse a top-level kbuild file If you have two modules, foo.ko and bar.ko, where foo.ko needs symbols from bar.ko, you can use a common top-level kbuild file so both modules are compiled in the same build. Consider the following directory layout:: ./foo/ <= contains foo.ko ./bar/ <= contains bar.ko The top-level kbuild file would then look like:: #./Kbuild (or ./Makefile): obj-m := foo/ bar/ And executing:: $ make -C $KDIR M=$PWD will then do the expected and compile both modules with full knowledge of symbols from either module. h](j`)}(hUse a top-level kbuild fileh]hUse a top-level kbuild file}(hjf hhhNhNubah}(h]h ]h"]h$]h&]uh1j_hhhMhjb ubjp)}(hhh](h)}(hIf you have two modules, foo.ko and bar.ko, where foo.ko needs symbols from bar.ko, you can use a common top-level kbuild file so both modules are compiled in the same build. Consider the following directory layout::h]hIf you have two modules, foo.ko and bar.ko, where foo.ko needs symbols from bar.ko, you can use a common top-level kbuild file so both modules are compiled in the same build. Consider the following directory layout:}(hjw hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjt ubjv)}(h3./foo/ <= contains foo.ko ./bar/ <= contains bar.koh]h3./foo/ <= contains foo.ko ./bar/ <= contains bar.ko}hj sbah}(h]h ]h"]h$]h&]jjuh1juhhhMhjt ubh)}(h0The top-level kbuild file would then look like::h]h/The top-level kbuild file would then look like:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjt ubjv)}(h5#./Kbuild (or ./Makefile): obj-m := foo/ bar/h]h5#./Kbuild (or ./Makefile): obj-m := foo/ bar/}hj sbah}(h]h ]h"]h$]h&]jjuh1juhhhMhjt ubh)}(hAnd executing::h]hAnd executing:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjt ubjv)}(h$ make -C $KDIR M=$PWDh]h$ make -C $KDIR M=$PWD}hj sbah}(h]h ]h"]h$]h&]jjuh1juhhhMhjt ubh)}(hewill then do the expected and compile both modules with full knowledge of symbols from either module.h]hewill then do the expected and compile both modules with full knowledge of symbols from either module.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjt ubeh}(h]h ]h"]h$]h&]uh1johjb ubeh}(h]h ]h"]h$]h&]uh1jYhhhMhj_ ubjZ)}(hXUse "make" variable KBUILD_EXTRA_SYMBOLS If it is impractical to add a top-level kbuild file, you can assign a space separated list of files to KBUILD_EXTRA_SYMBOLS in your build file. These files will be loaded by modpost during the initialization of its symbol tables. h](j`)}(h(Use "make" variable KBUILD_EXTRA_SYMBOLSh]h,Use “make” variable KBUILD_EXTRA_SYMBOLS}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j_hhhMhj ubjp)}(hhh]h)}(hIf it is impractical to add a top-level kbuild file, you can assign a space separated list of files to KBUILD_EXTRA_SYMBOLS in your build file. These files will be loaded by modpost during the initialization of its symbol tables.h]hIf it is impractical to add a top-level kbuild file, you can assign a space separated list of files to KBUILD_EXTRA_SYMBOLS in your build file. These files will be loaded by modpost during the initialization of its symbol tables.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1johj ubeh}(h]h ]h"]h$]h&]uh1jYhhhMhj_ ubeh}(h]h ]h"]h$]h&]uh1jThj? ubeh}(h]h ]h"]h$]h&]uh1jahhhMhj. hhubeh}(h]$symbols-from-another-external-moduleah ]h"]$symbols from another external moduleah$]h&]uh1hhjhhhhhMubeh}(h]module-versioningah ]h"]module versioningah$]h&]uh1hhhhhhhhMubh)}(hhh](h)}(h Tips & Tricksh]h Tips & Tricks}(hj3 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj0 hhhhhMubh)}(hhh](h)}(hTesting for CONFIG_FOO_BARh]hTesting for CONFIG_FOO_BAR}(hjD hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjA hhhhhMubjb)}(hXZModules often need to check for certain `CONFIG_` options to decide if a specific feature is included in the module. In kbuild this is done by referencing the `CONFIG_` variable directly:: #fs/ext2/Makefile obj-$(CONFIG_EXT2_FS) += ext2.o ext2-y := balloc.o bitmap.o dir.o ext2-$(CONFIG_EXT2_FS_XATTR) += xattr.oh](h)}(hModules often need to check for certain `CONFIG_` options to decide if a specific feature is included in the module. In kbuild this is done by referencing the `CONFIG_` variable directly::h](h(Modules often need to check for certain }(hjV hhhNhNubj)}(h `CONFIG_`h]hCONFIG_}(hj^ hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjV ubhn options to decide if a specific feature is included in the module. In kbuild this is done by referencing the }(hjV hhhNhNubj)}(h `CONFIG_`h]hCONFIG_}(hjp hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjV ubh variable directly:}(hjV hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjR ubjv)}(h|#fs/ext2/Makefile obj-$(CONFIG_EXT2_FS) += ext2.o ext2-y := balloc.o bitmap.o dir.o ext2-$(CONFIG_EXT2_FS_XATTR) += xattr.oh]h|#fs/ext2/Makefile obj-$(CONFIG_EXT2_FS) += ext2.o ext2-y := balloc.o bitmap.o dir.o ext2-$(CONFIG_EXT2_FS_XATTR) += xattr.o}hj sbah}(h]h ]h"]h$]h&]jjuh1juhhhMhjR ubeh}(h]h ]h"]h$]h&]uh1jahhhMhjA hhubeh}(h]testing-for-config-foo-barah ]h"]testing for config_foo_barah$]h&]uh1hhj0 hhhhhMubeh}(h] tips-tricksah ]h"] tips & tricksah$]h&]uh1hhhhhhhhMubeh}(h]building-external-modulesah ]h"]building external modulesah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerj error_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}(-creating a kbuild file for an external module]hamodule installation]jaurefids}nameids}(j j jjjyjvjjjjj$j!jqjnj jjGjDjjjjjjjj j[jXjjjjjjjjj- j* j j j j j+ j( j% j" j j j j u nametypes}(j jjyjjj$jqj jGjjjjj[jjjjj- j j j+ j% j j uh}(j hjhjvjjjPjjj!jjnj'jj|jDjjjJjjjj$j jjXjjj^jjjj:jjj* jj jj j j( j j" j. j j0 j jA u footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages] transformerN include_log] decorationNhhub.