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 <liang.huang@houmo.ai>
Assisted-by: Claude Code:claude-sonnet-5
This commit is contained in:
liang.huang
2026-08-05 21:51:25 +08:00
committed by Xiang Xiao
parent 2d323de0b8
commit 7d3d1c5567
2 changed files with 22 additions and 2 deletions
+12
View File
@@ -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])
+10 -2
View File
@@ -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: