https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128929
Bug ID: 128929
Summary: DW_AT_call_return_pc points into the delay slot of a
call
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: wrong-debug
Severity: normal
Priority: P3
Component: debug
Assignee: unassigned at gcc dot gnu.org
Reporter: stian at itx dot no
CC: ebotcazou at gcc dot gnu.org, jakub at gcc dot gnu.org
Target Milestone: ---
Target: sparc64-unknown-linux-gnu
Background:
I've been running the GCC (master) tests on sparc to find failures that
are caused by real bugs in GCC. My goal is to pass as many tests as
possible to catch existing bugs, and to prevent future regressions on
sparc. Some tests that fail on sparc also fail on x86 (not sparc
specific, so not my focus here), some are wrong assumptions in the
tests themselves (big vs little endian etc).
This issue looks like a real bug, though, since GCC 8:
When the delay slot of a call is filled, the call site label ends up
between the call and its delay slot. DW_AT_call_return_pc is then 4
bytes short of the real return address, gdb can't find the call site,
and entry values don't work.
cs.c:
volatile int v;
__attribute__((noipa)) void bar (void) { v = 0; }
__attribute__((noipa)) void foo (int x) { bar (); v = 1; }
int main (void) { foo (42); v = 2; return 0; }
$ gcc -O2 -g -S cs.c
call foo, 0
.LVL3:
mov 42, %o0
$ gcc -O2 -g cs.c
$ objdump -d a.out | grep -A1 'call.*<foo>'
5c4: 40 00 00 7b call 7b0 <foo>
5c8: 90 10 20 2a mov 0x2a, %o0
$ readelf --debug-dump=info a.out | grep call_return_pc
<72> DW_AT_call_return_pc: 0x5c8
The return address is 0x5cc. In gdb (18.1):
(gdb) break bar
(gdb) run
(gdb) up
(gdb) set debug entry-values 1
(gdb) print x@entry
DW_OP_entry_value resolving cannot find DW_TAG_call_site 0x100000005cc in main
This shows up in the guality failures on sparc64-linux, but not on
x86_64 (same gdb on both). It accounts for 131 failing checks in 10
gcc.dg/guality files, e.g. pr68860-1.c, pr36728-1.c, pr43177.c.
It's a regression from GCC 8. GCC 7.5 puts the label after the delay
slot, 8.1 puts it before (noinline, noclone for 7.5, which has no noipa):
7.5: call foo, 0 / mov 42, %o0 / .LVL3:
8.1: call foo, 0 / .LVL3: / mov 42, %o0
In 7 the label came from NOTE_INSN_CALL_ARG_LOCATION, which sat after
the SEQUENCE. The PR target/84146 change (r257826) replaced that note
with REG_CALL_ARG_LOCATION on the call itself, so the label is now
emitted while the call is output, inside the SEQUENCE. hppa, sh,
microblaze and mips -mno-abicalls (cross cc1) place it the same way.
The cause seems to be in final_scan_insn_1. For a SEQUENCE it scans the
call first, and debug_hooks->var_location for the call runs at the end
of that scan, before the delay slot insns are output. With an empty
slot the call prints its own nop and the label is right. Calling the
hook after the delay slots instead fixes the label for me, and those
checks pass.