Skip to content

mm/kasan: Fix compile options applied to wrong target in SPLIT build#19043

Merged
xiaoxiang781216 merged 3 commits into
apache:masterfrom
leisiji:master
Jun 8, 2026
Merged

mm/kasan: Fix compile options applied to wrong target in SPLIT build#19043
xiaoxiang781216 merged 3 commits into
apache:masterfrom
leisiji:master

Conversation

@leisiji

@leisiji leisiji commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • cmake/elf: Fix ELF entry point from __start to _start — The ELF entry point on ARM/ARM64/x86_64 incorrectly used __start (kernel boot entry) instead of _start (C runtime entry in crt0.c). arm64 and x86_64 elf.cmake already used _start; ARM was the outlier.
  • mm/kasan: Fix compile options applied to wrong target in SPLIT build — In SPLIT build, the kmm target carries the kasan code, but compile options were mistakenly applied to the mm target. In flat build, the kmm target does not exist, causing a CMake configuration error.
  • build/fix: remove nonexistent target in cmake — The nuttx_apps_mksymtab target does not exist in the nuttx repository, causing build failure when CONFIG_MODULES is enabled.

Impact

  • Impact on user: NO
  • Impact on build: YES — Fixes CMake build failures in SPLIT build, flat sim build, and CONFIG_MODULES scenarios.
  • Impact on hardware: NO
  • Impact on documentation: NO
  • Impact on security: NO
  • Impact on compatibility: NO

Testing

  • Build Host: Linux x86_64, GCC
  • Target: sim/mtdrwb, sim/note, sim/nsh, sim/nxffs (CMake flat build) and qemu-armv7a:knsh (SPLIT kernel build)

Testing logs before change:

CMake Error at mm/kasan/CMakeLists.txt:37 (target_compile_options):
Cannot specify compile options for target "kmm" which is not built by this project.

Testing logs after change:

Build succeeds for sim and qemu-armv7a configurations.

Testing Details:

build config:

diff --git a/boards/arm/qemu/qemu-armv7a/configs/knsh/defconfig b/boards/arm/qemu/qemu-armv7a/configs/knsh/defconfig
index 18b086834c..2f66e7df80 100644
--- a/boards/arm/qemu/qemu-armv7a/configs/knsh/defconfig
+++ b/boards/arm/qemu/qemu-armv7a/configs/knsh/defconfig
@@ -18,8 +18,8 @@ CONFIG_ARCH_DATA_NPAGES=256
 CONFIG_ARCH_DATA_VBASE=0x80100000
 CONFIG_ARCH_HEAP_NPAGES=256
 CONFIG_ARCH_HEAP_VBASE=0x80200000
-CONFIG_ARCH_INTERRUPTSTACK=2048
-CONFIG_ARCH_KERNEL_STACKSIZE=3072
+CONFIG_ARCH_INTERRUPTSTACK=8192
+CONFIG_ARCH_KERNEL_STACKSIZE=8192
 CONFIG_ARCH_LOWVECTORS=y
 CONFIG_ARCH_PGPOOL_MAPPING=y
 CONFIG_ARCH_PGPOOL_PBASE=0x40300000
@@ -39,7 +39,7 @@ CONFIG_DEBUG_ASSERTIONS=y
 CONFIG_DEBUG_FEATURES=y
 CONFIG_DEBUG_FULLOPT=y
 CONFIG_DEBUG_SYMBOLS=y
-CONFIG_DEFAULT_TASK_STACKSIZE=4096
+CONFIG_DEFAULT_TASK_STACKSIZE=8192
 CONFIG_ELF=y
 CONFIG_EXAMPLES_HELLO=m
 CONFIG_EXPERIMENTAL=y
@@ -48,7 +48,7 @@ CONFIG_FS_HOSTFS=y
 CONFIG_FS_PROCFS=y
 CONFIG_HAVE_CXX=y
 CONFIG_HAVE_CXXINITIALIZE=y
-CONFIG_IDLETHREAD_STACKSIZE=4096
+CONFIG_IDLETHREAD_STACKSIZE=8192
 CONFIG_INIT_FILEPATH="/system/bin/init"
 CONFIG_INIT_MOUNT=y
 CONFIG_INIT_MOUNT_DATA="fs=../apps"
