Linux M68K Architecture development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>,
	"Linus Torvalds" <torvalds@linux-foundation.org>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nicolas Schier" <nsc@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	"Bill Wendling" <morbo@google.com>,
	"Justin Stitt" <justinstitt@google.com>,
	"Geert Uytterhoeven" <geert@linux-m68k.org>,
	"Luis Chamberlain" <mcgrof@kernel.org>,
	"Petr Pavlu" <petr.pavlu@suse.com>,
	"Daniel Gomez" <da.gomez@kernel.org>,
	"Sami Tolvanen" <samitolvanen@google.com>,
	"Aaron Tomlin" <atomlin@atomlin.com>,
	"Josh Poimboeuf" <jpoimboe@kernel.org>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	"Nicolas Schier" <n.schier@fritz.com>,
	"Kees Cook" <kees@kernel.org>
Cc: linux-kbuild@vger.kernel.org, linux-m68k@lists.linux-m68k.org,
	linux-modules@vger.kernel.org
Subject: Re: [PATCH v6 2/7] kbuild: implement and use depcheck to check dependency timestamps
Date: Wed, 25 Nov 2026 12:21:34 +0000	[thread overview]
Message-ID: <sashiko-outbox-233360@kernel.org> (raw)
In-Reply-To: <20261124-build-speedup-v6-2-141a4f861c67@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] kbuild: missing ./ prefix normalization in target_of() and
  is_target()
- [Low] kbuild: silent read error in process() and EOF bug in
  deps_are_fresh()
--

commit 14f510d57242e0f215e4f785b8ee900180510d65
Author: Lorenzo Stoakes (ARM) <ljs@kernel.org>

kbuild: implement and use depcheck to check dependency timestamps

This commit adds the scripts/basic/depcheck host tool to check dependency
timestamps from .cmd files in C and emit a condensed .depcheck.mk fragment
for up-to-date targets.

> diff --git a/scripts/basic/depcheck.c b/scripts/basic/depcheck.c
> new file mode 100644
> index 0000000000000..454a38fb05779
> --- /dev/null
> +++ b/scripts/basic/depcheck.c
> @@ -0,0 +1,492 @@

[ ... ]

> +static void add_target(const char *path)
> +{
> +	struct target *target = xmalloc(sizeof(*target) + strlen(path) + 1);
> +
> +	strcpy(target->path, path);
> +	hash_add(target_table, &target->hnode, hash_str(path));
> +}
> +
> +static bool is_target(const char *path)
> +{
> +	const unsigned int key = hash_str(path);
> +	struct target *target;
> +
> +	hash_for_each_possible(target_table, target, hnode, key) {
> +		if (!strcmp(target->path, path))
> +			return true;
> +	}
> +
> +	return false;
> +}

[ ... ]

> +/* Is the path contained in line older than the target? */
> +static bool dep_is_fresh(struct line line, const struct timespec *target)
> +{
> +	char path[PATH_MAX];
> +	const struct dep *dep;
> +	bool optional;
> +
> +	line_strip_continuation(&line);
> +	line_trim(&line);
> +	if (!line.len)
> +		return false;
> +
> +	optional = line_unwrap_wildcard(&line);
> +	if (!line.len || !unescape_path(&line, path, sizeof(path)))
> +		return false;
> +
> +	/* A target can get 'remade' so its timestamp is meaningless. */
> +	if (is_target(path))
> +		return false;

[Severity: Medium]
Can is_target() miss matching a dependency against target_table when one
of the paths has a leading "./" prefix and the other does not?

When $(obj) is ".", scripts/Makefile.build does not prefix $(targets) with
"./", but $(dir $(f)) in cmd-files expands to "./", so target_of() inserts
"./<name>" into target_table while the compiler and fixdep record "<name>"
in deps_<target>.  Conversely, when $(obj) is a subdirectory, target_of()
stores "<subdir>/<name>", whereas rules passing -I$(objtree)/$(obj) (with
objtree := .) cause the compiler to emit "./<subdir>/<name>" into the .cmd
file.

In both cases strcmp() in is_target() returns false.  If a generated
header in the same directory already exists on disk from a previous build
and its own prerequisites change, depcheck stats the stale file before
make remakes it, treats the dependent object as fresh, and strips its
dependency block from .depcheck.mk, so make misses rebuilding the object.
Stripping leading "./" prefixes before hashing and comparing paths in
add_target() and is_target() would avoid the mismatch.

> +
> +	dep = lookup_dep(path);
> +	if (!dep->exists)
> +		return optional;
> +
> +	return !newer(&dep->mtime, target);
> +}
> +
> +/*
> + * Parse a dependency list which consists of one file per line and determine if
> + * all dependencies are 'fresh', i.e. older than the target.
> + */
> +static bool deps_are_fresh(const char *pos, const char *end,
> +			   const struct timespec *target)
> +{
> +	struct line line;
> +
> +	while (next_line(&pos, end, &line)) {
> +		if (line_is_blank(&line))
> +			return true;
> +		if (!dep_is_fresh(line, target))
> +			return false;
> +		if (!line_is_continued(&line))
> +			return true;
> +	}
> +
> +	return true;
> +}

