From 1393567e31f42d4ebae393ca9453d0cb532ab78f Mon Sep 17 00:00:00 2001 From: "liang.huang" Date: Sat, 25 Jul 2026 10:54:17 +0800 Subject: [PATCH 1/4] libs/libc/symtab: fix g_allsyms link failure in BUILD_PROTECTED/KERNEL g_allsyms/g_nallsyms only exist in the kernel image, but symtab_allsyms.c is unconditionally built into libc.a, so user-mode code under CONFIG_BUILD_PROTECTED/CONFIG_BUILD_KERNEL fails to link. Guard the affected code so user-mode libc.a no longer references these kernel-only symbols. Signed-off-by: liang.huang Assisted-by: Claude Code:claude-sonnet-5 --- libs/libc/symtab/symtab_allsyms.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libs/libc/symtab/symtab_allsyms.c b/libs/libc/symtab/symtab_allsyms.c index b2dd9ae5458..852b98d8df2 100644 --- a/libs/libc/symtab/symtab_allsyms.c +++ b/libs/libc/symtab/symtab_allsyms.c @@ -31,6 +31,8 @@ * Public Data ****************************************************************************/ +#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) + extern const struct symtab_s g_allsyms[]; extern const int g_nallsyms; @@ -115,3 +117,21 @@ FAR const struct symtab_s *allsyms_findbyvalue(FAR void *value, { return allsyms_lookup(NULL, value, size); } + +#else + +FAR const struct symtab_s *allsyms_findbyname(FAR const char *name, + FAR size_t *size) +{ + *size = 0; + return NULL; +} + +FAR const struct symtab_s *allsyms_findbyvalue(FAR void *value, + FAR size_t *size) +{ + *size = 0; + return NULL; +} + +#endif /* CONFIG_BUILD_FLAT || __KERNEL__ */ From 1de02e49d4962c8601273d60f04a3e8e22446ac7 Mon Sep 17 00:00:00 2001 From: "liang.huang" Date: Sat, 25 Jul 2026 13:07:26 +0800 Subject: [PATCH 2/4] libs/libc/symtab: fix bogus symbol names for out-of-range addresses allsyms_findbyvalue()/%pS printed a bogus name/offset for addresses outside the real symbol table's coverage, due to the boundary sentinels being matchable as real symbols. Compute the high sentinel from the actual symbol range and treat a sentinel match as "not found". Signed-off-by: liang.huang Assisted-by: Claude Code:claude-sonnet-5 --- libs/libc/symtab/symtab_allsyms.c | 12 ++++++++++++ tools/mkallsyms.py | 12 ++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/libs/libc/symtab/symtab_allsyms.c b/libs/libc/symtab/symtab_allsyms.c index 852b98d8df2..7e66533bf63 100644 --- a/libs/libc/symtab/symtab_allsyms.c +++ b/libs/libc/symtab/symtab_allsyms.c @@ -61,6 +61,18 @@ allsyms_lookup(FAR const char *name, FAR void *value, else if (value) { symbol = symtab_findbyvalue(g_allsyms, value, g_nallsyms); + + /* g_allsyms[0] and g_allsyms[g_nallsyms - 1] are boundary sentinels, + * not real symbols. A match against either one means 'value' falls + * outside the range covered by real symbols, so treat it as not + * found instead of reporting a bogus name/offset. + */ + + if (symbol == &g_allsyms[0] || + symbol == &g_allsyms[g_nallsyms - 1]) + { + symbol = NULL; + } } if (symbol && symbol != &g_allsyms[g_nallsyms - 1]) diff --git a/tools/mkallsyms.py b/tools/mkallsyms.py index f18f8190d54..703e8425606 100755 --- a/tools/mkallsyms.py +++ b/tools/mkallsyms.py @@ -47,6 +47,7 @@ class SymbolTables(object): self.elffile = None self.output = output self.symbol_list = [] + self.max_address = 0 def symbol_filter(self, symbol): if symbol["st_info"]["type"] != "STT_FUNC": @@ -78,7 +79,9 @@ class SymbolTables(object): self.emitline( ' { "%s", (FAR %s void *)%s },' % (symbol[1], noconst, hex(symbol[0])) ) - self.emitline(' { "Unknown", (FAR %s void *)0xffffffff }\n};' % (noconst)) + self.emitline( + ' { "Unknown", (FAR %s void *)%s }\n};' % (noconst, hex(self.max_address)) + ) def get_symtable(self): symbol_tables = [ @@ -111,7 +114,12 @@ class SymbolTables(object): func_name = re.sub(r"\(.*$", "", symbol_name) except cxxfilt.InvalidName: symbol_name = symbol.name - self.symbol_list.append((symbol["st_value"], func_name)) + self.symbol_list.append( + (symbol["st_value"], func_name, symbol["st_size"]) + ) + end = symbol["st_value"] + symbol["st_size"] + if end > self.max_address: + self.max_address = end if orderbyname: self.symbol_list = sorted(self.symbol_list, key=lambda item: item[1]) else: From c92684faecd3d11e4096ab2b045e8e95d243bb6b Mon Sep 17 00:00:00 2001 From: "liang.huang" Date: Sat, 25 Jul 2026 13:30:13 +0800 Subject: [PATCH 3/4] libs/libc/symtab: fix bogus symbol size under SYMTAB_ORDEREDBYNAME allsyms_lookup() derived a symbol's size from the physically next table entry, assuming address order. Under CONFIG_SYMTAB_ORDEREDBYNAME the table is sorted by name instead, producing a huge bogus size in %pS/backtrace output. Scan for the closest larger address instead of relying on table order. Signed-off-by: liang.huang Assisted-by: Claude Code:claude-sonnet-5 --- libs/libc/symtab/symtab_allsyms.c | 34 ++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/libs/libc/symtab/symtab_allsyms.c b/libs/libc/symtab/symtab_allsyms.c index 7e66533bf63..5cd856929f3 100644 --- a/libs/libc/symtab/symtab_allsyms.c +++ b/libs/libc/symtab/symtab_allsyms.c @@ -75,7 +75,38 @@ allsyms_lookup(FAR const char *name, FAR void *value, } } - if (symbol && symbol != &g_allsyms[g_nallsyms - 1]) + if (symbol == NULL) + { + *size = 0; + return NULL; + } + +#ifdef CONFIG_SYMTAB_ORDEREDBYNAME + /* g_allsyms is sorted by name here, not by value, so the physically + * next table entry is not necessarily the next symbol by address. + * Scan the real symbols (index 1..g_nallsyms - 2; 0 and g_nallsyms - 1 + * are the boundary sentinels) for the smallest address greater than + * this symbol's, falling back to the high sentinel's now-meaningful + * value if none is closer. + */ + + { + FAR const struct symtab_s *next = &g_allsyms[g_nallsyms - 1]; + int i; + + for (i = 1; i < g_nallsyms - 1; i++) + { + if (g_allsyms[i].sym_value > symbol->sym_value && + g_allsyms[i].sym_value < next->sym_value) + { + next = &g_allsyms[i]; + } + } + + *size = next->sym_value - symbol->sym_value; + } +#else + if (symbol != &g_allsyms[g_nallsyms - 1]) { *size = (symbol + 1)->sym_value - symbol->sym_value; } @@ -83,6 +114,7 @@ allsyms_lookup(FAR const char *name, FAR void *value, { *size = 0; } +#endif return symbol; } From 437f8666a77a6e345c1e90b71adedc5849b62cb5 Mon Sep 17 00:00:00 2001 From: "liang.huang" Date: Sat, 25 Jul 2026 13:48:50 +0800 Subject: [PATCH 4/4] arch/risc-v: add .type directives to exception/boot assembly labels Several risc-v assembly labels are .global but untyped, so mkallsyms.py (which only collects STT_FUNC symbols) silently drops them from the ALLSYMS table, and backtraces/%pS print raw addresses instead of names. Add .type , function to the affected labels, matching existing convention elsewhere in the tree. Signed-off-by: liang.huang Assisted-by: Claude Code:claude-sonnet-5 --- arch/risc-v/src/bl808/bl808_head.S | 1 + arch/risc-v/src/c906/c906_head.S | 1 + arch/risc-v/src/common/espressif/esp_head.S | 1 + arch/risc-v/src/common/riscv_exception_common.S | 3 +++ arch/risc-v/src/eic7700x/eic7700x_head.S | 1 + arch/risc-v/src/esp32c3-legacy/esp32c3_head.S | 1 + arch/risc-v/src/fe310/fe310_head.S | 1 + arch/risc-v/src/gd32vw55x/gd32vw55x_head.S | 1 + arch/risc-v/src/hpm6000/hpm_head.S | 1 + arch/risc-v/src/hpm6750/hpm6750_head.S | 1 + arch/risc-v/src/jh7110/jh7110_head.S | 1 + arch/risc-v/src/k210/k210_head.S | 1 + arch/risc-v/src/k230/k230_head.S | 2 ++ arch/risc-v/src/litex/litex_head.S | 1 + arch/risc-v/src/litex/litex_shead.S | 1 + arch/risc-v/src/mpfs/mpfs_head.S | 1 + arch/risc-v/src/mpfs/mpfs_shead.S | 2 ++ arch/risc-v/src/nuttsbi/sbi_head.S | 1 + arch/risc-v/src/qemu-rv/qemu_rv_head.S | 2 ++ arch/risc-v/src/rp23xx-rv/rp23xx_head.S | 1 + arch/risc-v/src/rv32m1/rv32m1_head.S | 1 + arch/risc-v/src/sg2000/sg2000_head.S | 1 + 22 files changed, 27 insertions(+) diff --git a/arch/risc-v/src/bl808/bl808_head.S b/arch/risc-v/src/bl808/bl808_head.S index 1c1aa0d16a7..e835c45b03e 100644 --- a/arch/risc-v/src/bl808/bl808_head.S +++ b/arch/risc-v/src/bl808/bl808_head.S @@ -41,6 +41,7 @@ .section .text .global __start + .type __start, function __start: diff --git a/arch/risc-v/src/c906/c906_head.S b/arch/risc-v/src/c906/c906_head.S index 3560ef4b260..716bc964a31 100644 --- a/arch/risc-v/src/c906/c906_head.S +++ b/arch/risc-v/src/c906/c906_head.S @@ -42,6 +42,7 @@ .section .text .global __start + .type __start, function __start: diff --git a/arch/risc-v/src/common/espressif/esp_head.S b/arch/risc-v/src/common/espressif/esp_head.S index 9b85bac5fff..d71ce3aae82 100644 --- a/arch/risc-v/src/common/espressif/esp_head.S +++ b/arch/risc-v/src/common/espressif/esp_head.S @@ -36,6 +36,7 @@ ****************************************************************************/ .global __start + .type __start, function /**************************************************************************** * Section: .text diff --git a/arch/risc-v/src/common/riscv_exception_common.S b/arch/risc-v/src/common/riscv_exception_common.S index 442407d0371..11570b3d69f 100644 --- a/arch/risc-v/src/common/riscv_exception_common.S +++ b/arch/risc-v/src/common/riscv_exception_common.S @@ -108,6 +108,8 @@ .global exception_common .global return_from_exception .global return_from_syscall + .type exception_common, function + .type return_from_exception, function .align 8 exception_common: @@ -337,6 +339,7 @@ return_from_exception: .section EXCEPTION_SECTION .global riscv_jump_to_user + .type riscv_jump_to_user, function riscv_jump_to_user: diff --git a/arch/risc-v/src/eic7700x/eic7700x_head.S b/arch/risc-v/src/eic7700x/eic7700x_head.S index 24a659fefb6..795411b0f99 100644 --- a/arch/risc-v/src/eic7700x/eic7700x_head.S +++ b/arch/risc-v/src/eic7700x/eic7700x_head.S @@ -41,6 +41,7 @@ .section .text .global __start + .type __start, function __start: diff --git a/arch/risc-v/src/esp32c3-legacy/esp32c3_head.S b/arch/risc-v/src/esp32c3-legacy/esp32c3_head.S index 9b274aa129f..b975e3914cd 100644 --- a/arch/risc-v/src/esp32c3-legacy/esp32c3_head.S +++ b/arch/risc-v/src/esp32c3-legacy/esp32c3_head.S @@ -35,6 +35,7 @@ ****************************************************************************/ .global __start + .type __start, function /**************************************************************************** * Section: .text diff --git a/arch/risc-v/src/fe310/fe310_head.S b/arch/risc-v/src/fe310/fe310_head.S index 80a575d5343..a38bd613536 100644 --- a/arch/risc-v/src/fe310/fe310_head.S +++ b/arch/risc-v/src/fe310/fe310_head.S @@ -41,6 +41,7 @@ .section .text .global __start + .type __start, function __start: diff --git a/arch/risc-v/src/gd32vw55x/gd32vw55x_head.S b/arch/risc-v/src/gd32vw55x/gd32vw55x_head.S index 8a089ad3da4..cb4f67a78d9 100644 --- a/arch/risc-v/src/gd32vw55x/gd32vw55x_head.S +++ b/arch/risc-v/src/gd32vw55x/gd32vw55x_head.S @@ -41,6 +41,7 @@ .section .text .global __start + .type __start, function __start: diff --git a/arch/risc-v/src/hpm6000/hpm_head.S b/arch/risc-v/src/hpm6000/hpm_head.S index af8af5435a3..b618b8d2b69 100644 --- a/arch/risc-v/src/hpm6000/hpm_head.S +++ b/arch/risc-v/src/hpm6000/hpm_head.S @@ -41,6 +41,7 @@ .section .text .global __start + .type __start, function __start: /* reset mstatus to 0*/ diff --git a/arch/risc-v/src/hpm6750/hpm6750_head.S b/arch/risc-v/src/hpm6750/hpm6750_head.S index a8a704ded15..e8c5d031fc0 100644 --- a/arch/risc-v/src/hpm6750/hpm6750_head.S +++ b/arch/risc-v/src/hpm6750/hpm6750_head.S @@ -41,6 +41,7 @@ .section .text .global __start + .type __start, function __start: /* reset mstatus to 0*/ diff --git a/arch/risc-v/src/jh7110/jh7110_head.S b/arch/risc-v/src/jh7110/jh7110_head.S index 05993c3663f..ce07af60c5c 100644 --- a/arch/risc-v/src/jh7110/jh7110_head.S +++ b/arch/risc-v/src/jh7110/jh7110_head.S @@ -41,6 +41,7 @@ .section .text .global __start + .type __start, function __start: diff --git a/arch/risc-v/src/k210/k210_head.S b/arch/risc-v/src/k210/k210_head.S index b59e3a38026..208aad0bbb8 100644 --- a/arch/risc-v/src/k210/k210_head.S +++ b/arch/risc-v/src/k210/k210_head.S @@ -42,6 +42,7 @@ .section .text .global __start + .type __start, function __start: diff --git a/arch/risc-v/src/k230/k230_head.S b/arch/risc-v/src/k230/k230_head.S index e7daca2f34b..7fbdc66de8e 100644 --- a/arch/risc-v/src/k230/k230_head.S +++ b/arch/risc-v/src/k230/k230_head.S @@ -48,12 +48,14 @@ #ifdef CONFIG_NUTTSBI .global __start_s + .type __start_s, function __start_s: #else .global __start + .type __start, function __start: diff --git a/arch/risc-v/src/litex/litex_head.S b/arch/risc-v/src/litex/litex_head.S index cd4312232fe..f5059dac7ac 100644 --- a/arch/risc-v/src/litex/litex_head.S +++ b/arch/risc-v/src/litex/litex_head.S @@ -39,6 +39,7 @@ .section .text .global __start + .type __start, function __start: diff --git a/arch/risc-v/src/litex/litex_shead.S b/arch/risc-v/src/litex/litex_shead.S index 5d5236287e8..de36680104d 100644 --- a/arch/risc-v/src/litex/litex_shead.S +++ b/arch/risc-v/src/litex/litex_shead.S @@ -43,6 +43,7 @@ .section .text .global __start + .type __start, function /**************************************************************************** * Name: __start diff --git a/arch/risc-v/src/mpfs/mpfs_head.S b/arch/risc-v/src/mpfs/mpfs_head.S index a3f666fa80c..144b38451ae 100644 --- a/arch/risc-v/src/mpfs/mpfs_head.S +++ b/arch/risc-v/src/mpfs/mpfs_head.S @@ -44,6 +44,7 @@ .section .start, "ax" .global __start + .type __start, function __start: diff --git a/arch/risc-v/src/mpfs/mpfs_shead.S b/arch/risc-v/src/mpfs/mpfs_shead.S index d6bf508c2ca..64825ae7ffc 100644 --- a/arch/risc-v/src/mpfs/mpfs_shead.S +++ b/arch/risc-v/src/mpfs/mpfs_shead.S @@ -44,8 +44,10 @@ .section .start, "ax" #ifdef CONFIG_NUTTSBI .global __start_s + .type __start_s, function #else .global __start + .type __start, function #endif /**************************************************************************** diff --git a/arch/risc-v/src/nuttsbi/sbi_head.S b/arch/risc-v/src/nuttsbi/sbi_head.S index a3bfb10351e..6f742b065ed 100644 --- a/arch/risc-v/src/nuttsbi/sbi_head.S +++ b/arch/risc-v/src/nuttsbi/sbi_head.S @@ -39,6 +39,7 @@ .section .text .global __start + .type __start, function __start: diff --git a/arch/risc-v/src/qemu-rv/qemu_rv_head.S b/arch/risc-v/src/qemu-rv/qemu_rv_head.S index 7a91c9e7284..9dd11e91f36 100644 --- a/arch/risc-v/src/qemu-rv/qemu_rv_head.S +++ b/arch/risc-v/src/qemu-rv/qemu_rv_head.S @@ -42,10 +42,12 @@ .section .text #ifndef CONFIG_NUTTSBI .global __start + .type __start, function __start: #else .global __start_s + .type __start_s, function __start_s: #endif diff --git a/arch/risc-v/src/rp23xx-rv/rp23xx_head.S b/arch/risc-v/src/rp23xx-rv/rp23xx_head.S index 772545d8004..520ed4b8b02 100644 --- a/arch/risc-v/src/rp23xx-rv/rp23xx_head.S +++ b/arch/risc-v/src/rp23xx-rv/rp23xx_head.S @@ -40,6 +40,7 @@ .section .text .global __start + .type __start, function __start: diff --git a/arch/risc-v/src/rv32m1/rv32m1_head.S b/arch/risc-v/src/rv32m1/rv32m1_head.S index db1bbf12e3c..6ab26e654ed 100644 --- a/arch/risc-v/src/rv32m1/rv32m1_head.S +++ b/arch/risc-v/src/rv32m1/rv32m1_head.S @@ -38,6 +38,7 @@ .global exception_common .global return_from_exception .global __start + .type __start, function .section .text diff --git a/arch/risc-v/src/sg2000/sg2000_head.S b/arch/risc-v/src/sg2000/sg2000_head.S index 325911fa15d..ee876ad9741 100644 --- a/arch/risc-v/src/sg2000/sg2000_head.S +++ b/arch/risc-v/src/sg2000/sg2000_head.S @@ -41,6 +41,7 @@ .section .text .global __start + .type __start, function __start: