include/linux/compiler-version.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
Include generated/randstruct_hash.h in linux/compiler-version.h to force
a complete rebuild if CONFIG_RANDSTRUCT is enabled and randstruct.seed
changes.
Removal or change of scripts/basic/randstruct.seed leads to a remake of
generated/randstruct_hash.h. As linux/compiler-version.h is a
hard-coded include for every kbuild induced compilation, conditionally
adding generated/randstruct_hash.h there adds it as build-dependency to
each object file.
Reported-by: Kees Cook <kees@kernel.org>
Closes: https://lore.kernel.org/linux-kbuild/202504161928.17A90D9B@keescook/
Signed-off-by: Nicolas Schier <n.schier@avm.de>
---
As I have no rust experience at all, yet: Do we have to consider
something for rust?
---
include/linux/compiler-version.h | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/include/linux/compiler-version.h b/include/linux/compiler-version.h
index 573fa85b6c0cd314dfeec66e8c77342798aa7e62..523eacf80c1a6149c513dccfd0dd9fd388e909a4 100644
--- a/include/linux/compiler-version.h
+++ b/include/linux/compiler-version.h
@@ -6,9 +6,19 @@
#define __LINUX_COMPILER_VERSION_H
/*
- * This header exists to force full rebuild when the compiler is upgraded.
+ * This header exists to force full rebuild when the compiler is upgraded or
+ * the randstruct is changed.
*
* When fixdep scans this, it will find this string "CONFIG_CC_VERSION_TEXT"
* and add dependency on include/config/CC_VERSION_TEXT, which is touched
* by Kconfig when the version string from the compiler changes.
*/
+#ifdef CONFIG_RANDSTRUCT
+/*
+ * If CONFIG_RANDSTRUCT is enabled and scripts/basic/randstruct.seed changes,
+ * randstruct_hash.h is updated. Including it here, makes it a build
+ * dependency for all build objects.
+ */
+#include <generated/randstruct_hash.h>
+#undef RANDSTRUCT_HASHED_SEED
+#endif
---
base-commit: 9c32cda43eb78f78c73aee4aa344b777714e259b
change-id: 20250429-rebuild-on-randstruct-seed-changes-6b45e327fb31
Best regards,
--
Nicolas Schier
On Tue, Apr 29, 2025 at 02:59:13PM +0200, Nicolas Schier wrote: > Include generated/randstruct_hash.h in linux/compiler-version.h to force > a complete rebuild if CONFIG_RANDSTRUCT is enabled and randstruct.seed > changes. > > Removal or change of scripts/basic/randstruct.seed leads to a remake of > generated/randstruct_hash.h. As linux/compiler-version.h is a > hard-coded include for every kbuild induced compilation, conditionally > adding generated/randstruct_hash.h there adds it as build-dependency to > each object file. This does technically work, but this feels like the wrong solution. Also, this won't work for another case where I need a similar thing: if the .scl file for the integer sanitizer changes, we need to do the same full rebuild, and that's not a C file. I think we need to explicitly inject something into fixdep... -- Kees Cook
On Tue, Apr 29, 2025 at 2:59 PM Nicolas Schier <n.schier@avm.de> wrote:
>
> As I have no rust experience at all, yet: Do we have to consider
> something for rust?
It cannot be enabled yet together with Rust, so no worries, but I need
to remember to update this patch:
https://lore.kernel.org/rust-for-linux/20241119185747.862544-1-ojeda@kernel.org/
So I will reply there with a backlink to this.
I guess since we need to rebuild even `core`, I may need to add
something like the `fixdep` workaround we have to rebuild on
`RUSTC_VERSION_TEXT` changes.
Thanks!
Cheers,
Miguel
© 2016 - 2026 Red Hat, Inc.