[PATCH 0/1] kbuild: record real-prereqs in .cmd files
Luis Augenstein <[email protected]>
| Newsgroups | org.kernel.vger.linux-kbuild,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
KernelSbom (scripts/sbom/sbom.py) reconstructs the kernel build graph
from the .cmd files written by Kbuild. For most build outputs,
KernelSbom must infer the build inputs from the shell command stored in
savedcmd_*. This requires command-specific parsers, which add
unnecessary complexity and are difficult to maintain.
Kbuild already knows these inputs as $(real-prereqs), the non-phony
prerequisites of the Make rule. This patch records them in .cmd files
using a new metadata field:
make_prereqs_<target> := <prerequisites>
KernelSbom will be able to read the new field instead of parsing the
shell command. This submission only records the field, support for using
it in KernelSbom will follow separately.
The issue of manually parsing shell commands was originally mentioned in
https://lore.kernel.org/r/[email protected].
This patch is a proposal to address that.
Cmd writers and consumers
=========================
The new field should not affect existing behavior.
Below is a summary of what I checked.
.cmd files are primarily written by cmd_and_savecmd and cmd_and_fixdep.
This patch extends both writers to add make_prereqs_*.
The following rules append information to existing .cmd files.
None of these is affected by the new field:
- scripts/Makefile.lib: cmd_gen_objtooldep only appends new rule
target: $(wildcard ./tools/objtool/objtool)
- scripts/Makefile.build: gen_symversions only appends comments
#SYMVER <name> <crc>
- scripts/Makefile.lib: cmd_save_c_flags only appends a variable
saved_c_flags_<target> := <flags>
- rust/Makefile: cmd_gendwarfksyms only appends comments
#SYMVER <name> <crc>
- kernel/Makefile: kheaders_data_dep appends a deps_* block
deps_<target> := <headers>.
This patch updates the following .cmd file consumers to account for the
new field:
- scripts/sbom/sbom/cmd_graph/cmd_file.py: CmdFile.create() parses
savedcmd_<target>, source_<target>, and deps_<target>. It is updated
to ignore make_prereqs_<target> for now. Parsing the new field will
follow in a separate patch.
- scripts/make_fit.py: process_dtb() previously read and split the
complete .cmd file to find the fdtoverlay command. It is changed to
read only savedcmd_<target>.
The remaining consumers are not affected:
- Kbuild Makefiles: -include reads .cmd files as Makefile fragments. The
new field is an ordinary variable assignment not used in any dependency
rule.
- scripts/Makefile.thinlto: the saved_c_flags_* lookup only reads
saved_c_flags_<target> := <flags>.
- scripts/mod/modpost.c: extract_crcs_for_object() only reads comments
#SYMVER <name> <crc>.
- scripts/mod/sumversion.c: parse_source_files() only reads
source_<target> := <source> and deps_<target> := <dependencies>.
- scripts/clang-tools/gen_compile_commands.py: main() only reads the
first line containing savedcmd_<target> := <command>.
- scripts/generate_builtin_ranges.awk and
scripts/verify_builtin_ranges.awk: get_module_info() only reads the
first line and searches the saved command for DKBUILD_MODFILE or
RUST_MODFILE.
Alternative: extending the deps_* field
=======================================
An alternative to the new make_prereqs_* field is to merge $(real-prereqs)
into the existing deps_* field for both cmd_and_savecmd and cmd_and_fixdep.
This would avoid a new field and provide one dependency list. However, it
would broaden the meaning of deps_* from dependencies discovered through
generated .d files to include prerequisites already declared to Make.
This increases the risk of undesired side effects.
The writers listed above would need to ensure that each .cmd file
contains only one deps_* block. In particular, kheaders_data_dep would
need to merge its header dependencies into the block written by
cmd_and_savecmd instead of appending a second deps_* block.
cmd_and_fixdep, or fixdep.c depending on the implementation, would
likewise need to merge $(real-prereqs) with the generated dependencies.
Apart from KernelSbom, scripts/mod/sumversion.c is the only consumer
that explicitly reads deps_*. It uses selected dependency files to
calculate a module's srcversion. Extending deps_* could change this
module metadata. Such an unrelated change should probably be avoided.
Kbuild Makefiles also consume deps_* by including .cmd files. This
should not be an issue though, because $(real-prereqs) are already
present on the original target rule, so repeating them through deps_*
should not change rebuild behavior.
Luis Augenstein (1):
kbuild: record real-prereqs in .cmd files
scripts/Kbuild.include | 9 +++++++--
scripts/basic/fixdep.c | 16 ++++++++++------
scripts/make_fit.py | 2 +-
scripts/sbom/sbom/cmd_graph/cmd_file.py | 4 ++++
4 files changed, 22 insertions(+), 9 deletions(-)
--
2.43.0