Skip to content

Commit 436b2ac

Browse files
committed
modpost: invoke modpost only when input files are updated
Currently, the second pass of modpost is always invoked when you run 'make' or 'make modules' even if none of modules is changed. Use if_changed to invoke it only when it is necessary. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
1 parent 269a535 commit 436b2ac

2 files changed

Lines changed: 37 additions & 15 deletions

File tree

‎scripts/Makefile.modpost‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,26 @@ endif
9090

9191
# modpost options for modules (both in-kernel and external)
9292
MODPOST += \
93-
$(addprefix -i ,$(input-symdump)) \
93+
$(addprefix -i ,$(wildcard $(input-symdump))) \
9494
$(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N)
9595

9696
# 'make -i -k' ignores compile errors, and builds as many modules as possible.
9797
ifneq ($(findstring i,$(filter-out --%,$(MAKEFLAGS))),)
9898
MODPOST += -n
9999
endif
100100

101+
$(input-symdump):
102+
@:
103+
101104
# Read out modules.order to pass in modpost.
102105
# Otherwise, allmodconfig would fail with "Argument list too long".
103106
quiet_cmd_modpost = MODPOST $@
104-
cmd_modpost = sed 's/ko$$/o/' $(MODORDER) | $(MODPOST) -T -
107+
cmd_modpost = sed 's/ko$$/o/' $< | $(MODPOST) -T -
105108

106-
$(output-symdump): FORCE
107-
$(call cmd,modpost)
109+
$(output-symdump): $(MODORDER) $(input-symdump) FORCE
110+
$(call if_changed,modpost)
111+
112+
targets += $(output-symdump)
108113

109114
__modpost: $(output-symdump)
110115
ifneq ($(KBUILD_MODPOST_NOFINAL),1)
@@ -114,6 +119,13 @@ endif
114119
PHONY += FORCE
115120
FORCE:
116121

122+
existing-targets := $(wildcard $(sort $(targets)))
123+
124+
-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
125+
126+
PHONY += FORCE
127+
FORCE:
128+
117129
endif
118130

119131
.PHONY: $(PHONY)

‎scripts/mod/modpost.c‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,6 +2375,25 @@ static void add_srcversion(struct buffer *b, struct module *mod)
23752375
}
23762376
}
23772377

2378+
static void write_buf(struct buffer *b, const char *fname)
2379+
{
2380+
FILE *file;
2381+
2382+
file = fopen(fname, "w");
2383+
if (!file) {
2384+
perror(fname);
2385+
exit(1);
2386+
}
2387+
if (fwrite(b->p, 1, b->pos, file) != b->pos) {
2388+
perror(fname);
2389+
exit(1);
2390+
}
2391+
if (fclose(file) != 0) {
2392+
perror(fname);
2393+
exit(1);
2394+
}
2395+
}
2396+
23782397
static void write_if_changed(struct buffer *b, const char *fname)
23792398
{
23802399
char *tmp;
@@ -2407,16 +2426,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
24072426
close_write:
24082427
fclose(file);
24092428
write:
2410-
file = fopen(fname, "w");
2411-
if (!file) {
2412-
perror(fname);
2413-
exit(1);
2414-
}
2415-
if (fwrite(b->p, 1, b->pos, file) != b->pos) {
2416-
perror(fname);
2417-
exit(1);
2418-
}
2419-
fclose(file);
2429+
write_buf(b, fname);
24202430
}
24212431

24222432
/* parse Module.symvers file. line format:
@@ -2508,7 +2518,7 @@ static void write_dump(const char *fname)
25082518
symbol = symbol->next;
25092519
}
25102520
}
2511-
write_if_changed(&buf, fname);
2521+
write_buf(&buf, fname);
25122522
free(buf.p);
25132523
}
25142524

0 commit comments

Comments
 (0)