Skip to content

Commit 7840fea

Browse files
michal42torvalds
authored andcommitted
kbuild: Fix computing srcversion for modules
Recent change to fixdep: commit b7bd182 Author: Michal Marek <mmarek@suse.cz> Date: Thu Feb 17 15:13:54 2011 +0100 fixdep: Do not record dependency on the source file itself changed the format of the *.cmd files without realizing that it is also used by modpost. Put the path to the source file to the file back, in a special variable, so that modpost sees all source files when calculating srcversion for modules. Reported-and-tested-by: Henrik Rydberg <rydberg@euromail.se> Signed-off-by: Michal Marek <mmarek@suse.cz> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e8444a3 commit 7840fea

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

scripts/basic/fixdep.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ static void do_config_file(const char *filename)
309309
close(fd);
310310
}
311311

312+
/*
313+
* Important: The below generated source_foo.o and deps_foo.o variable
314+
* assignments are parsed not only by make, but also by the rather simple
315+
* parser in scripts/mod/sumversion.c.
316+
*/
312317
static void parse_dep_file(void *map, size_t len)
313318
{
314319
char *m = map;
@@ -323,7 +328,6 @@ static void parse_dep_file(void *map, size_t len)
323328
exit(1);
324329
}
325330
memcpy(s, m, p-m); s[p-m] = 0;
326-
printf("deps_%s := \\\n", target);
327331
m = p+1;
328332

329333
clear_config();
@@ -343,12 +347,15 @@ static void parse_dep_file(void *map, size_t len)
343347
strrcmp(s, "arch/um/include/uml-config.h") &&
344348
strrcmp(s, ".ver")) {
345349
/*
346-
* Do not output the first dependency (the
347-
* source file), so that kbuild is not confused
348-
* if a .c file is rewritten into .S or vice
349-
* versa.
350+
* Do not list the source file as dependency, so that
351+
* kbuild is not confused if a .c file is rewritten
352+
* into .S or vice versa. Storing it in source_* is
353+
* needed for modpost to compute srcversions.
350354
*/
351-
if (!first)
355+
if (first) {
356+
printf("source_%s := %s\n\n", target, s);
357+
printf("deps_%s := \\\n", target);
358+
} else
352359
printf(" %s \\\n", s);
353360
do_config_file(s);
354361
}

scripts/mod/sumversion.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ static int is_static_library(const char *objfile)
300300
return 0;
301301
}
302302

303-
/* We have dir/file.o. Open dir/.file.o.cmd, look for deps_ line to
304-
* figure out source file. */
303+
/* We have dir/file.o. Open dir/.file.o.cmd, look for source_ and deps_ line
304+
* to figure out source files. */
305305
static int parse_source_files(const char *objfile, struct md4_ctx *md)
306306
{
307307
char *cmd, *file, *line, *dir;
@@ -340,6 +340,21 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md)
340340
*/
341341
while ((line = get_next_line(&pos, file, flen)) != NULL) {
342342
char* p = line;
343+
344+
if (strncmp(line, "source_", sizeof("source_")-1) == 0) {
345+
p = strrchr(line, ' ');
346+
if (!p) {
347+
warn("malformed line: %s\n", line);
348+
goto out_file;
349+
}
350+
p++;
351+
if (!parse_file(p, md)) {
352+
warn("could not open %s: %s\n",
353+
p, strerror(errno));
354+
goto out_file;
355+
}
356+
continue;
357+
}
343358
if (strncmp(line, "deps_", sizeof("deps_")-1) == 0) {
344359
check_files = 1;
345360
continue;

0 commit comments

Comments
 (0)