Skip to content

Commit 8b41fc4

Browse files
committed
kbuild: create modules.builtin without Makefile.modbuiltin or tristate.conf
Commit bc081dd ("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>
1 parent 1664a37 commit 8b41fc4

7 files changed

Lines changed: 22 additions & 128 deletions

File tree

‎Documentation/kbuild/kconfig.rst‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,6 @@ KCONFIG_AUTOCONFIG
154154
This environment variable can be set to specify the path & name of the
155155
"auto.conf" file. Its default value is "include/config/auto.conf".
156156

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-
162157
KCONFIG_AUTOHEADER
163158
------------------
164159
This environment variable can be set to specify the path & name of the

‎Makefile‎

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ $(KCONFIG_CONFIG):
674674
#
675675
# This exploits the 'multi-target pattern rule' trick.
676676
# 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)
678678
$(Q)$(MAKE) -f $(srctree)/Makefile syncconfig
679679
else # !may-sync-config
680680
# External modules and some install targets need include/generated/autoconf.h
@@ -1278,24 +1278,13 @@ all: modules
12781278
# using awk while concatenating to the final file.
12791279

12801280
PHONY += modules
1281-
modules: $(if $(KBUILD_BUILTIN),vmlinux) modules.order modules.builtin
1281+
modules: $(if $(KBUILD_BUILTIN),vmlinux) modules.order
12821282
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
12831283
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh
12841284

12851285
modules.order: descend
12861286
$(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(build-dirs)) > $@
12871287

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-
12991288
# Target to prepare building external modules
13001289
PHONY += modules_prepare
13011290
modules_prepare: prepare
@@ -1315,7 +1304,7 @@ _modinst_:
13151304
ln -s $(CURDIR) $(MODLIB)/build ; \
13161305
fi
13171306
@sed 's:^:kernel/:' modules.order > $(MODLIB)/modules.order
1318-
@sed 's:^:kernel/:' modules.builtin > $(MODLIB)/modules.builtin
1307+
@cp -f modules.builtin $(MODLIB)/
13191308
@cp -f $(objtree)/modules.builtin.modinfo $(MODLIB)/
13201309
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
13211310

@@ -1357,7 +1346,7 @@ endif # CONFIG_MODULES
13571346

13581347
# Directories & files removed with 'make clean'
13591348
CLEAN_DIRS += include/ksym
1360-
CLEAN_FILES += modules.builtin.modinfo modules.nsdeps
1349+
CLEAN_FILES += modules.builtin modules.builtin.modinfo modules.nsdeps
13611350

13621351
# Directories & files removed with 'make mrproper'
13631352
MRPROPER_DIRS += include/config include/generated \
@@ -1712,7 +1701,7 @@ clean: $(clean-dirs)
17121701
-o -name '*.lex.c' -o -name '*.tab.[ch]' \
17131702
-o -name '*.asn1.[ch]' \
17141703
-o -name '*.symtypes' -o -name 'modules.order' \
1715-
-o -name modules.builtin -o -name '.tmp_*.o.*' \
1704+
-o -name '.tmp_*.o.*' \
17161705
-o -name '*.c.[012]*.*' \
17171706
-o -name '*.ll' \
17181707
-o -name '*.gcno' \) -type f -print | xargs rm -f

‎include/linux/module.h‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ extern void cleanup_module(void);
169169
*/
170170
#define MODULE_SOFTDEP(_softdep) MODULE_INFO(softdep, _softdep)
171171

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+
172182
/*
173183
* The following license idents are currently accepted as indicating free
174184
* software modules
@@ -213,7 +223,7 @@ extern void cleanup_module(void);
213223
* 2. So the community can ignore bug reports including proprietary modules
214224
* 3. So vendors can do likewise based on their own policies
215225
*/
216-
#define MODULE_LICENSE(_license) MODULE_INFO(license, _license)
226+
#define MODULE_LICENSE(_license) MODULE_FILE MODULE_INFO(license, _license)
217227

