]> Cypherpunks repositories - gostls13.git/commit
cmd/5g, cmd/6g, cmd/8g: fix line number of caller of deferred func
authorRuss Cox <rsc@golang.org>
Fri, 12 Jul 2013 17:47:55 +0000 (13:47 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 12 Jul 2013 17:47:55 +0000 (13:47 -0400)
commit7e97d398795fd91e5ab9637572984291e19de4b9
treec1ad60f70c6290714d2ea9cdb7b9b6edbed5142a
parent031c107cad93174a6e33d3af31c1e3613129ad08
cmd/5g, cmd/6g, cmd/8g: fix line number of caller of deferred func

Deferred functions are not run by a call instruction. They are run by
the runtime editing registers to make the call start with a caller PC
returning to a
        CALL deferreturn
instruction.

That instruction has always had the line number of the function's
closing brace, but that instruction's line number is irrelevant.
Stack traces show the line number of the instruction before the
return PC, because normally that's what started the call. Not so here.
The instruction before the CALL deferreturn could be almost anywhere
in the function; it's unrelated and its line number is incorrect to show.

Fix the line number by inserting a true hardware no-op with the right
line number before the returned-to CALL instruction. That is, the deferred
calls now appear to start with a caller PC returning to the second instruction
in this sequence:
        NOP
        CALL deferreturn

The traceback will show the line number of the NOP, which we've set
to be the line number of the function's closing brace.

The NOP here is not the usual pseudo-instruction, which would be
elided by the linker. Instead it is the real hardware instruction:
XCHG AX, AX on 386 and amd64, and AND.EQ R0, R0, R0 on ARM.

Fixes #5856.

R=ken2, ken
CC=golang-dev
https://golang.org/cl/11223043
src/cmd/5g/ggen.c
src/cmd/6g/ggen.c
src/cmd/8g/ggen.c
test/fixedbugs/issue5856.go [new file with mode: 0644]