The following fixes PR81940 by allowing the case of missing early debug due to compiling with -g0 and linking with -g when using LTO.
Committed as obvious. If more intricate issues like this keep popping up another solution is to record whether -g0 was in effect at compile-time and override -g at link-time with that on a per function (and variable?) basis. Richard. 2017-08-23 Richard Biener <rguent...@suse.de> PR lto/81940 * dwarf2out.c (dwarf2out_abstract_function): Handle LTO with -g0 at compile-time. * g++.dg/lto/pr81940_0.C: New testcase. Index: gcc/dwarf2out.c =================================================================== --- gcc/dwarf2out.c (revision 251275) +++ gcc/dwarf2out.c (working copy) @@ -21609,7 +21578,10 @@ dwarf2out_abstract_function (tree decl) return; old_die = lookup_decl_die (decl); - /* With early debug we always have an old DIE. */ + /* With early debug we always have an old DIE unless we are in LTO + and the user did not compile but only link with debug. */ + if (in_lto_p && ! old_die) + return; gcc_assert (old_die != NULL); if (get_AT (old_die, DW_AT_inline) || get_AT (old_die, DW_AT_abstract_origin)) Index: gcc/testsuite/g++.dg/lto/pr81940_0.C =================================================================== --- gcc/testsuite/g++.dg/lto/pr81940_0.C (nonexistent) +++ gcc/testsuite/g++.dg/lto/pr81940_0.C (working copy) @@ -0,0 +1,5 @@ +// { dg-lto-do link } +// { dg-lto-options { { -O -flto } } } +// { dg-extra-ld-options "-r -nostdlib -g" } + +int a, b = a;