Skip to contentSkip to conversation

how to create early build deps?

DISCUSSION Kees Cook 3 participants 3 messages Apr 17, 2025 – Apr 29, 2025 Kbuild

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

Hi!

I am stumped...

I swear there was a time when changing the gcc-plugins would trigger a full rebuild of all kernel sources. I tried to bisect where that stopped happening, but it went back far enough that things stopped building with my compiler at all. ;)

Anyway, I need this also for the Clang randstruct seed file -- if it changes, we need to rebuild everything. I thought this worked back in v5.19 when I moved the randstruct seed generation into scripts/basic[1], but regenerating it doesn't trigger a rebuild (with v5.19 nor current Linus nor linux-next):

$ make O=clang-all LLVM=1 allmodconfig kernel/seccomp.o
make[1]: Entering directory '/srv/code/clang-all'
...
  GENSEED scripts/basic/randstruct.seed
...
  CC      kernel/seccomp.o
make[1]: Leaving directory '/srv/code/clang-all'
$ rm clang-all/scripts/basic/randstruct.seed
$ make O=clang-all LLVM=1 kernel/seccomp.o
make[1]: Entering directory '/srv/code/clang-all'
  GEN     Makefile
  GENSEED scripts/basic/randstruct.seed
  DESCEND objtool
  CALL    ../scripts/checksyscalls.sh
  INSTALL libsubcmd_headers
make[1]: Leaving directory '/srv/code/clang-all'

kernel/seccomp.o doesn't get rebuilt :(

By what mechanism can I convince kbuild to rebuild everything if randstruct.seed (or the gcc-plugins) are changed?

Thanks!

-Kees

[1] be2b34fa9be3 ("randstruct: Move seed generation into scripts/basic/")

Signature · 1 line
Kees Cook
#1 lore raw

Hi Kees,

Quoted 34 lines · Kees Cook

Hi!

I am stumped...

I swear there was a time when changing the gcc-plugins would trigger a full rebuild of all kernel sources. I tried to bisect where that stopped happening, but it went back far enough that things stopped building with my compiler at all. ;)

Anyway, I need this also for the Clang randstruct seed file -- if it changes, we need to rebuild everything. I thought this worked back in v5.19 when I moved the randstruct seed generation into scripts/basic[1], but regenerating it doesn't trigger a rebuild (with v5.19 nor current Linus nor linux-next):

$ make O=clang-all LLVM=1 allmodconfig kernel/seccomp.o
make[1]: Entering directory '/srv/code/clang-all'
...
  GENSEED scripts/basic/randstruct.seed
...
  CC      kernel/seccomp.o
make[1]: Leaving directory '/srv/code/clang-all'
$ rm clang-all/scripts/basic/randstruct.seed
$ make O=clang-all LLVM=1 kernel/seccomp.o
make[1]: Entering directory '/srv/code/clang-all'
  GEN     Makefile
  GENSEED scripts/basic/randstruct.seed
  DESCEND objtool
  CALL    ../scripts/checksyscalls.sh
  INSTALL libsubcmd_headers
make[1]: Leaving directory '/srv/code/clang-all'
Quoted 4 lines

kernel/seccomp.o doesn't get rebuilt :(

By what mechanism can I convince kbuild to rebuild everything if randstruct.seed (or the gcc-plugins) are changed?

I think the easiest way to achieve a full rebuild due to changes in scripts/basic/randstruct.seed would be to let it show up in .$(target).cmd. Limited testing with a very hacky thing like

scripts/Kbuild.include +1 -0
index 8c311b997e24..1aceedfe0791 100644
@@ -206,4 +206,5 @@ if_changed_dep = $(if $(if-changed-cond),$(cmd_and_fixdep),@:)
 cmd_and_fixdep =                                                             \
        $(cmd);                                                              \
        $(objtree)/scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\
+       sed -i -re 's,../include/linux/compiler.h,& $(objtree)/scripts/basic/randstruct.seed,' $(dot-target).cmd ;\
        rm -f $(depfile)

looks promising to me. But as far as I can see, fixdep does not have similar hard-coded dependencies included, yet. Thus I am unsure if fixdep is really the this we want to touch for randstruct.seed.

Kind regards,
Nicolas

#2 lore raw

On Fri, 25 Apr 2025, Nicolas Schier wrote:
[...]

Quoted 18 lines
Quoted 2 lines

By what mechanism can I convince kbuild to rebuild everything if randstruct.seed (or the gcc-plugins) are changed?

I think the easiest way to achieve a full rebuild due to changes in scripts/basic/randstruct.seed would be to let it show up in .$(target).cmd. Limited testing with a very hacky thing like

scripts/Kbuild.include +1 -0
index 8c311b997e24..1aceedfe0791 100644
@@ -206,4 +206,5 @@ if_changed_dep = $(if $(if-changed-cond),$(cmd_and_fixdep),@:)
 cmd_and_fixdep =                                                             \
        $(cmd);                                                              \
        $(objtree)/scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\
+       sed -i -re 's,../include/linux/compiler.h,& $(objtree)/scripts/basic/randstruct.seed,' $(dot-target).cmd ;\
        rm -f $(depfile)
Quoted 3 lines

looks promising to me. But as far as I can see, fixdep does not have similar hard-coded dependencies included, yet. Thus I am unsure if fixdep is really the this we want to touch for randstruct.seed.

well, touching fixdep would really not be a nice option. I'll send a patch that forces the rebuild by adding include/generated/randstruct_hash.h to include/linux/compiler-version.h.

Thanks for the report!

Kind regards,
Nicolas