blob: 0980c58d8afc8f77cafd5623fae9f7be0ea526b6 [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 = \
Jessica Yu54b77842020-03-06 17:02:06 +010044 $(if $(CONFIG_MODVERSIONS),-m) \
45 $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \
Jessica Yu54b77842020-03-06 17:02:06 +010046 $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \
Masahiro Yamada735aec52023-01-04 23:04:59 +090047 $(if $(KBUILD_MODPOST_WARN),-w) \
Masahiro Yamadaf73edc82022-09-25 03:19:13 +090048 $(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS)) \
49 $(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N) \
Masahiro Yamadabcfedae2020-06-01 14:57:09 +090050 -o $@
Masahiro Yamadaa7215882019-07-31 00:59:02 +090051
Masahiro Yamada3d57e1b2022-12-11 22:04:08 +090052modpost-deps := $(MODPOST)
53
Masahiro Yamadaf73edc82022-09-25 03:19:13 +090054# 'make -i -k' ignores compile errors, and builds as many modules as possible.
55ifneq ($(findstring i,$(filter-out --%,$(MAKEFLAGS))),)
Masahiro Yamada42593732022-09-15 15:26:23 +090056modpost-args += -n
Masahiro Yamadaf73edc82022-09-25 03:19:13 +090057endif
Masahiro Yamadaa7215882019-07-31 00:59:02 +090058
Samuel Holland63ffe002022-12-27 15:48:21 -060059# Read out modules.order to pass in modpost.
60# Otherwise, allmodconfig would fail with "Argument list too long".
61ifdef KBUILD_MODULES
62modpost-args += -T $(MODORDER)
63modpost-deps += $(MODORDER)
64endif
65
Masahiro Yamadaf73edc82022-09-25 03:19:13 +090066ifeq ($(KBUILD_EXTMOD),)
Masahiro Yamadabcfedae2020-06-01 14:57:09 +090067
Masahiro Yamada26ef40d2022-09-25 03:19:11 +090068# Generate the list of in-tree objects in vmlinux
69# ---------------------------------------------------------------------------
70
71# This is used to retrieve symbol versions generated by genksyms.
72ifdef CONFIG_MODVERSIONS
Masahiro Yamadaf73edc82022-09-25 03:19:13 +090073vmlinux.symvers Module.symvers: .vmlinux.objs
Masahiro Yamada26ef40d2022-09-25 03:19:11 +090074endif
75
76# Ignore libgcc.a
77# Some architectures do '$(CC) --print-libgcc-file-name' to borrow libgcc.a
78# from the toolchain, but there is no EXPORT_SYMBOL in it.
79
80quiet_cmd_vmlinux_objs = GEN $@
81 cmd_vmlinux_objs = \
82 for f in $(real-prereqs); do \
83 case $${f} in \
84 *libgcc.a) ;; \
Masahiro Yamada32164842022-09-25 03:19:14 +090085 *) $(AR) t $${f} ;; \
Masahiro Yamada26ef40d2022-09-25 03:19:11 +090086 esac \
87 done > $@
88
89targets += .vmlinux.objs
Masahiro Yamada32164842022-09-25 03:19:14 +090090.vmlinux.objs: vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
Masahiro Yamada26ef40d2022-09-25 03:19:11 +090091 $(call if_changed,vmlinux_objs)
92
Masahiro Yamada3d57e1b2022-12-11 22:04:08 +090093ifeq ($(wildcard vmlinux.o),)
94missing-input := vmlinux.o
95output-symdump := modules-only.symvers
96else
97modpost-args += vmlinux.o
98modpost-deps += vmlinux.o
99output-symdump := $(if $(KBUILD_MODULES), Module.symvers, vmlinux.symvers)
Masahiro Yamada69bc8d32021-03-26 03:54:09 +0900100endif
Masahiro Yamadabcfedae2020-06-01 14:57:09 +0900101
Masahiro Yamada1747269a2019-10-03 19:29:13 +0900102else
Sam Ravnborg96d97f22008-05-31 22:28:40 +0200103
Masahiro Yamadafab546e2019-11-06 23:52:15 +0900104# set src + obj - they may be used in the modules's Makefile
Sam Ravnborg96d97f22008-05-31 22:28:40 +0200105obj := $(KBUILD_EXTMOD)
106src := $(obj)
107
Richard Hacker0d96fb22008-02-28 09:40:58 +0100108# Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS
Masahiro Yamadaa2430b22022-11-19 04:15:50 +0900109include $(kbuild-file)
Masahiro Yamadae3fb4df2020-06-01 14:57:08 +0900110
Masahiro Yamadabcfedae2020-06-01 14:57:09 +0900111output-symdump := $(KBUILD_EXTMOD)/Module.symvers
112
Masahiro Yamada3d57e1b2022-12-11 22:04:08 +0900113ifeq ($(wildcard Module.symvers),)
114missing-input := Module.symvers
115else
116modpost-args += -i Module.symvers
117modpost-deps += Module.symvers
118endif
119
120modpost-args += -e $(addprefix -i , $(KBUILD_EXTRA_SYMBOLS))
Richard Hacker0d96fb22008-02-28 09:40:58 +0100121
Masahiro Yamadaf73edc82022-09-25 03:19:13 +0900122endif # ($(KBUILD_EXTMOD),)
Masahiro Yamada4475dff2021-03-26 03:54:11 +0900123
Masahiro Yamadabcfedae2020-06-01 14:57:09 +0900124quiet_cmd_modpost = MODPOST $@
Masahiro Yamadaf73edc82022-09-25 03:19:13 +0900125 cmd_modpost = \
126 $(if $(missing-input), \
127 echo >&2 "WARNING: $(missing-input) is missing."; \
128 echo >&2 " Modules may not have dependencies or modversions."; \
Masahiro Yamada5573b4d2023-01-26 11:26:43 +0900129 echo >&2 " You may get many unresolved symbol errors."; \
130 echo >&2 " You can set KBUILD_MODPOST_WARN=1 to turn errors into warning"; \
131 echo >&2 " if you want to proceed at your own risk.";) \
Masahiro Yamada3d57e1b2022-12-11 22:04:08 +0900132 $(MODPOST) $(modpost-args)
Masahiro Yamada436b2ac2020-06-01 14:57:12 +0900133
134targets += $(output-symdump)
Masahiro Yamada3d57e1b2022-12-11 22:04:08 +0900135$(output-symdump): $(modpost-deps) FORCE
Masahiro Yamadaf73edc82022-09-25 03:19:13 +0900136 $(call if_changed,modpost)
Masahiro Yamadabcfedae2020-06-01 14:57:09 +0900137
138__modpost: $(output-symdump)
Masahiro Yamadabcfedae2020-06-01 14:57:09 +0900139PHONY += FORCE
140FORCE:
141
Masahiro Yamada436b2ac2020-06-01 14:57:12 +0900142existing-targets := $(wildcard $(sort $(targets)))
143
144-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
145
Paul Smith4f193362006-03-05 17:14:10 -0500146.PHONY: $(PHONY)