b24413180f560 (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100 1) # SPDX-License-Identifier: GPL-2.0
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 2) # ===========================================================================
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 3) # Module versions
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 4) # ===========================================================================
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 5) #
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 6) # Stage one of module building created the following:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 7) # a) The individual .o files used for the module
c30fe7f731946 (Uwe Zeisberger 2006-03-24 18:23:14 +0100 8) # b) A <module>.o file which is the .o files above linked together
b7dca6dd1e591 (Masahiro Yamada 2019-07-17 15:17:57 +0900 9) # c) A <module>.mod file, listing the name of the preliminary <module>.o file,
b7dca6dd1e591 (Masahiro Yamada 2019-07-17 15:17:57 +0900 10) # plus all .o files
ff9b45c55b265 (Masahiro Yamada 2019-07-17 15:17:55 +0900 11) # d) modules.order, which lists all the modules
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 12)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 13) # Stage 2 is handled by this file and does the following
ff9b45c55b265 (Masahiro Yamada 2019-07-17 15:17:55 +0900 14) # 1) Find all modules listed in modules.order
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 15) # 2) modpost is then used to
7c80144626db4 (Ramji Jiyani 2021-09-16 09:21:22 +0000 16) # 3) create one <module>.mod.c file per module
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 17) # 4) create one Module.symvers file with CRC for all exported symbols
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 18)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 19) # Step 3 is used to place certain information in the module's ELF
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 20) # section, including information such as:
163d3fe6a2357 (Geert Uytterhoeven 2011-05-25 11:09:59 +0200 21) # Version magic (see include/linux/vermagic.h for full details)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 22) # - Kernel release
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 23) # - SMP is CONFIG_SMP
4b950bb9ac0c7 (Thomas Gleixner 2019-07-28 20:27:41 +0200 24) # - PREEMPT is CONFIG_PREEMPT[_RT]
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 25) # - GCC Version
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 26) # Module info
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 27) # - Module version (MODULE_VERSION)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 28) # - Module alias'es (MODULE_ALIAS)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 29) # - Module license (MODULE_LICENSE)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 30) # - See include/linux/module.h for more details
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 31)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 32) # Step 4 is solely used to allow module versioning in external modules,
4696e2958b345 (Uwe Kleine-König 2010-07-30 20:43:20 +0200 33) # where the CRC of each module is retrieved from the Module.symvers file.
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 34)
ea837f1c05034 (Sam Ravnborg 2006-10-01 11:35:24 +0200 35) # KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
25985edcedea6 (Lucas De Marchi 2011-03-30 22:57:33 -0300 36) # This is solely useful to speed up test compiles
a721588d9475c (Masahiro Yamada 2019-07-31 00:59:02 +0900 37)
a721588d9475c (Masahiro Yamada 2019-07-31 00:59:02 +0900 38) PHONY := __modpost
a721588d9475c (Masahiro Yamada 2019-07-31 00:59:02 +0900 39) __modpost:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 40)
c955ccafc38e7 (Roman Zippel 2006-06-08 22:12:39 -0700 41) include include/config/auto.conf
3204a7fb98a3b (Masahiro Yamada 2021-02-28 15:10:26 +0900 42) include $(srctree)/scripts/Kbuild.include
0d96fb20b7ed7 (Richard Hacker 2008-02-28 09:40:58 +0100 43)
850ded46c6429 (Sami Tolvanen 2021-08-16 11:05:19 -0700 44) # for mod-prelink-ext
3204a7fb98a3b (Masahiro Yamada 2021-02-28 15:10:26 +0900 45) include $(srctree)/scripts/Makefile.lib
dc5723b02e523 (Sami Tolvanen 2020-12-11 10:46:19 -0800 46)
54b778476941c (Jessica Yu 2020-03-06 17:02:06 +0100 47) MODPOST = scripts/mod/modpost \
54b778476941c (Jessica Yu 2020-03-06 17:02:06 +0100 48) $(if $(CONFIG_MODVERSIONS),-m) \
54b778476941c (Jessica Yu 2020-03-06 17:02:06 +0100 49) $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \
54b778476941c (Jessica Yu 2020-03-06 17:02:06 +0100 50) $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \
bcfedae7d9288 (Masahiro Yamada 2020-06-01 14:57:09 +0900 51) -o $@
a721588d9475c (Masahiro Yamada 2019-07-31 00:59:02 +0900 52)
a721588d9475c (Masahiro Yamada 2019-07-31 00:59:02 +0900 53) ifdef MODPOST_VMLINUX
a721588d9475c (Masahiro Yamada 2019-07-31 00:59:02 +0900 54)
bcfedae7d9288 (Masahiro Yamada 2020-06-01 14:57:09 +0900 55) quiet_cmd_modpost = MODPOST $@
bcfedae7d9288 (Masahiro Yamada 2020-06-01 14:57:09 +0900 56) cmd_modpost = $(MODPOST) $<
a721588d9475c (Masahiro Yamada 2019-07-31 00:59:02 +0900 57)
269a535ca931b (Masahiro Yamada 2020-06-01 14:57:11 +0900 58) vmlinux.symvers: vmlinux.o
a721588d9475c (Masahiro Yamada 2019-07-31 00:59:02 +0900 59) $(call cmd,modpost)
a721588d9475c (Masahiro Yamada 2019-07-31 00:59:02 +0900 60)
269a535ca931b (Masahiro Yamada 2020-06-01 14:57:11 +0900 61) __modpost: vmlinux.symvers
bcfedae7d9288 (Masahiro Yamada 2020-06-01 14:57:09 +0900 62)
a721588d9475c (Masahiro Yamada 2019-07-31 00:59:02 +0900 63) else
a721588d9475c (Masahiro Yamada 2019-07-31 00:59:02 +0900 64)
1747269ab016b (Masahiro Yamada 2019-10-03 19:29:13 +0900 65) ifeq ($(KBUILD_EXTMOD),)
269a535ca931b (Masahiro Yamada 2020-06-01 14:57:11 +0900 66)
269a535ca931b (Masahiro Yamada 2020-06-01 14:57:11 +0900 67) input-symdump := vmlinux.symvers
69bc8d386aebb (Masahiro Yamada 2021-03-26 03:54:09 +0900 68) output-symdump := modules-only.symvers
69bc8d386aebb (Masahiro Yamada 2021-03-26 03:54:09 +0900 69)
69bc8d386aebb (Masahiro Yamada 2021-03-26 03:54:09 +0900 70) quiet_cmd_cat = GEN $@
69bc8d386aebb (Masahiro Yamada 2021-03-26 03:54:09 +0900 71) cmd_cat = cat $(real-prereqs) > $@
69bc8d386aebb (Masahiro Yamada 2021-03-26 03:54:09 +0900 72)
69bc8d386aebb (Masahiro Yamada 2021-03-26 03:54:09 +0900 73) ifneq ($(wildcard vmlinux.symvers),)
69bc8d386aebb (Masahiro Yamada 2021-03-26 03:54:09 +0900 74)
69bc8d386aebb (Masahiro Yamada 2021-03-26 03:54:09 +0900 75) __modpost: Module.symvers
69bc8d386aebb (Masahiro Yamada 2021-03-26 03:54:09 +0900 76) Module.symvers: vmlinux.symvers modules-only.symvers FORCE
69bc8d386aebb (Masahiro Yamada 2021-03-26 03:54:09 +0900 77) $(call if_changed,cat)
69bc8d386aebb (Masahiro Yamada 2021-03-26 03:54:09 +0900 78)
69bc8d386aebb (Masahiro Yamada 2021-03-26 03:54:09 +0900 79) targets += Module.symvers
69bc8d386aebb (Masahiro Yamada 2021-03-26 03:54:09 +0900 80)
69bc8d386aebb (Masahiro Yamada 2021-03-26 03:54:09 +0900 81) endif
bcfedae7d9288 (Masahiro Yamada 2020-06-01 14:57:09 +0900 82)
1747269ab016b (Masahiro Yamada 2019-10-03 19:29:13 +0900 83) else
96d97f262aa61 (Sam Ravnborg 2008-05-31 22:28:40 +0200 84)
fab546e6cd7ae (Masahiro Yamada 2019-11-06 23:52:15 +0900 85) # set src + obj - they may be used in the modules's Makefile
96d97f262aa61 (Sam Ravnborg 2008-05-31 22:28:40 +0200 86) obj := $(KBUILD_EXTMOD)
96d97f262aa61 (Sam Ravnborg 2008-05-31 22:28:40 +0200 87) src := $(obj)
96d97f262aa61 (Sam Ravnborg 2008-05-31 22:28:40 +0200 88)
0d96fb20b7ed7 (Richard Hacker 2008-02-28 09:40:58 +0100 89) # Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS
0d96fb20b7ed7 (Richard Hacker 2008-02-28 09:40:58 +0100 90) include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \
0d96fb20b7ed7 (Richard Hacker 2008-02-28 09:40:58 +0100 91) $(KBUILD_EXTMOD)/Kbuild, $(KBUILD_EXTMOD)/Makefile)
e3fb4df7fe4e8 (Masahiro Yamada 2020-06-01 14:57:08 +0900 92)
e3fb4df7fe4e8 (Masahiro Yamada 2020-06-01 14:57:08 +0900 93) # modpost option for external modules
e3fb4df7fe4e8 (Masahiro Yamada 2020-06-01 14:57:08 +0900 94) MODPOST += -e
e3fb4df7fe4e8 (Masahiro Yamada 2020-06-01 14:57:08 +0900 95)
f1005b30ade71 (Masahiro Yamada 2020-06-01 14:57:10 +0900 96) input-symdump := Module.symvers $(KBUILD_EXTRA_SYMBOLS)
bcfedae7d9288 (Masahiro Yamada 2020-06-01 14:57:09 +0900 97) output-symdump := $(KBUILD_EXTMOD)/Module.symvers
bcfedae7d9288 (Masahiro Yamada 2020-06-01 14:57:09 +0900 98)
0d96fb20b7ed7 (Richard Hacker 2008-02-28 09:40:58 +0100 99) endif
0d96fb20b7ed7 (Richard Hacker 2008-02-28 09:40:58 +0100 100)
4475dff55c54d (Masahiro Yamada 2021-03-26 03:54:11 +0900 101) existing-input-symdump := $(wildcard $(input-symdump))
4475dff55c54d (Masahiro Yamada 2021-03-26 03:54:11 +0900 102)
4e5ab74c3cbbe (Masahiro Yamada 2020-06-01 14:57:03 +0900 103) # modpost options for modules (both in-kernel and external)
4e5ab74c3cbbe (Masahiro Yamada 2020-06-01 14:57:03 +0900 104) MODPOST += \
4475dff55c54d (Masahiro Yamada 2021-03-26 03:54:11 +0900 105) $(addprefix -i ,$(existing-input-symdump)) \
859c926aea293 (Masahiro Yamada 2020-06-01 14:57:23 +0900 106) $(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS)) \
4e5ab74c3cbbe (Masahiro Yamada 2020-06-01 14:57:03 +0900 107) $(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N)
4e5ab74c3cbbe (Masahiro Yamada 2020-06-01 14:57:03 +0900 108)
91e6ee581270b (Masahiro Yamada 2020-06-01 14:57:01 +0900 109) # 'make -i -k' ignores compile errors, and builds as many modules as possible.
91e6ee581270b (Masahiro Yamada 2020-06-01 14:57:01 +0900 110) ifneq ($(findstring i,$(filter-out --%,$(MAKEFLAGS))),)
91e6ee581270b (Masahiro Yamada 2020-06-01 14:57:01 +0900 111) MODPOST += -n
91e6ee581270b (Masahiro Yamada 2020-06-01 14:57:01 +0900 112) endif
91e6ee581270b (Masahiro Yamada 2020-06-01 14:57:01 +0900 113)
48a0f72797bdc (Masahiro Yamada 2020-06-01 14:57:14 +0900 114) # Clear VPATH to not search for *.symvers in $(srctree). Check only $(objtree).
48a0f72797bdc (Masahiro Yamada 2020-06-01 14:57:14 +0900 115) VPATH :=
436b2ac603d58 (Masahiro Yamada 2020-06-01 14:57:12 +0900 116) $(input-symdump):
48a0f72797bdc (Masahiro Yamada 2020-06-01 14:57:14 +0900 117) @echo >&2 'WARNING: Symbol version dump "$@" is missing.'
48a0f72797bdc (Masahiro Yamada 2020-06-01 14:57:14 +0900 118) @echo >&2 ' Modules may not have dependencies or modversions.'
4475dff55c54d (Masahiro Yamada 2021-03-26 03:54:11 +0900 119) @echo >&2 ' You may get many unresolved symbol warnings.'
436b2ac603d58 (Masahiro Yamada 2020-06-01 14:57:12 +0900 120)
dc5723b02e523 (Sami Tolvanen 2020-12-11 10:46:19 -0800 121) modules := $(sort $(shell cat $(MODORDER)))
dc5723b02e523 (Sami Tolvanen 2020-12-11 10:46:19 -0800 122)
5ab70ff4286f7 (Masahiro Yamada 2021-03-26 03:54:10 +0900 123) # KBUILD_MODPOST_WARN can be set to avoid error out in case of undefined symbols
4475dff55c54d (Masahiro Yamada 2021-03-26 03:54:11 +0900 124) ifneq ($(KBUILD_MODPOST_WARN)$(filter-out $(existing-input-symdump), $(input-symdump)),)
5ab70ff4286f7 (Masahiro Yamada 2021-03-26 03:54:10 +0900 125) MODPOST += -w
5ab70ff4286f7 (Masahiro Yamada 2021-03-26 03:54:10 +0900 126) endif
5ab70ff4286f7 (Masahiro Yamada 2021-03-26 03:54:10 +0900 127)
bcfedae7d9288 (Masahiro Yamada 2020-06-01 14:57:09 +0900 128) # Read out modules.order to pass in modpost.
9b9a3f20cbe0b (Masahiro Yamada 2019-08-15 01:06:23 +0900 129) # Otherwise, allmodconfig would fail with "Argument list too long".
bcfedae7d9288 (Masahiro Yamada 2020-06-01 14:57:09 +0900 130) quiet_cmd_modpost = MODPOST $@
850ded46c6429 (Sami Tolvanen 2021-08-16 11:05:19 -0700 131) cmd_modpost = sed 's/\.ko$$/$(mod-prelink-ext)\.o/' $< | $(MODPOST) -T -
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 132)
850ded46c6429 (Sami Tolvanen 2021-08-16 11:05:19 -0700 133) $(output-symdump): $(MODORDER) $(input-symdump) $(modules:.ko=$(mod-prelink-ext).o) FORCE
436b2ac603d58 (Masahiro Yamada 2020-06-01 14:57:12 +0900 134) $(call if_changed,modpost)
436b2ac603d58 (Masahiro Yamada 2020-06-01 14:57:12 +0900 135)
436b2ac603d58 (Masahiro Yamada 2020-06-01 14:57:12 +0900 136) targets += $(output-symdump)
bcfedae7d9288 (Masahiro Yamada 2020-06-01 14:57:09 +0900 137)
bcfedae7d9288 (Masahiro Yamada 2020-06-01 14:57:09 +0900 138) __modpost: $(output-symdump)
9b9a3f20cbe0b (Masahiro Yamada 2019-08-15 01:06:23 +0900 139) ifneq ($(KBUILD_MODPOST_NOFINAL),1)
9b9a3f20cbe0b (Masahiro Yamada 2019-08-15 01:06:23 +0900 140) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal
9b9a3f20cbe0b (Masahiro Yamada 2019-08-15 01:06:23 +0900 141) endif
4f1933620f571 (Paul Smith 2006-03-05 17:14:10 -0500 142)
bcfedae7d9288 (Masahiro Yamada 2020-06-01 14:57:09 +0900 143) PHONY += FORCE
bcfedae7d9288 (Masahiro Yamada 2020-06-01 14:57:09 +0900 144) FORCE:
bcfedae7d9288 (Masahiro Yamada 2020-06-01 14:57:09 +0900 145)
436b2ac603d58 (Masahiro Yamada 2020-06-01 14:57:12 +0900 146) existing-targets := $(wildcard $(sort $(targets)))
436b2ac603d58 (Masahiro Yamada 2020-06-01 14:57:12 +0900 147)
436b2ac603d58 (Masahiro Yamada 2020-06-01 14:57:12 +0900 148) -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
436b2ac603d58 (Masahiro Yamada 2020-06-01 14:57:12 +0900 149)
a721588d9475c (Masahiro Yamada 2019-07-31 00:59:02 +0900 150) endif
a721588d9475c (Masahiro Yamada 2019-07-31 00:59:02 +0900 151)
4f1933620f571 (Paul Smith 2006-03-05 17:14:10 -0500 152) .PHONY: $(PHONY)