Skip to content

Commit 69bc8d3

Browse files
committed
kbuild: generate Module.symvers only when vmlinux exists
The external module build shows the following warning if Module.symvers is missing in the kernel tree. WARNING: Symbol version dump "Module.symvers" is missing. Modules may not have dependencies or modversions. I think this is an important heads-up because the resulting modules may not work as expected. This happens when you did not build the entire kernel tree, for example, you might have prepared the minimal setups for external modules by 'make defconfig && make modules_preapre'. A problem is that 'make modules' creates Module.symvers even without vmlinux. In this case, that warning is suppressed since Module.symvers already exists in spite of its incomplete content. The incomplete (i.e. invalid) Module.symvers should not be created. This commit changes the second pass of modpost to dump symbols into modules-only.symvers. The final Module.symvers is created by concatenating vmlinux.symvers and modules-only.symvers if both exist. Module.symvers is supposed to collect symbols from both vmlinux and modules. It might be a bit confusing, and I am not quite sure if it is an official interface, but presumably it is difficult to rename it because some tools (e.g. kmod) parse it. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 987fdfe commit 69bc8d3

File tree

5 files changed

+18
-16
lines changed

5 files changed

+18
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ modules.order
5757
/tags
5858
/TAGS
5959
/linux
60+
/modules-only.symvers
6061
/vmlinux
6162
/vmlinux.32
6263
/vmlinux.map

Documentation/dontdiff

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ mktables
178178
mktree
179179
mkutf8data
180180
modpost
181+
modules-only.symvers
181182
modules.builtin
182183
modules.builtin.modinfo
183184
modules.nsdeps

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,7 @@ endif # CONFIG_MODULES
15321532
# make distclean Remove editor backup files, patch leftover files and the like
15331533

15341534
# Directories & files removed with 'make clean'
1535-
CLEAN_FILES += include/ksym vmlinux.symvers \
1535+
CLEAN_FILES += include/ksym vmlinux.symvers modules-only.symvers \
15361536
modules.builtin modules.builtin.modinfo modules.nsdeps \
15371537
compile_commands.json .thinlto-cache
15381538

scripts/Makefile.modpost

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,20 @@ else
6868
ifeq ($(KBUILD_EXTMOD),)
6969

7070
input-symdump := vmlinux.symvers
71-
output-symdump := Module.symvers
71+
output-symdump := modules-only.symvers
72+
73+
quiet_cmd_cat = GEN $@
74+
cmd_cat = cat $(real-prereqs) > $@
75+
76+
ifneq ($(wildcard vmlinux.symvers),)
77+
78+
__modpost: Module.symvers
79+
Module.symvers: vmlinux.symvers modules-only.symvers FORCE
80+
$(call if_changed,cat)
81+
82+
targets += Module.symvers
83+
84+
endif
7285

7386
else
7487

scripts/mod/modpost.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,19 +2423,6 @@ static void read_dump(const char *fname)
24232423
fatal("parse error in symbol dump file\n");
24242424
}
24252425

2426-
/* For normal builds always dump all symbols.
2427-
* For external modules only dump symbols
2428-
* that are not read from kernel Module.symvers.
2429-
**/
2430-
static int dump_sym(struct symbol *sym)
2431-
{
2432-
if (!external_module)
2433-
return 1;
2434-
if (sym->module->from_dump)
2435-
return 0;
2436-
return 1;
2437-
}
2438-
24392426
static void write_dump(const char *fname)
24402427
{
24412428
struct buffer buf = { };
@@ -2446,7 +2433,7 @@ static void write_dump(const char *fname)
24462433
for (n = 0; n < SYMBOL_HASH_SIZE ; n++) {
24472434
symbol = symbolhash[n];
24482435
while (symbol) {
2449-
if (dump_sym(symbol)) {
2436+
if (!symbol->module->from_dump) {
24502437
namespace = symbol->namespace;
24512438
buf_printf(&buf, "0x%08x\t%s\t%s\t%s\t%s\n",
24522439
symbol->crc, symbol->name,

0 commit comments

Comments
 (0)