https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94469
--- Comment #17 from Richard Biener <rguenth at gcc dot gnu.org> --- Created attachment 48241 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48241&action=edit patch for the DW_AT_declaration idea So this is a patch implementing DW_AT_declaration + DW_AT_specification for globals (it's against GCC 9 but I expect it to apply to trunk as well). Are there any other than DW_TAG_variable that are instantiations and where an instance with a DW_AT_abstract_origin is another instantiation? On the GCC side CONST_DECLs might qualify (but we only handle those for fortran, ada and D) which on the DWARF side would be DW_TAG_constant. The interesting bit will be to get + if (TREE_CODE (decl) == VAR_DECL + && TREE_STATIC (decl) + && DECL_FILE_SCOPE_P (decl)) and the scope based check + /* What about class local statics? What about function local + statics? */ + if (!is_unit_die (die) + && die->die_tag != DW_TAG_namespace) in sync so that DW_AT_declaration and DW_AT_specification will match up (at least a DW_AT_specification of sth not a DW_AT_declaration is invalid DWARF, likelwise declaration with locations). The above for sure isn't foolproof here. If we avoid undoing the "declarazation" until after LTO streaming we could add checking to dwarf2out_die_ref_for_decl. The question is also which (DWARF) contexts suffer from the multiple instantiation issue as the comment notes. The dwarf2out data structures don't give us the back mapping of DIE -> decl. The patch works on the testcases we have discussed sofar, test coverage for other cases (variables in namespaces, class local statics, function local statics) would need to be added.