From 8c8c60f70afe989d4530b38df12e45a41f47e87b Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Mon, 28 Mar 2022 02:55:53 +0800 Subject: [PATCH] arch: Add -fsanitize=kernel-address to ARCHCPUFLAGS if CONFIG_MM_KASAN=y Signed-off-by: Xiang Xiao --- arch/arm/src/arm/Toolchain.defs | 4 ++++ arch/arm/src/armv6-m/Toolchain.defs | 4 ++++ arch/arm/src/armv7-a/Toolchain.defs | 4 ++++ arch/arm/src/armv7-m/Toolchain.defs | 4 ++++ arch/arm/src/armv7-r/Toolchain.defs | 4 ++++ arch/arm/src/armv8-m/Toolchain.defs | 4 ++++ arch/risc-v/src/common/Toolchain.defs | 4 ++++ arch/xtensa/src/lx6/Toolchain.defs | 4 ++++ arch/xtensa/src/lx7/Toolchain.defs | 4 ++++ 9 files changed, 36 insertions(+) diff --git a/arch/arm/src/arm/Toolchain.defs b/arch/arm/src/arm/Toolchain.defs index 38919b40e0..07127dc568 100644 --- a/arch/arm/src/arm/Toolchain.defs +++ b/arch/arm/src/arm/Toolchain.defs @@ -73,6 +73,10 @@ else MAXOPTIMIZATION += -fomit-frame-pointer endif +ifeq ($(CONFIG_MM_KASAN),y) + ARCHCPUFLAGS += -fsanitize=kernel-address +endif + # NuttX buildroot under Linux or Cygwin ifeq ($(CONFIG_ARM_TOOLCHAIN),BUILDROOT) diff --git a/arch/arm/src/armv6-m/Toolchain.defs b/arch/arm/src/armv6-m/Toolchain.defs index ba4b7094f9..c08d23e5b7 100644 --- a/arch/arm/src/armv6-m/Toolchain.defs +++ b/arch/arm/src/armv6-m/Toolchain.defs @@ -81,6 +81,10 @@ ifeq ($(CONFIG_ARMV6M_TOOLCHAIN),GNU_EABI) ARCHCPUFLAGS = -mcpu=cortex-m0 -mthumb -mfloat-abi=soft endif +ifeq ($(CONFIG_MM_KASAN),y) + ARCHCPUFLAGS += -fsanitize=kernel-address +endif + # Default toolchain CC = $(CROSSDEV)gcc diff --git a/arch/arm/src/armv7-a/Toolchain.defs b/arch/arm/src/armv7-a/Toolchain.defs index f9fca4a831..23a7cf9680 100644 --- a/arch/arm/src/armv7-a/Toolchain.defs +++ b/arch/arm/src/armv7-a/Toolchain.defs @@ -102,6 +102,10 @@ else ARCHFPUFLAGS += -mfloat-abi=soft endif +ifeq ($(CONFIG_MM_KASAN),y) + ARCHCPUFLAGS += -fsanitize=kernel-address +endif + ifeq ($(CONFIG_DEBUG_CUSTOMOPT),y) MAXOPTIMIZATION := $(CONFIG_DEBUG_OPTLEVEL) else diff --git a/arch/arm/src/armv7-m/Toolchain.defs b/arch/arm/src/armv7-m/Toolchain.defs index 0752339f2c..c6f9639baa 100644 --- a/arch/arm/src/armv7-m/Toolchain.defs +++ b/arch/arm/src/armv7-m/Toolchain.defs @@ -130,6 +130,10 @@ else endif endif +ifeq ($(CONFIG_MM_KASAN),y) + ARCHCPUFLAGS += -fsanitize=kernel-address +endif + # Generic GNU EABI toolchain ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),GNU_EABI) diff --git a/arch/arm/src/armv7-r/Toolchain.defs b/arch/arm/src/armv7-r/Toolchain.defs index e7314cb0b5..43860d442c 100644 --- a/arch/arm/src/armv7-r/Toolchain.defs +++ b/arch/arm/src/armv7-r/Toolchain.defs @@ -90,6 +90,10 @@ ifeq ($(CONFIG_ENDIAN_BIG),y) ARCHCPUFLAGS += -mbig-endian endif +ifeq ($(CONFIG_MM_KASAN),y) + ARCHCPUFLAGS += -fsanitize=kernel-address +endif + ifeq ($(CONFIG_ENDIAN_BIG),y) TARGET_ARCH := armeb else diff --git a/arch/arm/src/armv8-m/Toolchain.defs b/arch/arm/src/armv8-m/Toolchain.defs index b6fa30cf7a..1a8f38e0c7 100644 --- a/arch/arm/src/armv8-m/Toolchain.defs +++ b/arch/arm/src/armv8-m/Toolchain.defs @@ -128,6 +128,10 @@ else endif endif +ifeq ($(CONFIG_MM_KASAN),y) + ARCHCPUFLAGS += -fsanitize=kernel-address +endif + # Generic GNU EABI toolchain ifeq ($(CONFIG_ARMV8M_TOOLCHAIN),GNU_EABI) diff --git a/arch/risc-v/src/common/Toolchain.defs b/arch/risc-v/src/common/Toolchain.defs index f6fa879734..1c871110dd 100644 --- a/arch/risc-v/src/common/Toolchain.defs +++ b/arch/risc-v/src/common/Toolchain.defs @@ -115,6 +115,10 @@ ifeq ($(CONFIG_RISCV_TOOLCHAIN),GNU_RVG) endif +ifeq ($(CONFIG_MM_KASAN),y) + ARCHCPUFLAGS += -fsanitize=kernel-address +endif + # Default toolchain CC = $(CROSSDEV)gcc diff --git a/arch/xtensa/src/lx6/Toolchain.defs b/arch/xtensa/src/lx6/Toolchain.defs index b0ac9787d5..4dc7236e9e 100644 --- a/arch/xtensa/src/lx6/Toolchain.defs +++ b/arch/xtensa/src/lx6/Toolchain.defs @@ -55,6 +55,10 @@ else MAXOPTIMIZATION += -fomit-frame-pointer endif +ifeq ($(CONFIG_MM_KASAN),y) + ARCHCPUFLAGS += -fsanitize=kernel-address +endif + # Default toolchain ifeq ($(CONFIG_XTENSA_TOOLCHAIN_XCC), y) CC = $(CROSSDEV)xcc diff --git a/arch/xtensa/src/lx7/Toolchain.defs b/arch/xtensa/src/lx7/Toolchain.defs index 2fb8e5d7d9..9f94f87cc7 100644 --- a/arch/xtensa/src/lx7/Toolchain.defs +++ b/arch/xtensa/src/lx7/Toolchain.defs @@ -55,6 +55,10 @@ else MAXOPTIMIZATION += -fomit-frame-pointer endif +ifeq ($(CONFIG_MM_KASAN),y) + ARCHCPUFLAGS += -fsanitize=kernel-address +endif + # Default toolchain ifeq ($(CONFIG_XTENSA_TOOLCHAIN_XCC), y) CC = $(CROSSDEV)xcc