Skip to content

Commit

Permalink
modpost: invoke modpost only when input files are updated
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
masahir0y committed Jun 6, 2020
1 parent 269a535 commit 436b2ac
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
20 changes: 16 additions & 4 deletions scripts/Makefile.modpost
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,26 @@ endif

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

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

$(input-symdump):
@:

# Read out modules.order to pass in modpost.
# Otherwise, allmodconfig would fail with "Argument list too long".
quiet_cmd_modpost = MODPOST $@
cmd_modpost = sed 's/ko$$/o/' $(MODORDER) | $(MODPOST) -T -
cmd_modpost = sed 's/ko$$/o/' $< | $(MODPOST) -T -

$(output-symdump): FORCE
$(call cmd,modpost)
$(output-symdump): $(MODORDER) $(input-symdump) FORCE
$(call if_changed,modpost)

targets += $(output-symdump)

__modpost: $(output-symdump)
ifneq ($(KBUILD_MODPOST_NOFINAL),1)
Expand All @@ -114,6 +119,13 @@ endif
PHONY += FORCE
FORCE:

existing-targets := $(wildcard $(sort $(targets)))

-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)

PHONY += FORCE
FORCE:

endif

.PHONY: $(PHONY)
32 changes: 21 additions & 11 deletions scripts/mod/modpost.c
Original file line number Diff line number Diff line change
Expand Up @@ -2375,6 +2375,25 @@ static void add_srcversion(struct buffer *b, struct module *mod)
}
}

static void write_buf(struct buffer *b, const char *fname)
{
FILE *file;

file = fopen(fname, "w");
if (!file) {
perror(fname);
exit(1);
}
if (fwrite(b->p, 1, b->pos, file) != b->pos) {
perror(fname);
exit(1);
}
if (fclose(file) != 0) {
perror(fname);
exit(1);
}
}

static void write_if_changed(struct buffer *b, const char *fname)
{
char *tmp;
Expand Down Expand Up @@ -2407,16 +2426,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
close_write:
fclose(file);
write:
file = fopen(fname, "w");
if (!file) {
perror(fname);
exit(1);
}
if (fwrite(b->p, 1, b->pos, file) != b->pos) {
perror(fname);
exit(1);
}
fclose(file);
write_buf(b, fname);
}

/* parse Module.symvers file. line format:
Expand Down Expand Up @@ -2508,7 +2518,7 @@ static void write_dump(const char *fname)
symbol = symbol->next;
}
}
write_if_changed(&buf, fname);
write_buf(&buf, fname);
free(buf.p);
}

Expand Down

0 comments on commit 436b2ac

Please sign in to comment.