[PATCH] kernel: disable stack validation for external module builds as needed

Mark Mentovai mark at mentovai.com
Sun Sep 11 11:31:10 PDT 2022


c3e31b6a9b04 and 5f8e5872406d disable stack validation when the build
host is not running Linux, as the objtool kernel build tool required for
stack validation is not portable to other build host environments. This
was achieved by setting CONFIG_STACK_VALIDATION= in KERNEL_MAKEOPTS, and
by setting SKIP_STACK_VALIDATION=1 in the environment. KERNEL_MAKEOPTS
only has effect for the kernel build, not for external module builds,
but through kernel 5.14, SKIP_STACK_VALIDATION worked to disable this
feature too, so stack validation was disabled for external module builds
as well. Since kernel 0d989ac2c90b, the kernel build no longer considers
SKIP_STACK_VALIDATION, so the feature will be disabled for the kernel
build, but not for external module builds.

When building OpenWrt on a non-Linux build host targeting x86 (the only
target architecture for which OpenWrt enables the kernel
CONFIG_STACK_VALIDATION) and using kernel 5.15 (such as via
CONFIG_TESTING_KERNEL), this caused a build failure during any external
module build, such as kmod-button-hotplug. This manifested as build
errors such as:

  make[4]: *** No rule to make target
  '.../build_dir/target-x86_64_musl/linux-x86_64/button-hotplug/button-hotplug.o',
  needed by
  '.../build_dir/target-x86_64_musl/linux-x86_64/button-hotplug/button-hotplug.mod'.
  Stop.

Although button-hotplug.c was present, the implicit rule to make
$(obj)/%.o from $(src)/%.c in the kernel's scripts/Makefile.build could
not be satisfied in this case, as it also depends on $(objtool_dep),
non-empty as a result of the failure to propagate disabling of stack
validation to external module builds, in a configuration where it is not
possible to build objtool.

KERNEL_MAKEOPTS is used for just the kernel build itself, while
KERNEL_MAKE_FLAGS is used for both the kernel build and for external
module builds. This restores the ability to build OpenWrt in such
configurations by moving the CONFIG_STACK_VALIDATION= make argument from
KERNEL_MAKEOPTS to KERNEL_MAKE_FLAGS where it is able to affect external
module builds properly.

Note that the kernel's objtool and related configuration have seen a
major overhaul since kernel 5.15, and may need more attention again
after 22922deae13f, in kernel 5.19.

Signed-off-by: Mark Mentovai <mark at mentovai.com>
---
 include/kernel.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/kernel.mk b/include/kernel.mk
index 001718d89d8b..3cc2fc41b7a0 100644
--- a/include/kernel.mk
+++ b/include/kernel.mk
@@ -132,7 +132,7 @@ ifdef CONFIG_USE_SPARSE
 endif
 
 ifneq ($(HOST_OS),Linux)
-  KERNEL_MAKEOPTS += CONFIG_STACK_VALIDATION=
+  KERNEL_MAKE_FLAGS += CONFIG_STACK_VALIDATION=
   export SKIP_STACK_VALIDATION:=1
 endif
 
-- 
2.37.3




More information about the openwrt-devel mailing list