Skip to content

Commit faa91c4

Browse files
committed
fixdep: avoid parsing the same file over again
The dep files (*.d files) emitted by C compilers usually contain the deduplicated list of included files. One exceptional case is when a header is included by the -include command line option, and also by #include directive. For example, the top Makefile adds the command line option, "-include $(srctree)/include/linux/kconfig.h". You do not need to include <linux/kconfig.h> in every source file. In fact, include/linux/kconfig.h is listed twice in many .*.cmd files due to include/linux/xarray.h having "#include <linux/kconfig.h>". I did not fix that since it is a small redundancy. However, this is more annoying for rustc. rustc emits the dependency for each emission type. For example, cmd_rustc_library emits dep-info, obj, and metadata. So, the emitted *.d file contains the dependency for those 3 targets, which makes fixdep parse the same file 3 times. $ grep rust/alloc/raw_vec.rs rust/.alloc.o.cmd rust/alloc/raw_vec.rs \ rust/alloc/raw_vec.rs \ rust/alloc/raw_vec.rs \ To skip the second parsing, this commit adds a hash table for parsed files, just like we did for CONFIG options. Signed-off-by: Masahiro Yamada <[email protected]> Acked-by: Miguel Ojeda <[email protected]> Tested-by: Miguel Ojeda <[email protected]> Reviewed-by: Vincenzo Palazzo <[email protected]>
1 parent 871d657 commit faa91c4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

scripts/basic/fixdep.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ struct item {
113113
};
114114

115115
#define HASHSZ 256
116-
static struct item *config_hashtab[HASHSZ];
116+
static struct item *config_hashtab[HASHSZ], *file_hashtab[HASHSZ];
117117

118118
static unsigned int strhash(const char *str, unsigned int sz)
119119
{
@@ -365,14 +365,19 @@ static void parse_dep_file(char *p, const char *target)
365365
* name, which will be the original one, and ignore any
366366
* other source names, which will be intermediate
367367
* temporary files.
368+
*
369+
* rustc emits the same dependency list for each
370+
* emission type. It is enough to list the source name
371+
* just once.
368372
*/
369373
if (!saw_any_target) {
370374
saw_any_target = true;
371375
printf("source_%s := %s\n\n", target, p);
372376
printf("deps_%s := \\\n", target);
373377
need_parse = true;
374378
}
375-
} else if (!is_ignored_file(p, q - p)) {
379+
} else if (!is_ignored_file(p, q - p) &&
380+
!in_hashtable(p, q - p, file_hashtab)) {
376381
printf(" %s \\\n", p);
377382
need_parse = true;
378383
}

0 commit comments

Comments
 (0)