This fixes inconsistencies with respect to computing DIE sizes and abbrevs when using -fdebug-types-section and LTO where we have external refs that are _not_ refs to comdat_type_p's. output_die gets this correct but both size_of_die and value_format simply key on use_debug_types which causes the LTO external refs to the early debug represented as type signatures for DIE size accounting and in the abbrev while then actually being output correctly. This obviously corrupts the DWARF quite a bit.
Fixed by doing what output_die does, check AT_ref (a)->comdat_type_p instead of use_debug_types. Bootstrap and regtest running on x86_64-unknown-linux-gnu. There's no way to scan ltrans assembly so no testcase. I've refrained from "ignoring" -fdebug-types-section for the late debug (where it doesn't make any sense), the above inconsistency warrants fixing anyway. But a followup could adjust the use_debug_types #define to include && !in_lto_p like I did for want_pubnames. Richard. 2019-02-27 Richard Biener <rguent...@suse.de> PR debug/89514 * dwarf2out.c (size_of_die): Key on AT_ref (a)->comdat_type_p rather than on use_debug_types, doing what output_die does. (value_format): Likewise. Index: gcc/dwarf2out.c =================================================================== --- gcc/dwarf2out.c (revision 269204) +++ gcc/dwarf2out.c (working copy) @@ -9425,7 +9425,7 @@ size_of_die (dw_die_ref die) we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr is sized by target address length, whereas in DWARF3 it's always sized as an offset. */ - if (use_debug_types) + if (AT_ref (a)->comdat_type_p) size += DWARF_TYPE_SIGNATURE_SIZE; else if (dwarf_version == 2) size += DWARF2_ADDR_SIZE; @@ -9869,7 +9869,12 @@ value_format (dw_attr_node *a) return DW_FORM_flag; case dw_val_class_die_ref: if (AT_ref_external (a)) - return use_debug_types ? DW_FORM_ref_sig8 : DW_FORM_ref_addr; + { + if (AT_ref (a)->comdat_type_p) + return DW_FORM_ref_sig8; + else + return DW_FORM_ref_addr; + } else return DW_FORM_ref; case dw_val_class_fde_ref: