https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94235
Bug ID: 94235
Summary: worse debug info with O0 than with O2 with flto
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: debug
Assignee: unassigned at gcc dot gnu.org
Reporter: vries at gcc dot gnu.org
Target Milestone: ---
Consider the following test-case (minimized from
gdb/testsuite/gdb.threads/step-bg-decr-pc-switch-thread.c):
...
$ cat -n test.c
1 int i;
2
3 int
4 main (void)
5 {
6 i++;
7
8 while (1);
9
10 return 0;
11 }
12
...
When compiled normally:
...
$ gcc-10 test.c -g
...
We can run to main, and step once:
...
$ gdb -batch a.out -ex start -ex s
Temporary breakpoint 1 at 0x400496: file test.c, line 6.
Temporary breakpoint 1, main () at test.c:6
6 i++;
8 while (1);
$
...
But if we use -flto -O0:
...
$ gcc-10 test.c -g -flto -O0
...
instead we have:
...
$ gdb -batch a.out -ex start -ex s
Temporary breakpoint 1 at 0x400496: file test.c, line 6.
Temporary breakpoint 1, main () at test.c:6
6 i++;
<hangs>
...
Looking at the differences with objdump -dS, we have normally:
...
0000000000400492 <main>:
int i;
int
main (void)
{
400492: 55 push %rbp
400493: 48 89 e5 mov %rsp,%rbp
i++;
400496: 8b 05 90 0b 20 00 mov 0x200b90(%rip),%eax #
60102c <i>
40049c: 83 c0 01 add $0x1,%eax
40049f: 89 05 87 0b 20 00 mov %eax,0x200b87(%rip) #
60102c <i>
while (1);
4004a5: eb fe jmp 4004a5 <main+0x13>
4004a7: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1)
4004ae: 00 00
...
but with lto there's no line number info for the loop:
...
0000000000400492 <main>:
int i;
int
main (void)
{
400492: 55 push %rbp
400493: 48 89 e5 mov %rsp,%rbp
i++;
400496: 8b 05 90 0b 20 00 mov 0x200b90(%rip),%eax #
60102c <i>
40049c: 83 c0 01 add $0x1,%eax
40049f: 89 05 87 0b 20 00 mov %eax,0x200b87(%rip) #
60102c <i>
4004a5: eb fe jmp 4004a5 <main+0x13>
4004a7: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1)
4004ae: 00 00
...
Amazingly, with -flto -O2, we have:
...
00000000004003c0 <main>:
int i;
int
main (void)
{
i++;
4003c0: 83 05 65 0c 20 00 01 addl $0x1,0x200c65(%rip) #
60102c <i>
while (1);
4003c7: eb fe jmp 4003c7 <main+0x7>
4003c9: 0f 1f 80 00 00 00 00 nopl 0x0(%rax)
...
and:
...
$ gdb -batch a.out -ex start -ex s
Temporary breakpoint 1 at 0x4003c0: file test.c, line 6.
Temporary breakpoint 1, main () at test.c:6
6 i++;
8 while (1);
$
...
Same for O1 as for O2.
For some reason, we have worse debug info with O0 than with O2.