Linux kbuild/kconfig development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Luis Augenstein" <luis.augenstein@tngtech.com>,
	nathan@kernel.org, nsc@kernel.org
Cc: linux-kbuild@vger.kernel.org, akpm@linux-foundation.org,
	gregkh@linuxfoundation.org, kstewart@linuxfoundation.org,
	maximilian.huber@tngtech.com
Subject: Re: [PATCH v5 4/7] kbuild: record cmd-prereqs in .cmd files
Date: Tue, 17 Nov 2026 17:52:40 +0000	[thread overview]
Message-ID: <sashiko-outbox-219281@kernel.org> (raw)
In-Reply-To: <20261116175215.1337416-5-luis.augenstein@tngtech.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] kbuild: './'-prefixed deps leak into make_prereqs in
  print_make_prereqs()
- [Low] kbuild: cmd_gen_objtooldep leaks objtool into make_prereqs on
  rebuilds
--

commit 013a791546dd17e4abcec9c63932e5f18a7cbcc6
Author: Luis Augenstein <luis.augenstein@tngtech.com>

kbuild: record cmd-prereqs in .cmd files

This commit records Make prerequisites (excluding depfile dependencies) in
a new make_prereqs_<target> variable in .cmd files via cmd_and_savecmd and
fixdep.

Link: https://lore.kernel.org/r/a01233b9-23a2-4666-91ed-f1cf030dcb9f@tngtech.com

> diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
> index 8c311b997e246..7790519f92ffe 100644
> --- a/scripts/Kbuild.include
> +++ b/scripts/Kbuild.include
> @@ -181,6 +181,9 @@ endif
>  # (needed for the shell)
>  make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1)))))
>  
> +# prerequisites to record in .cmd files, excluding those covered in deps_*
> +cmd-prereqs = $(call escsq,$(filter-out $(deps_$@), $(real-prereqs)))

[Severity: Low]
Does cmd-prereqs include tools/objtool/objtool on incremental builds while
omitting it on clean builds?

In scripts/Makefile.lib, cmd_gen_objtooldep appends a standalone rule to
the .cmd file after cmd_and_fixdep or cmd_and_savecmd runs:

scripts/Makefile.lib:
cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)

On a clean build, $(dot-target).cmd does not exist yet, so $(real-prereqs)
and make_prereqs_<target> do not include $(objtool).  On an incremental
rebuild, Make includes the previous .cmd file and adds tools/objtool/objtool
to $^ and $(real-prereqs).  Because it is neither in $(deps_$@) nor in the
compiler depfile, neither cmd-prereqs nor fixdep filters it out, leaving
make_prereqs_<target> inconsistent between clean and incremental builds.

[ ... ]

> diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
> index f514ef606ec63..005c1c3df494a 100644
> --- a/scripts/basic/fixdep.c
> +++ b/scripts/basic/fixdep.c

[ ... ]

> @@ -478,23 +480,63 @@ static void print_dep_file(const char *target, const struct dep_info *info)
>  	printf("$(deps_%s):\n", target);
>  }
>  
> +/*
> + * Print make_prereqs_<target> from prereqs, excluding the deps listed
> + * in info.
> + */
> +static void print_make_prereqs(const char *target, const char *prereqs,
> +			       const struct dep_info *info)
> +{
> +	struct item *seen_prereqs_hashtab[HASHSZ] = {};
> +	const struct dep_item *dep;
> +	const char *p = prereqs;
> +
> +	for (dep = info->deps; dep; dep = dep->next)
> +		in_hashtable(dep->name, strlen(dep->name),
> +			     seen_prereqs_hashtab);
> +
> +	printf("make_prereqs_%s :=", target);
> +
> +	while (*p) {
> +		const char *start;
> +		int len;
> +
> +		while (*p == ' ' || *p == '\t')
> +			p++;
> +		if (!*p)
> +			break;
> +
> +		start = p;
> +		while (*p && *p != ' ' && *p != '\t')
> +			p++;
> +		len = p - start;
> +
> +		if (!in_hashtable(start, len, seen_prereqs_hashtab))
> +			printf(" %.*s", len, start);
> +	}

[Severity: Medium]
Do './'-prefixed header dependencies fail to match in both cmd-prereqs and
print_make_prereqs() on incremental builds?

Kbuild passes include paths beginning with './' (such as -I./include and
-include ./include/linux/kconfig.h), so the compiler depfile and
deps_<target> record paths with a leading './'.  When Make parses
'<target>: $(deps_<target>)' on an incremental build, it strips leading
'./' from target names when populating $^ and $(real-prereqs).

As a result, $(filter-out $(deps_$@), $(real-prereqs)) in cmd-prereqs and
the seen_prereqs_hashtab lookup in print_make_prereqs() compare './'-prefixed
strings against stripped tokens in prereqs.  Every './'-prefixed header in
deps_<target> (including headers removed since the previous build) then
leaks into make_prereqs_<target> on incremental rebuilds.

Stripping leading './' when normalizing deps_<target> in cmd-prereqs and
when inserting or looking up entries in print_make_prereqs() would allow
both filters to match the paths in $(real-prereqs).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116175215.1337416-1-luis.augenstein@tngtech.com?part=4

  reply	other threads:[~2026-11-17 17:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 17:51 [PATCH v5 0/7] kbuild: record cmd-prereqs in .cmd files Luis Augenstein
2026-11-16 17:51 ` [PATCH v5 1/7] scripts/make_fit: limit .cmd file parsing to the savedcmd_ line Luis Augenstein
2026-11-16 17:51 ` [PATCH v5 2/7] kbuild: refactor fixdep to collect dependencies before printing Luis Augenstein
2026-11-16 17:51 ` [PATCH v5 3/7] scripts/sbom: skip make_prereqs lines when parsing .cmd files Luis Augenstein
2026-11-16 17:51 ` [PATCH v5 4/7] kbuild: record cmd-prereqs in " Luis Augenstein
2026-11-17 17:52   ` sashiko-bot [this message]
2026-11-16 17:51 ` [PATCH v5 5/7] scripts/sbom: parse make_prereqs from " Luis Augenstein
2026-11-16 17:51 ` [PATCH v5 6/7] scripts/sbom: use make_prereqs to determine build inputs Luis Augenstein
2026-11-16 17:51 ` [PATCH v5 7/7] scripts/sbom: remove the command-specific parsers Luis Augenstein

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-219281@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kstewart@linuxfoundation.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=luis.augenstein@tngtech.com \
    --cc=maximilian.huber@tngtech.com \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=sashiko-reviews@lists.linux.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