]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
objtool: Make find_symbol_containing() less arbitrary
authorJosh Poimboeuf <jpoimboe@kernel.org>
Wed, 17 Sep 2025 16:03:21 +0000 (09:03 -0700)
committerJosh Poimboeuf <jpoimboe@kernel.org>
Tue, 14 Oct 2025 21:45:23 +0000 (14:45 -0700)
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 <pmladek@suse.com>
Tested-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
tools/objtool/elf.c

index ca5d77db692a23b7d4f7b9f8a69b94e32002b881..1c1bb2cb960dae2f88458c0d202e8fc20d9c4ee7 100644 (file)
@@ -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;
 }
 
 /*