blob: 739402f4550979850d71dcdc31649f4daac9d44d [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002# ===========================================================================
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 Zeisbergerc30fe7f2006-03-24 18:23:14 +01008# b) A <module>.o file which is the .o files above linked together
Masahiro Yamadab7dca6d2019-07-17 15:17:57 +09009# c) A <module>.mod file, listing the name of the preliminary <module>.o file,
10# plus all .o files
Masahiro Yamadaff9b45c2019-07-17 15:17:55 +090011# d) modules.order, which lists all the modules
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13# Stage 2 is handled by this file and does the following
Masahiro Yamadaff9b45c2019-07-17 15:17:55 +090014# 1) Find all modules listed in modules.order
Linus Torvalds1da177e2005-04-16 15:20:36 -070015# 2) modpost is then used to
Ramji Jiyani7c801442021-09-16 09:21:22 +000016# 3) create one <module>.mod.c file per module
Linus Torvalds1da177e2005-04-16 15:20:36 -070017# 4) create one Module.symvers file with CRC for all exported symbols
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19# Step 3 is used to place certain information in the module's ELF
20# section, including information such as:
Geert Uytterhoeven163d3fe2011-05-25 11:09:59 +020021# Version magic (see include/linux/vermagic.h for full details)
Linus Torvalds1da177e2005-04-16 15:20:36 -070022# - Kernel release
23# - SMP is CONFIG_SMP
Thomas Gleixner4b950bb2019-07-28 20:27:41 +020024# - PREEMPT is CONFIG_PREEMPT[_RT]
Linus Torvalds1da177e2005-04-16 15:20:36 -070025# - 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önig4696e292010-07-30 20:43:20 +020033# where the CRC of each module is retrieved from the Module.symvers file.
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Masahiro Yamadaa7215882019-07-31 00:59:02 +090035PHONY := __modpost
36__modpost:
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Roman Zippelc955cca2006-06-08 22:12:39 -070038include include/config/auto.conf
Masahiro Yamada3204a7f2021-02-28 15:10:26 +090039include $(srctree)/scripts/Kbuild.include
Richard Hacker0d96fb22008-02-28 09:40:58 +010040
Masahiro Yamada3d57e1b2022-12-11 22:04:08 +090041MODPOST = scripts/mod/modpost
42
Masahiro Yamada42593732022-09-15 15:26:23 +090043modpost-args = \
Masahiro Yamada481461f2023-07-16 19:15:54 +090044 $(if $(CONFIG_MODULES),-M) \
Jessica Yu54b77842020-03-06 17:02:06 +010045 $(if $(CONFIG_MODVERSIONS),-m) \
46 $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \
Jessica Yu54b77842020-03-06 17:02:06 +010047 $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \
Masahiro Yamada735aec52023-01-04 23:04:59 +090048 $(if $(KBUILD_MODPOST_WARN),-w) \
Masahiro Yamadaf73edc82022-09-25 03:19:13 +090049 $(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS)) \
50 $(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N) \
Masahiro Yamada20ff3682023-06-06 18:41:59 +090051 $(if $(findstring 1, $(KBUILD_EXTRA_WARN)),-W) \
Masahiro Yamadabcfedae2020-06-01 14:57:09 +090052 -o $@
Masahiro Yamadaa7215882019-07-31 00:59:02 +090053
Masahiro Yamada3d57e1b2022-12-11 22:04:08 +090054modpost-deps := $(MODPOST)
55
Masahiro Yamadaf73edc82022-09-25 03:19:13 +090056# 'make -i -k' ignores compile errors, and builds as many modules as possible.
57ifneq ($(findstring i,$(filter-out --%,$(MAKEFLAGS))),)
Masahiro Yamada42593732022-09-15 15:26:23 +090058modpost-args += -n
Masahiro Yamadaf73edc82022-09-25 03:19:13 +090059endif
Masahiro Yamadaa7215882019-07-31 00:59:02 +090060
Samuel Holland63ffe002022-12-27 15:48:21 -060061# Read out modules.order to pass in modpost.
62# Otherwise, allmodconfig would fail with "Argument list too long".
63ifdef KBUILD_MODULES
64modpost-args += -T $(MODORDER)
65modpost-deps += $(MODORDER)
66endif
67
Masahiro Yamadaf73edc82022-09-25 03:19:13 +090068ifeq ($(KBUILD_EXTMOD),)
Masahiro Yamadabcfedae2020-06-01 14:57:09 +090069
Masahiro Yamada26ef40d2022-09-25 03:19:11 +090070# Generate the list of in-tree objects in vmlinux
71# ---------------------------------------------------------------------------
72
73# This is used to retrieve symbol versions generated by genksyms.
74ifdef CONFIG_MODVERSIONS
Masahiro Yamadaf73edc82022-09-25 03:19:13 +090075vmlinux.symvers Module.symvers: .vmlinux.objs
Masahiro Yamada26ef40d2022-09-25 03:19:11 +090076endif
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
82quiet_cmd_vmlinux_objs = GEN $@
83 cmd_vmlinux_objs = \
84 for f in $(real-prereqs); do \
85 case $${f} in \
86 *libgcc.a) ;; \
Masahiro Yamada32164842022-09-25 03:19:14 +090087 *) $(AR) t $${f} ;; \
Masahiro Yamada26ef40d2022-09-25 03:19:11 +090088 esac \
89 done > $@
90
91targets += .vmlinux.objs
Masahiro Yamada32164842022-09-25 03:19:14 +090092.vmlinux.objs: vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
Masahiro Yamada26ef40d2022-09-25 03:19:11 +090093 $(call if_changed,vmlinux_objs)
94
Masahiro Yamada5e9e95cc92023-06-12 00:50:57 +090095ifdef CONFIG_TRIM_UNUSED_KSYMS
96ksym-wl := $(CONFIG_UNUSED_KSYMS_WHITELIST)
97ksym-wl := $(if $(filter-out /%, $(ksym-wl)),$(srctree)/)$(ksym-wl)
98modpost-args += -t $(addprefix -u , $(ksym-wl))
99modpost-deps += $(ksym-wl)
100endif
101
Masahiro Yamada3d57e1b2022-12-11 22:04:08 +0900102ifeq ($(wildcard vmlinux.o),)
103missing-input := vmlinux.o
104output-symdump := modules-only.symvers
105else
106modpost-args += vmlinux.o
107modpost-deps += vmlinux.o
108output-symdump := $(if $(KBUILD_MODULES), Module.symvers, vmlinux.symvers)
Masahiro Yamada69bc8d32021-03-26 03:54:09 +0900109endif
Masahiro Yamadabcfedae2020-06-01 14:57:09 +0900110
Masahiro Yamada1747269a2019-10-03 19:29:13 +0900111else
Sam Ravnborg96d97f22008-05-31 22:28:40 +0200112
Masahiro Yamadafab546e2019-11-06 23:52:15 +0900113# set src + obj - they may be used in the modules's Makefile
Sam Ravnborg96d97f22008-05-31 22:28:40 +0200114obj := $(KBUILD_EXTMOD)
115src := $(obj)
116
Richard Hacker0d96fb22008-02-28 09:40:58 +0100117# Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS
Masahiro Yamadaa2430b22022-11-19 04:15:50 +0900118include $(kbuild-file)
Masahiro Yamadae3fb4df2020-06-01 14:57:08 +0900119
Masahiro Yamadabcfedae2020-06-01 14:57:09 +0900120output-symdump := $(KBUILD_EXTMOD)/Module.symvers
121
Masahiro Yamada3d57e1b2022-12-11 22:04:08 +0900122ifeq ($(wildcard Module.symvers),)
123missing-input := Module.symvers
124else
125modpost-args += -i Module.symvers
126modpost-deps += Module.symvers
127endif
128
129modpost-args += -e $(addprefix -i , $(KBUILD_EXTRA_SYMBOLS))
Richard Hacker0d96fb22008-02-28 09:40:58 +0100130
Masahiro Yamadaf73edc82022-09-25 03:19:13 +0900131endif # ($(KBUILD_EXTMOD),)
Masahiro Yamada4475dff2021-03-26 03:54:11 +0900132
Masahiro Yamadabcfedae2020-06-01 14:57:09 +0900133quiet_cmd_modpost = MODPOST $@
Masahiro Yamadaf73edc82022-09-25 03:19:13 +0900134 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 Yamada5573b4d2023-01-26 11:26:43 +0900138 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 Yamada3d57e1b2022-12-11 22:04:08 +0900141 $(MODPOST) $(modpost-args)
Masahiro Yamada436b2ac2020-06-01 14:57:12 +0900142
143targets += $(output-symdump)
Masahiro Yamada3d57e1b2022-12-11 22:04:08 +0900144$(output-symdump): $(modpost-deps) FORCE
Masahiro Yamadaf73edc82022-09-25 03:19:13 +0900145 $(call if_changed,modpost)
Masahiro Yamadabcfedae2020-06-01 14:57:09 +0900146
147__modpost: $(output-symdump)
Masahiro Yamadabcfedae2020-06-01 14:57:09 +0900148PHONY += FORCE
149FORCE:
150
Masahiro Yamada436b2ac2020-06-01 14:57:12 +0900151existing-targets := $(wildcard $(sort $(targets)))
152
153-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
154
Paul Smith4f193362006-03-05 17:14:10 -0500155.PHONY: $(PHONY)