llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[DWARF] Inefficiency with retained pointer types and type units

Open OCHyams opened this issue 4 years ago • 1 comments

Retained types that are pointers to a type that can be emitted as a type unit and are not referenced in the CU don't need a skeleton CU DIE, but currently do get one.

Split from discussion on D115325 for PR51087.

target x86_64-unknown-linux-gnu using clang built at 54586582d3e1 (17th Dec 2021)

$ cat test.cpp
struct O { struct S { int x; } y; };
int f(void *p) {
  return static_cast<O::S*>(p)->x;
}

$ clang++ test.cpp -c -gdwarf-5 -fdebug-types-section -o - | llvm-dwarfdump - -o -
<snip>
<Type Unit for O:>
0x00000000: Type Unit: length = 0x00000026, format = DWARF32, version = 0x0005, unit_type = DW_UT_type, abbr_offset = 0x0000, addr_size = 0x08, name = 'O', type_signature = 0x9ff533511b48ced2, type_offset = 0x0023 (next unit at 0x0000002a)
<snip>
<Type Unit for S:>
0x00000000: Type Unit: length = 0x0000003e, format = DWARF32, version = 0x0005, unit_type = DW_UT_type, abbr_offset = 0x0000, addr_size = 0x08, name = 'S', type_signature = 0x7b36f109e857d200, type_offset = 0x002c (next unit at 0x00000042)
<snip>
<Compile Unit:>
0x0000003f:   DW_TAG_pointer_type
                DW_AT_type	(0x0000004d "O::S")

0x00000044:   DW_TAG_structure_type
                DW_AT_declaration	(true)
                DW_AT_signature	(0x9ff533511b48ced2)

0x0000004d:     DW_TAG_structure_type
                  DW_AT_declaration	(true)
                  DW_AT_signature	(0x7b36f109e857d200)
<snip>

DIE 0x0000003f is not referenced in the CU. Consumers should be able to build non-user-defined types (e.g. a pointer to user-defined-type) so if we emit a type unit for the type - as we do in this example - we don't need the CU DIE; it could be omitted.

OCHyams avatar Dec 17 '21 15:12 OCHyams

Yeah, I /tend/ to think the right solution is that frontends should decompose the type and only add the user defined types to the retained types list. But I realize that's a bunch of work for frontends to do that they don't have to do today...

dwblaikie avatar Dec 18 '21 00:12 dwblaikie