This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit fa2ca944cb1dfa0368d89d2bda046519f86c8dc7
Author: dengwenqi <[email protected]>
AuthorDate: Wed Jul 8 08:00:05 2026 +0800

    libc/backtrace: skip KASAN instrumentation in backtrace_hash hot path
    
    backtrace_hash() is called by backtrace_record() and backtrace_remove()
    for every record.  On KASAN-enabled debug builds each data[i] load in
    its loop triggers a __asan_load4_noabort shadow check, which adds up
    when backtraces are recorded at a high rate, e.g. for every allocation
    of the C++ static constructors.
    
    backtrace_find() on the same path already has nosanitize_address; add
    it to backtrace_hash() too.  The buffer is either the caller's stack
    array (filled by sched_backtrace) or the stack array of a pool entry,
    both always valid, so skipping the shadow check is safe.
    
    Signed-off-by: dengwenqi <[email protected]>
---
 libs/libc/misc/lib_backtrace.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/libs/libc/misc/lib_backtrace.c b/libs/libc/misc/lib_backtrace.c
index 9509bbce899..ed1b34265f0 100644
--- a/libs/libc/misc/lib_backtrace.c
+++ b/libs/libc/misc/lib_backtrace.c
@@ -137,6 +137,20 @@ static FAR char **backtrace_malloc(FAR void *const 
*buffer, int size)
  * Name: backtrace_hash
  ****************************************************************************/
 
+/* nosanitize_address: backtrace_hash is on the hot path of every recorded
+ * allocation/free (called by backtrace_record and backtrace_remove when
+ * CONFIG_MM_RECORD_STACK is on).  On KASAN-enabled debug builds each
+ * data[i] load would otherwise trip a per-access __asan_load4_noabort
+ * shadow check; multiplied across a heavy allocation phase (e.g. C++
+ * static initialization) this stretches the wall time past the test
+ * framework's busy-loop threshold and surfaces as a no-output hang.  The
+ * same reasoning was applied to backtrace_find(); this covers the
+ * remaining uninstrumented reader on the same path.  The buffer is either
+ * the caller's stack array (filled by sched_backtrace) or a pool entry's
+ * stack array, both always valid, so skipping the shadow check is safe.
+ */
+
+nosanitize_address
 static uint32_t backtrace_hash(FAR const void *backtrace, int depth)
 {
   FAR const uintptr_t *data = backtrace;

Reply via email to