[PATCH v3] scripts/gcc-plugins: suppress recorded GCC switches for extmod builds

Jaihind Yadav <[email protected]>
Newsgroups org.kernel.vger.linux-kbuild,org.kernel.vger.linux-hardening,org.kernel.vger.linux-kernel,org.kernel.vger.linux-modules
Message-ID <[email protected]>
With GCC plugins enabled, external module builds can record
-fplugin=... paths in DWARF producer metadata via
-grecord-gcc-switches, leaking host/build specific paths and
triggering QA checks.

Handle this in scripts/Makefile.gcc-plugins for KBUILD_EXTMOD
builds by adding -gno-record-gcc-switches to plugin cflags.

This keeps plugin behavior unchanged while avoiding absolute
plugin path leakage in external module debug metadata.

Suggested-by: Nathan Chancellor <[email protected]>
Link: https://lore.kernel.org/all/20260817185146.GC1249844@ax162/
Signed-off-by: Jaihind Yadav <[email protected]>
---
 scripts/Makefile.gcc-plugins | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins
index b0e1423b09c2..9b9899580571 100644
--- a/scripts/Makefile.gcc-plugins
+++ b/scripts/Makefile.gcc-plugins
@@ -8,6 +8,10 @@ ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY
 endif
 export DISABLE_LATENT_ENTROPY_PLUGIN
 
+# Disable recording GCC options in debug info when building external modules to
+# avoid leaking absolute host build paths
+gcc-plugin-cflags-$(if $(KBUILD_EXTMOD),y) += -gno-record-gcc-switches
+
 # All the plugin CFLAGS are collected here in case a build target needs to
 # filter them out of the KBUILD_CFLAGS.
 GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y)) -DGCC_PLUGINS
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.