Re: [PATCH v2 2/4] perf dwarf-aux: Add die_has_flex_array() helper

From: Google

Date: Wed Sep 16 2026 - 10:17:54 EST


On Mon, 14 Sep 2026 22:54:19 -0700
Namhyung Kim <namhyung@xxxxxxxxxx> wrote:

> > > +
> > > + do {
> > > + if (dwarf_tag(&die_mem) != DW_TAG_member)
> > > + continue;
> >
> > If the member is a "const" member, you may have to use
> > die_get_real_type() to get the actual type.
> > (in this case, you need a cursor DIE for dwarf_siblingof())
>
> Doesn't it belong to a type of the member? In my simple test program,
> it shows the struct type only has children of members and their types
> including const are referenced from the member DIEs.
>
> Also I don't think flexible arrays will be const as they cannot be
> initialized.

Ah, indeed. flex array needs to be initialized. :)

>
> >
> > > +
> > > + if (tag == DW_TAG_union_type) {
> > > + if (is_flex_array_member(&die_mem))
> > > + return true;
> > > +
> > > + if (die_get_real_type(&die_mem, &last_mb) &&
> > > + die_has_flex_array_recurse(&last_mb, depth + 1))
> > > + return true;
> > > + }
> > > +
> > > + if (tag == DW_TAG_structure_type)
> > > + memcpy(&last_mb, &die_mem, sizeof(last_mb));
> >
> > To find the last member, I think you'd better check the
> > DW_AT_data_member_location and DW_AT_decl_line to ensure the
> > DIE is the last member.
>
> Good point. I can add the member location check. I'm afraid decl line
> may be incorrect if compiler randomized the layout.
>
> So far I haven't seen DWARF data having unsorted members (by location),
> but it'd be better to make sure it's sorted.

OK, that maybe enough.

Thanks!


--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>