https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78835

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The important thing is that it is only possible to refer to a single DIE in the
type unit (.debug.types.* in DWARF4, .debug_info DW_UT_type unit in DWARF5);
in the #c0 case it is the Bar DW_TAG_structure_type, a child of
DW_TAG_unit_type.
If one needs to refer to anything else, the DIE with selected needed children
needs to be copied from the type unit to the compilation unit.
So if you e.g. look at what debug info we generate for:
struct Bar { void Baz (); int i; };
Bar b;
void Foo (Bar &t) { t.Baz (); }
(compile with -g -fdebug-types-section -O2 -dA -gstrict-dwarf, the last option
so that it doesn't ICE), and
struct Bar { void Baz (); static int i; };
int Bar::i = 17;
Bar b;
void Foo (Bar &t) { t.Baz (); }
(compile with -g -fdebug-types-section -O2 -dA), you'll see that in the former
case we don't know about any references to Bar::Baz and everything that needs
Bar only needs Bar itself and thus there is the type unit, the b variable's
DW_AT_type uses DW_FORM_ref_sig8 to refer to the Bar DIE in the type unit and
similarly DW_TAG_reference_type's DW_AT_type (used in t's type).
Without -gstrict-dwarf there is a need for the reference to Bar::Baz that can't
refer to the type unit, but we don't know about that reference during early
debug finish.
Now compare that to the second case.  We need to refer to Bar::i, because we
provide a definition for that.  So there is a skeleton DW_TAG_structure_type in
the compilation unit for Bar type, with DW_AT_signature that says for anything
not mentioned here, refer to the type unit's Bar.  This testcase doesn't ICE
without -gstrict-dwarf.

Reply via email to