https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91772
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|WAITING |ASSIGNED Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot gnu.org --- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> --- OK, so this happens when the DIE was not created early (due to -g1) then we do /* We may have to generate early debug late for LTO in case debug was not enabled at compile-time or the target doesn't support the LTO early debug scheme. */ if (! die && in_lto_p) { dwarf2out_decl (decl); die = lookup_decl_die (decl); } where dwarf2out_decl already adds a DW_AT_location attribute. Then we fall through to if (die) { /* We get called via the symtab code invoking late_global_decl for symbols that are optimized out. Do not add locations for those, except if they have a DECL_VALUE_EXPR, in which case they are relevant for debuggers. Still don't add a location if the DECL_VALUE_EXPR is not a trivial INDIRECT_REF expression, as this could generate relocations to text symbols in LTO object files, which is invalid. */ varpool_node *node = varpool_node::get (decl); if ((! node || ! node->definition) && ! (DECL_HAS_VALUE_EXPR_P (decl) && is_trivial_indirect_ref (DECL_VALUE_EXPR (decl)))) tree_add_const_value_attribute_for_decl (die, decl); else add_location_or_const_value_attribute (die, decl, false); } obviously above we're not only creating "early" debug. It seems obvious to me that we want to skip the later code which is intended for early dwarf only.