218228
/*
219229
* Author(s), use "Name <email>" or just "Name", for multiple

‎scripts/Kbuild.include‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,6 @@ ld-ifversion = $(shell [ $(ld-version) $(1) $(2) ] && echo $(3) || echo $(4))
163163
# $(Q)$(MAKE) $(build)=dir
164164
build := -f $(srctree)/scripts/Makefile.build obj
165165

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-
172166
###
173167
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj=
174168
# Usage:

‎scripts/Makefile.modbuiltin‎

Lines changed: 0 additions & 57 deletions
This file was deleted.

‎scripts/kconfig/confdata.c‎

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -710,25 +710,6 @@ static struct conf_printer header_printer_cb =
710710
.print_comment = header_print_comment,
711711
};
712712

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-
732713
static void conf_write_symbol(FILE *fp, struct symbol *sym,
733714
struct conf_printer *printer, void *printer_arg)
734715
{
@@ -1062,7 +1043,7 @@ int conf_write_autoconf(int overwrite)
10621043
struct symbol *sym;
10631044
const char *name;
10641045
const char *autoconf_name = conf_get_autoconfig_name();
1065-
FILE *out, *tristate, *out_h;
1046+
FILE *out, *out_h;
10661047
int i;
10671048

10681049
if (!overwrite && is_present(autoconf_name))
@@ -1077,39 +1058,25 @@ int conf_write_autoconf(int overwrite)
10771058
if (!out)
10781059
return 1;
10791060

1080-
tristate = fopen(".tmpconfig_tristate", "w");
1081-
if (!tristate) {
1082-
fclose(out);
1083-
return 1;
1084-
}
1085-
10861061
out_h = fopen(".tmpconfig.h", "w");
10871062
if (!out_h) {
10881063
fclose(out);
1089-
fclose(tristate);
10901064
return 1;
10911065
}
10921066

10931067
conf_write_heading(out, &kconfig_printer_cb, NULL);
1094-
1095-
conf_write_heading(tristate, &tristate_printer_cb, NULL);
1096-
10971068
conf_write_heading(out_h, &header_printer_cb, NULL);
10981069

10991070
for_all_symbols(i, sym) {
11001071
sym_calc_value(sym);
11011072
if (!(sym->flags & SYMBOL_WRITE) || !sym->name)
11021073
continue;
11031074

1104-
/* write symbol to auto.conf, tristate and header files */
1075+
/* write symbols to auto.conf and autoconf.h */
11051076
conf_write_symbol(out, sym, &kconfig_printer_cb, (void *)1);
1106-
1107-
conf_write_symbol(tristate, sym, &tristate_printer_cb, (void *)1);
1108-
11091077
conf_write_symbol(out_h, sym, &header_printer_cb, NULL);
11101078
}
11111079
fclose(out);
1112-
fclose(tristate);
11131080
fclose(out_h);
11141081

11151082
name = getenv("KCONFIG_AUTOHEADER");
@@ -1120,14 +1087,6 @@ int conf_write_autoconf(int overwrite)
11201087
if (rename(".tmpconfig.h", name))
11211088
return 1;
11221089

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-
11311090
if (make_parent_dir(autoconf_name))
11321091
return 1;
11331092
/*

‎scripts/link-vmlinux.sh‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ ${MAKE} -f "${srctree}/scripts/Makefile.modpost" MODPOST_VMLINUX=1
250250

251251
info MODINFO modules.builtin.modinfo
252252
${OBJCOPY} -j .modinfo -O binary vmlinux.o modules.builtin.modinfo
253+
info GEN modules.builtin
254+
# The second line aids cases where multiple modules share the same object.
255+
tr '\0' '\n' < modules.builtin.modinfo | sed -n 's/^[[:alnum:]:_]*\.file=//p' |
256+
tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$/.ko/' > modules.builtin
253257

254258
btf_vmlinux_bin_o=""
255259
if [ -n "${CONFIG_DEBUG_INFO_BTF}" ]; then

0 commit comments

Comments
 (0)