From fc705ecfb6455728db8ce6267043c431e8c6f878 Mon Sep 17 00:00:00 2001 From: sexenteen <130895816+sexenteen@users.noreply.github.com> Date: Sun, 1 Nov 2026 17:52:56 +0800 Subject: [PATCH 1/2] fix[klibc]: stop gcc from turning the kstring.c byte loops into memset/memcpy calls --- src/klibc/SConscript | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/klibc/SConscript b/src/klibc/SConscript index ce214ad1059d..219c52872013 100644 --- a/src/klibc/SConscript +++ b/src/klibc/SConscript @@ -1,5 +1,6 @@ from building import * import os +import rtconfig cwd = GetCurrentDir() src = ['kerrno.c', 'kstdio.c', 'kstring.c'] @@ -13,7 +14,15 @@ if not GetDepend(['RT_KLIBC_USING_LIBC_VSNPRINTF']): if not GetDepend(['RT_KLIBC_USING_LIBC_VSSCANF']): src += ['rt_vsscanf.c'] -group = DefineGroup('Libc', src, depend = ['']) +# at -O2/-Os, GCC recognises the byte loops used by rt_memset()/rt_memcpy()/ +# rt_memmove() in kstring.c and turns them into calls to memset()/memcpy()/ +# memmove(). Those symbols do not exist on targets built without a C library, +# so the firmware fails to link (see issue #6128). Keep the loops here. +local_cflags = '' +if rtconfig.CROSS_TOOL == 'gcc': + local_cflags = ' -fno-tree-loop-distribute-patterns' + +group = DefineGroup('Libc', src, depend = [''], LOCAL_CFLAGS = local_cflags) list = os.listdir(cwd) for item in list: From 9ceb217b2baae9b2e1a072e9f2fbfdab5e12fe3c Mon Sep 17 00:00:00 2001 From: sexenteen <130895816+sexenteen@users.noreply.github.com> Date: Mon, 2 Nov 2026 14:56:53 +0800 Subject: [PATCH 2/2] fix[klibc]: do not pass LOCAL_CFLAGS to the clang-analyzer build --- src/klibc/SConscript | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/klibc/SConscript b/src/klibc/SConscript index 219c52872013..7ea41b6aec31 100644 --- a/src/klibc/SConscript +++ b/src/klibc/SConscript @@ -18,11 +18,14 @@ if not GetDepend(['RT_KLIBC_USING_LIBC_VSSCANF']): # rt_memmove() in kstring.c and turns them into calls to memset()/memcpy()/ # memmove(). Those symbols do not exist on targets built without a C library, # so the firmware fails to link (see issue #6128). Keep the loops here. -local_cflags = '' -if rtconfig.CROSS_TOOL == 'gcc': - local_cflags = ' -fno-tree-loop-distribute-patterns' +group_args = {'depend': ['']} +if rtconfig.CROSS_TOOL == 'gcc' and not GetOption('clang-analyzer'): + # Do not pass LOCAL_CFLAGS in --clang-analyzer builds: building.py replaces + # CFLAGS with a list there, and local_group() concatenates it with this + # string, which raises TypeError and stops the static analysis. + group_args['LOCAL_CFLAGS'] = ' -fno-tree-loop-distribute-patterns' -group = DefineGroup('Libc', src, depend = [''], LOCAL_CFLAGS = local_cflags) +group = DefineGroup('Libc', src, **group_args) list = os.listdir(cwd) for item in list: