Re: [PATCH v1] perf test type profiling: Remote typedef on struct
From: Namhyung Kim
Date: Tue Mar 31 2026 - 02:42:37 EST
Hello,
On Sun, Mar 29, 2026 at 06:18:52PM +0200, Dmitry Dolgov wrote:
> > On Wed, Mar 04, 2026 at 11:44:16AM +0100, Dmitry Dolgov wrote:
> > > On Mon, Mar 02, 2026 at 03:58:21PM -0800, Ian Rogers wrote:
> > > The typedef creates an issue where the struct or the typedef may
> > > appear in the output and cause the "perf data type profiling tests" to
> > > fail. Let's remove the typedef to keep the test passing.
> >
> > Yes, makes sense to me, thanks. As mentioned in the previous message, it
> > sounds fishy to me that perf record and perf mem record capture
> > different data type -- I'll try to get to the bottom of it.
>
> I think I figured it out. To reiterate, the problem was that in my environment
> this:
>
> $ perf record ...
> $ perf annotate --code-with-type ...
>
> was showing a different data structure for workload_datasym_buf1 (buf vs struct
> _buf) than:
>
> $ perf mem record ...
> $ perf annotate --code-with-type ...
>
> It turns out that the type_die for this variable was derived differently: for
> "record" it was going through check_variable, for "mem record" through
> global_var__collect. If the type tag is DW_TAG_typedef, check_variable tries to
> figure out a real data type via die_get_real_type, which says this:
>
> /**
> * [...]
> * If the type is qualifiers (e.g. const) or typedef, this skips it
> * and tries to find real type (structure or basic types, e.g. int).
> */
>
> But the underlying implementation doesn't actually check for DW_TAG_typedef for
> some reason:
>
> while (tag == DW_TAG_const_type ||
> tag == DW_TAG_restrict_type ||
> tag == DW_TAG_volatile_type ||
> tag == DW_TAG_shared_type);
>
> By itself it doesn't look problematic, but for some reason datasym test was
> producing such a code, that had a chain of two DW_TAG_typedef in a row, so that
> die_get_real_type was returning a DW_TAG_typedef again.
>
> It looks to me like a deficiency of die_get_real_type, and the following code
> change fixes the problem for me:
>
> diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
> index 9267af204c7..de152fae1d9 100644
> --- a/tools/perf/util/dwarf-aux.c
> +++ b/tools/perf/util/dwarf-aux.c
> @@ -279,6 +279,7 @@ Dwarf_Die *__die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem)
> } while (tag == DW_TAG_const_type ||
> tag == DW_TAG_restrict_type ||
> tag == DW_TAG_volatile_type ||
> + tag == DW_TAG_typedef ||
> tag == DW_TAG_shared_type);
>
> return vr_die;
>
> Does this change sound reasonable?
We have this:
Dwarf_Die *die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem)
{
do {
vr_die = __die_get_real_type(vr_die, die_mem);
} while (vr_die && dwarf_tag(vr_die) == DW_TAG_typedef);
return vr_die;
}
Thanks,
Namhyung