Compile-time stack validation
Josh,
I've applied and tried to build your patchset against the latest mainline kernel with the following config:
http://paste.ubuntu.com/12058017/
I can build if I disable CONFIG_STACK_VALIDATION, then re-enable it after all objects are already built, so this seems like it should be resolvable in Makefiles. Any suggestions for debugging this?
Building from clean I get the following:
~/linux$ make
HOSTCC scripts/basic/fixdep HOSTCC scripts/basic/bin2c GEN arch/x86/lib/inat-tables.c HOSTCC arch/x86/tools/relocs_32.o HOSTCC arch/x86/tools/relocs_64.o HOSTCC arch/x86/tools/relocs_common.o HOSTLD arch/x86/tools/relocs CHK include/config/kernel.release CHK include/generated/uapi/linux/version.h CHK include/generated/utsrelease.h CC arch/x86/purgatory/purgatory.o AS arch/x86/purgatory/stack.o AS arch/x86/purgatory/setup-x86_64.o CC arch/x86/purgatory/sha256.o AS arch/x86/purgatory/entry64.o CC arch/x86/purgatory/string.o LD arch/x86/purgatory/purgatory.ro BIN2C arch/x86/purgatory/kexec-purgatory.c CC kernel/bounds.s CHK include/generated/bounds.h CHK include/generated/timeconst.h CC arch/x86/kernel/asm-offsets.s CHK include/generated/asm-offsets.h CALL scripts/checksyscalls.sh HOSTCC scripts/genksyms/genksyms.o HOSTCC scripts/genksyms/parse.tab.o HOSTCC scripts/genksyms/lex.lex.o HOSTLD scripts/genksyms/genksyms CC scripts/mod/empty.o
scripts/mod/empty.o
open: No such file or directory
error reading elf file scripts/mod/empty.o scripts/Makefile.build:284: recipe for target 'scripts/mod/empty.o' failed make[2]: *** [scripts/mod/empty.o] Error 1 scripts/Makefile.build:429: recipe for target 'scripts/mod' failed make[1]: *** [scripts/mod] Error 2
Makefile:545: recipe for target 'scripts' failed
make: *** [scripts] Error 2
Quoted 41 lines · Chris J Arges
Josh,
I've applied and tried to build your patchset against the latest mainline kernel with the following config:
http://paste.ubuntu.com/12058017/I can build if I disable
CONFIG_STACK_VALIDATION, then re-enable it after all objects are already built, so this seems like it should be resolvable in Makefiles. Any suggestions for debugging this?Building from clean I get the following:
~/linux$ makeHOSTCC scripts/basic/fixdep HOSTCC scripts/basic/bin2c GEN arch/x86/lib/inat-tables.c HOSTCC arch/x86/tools/relocs_32.o HOSTCC arch/x86/tools/relocs_64.o HOSTCC arch/x86/tools/relocs_common.o HOSTLD arch/x86/tools/relocs CHK include/config/kernel.release CHK include/generated/uapi/linux/version.h CHK include/generated/utsrelease.h CC arch/x86/purgatory/purgatory.o AS arch/x86/purgatory/stack.o AS arch/x86/purgatory/setup-x86_64.o CC arch/x86/purgatory/sha256.o AS arch/x86/purgatory/entry64.o CC arch/x86/purgatory/string.o LD arch/x86/purgatory/purgatory.ro BIN2C arch/x86/purgatory/kexec-purgatory.c CC kernel/bounds.s CHK include/generated/bounds.h CHK include/generated/timeconst.h CC arch/x86/kernel/asm-offsets.s CHK include/generated/asm-offsets.h CALL scripts/checksyscalls.sh HOSTCC scripts/genksyms/genksyms.o HOSTCC scripts/genksyms/parse.tab.o HOSTCC scripts/genksyms/lex.lex.o HOSTLD scripts/genksyms/genksyms CC scripts/mod/empty.o
Quoted 9 lines
scripts/mod/empty.o
open: No such file or directory
error reading elf filescripts/mod/empty.oscripts/Makefile.build:284: recipe for target 'scripts/mod/empty.o' failed make[2]: *** [scripts/mod/empty.o] Error 1scripts/Makefile.build:429: recipe for target 'scripts/mod' failed make[1]: *** [scripts/mod] Error 2
Makefile:545: recipe for target 'scripts' failed
make: *** [scripts] Error 2
Thanks for trying it out. I couldn't figure out how to recreate this exact error, but I played around with "make mrproper" and saw some probably related errors. Does this fix it?
---8<---
Subject: [PATCH] stackvalidate: fix circular build dependencies
After "make mrproper" with CONFIG_STACK_VALIDATION enabled, I get the following errors:
make[2]: *** No rule to make target 'arch/x86/purgatory/purgatory.o', needed by 'arch/x86/purgatory/purgatory.ro'. Stop. make[3]: *** No rule to make target 'scripts/mod/empty.o', needed by 'scripts/mod/elfconfig.h'. Stop.
These are caused by circular dependencies. The %.o pattern rules in scripts/Makefile.build have the stackvalidate binary listed as a dependency. But stackvalidate gets built *after* archprepare and scripts/mod, both of which build objects using the %.o pattern rules.
The STACKVALIDATE and STACKVALIDATE_foo.o variables are already used to determine whether to validate a given object. Also use them to determine whether to create the pattern rule dependency.
--- scripts/Makefile.build | 7 +++++-- scripts/mod/Makefile | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-)
scripts/Makefile.build +5 -2
@@ -243,7 +243,7 @@ endif ifdef CONFIG_STACK_VALIDATION -stackvalidate = $(objtree)/scripts/stackvalidate/stackvalidate +__stackvalidate = $(objtree)/scripts/stackvalidate/stackvalidate ifndef CONFIG_FRAME_POINTER nofp = --no-frame-pointer
@@ -251,9 +251,12 @@ endif # Set STACKVALIDATE_foo.o=n to skip stack validation for a file. # Set STACKVALIDATE=n to skip stack validation for a directory. +stackvalidate = $(if $(patsubst n%,, \ + $(STACKVALIDATE_$(basetarget).o)$(STACKVALIDATE)y), \ + $(__stackvalidate)) cmd_stackvalidate = $(if $(patsubst n%,, \ $(STACKVALIDATE_$(basetarget).o)$(STACKVALIDATE)y), \ - $(stackvalidate) $(nofp) "$(@)";) + $(__stackvalidate) $(nofp) "$(@)";) endif # CONFIG_STACK_VALIDATION
scripts/mod/Makefile +2 -0
@@ -1,3 +1,5 @@ +STACKVALIDATE := n + hostprogs-y := modpost mk_elfconfig always := $(hostprogs-y) empty.o
Signature · 1 line
2.4.3
<snip>
Quoted 63 lines
Thanks for trying it out. I couldn't figure out how to recreate this exact error, but I played around with "make mrproper" and saw some probably related errors. Does this fix it?
---8<---
Subject: [PATCH] stackvalidate: fix circular build dependencies
After "make mrproper" with
CONFIG_STACK_VALIDATIONenabled, I get the following errors:make[2]: *** No rule to make target '
arch/x86/purgatory/purgatory.o', needed by 'arch/x86/purgatory/purgatory.ro'. Stop. make[3]: *** No rule to make target 'scripts/mod/empty.o', needed by 'scripts/mod/elfconfig.h'. Stop.These are caused by circular dependencies. The %.o pattern rules in
scripts/Makefile.buildhave the stackvalidate binary listed as a dependency. But stackvalidate gets built *after* archprepare andscripts/mod, both of which build objects using the %.o pattern rules.The STACKVALIDATE and STACKVALIDATE_foo.o variables are already used to determine whether to validate a given object. Also use them to determine whether to create the pattern rule dependency.
Signed-off-by Josh Poimboeuf <[email protected]>--- scripts/Makefile.build | 7 +++++-- scripts/mod/Makefile | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-)scripts/Makefile.build +5
-2@@ -243,7 +243,7 @@ endif ifdef CONFIG_STACK_VALIDATION -stackvalidate = $(objtree)/scripts/stackvalidate/stackvalidate +__stackvalidate = $(objtree)/scripts/stackvalidate/stackvalidate ifndef CONFIG_FRAME_POINTER nofp = --no-frame-pointer@@ -251,9 +251,12 @@ endif # Set STACKVALIDATE_foo.o=n to skip stack validation for a file. # Set STACKVALIDATE=n to skip stack validation for a directory. +stackvalidate = $(if $(patsubst n%,, \ + $(STACKVALIDATE_$(basetarget).o)$(STACKVALIDATE)y), \ + $(__stackvalidate)) cmd_stackvalidate = $(if $(patsubst n%,, \ $(STACKVALIDATE_$(basetarget).o)$(STACKVALIDATE)y), \ - $(stackvalidate) $(nofp) "$(@)";) + $(__stackvalidate) $(nofp) "$(@)";) endif # CONFIG_STACK_VALIDATIONscripts/mod/Makefile +0
-0
scripts/mod/Makefile line 5
Quoted 5 lines
scripts/mod/Makefile +2
-0@@ -1,3 +1,5 @@ +STACKVALIDATE := n + hostprogs-y := modpost mk_elfconfig always := $(hostprogs-y) empty.o
Josh,
I still get build failures and I've pared it down to x86_64 defconfig plus:CONFIG_MODVERSIONS=yCONFIG_STACK_VALIDATION=y
And it seems like some modules may get the .tmp_foo.o treatment while others end up foo.o so something like the following will not work:
cmd_stackvalidate = $(if $(patsubst n%,, \
$(STACKVALIDATE_$(basetarget).o)$(STACKVALIDATE)y), \
$(__stackvalidate) $(nofp) "$(@D)/.tmp_$(@F)";)In addition, I'm not sure if skipping modules like STACKVALIDATE_foo.o=n will still function properly for modversioned modules.
I'll try to look at this more tomorrow,
--chris j arges
Quoted 72 lines · Chris J Arges
<snip>
Quoted 63 lines
Thanks for trying it out. I couldn't figure out how to recreate this exact error, but I played around with "make mrproper" and saw some probably related errors. Does this fix it?
---8<---
Subject: [PATCH] stackvalidate: fix circular build dependencies
After "make mrproper" with
CONFIG_STACK_VALIDATIONenabled, I get the following errors:make[2]: *** No rule to make target '
arch/x86/purgatory/purgatory.o', needed by 'arch/x86/purgatory/purgatory.ro'. Stop. make[3]: *** No rule to make target 'scripts/mod/empty.o', needed by 'scripts/mod/elfconfig.h'. Stop.These are caused by circular dependencies. The %.o pattern rules in
scripts/Makefile.buildhave the stackvalidate binary listed as a dependency. But stackvalidate gets built *after* archprepare andscripts/mod, both of which build objects using the %.o pattern rules.The STACKVALIDATE and STACKVALIDATE_foo.o variables are already used to determine whether to validate a given object. Also use them to determine whether to create the pattern rule dependency.
Signed-off-by Josh Poimboeuf <[email protected]>--- scripts/Makefile.build | 7 +++++-- scripts/mod/Makefile | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-)scripts/Makefile.build +5
-2@@ -243,7 +243,7 @@ endif ifdef CONFIG_STACK_VALIDATION -stackvalidate = $(objtree)/scripts/stackvalidate/stackvalidate +__stackvalidate = $(objtree)/scripts/stackvalidate/stackvalidate ifndef CONFIG_FRAME_POINTER nofp = --no-frame-pointer@@ -251,9 +251,12 @@ endif # Set STACKVALIDATE_foo.o=n to skip stack validation for a file. # Set STACKVALIDATE=n to skip stack validation for a directory. +stackvalidate = $(if $(patsubst n%,, \ + $(STACKVALIDATE_$(basetarget).o)$(STACKVALIDATE)y), \ + $(__stackvalidate)) cmd_stackvalidate = $(if $(patsubst n%,, \ $(STACKVALIDATE_$(basetarget).o)$(STACKVALIDATE)y), \ - $(stackvalidate) $(nofp) "$(@)";) + $(__stackvalidate) $(nofp) "$(@)";) endif # CONFIG_STACK_VALIDATIONscripts/mod/Makefile +0
-0scripts/mod/Makefile line 5
Quoted 5 lines
scripts/mod/Makefile +2
-0@@ -1,3 +1,5 @@ +STACKVALIDATE := n + hostprogs-y := modpost mk_elfconfig always := $(hostprogs-y) empty.oJosh,
Quoted 3 lines
I still get build failures and I've pared it down to
x86_64defconfig plus:CONFIG_MODVERSIONS=yCONFIG_STACK_VALIDATION=y
Are you still seeing the same error as before? I think the errors you saw were caused by stackvalidate choking on scripts/mod/empty.o. But I don't see how that's still possible with the above patch since I set STACKVALIDATE to 'n' in scripts/mod/Makefile which should tell it to skip the directory.
Quoted 9 lines
And it seems like some modules may get the .tmp_foo.o treatment while others end up foo.o so something like the following will not work:
cmd_stackvalidate = $(if $(patsubst n%,, \ $(STACKVALIDATE_$(basetarget).o)$(STACKVALIDATE)y), \ $(__stackvalidate) $(nofp) "$(@D)/.tmp_$(@F)";)In addition, I'm not sure if skipping modules like STACKVALIDATE_foo.o=n will still function properly for modversioned modules.
I'm not sure that's really a problem, since I don't think we'll need to skip validation of any module code. It's only used for skipping code which runs outside of the kernel's normal operation (e.g., boot, vdso, kexec).
Signature · 1 line
Josh
Quoted 10 lines · Chris J Arges
I still get build failures and I've pared it down to
x86_64defconfig plus:CONFIG_MODVERSIONS=yCONFIG_STACK_VALIDATION=yAnd it seems like some modules may get the .tmp_foo.o treatment while others end up foo.o so something like the following will not work:
cmd_stackvalidate = $(if $(patsubst n%,, \ $(STACKVALIDATE_$(basetarget).o)$(STACKVALIDATE)y), \ $(__stackvalidate) $(nofp) "$(@D)/.tmp_$(@F)";)
Does this fix it?
scripts/Makefile.build +1 -1
@@ -263,8 +263,8 @@ endif # CONFIG_STACK_VALIDATION define rule_cc_o_c $(call echo-cmd,checksrc) $(cmd_checksrc) \ $(call echo-cmd,cc_o_c) $(cmd_cc_o_c); \ - $(cmd_stackvalidate) \ $(cmd_modversions) \ + $(cmd_stackvalidate) \ $(call echo-cmd,record_mcount) \ $(cmd_record_mcount) \ scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_c)' > \
Quoted 20 lines · Josh Poimboeuf
Quoted 10 lines · Chris J Arges
I still get build failures and I've pared it down to
x86_64defconfig plus:CONFIG_MODVERSIONS=yCONFIG_STACK_VALIDATION=yAnd it seems like some modules may get the .tmp_foo.o treatment while others end up foo.o so something like the following will not work:
cmd_stackvalidate = $(if $(patsubst n%,, \ $(STACKVALIDATE_$(basetarget).o)$(STACKVALIDATE)y), \ $(__stackvalidate) $(nofp) "$(@D)/.tmp_$(@F)";)Does this fix it?
scripts/Makefile.build +0
-0
scripts/Makefile.build endif # CONFIG_STACK_VALIDATION · line 270
Quoted 9 lines
scripts/Makefile.build +1
-1@@ -263,8 +263,8 @@ endif # CONFIG_STACK_VALIDATION define rule_cc_o_c $(call echo-cmd,checksrc) $(cmd_checksrc) \ $(call echo-cmd,cc_o_c) $(cmd_cc_o_c); \ - $(cmd_stackvalidate) \ $(cmd_modversions) \ + $(cmd_stackvalidate) \ $(call echo-cmd,record_mcount) \ $(cmd_record_mcount) \ scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_c)' > \
Josh,
Yes, this fixes my build. For completeness this is my current diff:
scripts/Makefile.build +6 -3
@@ -243,7 +243,7 @@ endif ifdef CONFIG_STACK_VALIDATION -stackvalidate = $(objtree)/scripts/stackvalidate/stackvalidate +__stackvalidate = $(objtree)/scripts/stackvalidate/stackvalidate ifndef CONFIG_FRAME_POINTER nofp = --no-frame-pointer
@@ -251,17 +251,20 @@ endif # Set STACKVALIDATE_foo.o=n to skip stack validation for a file. # Set STACKVALIDATE=n to skip stack validation for a directory. +stackvalidate = $(if $(patsubst n%,, \ + $(STACKVALIDATE_$(basetarget).o)$(STACKVALIDATE)y), \ + $(__stackvalidate)) cmd_stackvalidate = $(if $(patsubst n%,, \ $(STACKVALIDATE_$(basetarget).o)$(STACKVALIDATE)y), \ - $(stackvalidate) $(nofp) "$(@)";) + $(__stackvalidate) $(nofp) "$(@)";) endif # CONFIG_STACK_VALIDATION define rule_cc_o_c $(call echo-cmd,checksrc) $(cmd_checksrc) \ $(call echo-cmd,cc_o_c) $(cmd_cc_o_c); \ - $(cmd_stackvalidate) \ $(cmd_modversions) \ + $(cmd_stackvalidate) \ $(call echo-cmd,record_mcount) \ $(cmd_record_mcount) \ scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_c)' > \
scripts/mod/Makefile +2 -0
@@ -1,3 +1,5 @@ +STACKVALIDATE := n + hostprogs-y := modpost mk_elfconfig always := $(hostprogs-y) empty.o
Thanks,
--chris
Quoted 33 lines · Chris J Arges
Quoted 20 lines · Josh Poimboeuf
Quoted 10 lines · Chris J Arges
I still get build failures and I've pared it down to
x86_64defconfig plus:CONFIG_MODVERSIONS=yCONFIG_STACK_VALIDATION=yAnd it seems like some modules may get the .tmp_foo.o treatment while others end up foo.o so something like the following will not work:
cmd_stackvalidate = $(if $(patsubst n%,, \ $(STACKVALIDATE_$(basetarget).o)$(STACKVALIDATE)y), \ $(__stackvalidate) $(nofp) "$(@D)/.tmp_$(@F)";)Does this fix it?
scripts/Makefile.build +0
-0scripts/Makefile.build endif # CONFIG_STACK_VALIDATION · line 270
Quoted 9 lines
scripts/Makefile.build +1
-1@@ -263,8 +263,8 @@ endif # CONFIG_STACK_VALIDATION define rule_cc_o_c $(call echo-cmd,checksrc) $(cmd_checksrc) \ $(call echo-cmd,cc_o_c) $(cmd_cc_o_c); \ - $(cmd_stackvalidate) \ $(cmd_modversions) \ + $(cmd_stackvalidate) \ $(call echo-cmd,record_mcount) \ $(cmd_record_mcount) \ scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_c)' > \Josh,
Quoted 1 line
Yes, this fixes my build. For completeness this is my current diff:
Great! I'll roll both patches into v10.
Signature · 1 line
Josh