Skip to content

Commit 3a48a91

Browse files
committed
kbuild: check uniqueness of module names
In the recent build test of linux-next, Stephen saw a build error caused by a broken .tmp_versions/*.mod file: https://lkml.org/lkml/2019/5/13/991 drivers/net/phy/asix.ko and drivers/net/usb/asix.ko have the same basename, and there is a race in generating .tmp_versions/asix.mod Kbuild has not checked this before, and it suddenly shows up with obscure error messages when this kind of race occurs. Non-unique module names cause various sort of problems, but it is not trivial to catch them by eyes. Hence, this script. It checks not only real modules, but also built-in modules (i.e. controlled by tristate CONFIG option, but currently compiled with =y). Non-unique names for built-in modules also cause problems because /sys/modules/ would fall over. For the latest kernel, I tested "make allmodconfig all" (or more quickly "make allyesconfig modules"), and it detected the following: warning: same basename if the following are built as modules: drivers/regulator/88pm800.ko drivers/mfd/88pm800.ko warning: same basename if the following are built as modules: drivers/gpu/drm/bridge/adv7511/adv7511.ko drivers/media/i2c/adv7511.ko warning: same basename if the following are built as modules: drivers/net/phy/asix.ko drivers/net/usb/asix.ko warning: same basename if the following are built as modules: fs/coda/coda.ko drivers/media/platform/coda/coda.ko warning: same basename if the following are built as modules: drivers/net/phy/realtek.ko drivers/net/dsa/realtek.ko Reported-by: Stephen Rothwell <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]> Reviewed-by: Kees Cook <[email protected]> Reviewed-by: Stephen Rothwell <[email protected]> Reviewed-by: Lucas De Marchi <[email protected]>
1 parent aff11cd commit 3a48a91

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,7 @@ modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
12881288
$(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
12891289
@$(kecho) ' Building modules, stage 2.';
12901290
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1291+
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh
12911292

12921293
modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
12931294
$(Q)$(AWK) '!x[$$0]++' $^ > $(objtree)/modules.builtin

scripts/modules-check.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
set -e
5+
6+
# Check uniqueness of module names
7+
check_same_name_modules()
8+
{
9+
for m in $(sed 's:.*/::' modules.order modules.builtin | sort | uniq -d)
10+
do
11+
echo "warning: same basename if the following are built as modules:" >&2
12+
sed "/\/$m/!d;s:^kernel/: :" modules.order modules.builtin >&2
13+
done
14+
}
15+
16+
check_same_name_modules

0 commit comments

Comments
 (0)