[ ... ]

> +static char *read_file(const char *path, size_t *len)
> +{
> +	FILE *file = fopen(path, "r");
> +	struct stat st;
> +	char *buf;
> +	size_t nr_read = 0;
> +
> +	if (!file)
> +		return NULL;
> +	if (fstat(fileno(file), &st)) {
> +		fclose(file);
> +		return NULL;
> +	}
> +
> +	buf = xmalloc(st.st_size + 1);
> +	while (nr_read < (size_t)st.st_size) {
> +		const size_t chunk = fread(buf + nr_read, 1, st.st_size - nr_read, file);
> +
> +		if (!chunk)
> +			break;
> +		nr_read += chunk;
> +	}
> +	fclose(file);
> +
> +	buf[nr_read] = '\0';
> +	*len = nr_read;
> +	return buf;
> +}

[ ... ]

> +static void process(FILE *out, const char *cmd_path)
> +{
> +	size_t len, deps_off;
> +	char *buf;
> +
> +	buf = read_file(cmd_path, &len);
> +	if (!buf)
> +		return;

[Severity: Low]
If reading a .cmd file fails or hits an I/O error, does process() silently
omit that target from .depcheck.mk instead of failing depcheck so
Makefile.build falls back to including $(cmd-files)?  read_file() also
does not check ferror(file) when fread() stops early, and if a .cmd file
is truncated right after a line continuation (" \"), deps_are_fresh() hits
EOF in next_line() and returns true, stripping the incomplete dependency
list.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-build-speedup-v6-0-141a4f861c67@kernel.org?part=2

  reply	other threads:[~2026-11-25 12:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 12:20 [PATCH v6 0/7] kbuild: significantly speed up kernel builds Lorenzo Stoakes (ARM)
2026-11-24 12:20 ` [PATCH v6 1/7] kbuild: calculate list, composite object state per object Lorenzo Stoakes (ARM)
2026-11-24 12:20 ` [PATCH v6 2/7] kbuild: implement and use depcheck to check dependency timestamps Lorenzo Stoakes (ARM)
2026-11-25 12:21   ` sashiko-bot [this message]
2026-11-24 12:20 ` [PATCH v6 3/7] modpost: cache section relocation mismatch state Lorenzo Stoakes (ARM)
2026-11-25 12:21   ` sashiko-bot
2026-11-24 12:20 ` [PATCH v6 4/7] modpost: emit module descriptors as assembly Lorenzo Stoakes (ARM)
2026-11-24 12:20 ` [PATCH v6 5/7] kbuild: batch module finalisation Lorenzo Stoakes (ARM)
2026-11-25  9:56   ` Nicolas Schier
2026-11-25 12:28     ` Lorenzo Stoakes (ARM)
2026-11-24 12:20 ` [PATCH v6 6/7] rust: make exports.o depend on the headers generated for it Lorenzo Stoakes (ARM)
2026-11-24 12:20 ` [PATCH v6 7/7] kbuild: build rust crates in parallel with the rest of the build Lorenzo Stoakes (ARM)
2026-11-25 10:02 ` [PATCH v6 0/7] kbuild: significantly speed up kernel builds Nicolas Schier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-233360@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=atomlin@atomlin.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=da.gomez@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=gary@garyguo.net \
    --cc=geert@linux-m68k.org \
    --cc=jpoimboe@kernel.org \
    --cc=justinstitt@google.com \
    --cc=kees@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-m68k@lists.linux-m68k.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=ljs@kernel.org \
    --cc=lossin@kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=morbo@google.com \
    --cc=n.schier@fritz.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=nsc@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=petr.pavlu@suse.com \
    --cc=samitolvanen@google.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=torvalds@linux-foundation.org \
    --cc=work@onurozkan.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox