History

kbuild: create modules.builtin without Makefile.modbuiltin or tristate.conf

Commit bc081dd6e9f6 ("kbuild: generate modules.builtin") added infrastructure to generate modules.builtin, the list of all builtin modules. Basically, it works like this: - Kconfig generates include/config/tristate.conf, the list of tristate CONFIG options with a value in a capital letter. - scripts/Makefile.modbuiltin makes Kbuild descend into directories to collect the information of builtin modules. I am not a big fan of it because Kbuild ends up with traversing the source tree twice. I am not sure how perfectly it should work, but this approach cannot avoid false positives; even if the relevant CONFIG option is tristate, some Makefiles forces obj-m to obj-y. Some examples are: arch/powerpc/platforms/powermac/Makefile: obj-$(CONFIG_NVRAM:m=y) += nvram.o net/ipv6/Makefile: obj-$(subst m,y,$(CONFIG_IPV6)) += inet6_hashtables.o net/netlabel/Makefile: obj-$(subst m,y,$(CONFIG_IPV6)) += netlabel_calipso.o Nobody has complained about (or noticed) it, so it is probably fine to have false positives in modules.builtin. This commit simplifies the implementation. Let's exploit the fact that every module has MODULE_LICENSE(). (modpost shows a warning if MODULE_LICENSE is missing. If so, 0-day bot would already have blocked such a module.) I added MODULE_FILE to <linux/module.h>. When the code is being compiled as builtin, it will be filled with the file path of the module, and collected into modules.builtin.info. Then, scripts/link-vmlinux.sh extracts the list of builtin modules out of it. This new approach fixes the false-positives above, but adds another type of false-positives; non-modular code may have MODULE_LICENSE() by mistake. This is not a big deal, it is just the code is always orphan. We can clean it up if we like. You can see cleanup examples by: $ git log --grep='make.* explicitly non-modular' To sum up, this commits deletes lots of code, but still produces almost equivalent results. Please note it does not increase the vmlinux size at all. As you can see in include/asm-generic/vmlinux.lds.h, the .modinfo section is discarded in the link stage.

Masahiro Yamada committed 6 years ago

Commit 8b41fc41 parent 1664a377 files · +22 −128Browse files

Unified · Split

7 files
  1. Documentation/kbuild/kconfig.rst +0 −5
  2. Makefile +5 −16
  3. include/linux/module.h +11 −1
  4. scripts/Kbuild.include +0 −6
  5. scripts/Makefile.modbuiltin +0 −57
  6. scripts/kconfig/confdata.c +2 −43
  7. scripts/link-vmlinux.sh +4 −0
