From: <daniel.turull@ericsson.com>
To: <openembedded-core@lists.openembedded.org>
Cc: Daniel Turull <daniel.turull@ericsson.com>,
Marta Rybczynska <rybczynska@gmail.com>,
Bruce Ashfield <bruce.ashfield@gmail.com>,
"Peter Marko" <peter.marko@siemens.com>
Subject: [PATCH v4 2/3] kernel: add support to extract compiled files
Date: Wed, 14 May 2025 14:57:05 +0200 [thread overview]
Message-ID: <20250514125706.495571-3-daniel.turull@ericsson.com> (raw)
In-Reply-To: <20250514125706.495571-1-daniel.turull@ericsson.com>
From: Daniel Turull <daniel.turull@ericsson.com>
Use gen_compile_commands.py to extract files used during compilation
for the used kernel configuration.
To enable set SPDX_INCLUDED_COMPILED_SOURCES="1"
The location can be controlled with KERNEL_FILES_DIR
CC: Marta Rybczynska <rybczynska@gmail.com>
CC: Bruce Ashfield <bruce.ashfield@gmail.com>
CC: Peter Marko <peter.marko@siemens.com>
Signed-off-by: Daniel Turull <daniel.turull@ericsson.com>
---
meta/classes-recipe/kernel.bbclass | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/meta/classes-recipe/kernel.bbclass b/meta/classes-recipe/kernel.bbclass
index 36ce659762..acef8b86ce 100644
--- a/meta/classes-recipe/kernel.bbclass
+++ b/meta/classes-recipe/kernel.bbclass
@@ -159,6 +159,9 @@ set -e
image_task = d.getVar('INITRAMFS_TASK')
if image_task:
d.appendVarFlag('do_configure', 'depends', ' ${INITRAMFS_TASK}')
+ if d.getVar("SPDX_INCLUDE_COMPILED_SOURCES") == "1":
+ bb.build.addtask('do_save_compiled_files', 'do_build', 'do_compile do_compile_kernelmodules', d)
+ d.appendVarFlag('do_create_spdx', 'depends', f'{pn}:do_save_compiled_files')
}
# Here we pull in all various kernel image types which we support.
@@ -867,3 +870,19 @@ EXPORT_FUNCTIONS do_deploy
# Add using Device Tree support
inherit kernel-devicetree
+
+# in case we don't use spdx bbclass
+SPDX_COMPILED_SOURCES_DIR ?= "${LOG_DIR}/spdx-compiled/${PN}"
+SPDX_COMPILED_SOURCES ?= "${SPDX_COMPILED_SOURCES_DIR}/compiled_src-${MACHINE}-${BP}.txt"
+
+KERNEL_COMPILED_FILES ?= "${SPDX_COMPILED_SOURCES_DIR}/compiled_commands-${MACHINE}-${BP}.json"
+
+do_save_compiled_files() {
+ bbdebug 1 "Saving compiled files in ${SPDX_COMPILED_SOURCES}"
+ mkdir -p ${SPDX_COMPILED_SOURCES_DIR}
+ ${S}/scripts/clang-tools/gen_compile_commands.py -o ${KERNEL_COMPILED_FILES} -d ${B}
+ # Make paths releative to the kernel source
+ sed -i 's|${B}/||g' ${KERNEL_COMPILED_FILES}
+ sed -i 's|${S}/||g' ${KERNEL_COMPILED_FILES}
+ grep '"file": ' ${KERNEL_COMPILED_FILES} | awk '{print $2}' | tr -d '"' > ${SPDX_COMPILED_SOURCES}
+}
next prev parent reply other threads:[~2025-05-15 1:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-14 12:57 [PATCH v4 0/3] Check compiled files to filter kernel CVEs daniel.turull
2025-05-14 12:57 ` [PATCH v4 1/3] spdx: add option to include only compiled sources daniel.turull
2025-05-15 12:10 ` [OE-core] " Quentin Schulz
2025-05-15 13:12 ` Daniel Turull
2025-05-15 13:32 ` Quentin Schulz
2025-05-15 13:44 ` Daniel Turull
2025-05-15 13:58 ` Quentin Schulz
2025-05-15 14:04 ` Daniel Turull
2025-05-15 14:03 ` Richard Purdie
2025-05-15 14:09 ` Daniel Turull
2025-05-15 14:21 ` Richard Purdie
2025-05-15 14:24 ` Daniel Turull
2025-05-14 12:57 ` daniel.turull [this message]
2025-05-14 12:57 ` [PATCH v4 3/3] improve_kernel_cve_report: add script for postprocesing of kernel CVE data daniel.turull
-- strict thread matches above, loose matches on Subject: below --
2025-05-14 13:11 [PATCH v4 0/3] Check compiled files to filter kernel CVEs daniel.turull
2025-05-14 13:11 ` [PATCH v4 2/3] kernel: add support to extract compiled files daniel.turull
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=20250514125706.495571-3-daniel.turull@ericsson.com \
--to=daniel.turull@ericsson.com \
--cc=bruce.ashfield@gmail.com \
--cc=openembedded-core@lists.openembedded.org \
--cc=peter.marko@siemens.com \
--cc=rybczynska@gmail.com \
/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