Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | # =========================================================================== |
| 3 | # Module versions |
| 4 | # =========================================================================== |
| 5 | # |
| 6 | # Stage one of module building created the following: |
| 7 | # a) The individual .o files used for the module |
Uwe Zeisberger | c30fe7f | 2006-03-24 18:23:14 +0100 | [diff] [blame] | 8 | # b) A <module>.o file which is the .o files above linked together |
Masahiro Yamada | b7dca6d | 2019-07-17 15:17:57 +0900 | [diff] [blame] | 9 | # c) A <module>.mod file, listing the name of the preliminary <module>.o file, |
| 10 | # plus all .o files |
Masahiro Yamada | ff9b45c | 2019-07-17 15:17:55 +0900 | [diff] [blame] | 11 | # d) modules.order, which lists all the modules |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
| 13 | # Stage 2 is handled by this file and does the following |
Masahiro Yamada | ff9b45c | 2019-07-17 15:17:55 +0900 | [diff] [blame] | 14 | # 1) Find all modules listed in modules.order |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | # 2) modpost is then used to |
Ramji Jiyani | 7c80144 | 2021-09-16 09:21:22 +0000 | [diff] [blame] | 16 | # 3) create one <module>.mod.c file per module |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | # 4) create one Module.symvers file with CRC for all exported symbols |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | # Step 3 is used to place certain information in the module's ELF |
| 20 | # section, including information such as: |
Geert Uytterhoeven | 163d3fe | 2011-05-25 11:09:59 +0200 | [diff] [blame] | 21 | # Version magic (see include/linux/vermagic.h for full details) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | # - Kernel release |
| 23 | # - SMP is CONFIG_SMP |
Thomas Gleixner | 4b950bb | 2019-07-28 20:27:41 +0200 | [diff] [blame] | 24 | # - PREEMPT is CONFIG_PREEMPT[_RT] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | # - GCC Version |
| 26 | # Module info |
| 27 | # - Module version (MODULE_VERSION) |
| 28 | # - Module alias'es (MODULE_ALIAS) |
| 29 | # - Module license (MODULE_LICENSE) |
| 30 | # - See include/linux/module.h for more details |
| 31 | |
| 32 | # Step 4 is solely used to allow module versioning in external modules, |
Uwe Kleine-König | 4696e29 | 2010-07-30 20:43:20 +0200 | [diff] [blame] | 33 | # where the CRC of each module is retrieved from the Module.symvers file. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Masahiro Yamada | a721588 | 2019-07-31 00:59:02 +0900 | [diff] [blame] | 35 | PHONY := __modpost |
| 36 | __modpost: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 38 | include include/config/auto.conf |
Masahiro Yamada | 3204a7f | 2021-02-28 15:10:26 +0900 | [diff] [blame] | 39 | include $(srctree)/scripts/Kbuild.include |
Richard Hacker | 0d96fb2 | 2008-02-28 09:40:58 +0100 | [diff] [blame] | 40 | |
Masahiro Yamada | 3d57e1b | 2022-12-11 22:04:08 +0900 | [diff] [blame] | 41 | MODPOST = scripts/mod/modpost |
| 42 | |
Masahiro Yamada | 4259373 | 2022-09-15 15:26:23 +0900 | [diff] [blame] | 43 | modpost-args = \ |
Masahiro Yamada | 481461f | 2023-07-16 19:15:54 +0900 | [diff] [blame] | 44 | $(if $(CONFIG_MODULES),-M) \ |
Jessica Yu | 54b7784 | 2020-03-06 17:02:06 +0100 | [diff] [blame] | 45 | $(if $(CONFIG_MODVERSIONS),-m) \ |
| 46 | $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \ |
Jessica Yu | 54b7784 | 2020-03-06 17:02:06 +0100 | [diff] [blame] | 47 | $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \ |
Masahiro Yamada | 735aec5 | 2023-01-04 23:04:59 +0900 | [diff] [blame] | 48 | $(if $(KBUILD_MODPOST_WARN),-w) \ |
Masahiro Yamada | f73edc8 | 2022-09-25 03:19:13 +0900 | [diff] [blame] | 49 | $(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS)) \ |
| 50 | $(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N) \ |
Masahiro Yamada | 20ff368 | 2023-06-06 18:41:59 +0900 | [diff] [blame] | 51 | $(if $(findstring 1, $(KBUILD_EXTRA_WARN)),-W) \ |
Masahiro Yamada | bcfedae | 2020-06-01 14:57:09 +0900 | [diff] [blame] | 52 | -o $@ |
Masahiro Yamada | a721588 | 2019-07-31 00:59:02 +0900 | [diff] [blame] | 53 | |
Masahiro Yamada | 3d57e1b | 2022-12-11 22:04:08 +0900 | [diff] [blame] | 54 | modpost-deps := $(MODPOST) |
| 55 | |
Masahiro Yamada | f73edc8 | 2022-09-25 03:19:13 +0900 | [diff] [blame] | 56 | # 'make -i -k' ignores compile errors, and builds as many modules as possible. |
| 57 | ifneq ($(findstring i,$(filter-out --%,$(MAKEFLAGS))),) |
Masahiro Yamada | 4259373 | 2022-09-15 15:26:23 +0900 | [diff] [blame] | 58 | modpost-args += -n |
Masahiro Yamada | f73edc8 | 2022-09-25 03:19:13 +0900 | [diff] [blame] | 59 | endif |
Masahiro Yamada | a721588 | 2019-07-31 00:59:02 +0900 | [diff] [blame] | 60 | |
Samuel Holland | 63ffe00 | 2022-12-27 15:48:21 -0600 | [diff] [blame] | 61 | # Read out modules.order to pass in modpost. |
| 62 | # Otherwise, allmodconfig would fail with "Argument list too long". |
| 63 | ifdef KBUILD_MODULES |
| 64 | modpost-args += -T $(MODORDER) |
| 65 | modpost-deps += $(MODORDER) |
| 66 | endif |
| 67 | |
Masahiro Yamada | f73edc8 | 2022-09-25 03:19:13 +0900 | [diff] [blame] | 68 | ifeq ($(KBUILD_EXTMOD),) |
Masahiro Yamada | bcfedae | 2020-06-01 14:57:09 +0900 | [diff] [blame] | 69 | |
Masahiro Yamada | 26ef40d | 2022-09-25 03:19:11 +0900 | [diff] [blame] | 70 | # Generate the list of in-tree objects in vmlinux |
| 71 | # --------------------------------------------------------------------------- |
| 72 | |
| 73 | # This is used to retrieve symbol versions generated by genksyms. |
| 74 | ifdef CONFIG_MODVERSIONS |
Masahiro Yamada | f73edc8 | 2022-09-25 03:19:13 +0900 | [diff] [blame] | 75 | vmlinux.symvers Module.symvers: .vmlinux.objs |
Masahiro Yamada | 26ef40d | 2022-09-25 03:19:11 +0900 | [diff] [blame] | 76 | endif |
| 77 | |
| 78 | # Ignore libgcc.a |
| 79 | # Some architectures do '$(CC) --print-libgcc-file-name' to borrow libgcc.a |
| 80 | # from the toolchain, but there is no EXPORT_SYMBOL in it. |
| 81 | |
| 82 | quiet_cmd_vmlinux_objs = GEN $@ |
| 83 | cmd_vmlinux_objs = \ |
| 84 | for f in $(real-prereqs); do \ |
| 85 | case $${f} in \ |
| 86 | *libgcc.a) ;; \ |
Masahiro Yamada | 3216484 | 2022-09-25 03:19:14 +0900 | [diff] [blame] | 87 | *) $(AR) t $${f} ;; \ |
Masahiro Yamada | 26ef40d | 2022-09-25 03:19:11 +0900 | [diff] [blame] | 88 | esac \ |
| 89 | done > $@ |
| 90 | |
| 91 | targets += .vmlinux.objs |
Masahiro Yamada | 3216484 | 2022-09-25 03:19:14 +0900 | [diff] [blame] | 92 | .vmlinux.objs: vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE |
Masahiro Yamada | 26ef40d | 2022-09-25 03:19:11 +0900 | [diff] [blame] | 93 | $(call if_changed,vmlinux_objs) |
| 94 | |
Masahiro Yamada | 5e9e95cc9 | 2023-06-12 00:50:57 +0900 | [diff] [blame] | 95 | ifdef CONFIG_TRIM_UNUSED_KSYMS |
| 96 | ksym-wl := $(CONFIG_UNUSED_KSYMS_WHITELIST) |
| 97 | ksym-wl := $(if $(filter-out /%, $(ksym-wl)),$(srctree)/)$(ksym-wl) |
| 98 | modpost-args += -t $(addprefix -u , $(ksym-wl)) |
| 99 | modpost-deps += $(ksym-wl) |
| 100 | endif |
| 101 | |
Masahiro Yamada | 3d57e1b | 2022-12-11 22:04:08 +0900 | [diff] [blame] | 102 | ifeq ($(wildcard vmlinux.o),) |
| 103 | missing-input := vmlinux.o |
| 104 | output-symdump := modules-only.symvers |
| 105 | else |
| 106 | modpost-args += vmlinux.o |
| 107 | modpost-deps += vmlinux.o |
| 108 | output-symdump := $(if $(KBUILD_MODULES), Module.symvers, vmlinux.symvers) |
Masahiro Yamada | 69bc8d3 | 2021-03-26 03:54:09 +0900 | [diff] [blame] | 109 | endif |
Masahiro Yamada | bcfedae | 2020-06-01 14:57:09 +0900 | [diff] [blame] | 110 | |
Masahiro Yamada | 1747269a | 2019-10-03 19:29:13 +0900 | [diff] [blame] | 111 | else |
Sam Ravnborg | 96d97f2 | 2008-05-31 22:28:40 +0200 | [diff] [blame] | 112 | |
Masahiro Yamada | fab546e | 2019-11-06 23:52:15 +0900 | [diff] [blame] | 113 | # set src + obj - they may be used in the modules's Makefile |
Sam Ravnborg | 96d97f2 | 2008-05-31 22:28:40 +0200 | [diff] [blame] | 114 | obj := $(KBUILD_EXTMOD) |
| 115 | src := $(obj) |
| 116 | |
Richard Hacker | 0d96fb2 | 2008-02-28 09:40:58 +0100 | [diff] [blame] | 117 | # Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS |
Masahiro Yamada | a2430b2 | 2022-11-19 04:15:50 +0900 | [diff] [blame] | 118 | include $(kbuild-file) |
Masahiro Yamada | e3fb4df | 2020-06-01 14:57:08 +0900 | [diff] [blame] | 119 | |
Masahiro Yamada | bcfedae | 2020-06-01 14:57:09 +0900 | [diff] [blame] | 120 | output-symdump := $(KBUILD_EXTMOD)/Module.symvers |
| 121 | |
Masahiro Yamada | 3d57e1b | 2022-12-11 22:04:08 +0900 | [diff] [blame] | 122 | ifeq ($(wildcard Module.symvers),) |
| 123 | missing-input := Module.symvers |
| 124 | else |
| 125 | modpost-args += -i Module.symvers |
| 126 | modpost-deps += Module.symvers |
| 127 | endif |
| 128 | |
| 129 | modpost-args += -e $(addprefix -i , $(KBUILD_EXTRA_SYMBOLS)) |
Richard Hacker | 0d96fb2 | 2008-02-28 09:40:58 +0100 | [diff] [blame] | 130 | |
Masahiro Yamada | f73edc8 | 2022-09-25 03:19:13 +0900 | [diff] [blame] | 131 | endif # ($(KBUILD_EXTMOD),) |
Masahiro Yamada | 4475dff | 2021-03-26 03:54:11 +0900 | [diff] [blame] | 132 | |
Masahiro Yamada | bcfedae | 2020-06-01 14:57:09 +0900 | [diff] [blame] | 133 | quiet_cmd_modpost = MODPOST $@ |
Masahiro Yamada | f73edc8 | 2022-09-25 03:19:13 +0900 | [diff] [blame] | 134 | cmd_modpost = \ |
| 135 | $(if $(missing-input), \ |
| 136 | echo >&2 "WARNING: $(missing-input) is missing."; \ |
| 137 | echo >&2 " Modules may not have dependencies or modversions."; \ |
Masahiro Yamada | 5573b4d | 2023-01-26 11:26:43 +0900 | [diff] [blame] | 138 | echo >&2 " You may get many unresolved symbol errors."; \ |
| 139 | echo >&2 " You can set KBUILD_MODPOST_WARN=1 to turn errors into warning"; \ |
| 140 | echo >&2 " if you want to proceed at your own risk.";) \ |
Masahiro Yamada | 3d57e1b | 2022-12-11 22:04:08 +0900 | [diff] [blame] | 141 | $(MODPOST) $(modpost-args) |
Masahiro Yamada | 436b2ac | 2020-06-01 14:57:12 +0900 | [diff] [blame] | 142 | |
| 143 | targets += $(output-symdump) |
Masahiro Yamada | 3d57e1b | 2022-12-11 22:04:08 +0900 | [diff] [blame] | 144 | $(output-symdump): $(modpost-deps) FORCE |
Masahiro Yamada | f73edc8 | 2022-09-25 03:19:13 +0900 | [diff] [blame] | 145 | $(call if_changed,modpost) |
Masahiro Yamada | bcfedae | 2020-06-01 14:57:09 +0900 | [diff] [blame] | 146 | |
| 147 | __modpost: $(output-symdump) |
Masahiro Yamada | bcfedae | 2020-06-01 14:57:09 +0900 | [diff] [blame] | 148 | PHONY += FORCE |
| 149 | FORCE: |
| 150 | |
Masahiro Yamada | 436b2ac | 2020-06-01 14:57:12 +0900 | [diff] [blame] | 151 | existing-targets := $(wildcard $(sort $(targets))) |
| 152 | |
| 153 | -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) |
| 154 | |
Paul Smith | 4f19336 | 2006-03-05 17:14:10 -0500 | [diff] [blame] | 155 | .PHONY: $(PHONY) |