Documentation/kbuild/kconfig.rst+0−5
@@ -154,11 +154,6 @@ KCONFIG_AUTOCONFIG · 153 unmodified lines
154This environment variable can be set to specify the path & name of the154This environment variable can be set to specify the path & name of the
155"auto.conf" file. Its default value is "include/config/auto.conf".155"auto.conf" file. Its default value is "include/config/auto.conf".
156 156
157KCONFIG_TRISTATE
158----------------
159This environment variable can be set to specify the path & name of the
160"tristate.conf" file. Its default value is "include/config/tristate.conf".
161
162KCONFIG_AUTOHEADER157KCONFIG_AUTOHEADER
163------------------158------------------
164This environment variable can be set to specify the path & name of the159This environment variable can be set to specify the path & name of the
Makefile+5−16
@@ -674,7 +674,7 @@ $(KCONFIG_CONFIG): · 673 unmodified lines
674#674#
675# This exploits the 'multi-target pattern rule' trick.675# This exploits the 'multi-target pattern rule' trick.
676# The syncconfig should be executed only once to make all the targets.676# The syncconfig should be executed only once to make all the targets.
677%/auto.conf %/auto.conf.cmd %/tristate.conf: $(KCONFIG_CONFIG)677%/auto.conf %/auto.conf.cmd: $(KCONFIG_CONFIG)
678 $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig678 $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig
679else # !may-sync-config679else # !may-sync-config
680# External modules and some install targets need include/generated/autoconf.h680# External modules and some install targets need include/generated/autoconf.h
@@ -1278,24 +1278,13 @@ all: modules · 597 unmodified lines
1278# using awk while concatenating to the final file.1278# using awk while concatenating to the final file.
1279 1279
1280PHONY += modules1280PHONY += modules
1281modules: $(if $(KBUILD_BUILTIN),vmlinux) modules.order modules.builtin1281modules: $(if $(KBUILD_BUILTIN),vmlinux) modules.order
1282 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost1282 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1283 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh1283 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh
1284 1284
1285modules.order: descend1285modules.order: descend
1286 $(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(build-dirs)) > $@1286 $(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(build-dirs)) > $@
1287 1287
1288modbuiltin-dirs := $(addprefix _modbuiltin_, $(build-dirs))
1289
1290modules.builtin: $(modbuiltin-dirs)
1291 $(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(build-dirs)) > $@
1292
1293PHONY += $(modbuiltin-dirs)
1294# tristate.conf is not included from this Makefile. Add it as a prerequisite
1295# here to make it self-healing in case somebody accidentally removes it.
1296$(modbuiltin-dirs): include/config/tristate.conf
1297 $(Q)$(MAKE) $(modbuiltin)=$(patsubst _modbuiltin_%,%,$@)
1298
1299# Target to prepare building external modules1288# Target to prepare building external modules
1300PHONY += modules_prepare1289PHONY += modules_prepare
1301modules_prepare: prepare1290modules_prepare: prepare
@@ -1315,7 +1304,7 @@ _modinst_: · 13 unmodified lines
1315 ln -s $(CURDIR) $(MODLIB)/build ; \1304 ln -s $(CURDIR) $(MODLIB)/build ; \
1316 fi1305 fi
1317 @sed 's:^:kernel/:' modules.order > $(MODLIB)/modules.order1306 @sed 's:^:kernel/:' modules.order > $(MODLIB)/modules.order
1318 @sed 's:^:kernel/:' modules.builtin > $(MODLIB)/modules.builtin1307 @cp -f modules.builtin $(MODLIB)/
1319 @cp -f $(objtree)/modules.builtin.modinfo $(MODLIB)/1308 @cp -f $(objtree)/modules.builtin.modinfo $(MODLIB)/
1320 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst1309 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
1321 1310
@@ -1357,7 +1346,7 @@ endif # CONFIG_MODULES · 35 unmodified lines
1357 1346
1358# Directories & files removed with 'make clean'1347# Directories & files removed with 'make clean'
1359CLEAN_DIRS += include/ksym1348CLEAN_DIRS += include/ksym
1360CLEAN_FILES += modules.builtin.modinfo modules.nsdeps1349CLEAN_FILES += modules.builtin modules.builtin.modinfo modules.nsdeps
1361 1350
1362# Directories & files removed with 'make mrproper'1351# Directories & files removed with 'make mrproper'
1363MRPROPER_DIRS += include/config include/generated \1352MRPROPER_DIRS += include/config include/generated \
@@ -1712,7 +1701,7 @@ clean: $(clean-dirs) · 348 unmodified lines
1712 -o -name '*.lex.c' -o -name '*.tab.[ch]' \1701 -o -name '*.lex.c' -o -name '*.tab.[ch]' \
1713 -o -name '*.asn1.[ch]' \1702 -o -name '*.asn1.[ch]' \
1714 -o -name '*.symtypes' -o -name 'modules.order' \1703 -o -name '*.symtypes' -o -name 'modules.order' \
1715 -o -name modules.builtin -o -name '.tmp_*.o.*' \1704 -o -name '.tmp_*.o.*' \
1716 -o -name '*.c.[012]*.*' \1705 -o -name '*.c.[012]*.*' \
1717 -o -name '*.ll' \1706 -o -name '*.ll' \
1718 -o -name '*.gcno' \) -type f -print | xargs rm -f1707 -o -name '*.gcno' \) -type f -print | xargs rm -f
include/linux/module.h+11−1
@@ -169,6 +169,16 @@ extern void cleanup_module(void); · 168 unmodified lines
169 */169 */
170#define MODULE_SOFTDEP(_softdep) MODULE_INFO(softdep, _softdep)170#define MODULE_SOFTDEP(_softdep) MODULE_INFO(softdep, _softdep)
171 171
172/*
173 * MODULE_FILE is used for generating modules.builtin
174 * So, make it no-op when this is being built as a module
175 */
176#ifdef MODULE
177#define MODULE_FILE
178#else
179#define MODULE_FILE MODULE_INFO(file, KBUILD_MODFILE);
180#endif
181
172/*182/*
173 * The following license idents are currently accepted as indicating free183 * The following license idents are currently accepted as indicating free
174 * software modules184 * software modules
@@ -213,7 +223,7 @@ extern void cleanup_module(void); · 38 unmodified lines
213 * 2. So the community can ignore bug reports including proprietary modules223 * 2. So the community can ignore bug reports including proprietary modules
214 * 3. So vendors can do likewise based on their own policies224 * 3. So vendors can do likewise based on their own policies
215 */225 */
216#define MODULE_LICENSE(_license) MODULE_INFO(license, _license)226#define MODULE_LICENSE(_license) MODULE_FILE MODULE_INFO(license, _license)
217 227
218/*228/*
219 * Author(s), use "Name <email>" or just "Name", for multiple229 * Author(s), use "Name <email>" or just "Name", for multiple
scripts/Kbuild.include+0−6
@@ -163,12 +163,6 @@ ld-ifversion = $(shell [ $(ld-version) $(1) $(2) ] && echo $(3) || echo $(4)) · 162 unmodified lines
163# $(Q)$(MAKE) $(build)=dir163# $(Q)$(MAKE) $(build)=dir
164build := -f $(srctree)/scripts/Makefile.build obj164build := -f $(srctree)/scripts/Makefile.build obj
165 165
166###
167# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.modbuiltin obj=
168# Usage:
169# $(Q)$(MAKE) $(modbuiltin)=dir
170modbuiltin := -f $(srctree)/scripts/Makefile.modbuiltin obj
171
172###166###
173# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj=167# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj=
174# Usage:168# Usage:
scripts/Makefile.modbuiltin+0−57
@@ -1,57 +0,0 @@
1# SPDX-License-Identifier: GPL-2.0
2# ==========================================================================
3# Generating modules.builtin
4# ==========================================================================
5
6src := $(obj)
7
8PHONY := __modbuiltin
9__modbuiltin:
10
11include include/config/auto.conf
12# tristate.conf sets tristate variables to uppercase 'Y' or 'M'
13# That way, we get the list of built-in modules in obj-Y
14include include/config/tristate.conf
15
16include scripts/Kbuild.include
17
18ifdef building_out_of_srctree
19# Create output directory if not already present
20_dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
21endif
22
23# The filename Kbuild has precedence over Makefile
24kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
25kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile)
26include $(kbuild-file)
27
28include scripts/Makefile.lib
29__subdir-Y := $(patsubst %/,%,$(filter %/, $(obj-Y)))
30subdir-Y += $(__subdir-Y)
31subdir-ym := $(sort $(subdir-y) $(subdir-Y) $(subdir-m))
32subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
33obj-Y := $(addprefix $(obj)/,$(obj-Y))
34
35modbuiltin-subdirs := $(patsubst %,%/modules.builtin, $(subdir-ym))
36modbuiltin-mods := $(filter %.ko, $(obj-Y:.o=.ko))
37modbuiltin-target := $(obj)/modules.builtin
38
39__modbuiltin: $(modbuiltin-target) $(subdir-ym)
40 @:
41
42$(modbuiltin-target): $(subdir-ym) FORCE
43 $(Q)(for m in $(modbuiltin-mods); do echo $$m; done; \
44 cat /dev/null $(modbuiltin-subdirs)) > $@
45
46PHONY += FORCE
47
48FORCE:
49
50# Descending
51# ---------------------------------------------------------------------------
52
53PHONY += $(subdir-ym)
54$(subdir-ym):
55 $(Q)$(MAKE) $(modbuiltin)=$@
56
57.PHONY: $(PHONY)
scripts/kconfig/confdata.c+2−43
@@ -710,25 +710,6 @@ static struct conf_printer header_printer_cb = · 709 unmodified lines
710 .print_comment = header_print_comment,710 .print_comment = header_print_comment,
711};711};
712 712
713/*
714 * Tristate printer
715 *
716 * This printer is used when generating the `include/config/tristate.conf' file.
717 */
718static void
719tristate_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
720{
721
722 if (sym->type == S_TRISTATE && *value != 'n')
723 fprintf(fp, "%s%s=%c\n", CONFIG_, sym->name, (char)toupper(*value));
724}
725
726static struct conf_printer tristate_printer_cb =
727{
728 .print_symbol = tristate_print_symbol,
729 .print_comment = kconfig_print_comment,
730};
731
732static void conf_write_symbol(FILE *fp, struct symbol *sym,713static void conf_write_symbol(FILE *fp, struct symbol *sym,
733 struct conf_printer *printer, void *printer_arg)714 struct conf_printer *printer, void *printer_arg)
734{715{
@@ -1062,7 +1043,7 @@ int conf_write_autoconf(int overwrite) · 327 unmodified lines
1062 struct symbol *sym;1043 struct symbol *sym;
1063 const char *name;1044 const char *name;
1064 const char *autoconf_name = conf_get_autoconfig_name();1045 const char *autoconf_name = conf_get_autoconfig_name();
1065 FILE *out, *tristate, *out_h;1046 FILE *out, *out_h;
1066 int i;1047 int i;
1067 1048
1068 if (!overwrite && is_present(autoconf_name))1049 if (!overwrite && is_present(autoconf_name))
@@ -1077,23 +1058,13 @@ int conf_write_autoconf(int overwrite) · 8 unmodified lines
1077 if (!out)1058 if (!out)
1078 return 1;1059 return 1;
1079 1060
1080 tristate = fopen(".tmpconfig_tristate", "w");
1081 if (!tristate) {
1082 fclose(out);
1083 return 1;
1084 }
1085
1086 out_h = fopen(".tmpconfig.h", "w");1061 out_h = fopen(".tmpconfig.h", "w");
1087 if (!out_h) {1062 if (!out_h) {
1088 fclose(out);1063 fclose(out);
1089 fclose(tristate);
1090 return 1;1064 return 1;
1091 }1065 }
1092 1066
1093 conf_write_heading(out, &kconfig_printer_cb, NULL);1067 conf_write_heading(out, &kconfig_printer_cb, NULL);
1094
1095 conf_write_heading(tristate, &tristate_printer_cb, NULL);
1096
1097 conf_write_heading(out_h, &header_printer_cb, NULL);1068 conf_write_heading(out_h, &header_printer_cb, NULL);
1098 1069
1099 for_all_symbols(i, sym) {1070 for_all_symbols(i, sym) {
@@ -1101,15 +1072,11 @@ int conf_write_autoconf(int overwrite) · 1 unmodified line
1101 if (!(sym->flags & SYMBOL_WRITE) || !sym->name)1072 if (!(sym->flags & SYMBOL_WRITE) || !sym->name)
1102 continue;1073 continue;
1103 1074
1104 /* write symbol to auto.conf, tristate and header files */1075 /* write symbols to auto.conf and autoconf.h */
1105 conf_write_symbol(out, sym, &kconfig_printer_cb, (void *)1);1076 conf_write_symbol(out, sym, &kconfig_printer_cb, (void *)1);
1106
1107 conf_write_symbol(tristate, sym, &tristate_printer_cb, (void *)1);
1108
1109 conf_write_symbol(out_h, sym, &header_printer_cb, NULL);1077 conf_write_symbol(out_h, sym, &header_printer_cb, NULL);
1110 }1078 }
1111 fclose(out);1079 fclose(out);
1112 fclose(tristate);
1113 fclose(out_h);1080 fclose(out_h);
1114 1081
1115 name = getenv("KCONFIG_AUTOHEADER");1082 name = getenv("KCONFIG_AUTOHEADER");
@@ -1120,14 +1087,6 @@ int conf_write_autoconf(int overwrite) · 4 unmodified lines
1120 if (rename(".tmpconfig.h", name))1087 if (rename(".tmpconfig.h", name))
1121 return 1;1088 return 1;
1122 1089
1123 name = getenv("KCONFIG_TRISTATE");
1124 if (!name)
1125 name = "include/config/tristate.conf";
1126 if (make_parent_dir(name))
1127 return 1;
1128 if (rename(".tmpconfig_tristate", name))
1129 return 1;
1130
1131 if (make_parent_dir(autoconf_name))1090 if (make_parent_dir(autoconf_name))
1132 return 1;1091 return 1;
1133 /*1092 /*
scripts/link-vmlinux.sh+4−0
@@ -250,6 +250,10 @@ ${MAKE} -f "${srctree}/scripts/Makefile.modpost" MODPOST_VMLINUX=1 · 249 unmodified lines
250 250
251info MODINFO modules.builtin.modinfo251info MODINFO modules.builtin.modinfo
252${OBJCOPY} -j .modinfo -O binary vmlinux.o modules.builtin.modinfo252${OBJCOPY} -j .modinfo -O binary vmlinux.o modules.builtin.modinfo
253info GEN modules.builtin
254# The second line aids cases where multiple modules share the same object.
255tr '\0' '\n' < modules.builtin.modinfo | sed -n 's/^[[:alnum:]:_]*\.file=//p' |
256 tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$/.ko/' > modules.builtin
253 257
254btf_vmlinux_bin_o=""258btf_vmlinux_bin_o=""
255if [ -n "${CONFIG_DEBUG_INFO_BTF}" ]; then259if [ -n "${CONFIG_DEBUG_INFO_BTF}" ]; then