Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0
0002 # ===========================================================================
0003 # Module versions
0004 # ===========================================================================
0005 #
0006 # Stage one of module building created the following:
0007 # a) The individual .o files used for the module
0008 # b) A <module>.o file which is the .o files above linked together
0009 # c) A <module>.mod file, listing the name of the preliminary <module>.o file,
0010 #    plus all .o files
0011 # d) modules.order, which lists all the modules
0012 
0013 # Stage 2 is handled by this file and does the following
0014 # 1) Find all modules listed in modules.order
0015 # 2) modpost is then used to
0016 # 3)  create one <module>.mod.c file per module
0017 # 4)  create one Module.symvers file with CRC for all exported symbols
0018 
0019 # Step 3 is used to place certain information in the module's ELF
0020 # section, including information such as:
0021 #   Version magic (see include/linux/vermagic.h for full details)
0022 #     - Kernel release
0023 #     - SMP is CONFIG_SMP
0024 #     - PREEMPT is CONFIG_PREEMPT[_RT]
0025 #     - GCC Version
0026 #   Module info
0027 #     - Module version (MODULE_VERSION)
0028 #     - Module alias'es (MODULE_ALIAS)
0029 #     - Module license (MODULE_LICENSE)
0030 #     - See include/linux/module.h for more details
0031 
0032 # Step 4 is solely used to allow module versioning in external modules,
0033 # where the CRC of each module is retrieved from the Module.symvers file.
0034 
0035 # KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
0036 # This is solely useful to speed up test compiles
0037 
0038 PHONY := __modpost
0039 __modpost:
0040 
0041 include include/config/auto.conf
0042 include $(srctree)/scripts/Kbuild.include
0043 
0044 MODPOST = scripts/mod/modpost                                                           \
0045         $(if $(CONFIG_MODVERSIONS),-m)                                                  \
0046         $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a)                                        \
0047         $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E)                                  \
0048         -o $@
0049 
0050 ifdef MODPOST_VMLINUX
0051 
0052 quiet_cmd_modpost = MODPOST $@
0053       cmd_modpost = $(MODPOST) $<
0054 
0055 vmlinux.symvers: vmlinux.o
0056         $(call cmd,modpost)
0057 
0058 __modpost: vmlinux.symvers
0059 
0060 else
0061 
0062 ifeq ($(KBUILD_EXTMOD),)
0063 
0064 input-symdump := vmlinux.symvers
0065 output-symdump := modules-only.symvers
0066 
0067 quiet_cmd_cat = GEN     $@
0068       cmd_cat = cat $(real-prereqs) > $@
0069 
0070 ifneq ($(wildcard vmlinux.symvers),)
0071 
0072 __modpost: Module.symvers
0073 Module.symvers: vmlinux.symvers modules-only.symvers FORCE
0074         $(call if_changed,cat)
0075 
0076 targets += Module.symvers
0077 
0078 endif
0079 
0080 else
0081 
0082 # set src + obj - they may be used in the modules's Makefile
0083 obj := $(KBUILD_EXTMOD)
0084 src := $(obj)
0085 
0086 # Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS
0087 include $(or $(wildcard $(src)/Kbuild), $(src)/Makefile) 
0088 
0089 # modpost option for external modules
0090 MODPOST += -e
0091 
0092 input-symdump := Module.symvers $(KBUILD_EXTRA_SYMBOLS)
0093 output-symdump := $(KBUILD_EXTMOD)/Module.symvers
0094 
0095 endif
0096 
0097 existing-input-symdump := $(wildcard $(input-symdump))
0098 
0099 # modpost options for modules (both in-kernel and external)
0100 MODPOST += \
0101         $(addprefix -i ,$(existing-input-symdump)) \
0102         $(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS)) \
0103         $(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N)
0104 
0105 # 'make -i -k' ignores compile errors, and builds as many modules as possible.
0106 ifneq ($(findstring i,$(filter-out --%,$(MAKEFLAGS))),)
0107 MODPOST += -n
0108 endif
0109 
0110 # Clear VPATH to not search for *.symvers in $(srctree). Check only $(objtree).
0111 VPATH :=
0112 $(input-symdump):
0113         @echo >&2 'WARNING: Symbol version dump "$@" is missing.'
0114         @echo >&2 '         Modules may not have dependencies or modversions.'
0115         @echo >&2 '         You may get many unresolved symbol warnings.'
0116 
0117 # KBUILD_MODPOST_WARN can be set to avoid error out in case of undefined symbols
0118 ifneq ($(KBUILD_MODPOST_WARN)$(filter-out $(existing-input-symdump), $(input-symdump)),)
0119 MODPOST += -w
0120 endif
0121 
0122 # Read out modules.order to pass in modpost.
0123 # Otherwise, allmodconfig would fail with "Argument list too long".
0124 quiet_cmd_modpost = MODPOST $@
0125       cmd_modpost = sed 's/ko$$/o/' $< | $(MODPOST) -T -
0126 
0127 $(output-symdump): $(MODORDER) $(input-symdump) FORCE
0128         $(call if_changed,modpost)
0129 
0130 targets += $(output-symdump)
0131 
0132 __modpost: $(output-symdump)
0133 ifneq ($(KBUILD_MODPOST_NOFINAL),1)
0134         $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal
0135 endif
0136 
0137 PHONY += FORCE
0138 FORCE:
0139 
0140 existing-targets := $(wildcard $(sort $(targets)))
0141 
0142 -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 
0143 
0144 endif
0145 
0146 .PHONY: $(PHONY)