@@ -56,7 +56,7 @@ CONFIG_INIT_MOUNT_FLAGS=0x1
 CONFIG_INIT_MOUNT_FSTYPE="hostfs"
 CONFIG_INIT_MOUNT_SOURCE=""
 CONFIG_INIT_MOUNT_TARGET="/system"
-CONFIG_INIT_STACKSIZE=3072
+CONFIG_INIT_STACKSIZE=8192
 CONFIG_INTELHEX_BINARY=y
 CONFIG_LIBC_ENVPATH=y
 CONFIG_LIBC_EXECFUNCS=y
@@ -66,7 +66,7 @@ CONFIG_NSH_FILE_APPS=y
 CONFIG_NSH_READLINE=y
 CONFIG_PATH_INITIAL="/system/bin"
 CONFIG_PREALLOC_TIMERS=4
-CONFIG_RAM_SIZE=16777216
+CONFIG_RAM_SIZE=33554432
 CONFIG_RAM_START=0x40000000
 CONFIG_RAM_VSTART=0x40000000
 CONFIG_RAW_BINARY=y
@@ -91,3 +91,5 @@ CONFIG_UART1_PL011=y
 CONFIG_UART1_SERIAL_CONSOLE=y
 CONFIG_UART_PL011=y
 CONFIG_USEC_PER_TICK=1000
+CONFIG_MM_KASAN=y
+CONFIG_MM_KASAN_INSTRUMENT_ALL=y

build and run:

cmake -B build -DBOARD_CONFIG=qemu-armv7a:knsh -GNinja && cmake --build build
mkdir -p ../apps/bin
ln -sf $(realpath build/bin)/* ../apps/bin/
qemu-system-arm -semihosting -M virt -m 128 -nographic -kernel ./build/nuttx

If built with cmake and kasan hook itself, it cannot launch into nsh

@github-actions github-actions Bot added Area: Memory Management Memory Management issues Size: XS The size of the change in this PR is very small labels Jun 5, 2026
@linguini1

linguini1 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Can you please explain more about how you tested this change? It seems fine but I'm not understanding what was broken before?

@leisiji

leisiji commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

I have updated the testing detail and another 2 necessary commits in this pr.

@github-actions github-actions Bot added Area: Build system Arch: arm Issues related to ARM (32-bit) architecture Arch: arm64 Issues related to ARM64 (64-bit) architecture Arch: x86_64 Issues related to the x86_64 architecture Size: S The size of the change in this PR is small and removed Area: Memory Management Memory Management issues Size: XS The size of the change in this PR is very small labels Jun 6, 2026
@linguini1 linguini1 requested a review from xiaoxiang781216 June 6, 2026 03:14
leisiji added 3 commits June 6, 2026 12:51
In SPLIT build mode, nuttx_add_kernel_library(mm SPLIT) creates two
targets: mm (system library) and kmm (kernel library). The compile
options were being applied to the mm target via
target_compile_options(mm ...), but the kasan instrumentation is
compiled as part of the kmm target.

Change target_compile_options(mm ...) to target_compile_options(kmm
...) so that FLAGS (including -fno-builtin and NO_LTO) are correctly
applied to the kernel target where kasan code is compiled.

Signed-off-by: leisiji <2265215145@qq.com>
nuttx_apps_mksymtab is nonexistent in nuttx,
which produce error when build with CONFIG_MODULES

Signed-off-by: leisiji <2265215145@qq.com>
__start is the kernel boot entry for each chip, while _start (defined
in crt0.c) is the correct C runtime entry point for ELF executables.

Signed-off-by: leisiji <2265215145@qq.com>
@xiaoxiang781216 xiaoxiang781216 merged commit 8121b88 into apache:master Jun 8, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Arch: arm64 Issues related to ARM64 (64-bit) architecture Arch: x86_64 Issues related to the x86_64 architecture Area: Build system Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] cmake build report an error "Cannot add target-level dependencies to non-existent target "nuttx_apps_mksymtab". "

5 participants