Skip to content

Commit f65a486

Browse files
committed
kbuild: change module.order to list *.o instead of *.ko
scripts/Makefile.build replaces the suffix .o with .ko, then scripts/Makefile.modpost calls the sed command to change .ko back to the original .o suffix. Instead of converting the suffixes back-and-forth, store the .o paths in modules.order, and replace it with .ko in 'make modules_install'. This avoids the unneeded sed command. Signed-off-by: Masahiro Yamada <[email protected]> Reviewed-by: Luis Chamberlain <[email protected]>
1 parent 875ef1a commit f65a486

File tree

9 files changed

+21
-21
lines changed

9 files changed

+21
-21
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,7 @@ __modinst_pre:
15641564
rm -f $(MODLIB)/build ; \
15651565
ln -s $(CURDIR) $(MODLIB)/build ; \
15661566
fi
1567-
@sed 's:^:kernel/:' modules.order > $(MODLIB)/modules.order
1567+
@sed 's:^\(.*\)\.o$$:kernel/\1.ko:' modules.order > $(MODLIB)/modules.order
15681568
@cp -f modules.builtin $(MODLIB)/
15691569
@cp -f $(objtree)/modules.builtin.modinfo $(MODLIB)/
15701570

scripts/Makefile.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ $(obj)/built-in.a: $(real-obj-y) FORCE
435435
# modules.order unless contained modules are updated.
436436

437437
cmd_modules_order = { $(foreach m, $(real-prereqs), \
438-
$(if $(filter %/modules.order, $m), cat $m, echo $(patsubst %.o,%.ko,$m));) :; } \
438+
$(if $(filter %/modules.order, $m), cat $m, echo $m);) :; } \
439439
> $@
440440

441441
$(obj)/modules.order: $(obj-m) FORCE

scripts/Makefile.modfinal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ include $(srctree)/scripts/Makefile.lib
1515
# find all modules listed in modules.order
1616
modules := $(call read-file, $(MODORDER))
1717

18-
__modfinal: $(modules)
18+
__modfinal: $(modules:%.o=%.ko)
1919
@:
2020

2121
# modname and part-of-module are set to make c_flags define proper module flags
@@ -57,13 +57,13 @@ if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \
5757
printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
5858

5959
# Re-generate module BTFs if either module's .ko or vmlinux changed
60-
$(modules): %.ko: %.o %.mod.o scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),vmlinux) FORCE
60+
%.ko: %.o %.mod.o scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),vmlinux) FORCE
6161
+$(call if_changed_except,ld_ko_o,vmlinux)
6262
ifdef CONFIG_DEBUG_INFO_BTF_MODULES
6363
+$(if $(newer-prereqs),$(call cmd,btf_ko))
6464
endif
6565

66-
targets += $(modules) $(modules:.ko=.mod.o)
66+
targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o)
6767

6868
# Add FORCE to the prequisites of a target to force it to be always rebuilt.
6969
# ---------------------------------------------------------------------------

scripts/Makefile.modinst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ suffix-$(CONFIG_MODULE_COMPRESS_GZIP) := .gz
2626
suffix-$(CONFIG_MODULE_COMPRESS_XZ) := .xz
2727
suffix-$(CONFIG_MODULE_COMPRESS_ZSTD) := .zst
2828

29-
modules := $(patsubst $(extmod_prefix)%, $(dst)/%$(suffix-y), $(modules))
29+
modules := $(patsubst $(extmod_prefix)%.o, $(dst)/%.ko$(suffix-y), $(modules))
3030

3131
__modinst: $(modules)
3232
@:

scripts/Makefile.modpost

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ ifneq ($(KBUILD_MODPOST_WARN)$(missing-input),)
107107
modpost-args += -w
108108
endif
109109

110-
modorder-if-needed := $(if $(KBUILD_MODULES), $(MODORDER))
110+
ifdef KBUILD_MODULES
111+
modorder-if-needed := $(MODORDER)
112+
modpost-args += -T $(MODORDER)
113+
endif
111114

112115
MODPOST = scripts/mod/modpost
113116

@@ -119,7 +122,7 @@ quiet_cmd_modpost = MODPOST $@
119122
echo >&2 "WARNING: $(missing-input) is missing."; \
120123
echo >&2 " Modules may not have dependencies or modversions."; \
121124
echo >&2 " You may get many unresolved symbol warnings.";) \
122-
sed 's/ko$$/o/' $(or $(modorder-if-needed), /dev/null) | $(MODPOST) $(modpost-args) -T - $(vmlinux.o-if-present)
125+
$(MODPOST) $(modpost-args) $(vmlinux.o-if-present)
123126

124127
targets += $(output-symdump)
125128
$(output-symdump): $(modorder-if-needed) $(vmlinux.o-if-present) $(module.symvers-if-present) $(MODPOST) FORCE

scripts/clang-tools/gen_compile_commands.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ def cmdfiles_for_modorder(modorder):
138138
"""
139139
with open(modorder) as f:
140140
for line in f:
141-
ko = line.rstrip()
142-
base, ext = os.path.splitext(ko)
143-
if ext != '.ko':
144-
sys.exit('{}: module path must end with .ko'.format(ko))
141+
obj = line.rstrip()
142+
base, ext = os.path.splitext(obj)
143+
if ext != '.o':
144+
sys.exit('{}: module path must end with .o'.format(obj))
145145
mod = base + '.mod'
146146
# Read from *.mod, to get a list of objects that compose the module.
147147
with open(mod) as m:

scripts/gen_autoksyms.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ cat > "$output_file" << EOT
4848
EOT
4949

5050
{
51-
[ -n "${read_modorder}" ] && sed 's/ko$/usyms/' modules.order | xargs cat
51+
[ -n "${read_modorder}" ] && sed 's/o$/usyms/' modules.order | xargs cat
5252
echo "$needed_symbols"
5353
[ -n "$ksym_wl" ] && cat "$ksym_wl"
5454
} | sed -e 's/ /\n/g' | sed -n -e '/^$/!p' |

scripts/mod/modpost.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,20 +1856,17 @@ static void read_symbols_from_files(const char *filename)
18561856
FILE *in = stdin;
18571857
char fname[PATH_MAX];
18581858

1859-
if (strcmp(filename, "-") != 0) {
1860-
in = fopen(filename, "r");
1861-
if (!in)
1862-
fatal("Can't open filenames file %s: %m", filename);
1863-
}
1859+
in = fopen(filename, "r");
1860+
if (!in)
1861+
fatal("Can't open filenames file %s: %m", filename);
18641862

18651863
while (fgets(fname, PATH_MAX, in) != NULL) {
18661864
if (strends(fname, "\n"))
18671865
fname[strlen(fname)-1] = '\0';
18681866
read_symbols(fname);
18691867
}
18701868

1871-
if (in != stdin)
1872-
fclose(in);
1869+
fclose(in);
18731870
}
18741871

18751872
#define SZ 500

scripts/modules-check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ check_same_name_modules()
1616
for m in $(sed 's:.*/::' "$1" | sort | uniq -d)
1717
do
1818
echo "error: the following would cause module name conflict:" >&2
19-
sed -n "/\/$m/s:^: :p" "$1" >&2
19+
sed -n "/\/$m/s:^\(.*\)\.o\$: \1.ko:p" "$1" >&2
2020
exit_code=1
2121
done
2222
}

0 commit comments

Comments
 (0)