From: Zecheng Li Date: Mon, 9 Mar 2026 17:55:17 +0000 (-0400) Subject: perf annotate-data: Improve type comparison from different scopes X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=69953f9c65856fc9438fc2ad4b9fd8255a2e47da;p=thirdparty%2Fkernel%2Flinux.git perf annotate-data: Improve type comparison from different scopes When comparing types from different scopes, first compare their type offsets. A larger offset means the field belongs to an outer (enclosing) struct. This helps resolve cases where a pointer is found in an inner scope, but a struct containing that pointer exists in an outer scope. Previously, is_better_type would prefer the pointer type, but the struct type is actually more complete and should be chosen. Prefer types from outer scopes when is_better_type cannot determine a better type. This is a heuristic for the case `struct A { struct B; }` where A and B have the same size but I think in most cases A is in the outer scope and should be preferred. Signed-off-by: Zecheng Li Signed-off-by: Zecheng Li Signed-off-by: Namhyung Kim --- diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-data.c index 23a09bf58f864..6fe2efd48a832 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -1629,7 +1629,9 @@ retry: pr_debug_dtp("type_offset=%#x\n", type_offset); } - if (!found || is_better_type(type_die, &mem_die)) { + if (!found || dloc->type_offset < type_offset || + (dloc->type_offset == type_offset && + !is_better_type(&mem_die, type_die))) { *type_die = mem_die; dloc->type_offset = type_offset; found = true;