From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796502543; b=hT65a1F91A8QtmVJGT73E9/gRvSqGWzjrAlPio0IhZ9SYa/49FZcaJYltipNhuY+Q9wa w8tBqWmrHRDQdJNl97BRxu41Vu/DeGig1D8q4cxqHvey9G76w8BvZU7vEayQsdsS6A+C6 ckOC0YdQmbS7mrOu3AzAB8mdGLp64t+Gz2FiB0ztwOjpN7+e88gQq2ChPOSJaQ4waRIyB GyXLvMmCxRDJdzNB1oJRU96/ugZu5kWmOb9Va+4LbpbM2/2y9WQ5C1t4MFC5SyU4XEPj5 SoAPlLlu5ei0bn84ai3Cckm1d2KaEiKlPyxkPgblRRduT4wD4oympT8du4Gro+PzmKQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796502543; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=RC1gcT6EhDcBoP4AW72OTk7XnMWmuW/Hc87ouPwIsWg=; b=sEASPfhLztrQBIMfp7EA2HWGR+P06BaETA8btQly7z+KJPEvzuovt4LGrYq4K7gQf9ip XONVBXQP9zNMGgriby7CEzMAol9spljkt45qYzKeVkkco8H0wJhhe38ZI++UfK1SD0luU aMbkUMwTQaNDK3byAjE0622svEkLJxOlCzTaTlF2s4Bcr407Kywj8Sx/cItzjhI0BbFob FL98OMEhAHp2CfOiks90y8ZfIzKJRXXqbi0l/hkzwBesVjy9PFkysWf3L8GMCIW5TPuyZ 2RT5/oQwStI6mpKcMwiILQu4w9UOjzvDpIVlJ6yA0VitTBpEpeWUYLhFHrP0GqK6lkg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XsxlFUwN; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8487606A31F; Sat, 5 Dec 2026 20:29:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XsxlFUwN Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59DBB1F0092B; Sat, 5 Dec 2026 20:29:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796502543; bh=RC1gcT6EhDcBoP4AW72OTk7XnMWmuW/Hc87ouPwIsWg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=XsxlFUwNmkLy5OEHO2bjQJ4NcRiqUxmdz+JvpnwuVgbtkhWUPxPYO99+19ehgvW+U suKOVX7rH9fNXF3XxGZ/wAhGH7bxccZQvGq6CsW5H0BsQ1IsnlmJfJ4a4XKn7nHIvh 4o82sqqzRlngmAxUvRl8z/OR1RpzmzlXdbQIBlujWS6dMO8LN5MiEaohiPIvhAXQ2M bc+jvs9OdGlQAr8md0je5i00LJHBGm1MS71PsDCcXKsY4XyYV0mWhbc/gJtusRGvn2 rRMbPnRnZ+Qy37F01tSL/V/HwlzzYPeF12ylHu92el0JSfsMx8o/2v3J32THslQoVX AwU8rhgrkXawg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v7 2/7] kbuild: implement and use depcheck to check dependency timestamps Reply-To: sashiko-reviews@lists.linux.dev To: =?utf-8?b?TG9yZW56byBTdG9ha2VzIChBUk0p?= , "Linus Torvalds" , "Nathan Chancellor" , "Nicolas Schier" , "Nick Desaulniers" , "Bill Wendling" , "Justin Stitt" , "Geert Uytterhoeven" , "Luis Chamberlain" , "Petr Pavlu" , "Daniel Gomez" , "Sami Tolvanen" , "Aaron Tomlin" , "Josh Poimboeuf" , "Peter Zijlstra" , "Miguel Ojeda" , "Boqun Feng" , "Gary Guo" , =?utf-8?b?QmrDtnJuIFJveSBCYXJvbg==?= , "Benno Lossin" , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , "Danilo Krummrich" , "Daniel Almeida" , "Tamir Duberstein" , "Alexandre Courbot" , =?utf-8?b?T251ciDDlnprYW4=?= , "Nicolas Schier" , "Kees Cook" Cc: linux-kbuild@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-modules@vger.kernel.org In-Reply-To: <20261204-build-speedup-v7-2-19a89034d8d1@kernel.org> References: <20261204-build-speedup-v7-0-19a89034d8d1@kernel.org> <20261204-build-speedup-v7-2-19a89034d8d1@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 20:29:01 +0000 X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [Medium] kbuild: depcheck ignores MAKEFLAGS, breaking -W/-L and writing on -n/-q - [Medium] kbuild: depcheck process() concatenates truncated .cmd files without fallback - [Medium] kbuild: depcheck shell invocation hits 128 KiB MAX_ARG_STRLEN via /bin/sh -c - [Medium] kbuild: depcheck treats truncated or unclosed deps blocks as fresh - [Low] kbuild: depcheck invocation spawns /bin/sh and runs on dep-less directories - [Low] kbuild: depcheck process() omits newline/continuation break after .cmd files -- commit d40b5bf6ef4883f8af87fca5ed44b1b1cea0e1ba Author: Lorenzo Stoakes (ARM) kbuild: implement and use depcheck to check dependency timestamps This commit adds scripts/basic/depcheck to check .cmd file dependency timestamps in C and emit a pruned .depcheck.mk fragment for scripts/Makefile.build to include in place of individual .cmd files. > diff --git a/scripts/Makefile.build b/scripts/Makefile.build > index bbe9555c47a8b..0c4ec5b71658b 100644 > --- a/scripts/Makefile.build > +++ b/scripts/Makefile.build > @@ -613,7 +613,24 @@ $(obj)/: $(if $(KBUILD_BUILTIN), $(targets-for-built= in)) \ > =20 > existing-targets :=3D $(wildcard $(sort $(targets))) > =20 > --include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) > +cmd-files :=3D $(wildcard $(foreach f,$(existing-targets),$(dir $(f)).$(= notdir $(f)).cmd)) > + > +# depcheck checks timestamps first and outputs only saved command lines = of > +# up-to-date targets, falling back to .cmd files if it fails. A directory > +# whose targets all lie elsewhere may not exist in the output tree. > +depcheck :=3D $(wildcard $(objtree)/scripts/basic/depcheck) > + > +# A single target such as foo.s may depend on a header depcheck cannot s= ee > +# being remade, so leave single-target builds to make. > +ifeq ($(MAKECMDGOALS),) [Severity: Medium] Should this also check MAKEFLAGS before invoking depcheck? GNU Make propagates flags such as -W (--what-if) and -L (--check-symlink-times) via MAKEFLAGS while MAKECMDGOALS stays empty in recursive Makefile.build runs. Because lookup_dep() only inspects on-disk mtimes via stat(), depcheck treats objects depending on a -W header as fresh and strips their dependency rules, so make silently skips rebuilding or reporting them. In addition, make still evaluates $(shell ...) under -n (--dry-run) and -q (--question), so depcheck runs mkstemp() and rename() to create or overwrite $(obj)/.depcheck.mk in every visited directory (or prints perror() errors on read-only build trees). > +ifneq ($(and $(depcheck),$(cmd-files),$(wildcard $(obj))),) > +ifeq ($(shell $(depcheck) $(obj)/.depcheck.mk $(cmd-files) && echo ok),o= k) [Severity: Medium] Can this $(shell ...) invocation hit the 128 KiB MAX_ARG_STRLEN limit? The && operator forces GNU Make to run /bin/sh -c with all $(cmd-files) packed into a single argv[2] string, which execve() caps at 128 KiB on 4 KiB-page Linux hosts. In Documentation/devicetree/bindings/, targets includes over 10,400 .example.dts and .example.dtb files whose .cmd paths expand to roughly 800 KiB, causing execve() to fail with E2BIG on incremental dt_binding_check runs and fall back to make. Having depcheck print ok itself allows dropping && echo ok so make can exec depcheck directly, and passing the list via stdin or $(file >...) would also avoid total argument limits. > +cmd-files :=3D $(obj)/.depcheck.mk > +endif > +endif > +endif [Severity: Low] Does this spawn /bin/sh and run depcheck even on directories that have no dependency lists to prune? Because && echo ok prevents make's direct execvp() fast path, every visited directory pays an extra /bin/sh fork and exec. Also, rules using if_changed such as built-in.a and modules.order always populate cmd-files with one-line .cmd files that contain no deps_ block, so pure parent and empty-config directories still fork depcheck, create a temp file, copy the lines verbatim, and rename it to .depcheck.mk. Printing ok from depcheck and filtering out known if_changed-only .cmd files before invoking it would avoid that overhead. > diff --git a/scripts/basic/depcheck.c b/scripts/basic/depcheck.c > new file mode 100644 > index 0000000000000..339c058ba1602 > --- /dev/null > +++ b/scripts/basic/depcheck.c [ ... ] > +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; > + } > + > + /* The list was cut off by the end of the file. */ > + return false; > +} [ ... ] > +static bool find_deps(const char *buf, size_t len, size_t *deps_off, > + const char **list) > +{ > + const char *pos =3D buf, *end =3D buf + len; > + struct line line; > + > + while (next_line(&pos, end, &line)) { > + if (!line_starts_with(&line, DEPS_PREFIX)) > + continue; > + > + *deps_off =3D line.text - buf; > + *list =3D line_is_continued(&line) ? pos : NULL; > + return true; > + } > + > + return false; > +} [ ... ] > +static bool target_is_fresh(const char *cmd_path, const char *buf, size_= t len, > + size_t *deps_off) > +{ > + char target[PATH_MAX]; > + struct stat st; > + const char *list; > + > + if (!target_of(cmd_path, target, sizeof(target)) || stat(target, &st)) > + return false; > + if (!find_deps(buf, len, deps_off, &list)) > + return false; > + if (!list) > + return true; > + > + return deps_are_fresh(list, buf + len, &st.st_mtim); > +} [ ... ] > +static size_t deps_block_end(const char *buf, size_t len, size_t deps_of= f) > +{ > + const char *pos =3D buf + deps_off, *end =3D buf + len; > + struct line line; > + > + while (next_line(&pos, end, &line)) { > + if (line_starts_with(&line, DEPS_RULE_PREFIX) && > + line_ends_with(&line, RULE_SUFFIX)) > + return pos - buf; > + } > + > + return len; > +} [Severity: Medium] Can truncated or unclosed deps_ blocks be misclassified as fresh here? If a build is killed after creating the target while cmd_and_fixdep is still writing $(dot-target).cmd, the .cmd file can be cut off mid-write: - A deps_ header truncated before its trailing " \" causes find_deps() to set *list to NULL and target_is_fresh() to return true immediately. - A dependency line truncated before its trailing " \" returns true at !line_is_continued(&line) in deps_are_fresh(), bypassing the end-of-file fallback. - A file truncated after the blank line without its closing $(deps_...): rule causes deps_block_end() to return len, so write_without_deps() silently discards everything from deps_off to the end of the file. In all three cases, depcheck strips the broken block and hides errors that make would otherwise catch. Requiring a continued deps_ header, continued dependency lines, and a matching closing $(deps_...): line in target_is_fresh() would avoid this. > + > +/* The target is fresh: pass on everything but the dependency block. */ > +static void write_without_deps(FILE *out, const char *buf, size_t len, > + size_t deps_off) > +{ > + const size_t tail_off =3D deps_block_end(buf, len, deps_off); > + > + fwrite(buf, 1, deps_off, out); > + fputc('\n', out); > + fwrite(buf + tail_off, 1, len - tail_off, out); > +} [Severity: Low] Does concatenating .cmd files into .depcheck.mk need a newline or line continuation break between entries? write_without_deps() copies the tail after $(deps_...): verbatim, and process() writes non-fresh .cmd files verbatim without ensuring a trailing newline. If a truncated .cmd file lacks a final newline or ends with a backslash continuation, the next file's savedcmd_ line is appended directly onto it rather than starting a new assignment, which cannot happen when make includes each .cmd file separately. > + > +/* > + * Generate a fragment for make from one .cmd file - without the depende= ncy > + * block if the target is fresh, otherwise all of it. Returns false if t= he file > + * cannot be read. > + */ > +static bool process(FILE *out, const char *cmd_path) > +{ > + size_t len, deps_off; > + char *buf; > + > + buf =3D read_file(cmd_path, &len); > + if (!buf) { > + perror(cmd_path); > + return false; > + } > + > + if (target_is_fresh(cmd_path, buf, len, &deps_off)) > + write_without_deps(out, buf, len, deps_off); > + else > + fwrite(buf, 1, len, out); > + > + free(buf); > + return true; > +} [Severity: Medium] Should process() return false when a .cmd file is truncated instead of writing it into .depcheck.mk? When deps_are_fresh() detects a dependency list cut off by end of file, it returns false and target_is_fresh() propagates that to process(), which then writes the truncated buffer verbatim and returns true. Because fixdep ends every dependency entry with a backslash continuation, a truncated .cmd file swallows the next target's savedcmd_ line into deps_ or causes a make parse error for the directory. This can happen during a parallel build with CONFIG_HEADERS_INSTALL=3Dy, where scripts_unifdef rewrites scripts/.unifdef.cmd via shell redirection in cmd_and_fixdep concurrently with depcheck reading it. Returning false from process() on truncated input would let kbuild fall back to the original .cmd files as intended. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-build-spee= dup-v7-0-19a89034d8d1@kernel.org?part=3D2