From: Josh Poimboeuf Date: Wed, 17 Sep 2025 16:03:21 +0000 (-0700) Subject: objtool: Make find_symbol_containing() less arbitrary X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=07e1c3fd86d7a2ddce3ebc6b7390590c8524a484;p=thirdparty%2Fkernel%2Flinux.git objtool: Make find_symbol_containing() less arbitrary In the rare case of overlapping symbols, find_symbol_containing() just returns the first one it finds. Make it slightly less arbitrary by returning the smallest symbol with size > 0. Acked-by: Petr Mladek Tested-by: Joe Lawrence Signed-off-by: Josh Poimboeuf --- diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index ca5d77db692a2..1c1bb2cb960da 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -193,14 +193,29 @@ struct symbol *find_func_by_offset(struct section *sec, unsigned long offset) struct symbol *find_symbol_containing(const struct section *sec, unsigned long offset) { struct rb_root_cached *tree = (struct rb_root_cached *)&sec->symbol_tree; - struct symbol *iter; + struct symbol *sym = NULL, *tmp; - __sym_for_each(iter, tree, offset, offset) { - if (iter->type != STT_SECTION) - return iter; + __sym_for_each(tmp, tree, offset, offset) { + if (tmp->len) { + if (!sym) { + sym = tmp; + continue; + } + + if (sym->offset != tmp->offset || sym->len != tmp->len) { + /* + * In the rare case of overlapping symbols, + * pick the smaller one. + * + * TODO: outlaw overlapping symbols + */ + if (tmp->len < sym->len) + sym = tmp; + } + } } - return NULL; + return sym; } /*