Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

+22 -128
-5
Documentation/kbuild/kconfig.rst
··· 154 154 This environment variable can be set to specify the path & name of the 155 155 "auto.conf" file. Its default value is "include/config/auto.conf". 156 156 157 - KCONFIG_TRISTATE 158 - ---------------- 159 - This 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 - 162 157 KCONFIG_AUTOHEADER 163 158 ------------------ 164 159 This environment variable can be set to specify the path & name of the
+5 -16
Makefile
··· 674 674 # 675 675 # This exploits the 'multi-target pattern rule' trick. 676 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 678 $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig 679 679 else # !may-sync-config 680 680 # External modules and some install targets need include/generated/autoconf.h ··· 1278 1278 # using awk while concatenating to the final file. 1279 1279 1280 1280 PHONY += modules 1281 - modules: $(if $(KBUILD_BUILTIN),vmlinux) modules.order modules.builtin 1281 + modules: $(if $(KBUILD_BUILTIN),vmlinux) modules.order 1282 1282 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost 1283 1283 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh 1284 1284 1285 1285 modules.order: descend 1286 1286 $(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(build-dirs)) > $@ 1287 - 1288 - modbuiltin-dirs := $(addprefix _modbuiltin_, $(build-dirs)) 1289 - 1290 - modules.builtin: $(modbuiltin-dirs) 1291 - $(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(build-dirs)) > $@ 1292 - 1293 - PHONY += $(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 1287 1299 1288 # Target to prepare building external modules 1300 1289 PHONY += modules_prepare ··· 1304 1315 ln -s $(CURDIR) $(MODLIB)/build ; \ 1305 1316 fi 1306 1317 @sed 's:^:kernel/:' modules.order > $(MODLIB)/modules.order 1307 - @sed 's:^:kernel/:' modules.builtin > $(MODLIB)/modules.builtin 1318 + @cp -f modules.builtin $(MODLIB)/ 1308 1319 @cp -f $(objtree)/modules.builtin.modinfo $(MODLIB)/ 1309 1320 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst 1310 1321 ··· 1346 1357 1347 1358 # Directories & files removed with 'make clean' 1348 1359 CLEAN_DIRS += include/ksym 1349 - CLEAN_FILES += modules.builtin.modinfo modules.nsdeps 1360 + CLEAN_FILES += modules.builtin modules.builtin.modinfo modules.nsdeps 1350 1361 1351 1362 # Directories & files removed with 'make mrproper' 1352 1363 MRPROPER_DIRS += include/config include/generated \ ··· 1701 1712 -o -name '*.lex.c' -o -name '*.tab.[ch]' \ 1702 1713 -o -name '*.asn1.[ch]' \ 1703 1714 -o -name '*.symtypes' -o -name 'modules.order' \ 1704 - -o -name modules.builtin -o -name '.tmp_*.o.*' \ 1715 + -o -name '.tmp_*.o.*' \ 1705 1716 -o -name '*.c.[012]*.*' \ 1706 1717 -o -name '*.ll' \ 1707 1718 -o -name '*.gcno' \) -type f -print | xargs rm -f
+11 -1
include/linux/module.h
··· 170 170 #define MODULE_SOFTDEP(_softdep) MODULE_INFO(softdep, _softdep) 171 171 172 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 + 182 + /* 173 183 * The following license idents are currently accepted as indicating free 174 184 * software modules 175 185 * ··· 223 213 * 2. So the community can ignore bug reports including proprietary modules 224 214 * 3. So vendors can do likewise based on their own policies 225 215 */ 226 - #define MODULE_LICENSE(_license) MODULE_INFO(license, _license) 216 + #define MODULE_LICENSE(_license) MODULE_FILE MODULE_INFO(license, _license) 227 217 228 218 /* 229 219 * Author(s), use "Name <email>" or just "Name", for multiple
-6
scripts/Kbuild.include
··· 164 164 build := -f $(srctree)/scripts/Makefile.build obj 165 165 166 166 ### 167 - # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.modbuiltin obj= 168 - # Usage: 169 - # $(Q)$(MAKE) $(modbuiltin)=dir 170 - modbuiltin := -f $(srctree)/scripts/Makefile.modbuiltin obj 171 - 172 - ### 173 167 # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj= 174 168 # Usage: 175 169 # $(Q)$(MAKE) $(dtbinst)=dir
-57
scripts/Makefile.modbuiltin
··· 1 - # SPDX-License-Identifier: GPL-2.0 2 - # ========================================================================== 3 - # Generating modules.builtin 4 - # ========================================================================== 5 - 6 - src := $(obj) 7 - 8 - PHONY := __modbuiltin 9 - __modbuiltin: 10 - 11 - include 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 14 - include include/config/tristate.conf 15 - 16 - include scripts/Kbuild.include 17 - 18 - ifdef building_out_of_srctree 19 - # Create output directory if not already present 20 - _dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj)) 21 - endif 22 - 23 - # The filename Kbuild has precedence over Makefile 24 - kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) 25 - kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile) 26 - include $(kbuild-file) 27 - 28 - include scripts/Makefile.lib 29 - __subdir-Y := $(patsubst %/,%,$(filter %/, $(obj-Y))) 30 - subdir-Y += $(__subdir-Y) 31 - subdir-ym := $(sort $(subdir-y) $(subdir-Y) $(subdir-m)) 32 - subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) 33 - obj-Y := $(addprefix $(obj)/,$(obj-Y)) 34 - 35 - modbuiltin-subdirs := $(patsubst %,%/modules.builtin, $(subdir-ym)) 36 - modbuiltin-mods := $(filter %.ko, $(obj-Y:.o=.ko)) 37 - modbuiltin-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 - 46 - PHONY += FORCE 47 - 48 - FORCE: 49 - 50 - # Descending 51 - # --------------------------------------------------------------------------- 52 - 53 - PHONY += $(subdir-ym) 54 - $(subdir-ym): 55 - $(Q)$(MAKE) $(modbuiltin)=$@ 56 - 57 - .PHONY: $(PHONY)
+2 -43
scripts/kconfig/confdata.c
··· 710 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 - */ 718 - static void 719 - tristate_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 - 726 - static struct conf_printer tristate_printer_cb = 727 - { 728 - .print_symbol = tristate_print_symbol, 729 - .print_comment = kconfig_print_comment, 730 - }; 731 - 732 713 static void conf_write_symbol(FILE *fp, struct symbol *sym, 733 714 struct conf_printer *printer, void *printer_arg) 734 715 { ··· 1043 1062 struct symbol *sym; 1044 1063 const char *name; 1045 1064 const char *autoconf_name = conf_get_autoconfig_name(); 1046 - FILE *out, *tristate, *out_h; 1065 + FILE *out, *out_h; 1047 1066 int i; 1048 1067 1049 1068 if (!overwrite && is_present(autoconf_name)) ··· 1058 1077 if (!out) 1059 1078 return 1; 1060 1079 1061 - tristate = fopen(".tmpconfig_tristate", "w"); 1062 - if (!tristate) { 1063 - fclose(out); 1064 - return 1; 1065 - } 1066 - 1067 1080 out_h = fopen(".tmpconfig.h", "w"); 1068 1081 if (!out_h) { 1069 1082 fclose(out); 1070 - fclose(tristate); 1071 1083 return 1; 1072 1084 } 1073 1085 1074 1086 conf_write_heading(out, &kconfig_printer_cb, NULL); 1075 - 1076 - conf_write_heading(tristate, &tristate_printer_cb, NULL); 1077 - 1078 1087 conf_write_heading(out_h, &header_printer_cb, NULL); 1079 1088 1080 1089 for_all_symbols(i, sym) { ··· 1072 1101 if (!(sym->flags & SYMBOL_WRITE) || !sym->name) 1073 1102 continue; 1074 1103 1075 - /* write symbol to auto.conf, tristate and header files */ 1104 + /* write symbols to auto.conf and autoconf.h */ 1076 1105 conf_write_symbol(out, sym, &kconfig_printer_cb, (void *)1); 1077 - 1078 - conf_write_symbol(tristate, sym, &tristate_printer_cb, (void *)1); 1079 - 1080 1106 conf_write_symbol(out_h, sym, &header_printer_cb, NULL); 1081 1107 } 1082 1108 fclose(out); 1083 - fclose(tristate); 1084 1109 fclose(out_h); 1085 1110 1086 1111 name = getenv("KCONFIG_AUTOHEADER"); ··· 1085 1118 if (make_parent_dir(name)) 1086 1119 return 1; 1087 1120 if (rename(".tmpconfig.h", name)) 1088 - return 1; 1089 - 1090 - name = getenv("KCONFIG_TRISTATE"); 1091 - if (!name) 1092 - name = "include/config/tristate.conf"; 1093 - if (make_parent_dir(name)) 1094 - return 1; 1095 - if (rename(".tmpconfig_tristate", name)) 1096 1121 return 1; 1097 1122 1098 1123 if (make_parent_dir(autoconf_name))