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 7d3d1c55677adeff16f304015ef4c63b2183341b
Author: liang.huang <[email protected]>
AuthorDate: Sat Jul 25 13:07:26 2026 +0800

    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 <[email protected]>
    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:

Reply via email to