From 12db6bb497226c7de224a55ec91f863f2a444439 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 13 Nov 2024 11:26:34 +0100 Subject: tools/syz-declextract: refine kernel file check Some kernel build systems build some additional host files that are not part of the kernel. Also check for -DKBUILD_BASENAME define to filter them out. --- tools/syz-declextract/run.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/syz-declextract/run.go b/tools/syz-declextract/run.go index 2feddfec8..e185d65fb 100644 --- a/tools/syz-declextract/run.go +++ b/tools/syz-declextract/run.go @@ -75,10 +75,7 @@ func main() { } for _, cmd := range cmds { - // Files compiled with gcc are not a part of the kernel - // (assuming compile commands were generated with make CC=clang). - // They are probably a part of some host tool. - if !strings.HasSuffix(cmd.File, ".c") || strings.HasPrefix(cmd.Command, "gcc") { + if !cmd.isKernel() { outputs <- nil continue } @@ -134,6 +131,18 @@ type compileCommand struct { File string } +// isKernel says if the command refers to a kernel object file +// rather than some host tools, etc. +func (cmd *compileCommand) isKernel() bool { + return strings.HasSuffix(cmd.File, ".c") && + // Files compiled with gcc are not a part of the kernel + // (assuming compile commands were generated with make CC=clang). + // They are probably a part of some host tool. + !strings.HasPrefix(cmd.Command, "gcc") && + // KBUILD should add this define all kernel files. + strings.Contains(cmd.Command, "-DKBUILD_BASENAME") +} + type output struct { file string output []byte -- cgit mrf-deployment