[Bug lto/104237] [11 Regression] Emitted binary code changes when -g is enabled at -O1 -flto and optimize attribute since r11-3126-ga8f9b4c54cc35062

cnsun at uwaterloo dot ca gcc-bugzilla@gcc.gnu.org
Wed Feb 23 16:03:43 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104237

--- Comment #13 from Chengnian Sun <cnsun at uwaterloo dot ca> ---
(In reply to Jakub Jelinek from comment #10)
> Because -fcompare-debug tells the driver to compile the TU twice, once
> without and once with -gtoggle, and compare the result.
> So, if there is a difference in the generated IL e.g. for -flto
> -ffat-lto-objects, it will detect it.
> Just watch
> gcc -flto -O1 pr104237.c  -o pr104237 -g -fcompare-debug -v 2>&1 | grep
> 'cc1\|lto1'
> to see that, cc1 is invoked twice, once without -gtoggle, once with it, but
> lto1 is invoked just twice, once for wpa and once for ltrans.
> Even if you convince the linker plugin to pass -fcompare-debug even to the
> driver that invokes lto1, that would again compare lto1 with and without -g
> but only
> on a single input (depending on whether the original command line has -g
> with or without debug stmts in it).
> To reproduce this bug, one needs to do a "manual -fcompare-debug", which is
> gcc -flto -O1 pr104237.c  -o pr104237 -g // + force lto1 to pass
> -fdump-final-insns=1
> gcc -flto -O1 pr104237.c  -o pr104237 // + force lto1 to pass
> -fdump-final-insns=2
> diff -up 1 2
> Now, in theory the driver could arrange that, but it would only handle the
> trivial case when the compilation and linking are from the same command.
> Typically with LTO, compilation is done separately and linking is done
> separately, and I don't see how the driver could arrange for that to work,
> we need in that case two sets of *.o files with the IL, one with -g0 and one
> with -g, link twice and compare the result at the end.

Thank you so much for the detailed explanation.


More information about the Gcc-bugs mailing list