The libbacktrace library returns a PC that was (usually) decremented
to be part of the call instruction.  The Go code that uses
runtime.Callers does not expect this, and Go code that adjusts the PC
value, such as libgo/go/runtime/pprof/pprof.go, can get fooled by it.
This leads to GCC PRs 64999 and 65180.

This patch from Lynn Boger adjusts the PC value so that the Go code
makes the correct adjustments.

Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline and GCC 5 branch.

Ian
diff -r f9a377ea92a9 libgo/runtime/go-callers.c
--- a/libgo/runtime/go-callers.c        Fri Apr 17 11:17:24 2015 -0700
+++ b/libgo/runtime/go-callers.c        Fri Apr 17 11:46:32 2015 -0700
@@ -83,7 +83,20 @@
     }
 
   loc = &arg->locbuf[arg->index];
-  loc->pc = pc;
+
+  /* On the call to backtrace_full the pc value was most likely
+     decremented if there was a normal call, since the pc referred to
+     the instruction where the call returned and not the call itself.
+     This was done so that the line number referred to the call
+     instruction.  To make sure the actual pc from the call stack is
+     used, it is incremented here.
+
+     In the case of a signal, the pc was not decremented by
+     backtrace_full but still incremented here.  That doesn't really
+     hurt anything since the line number is right and the pc refers to
+     the same instruction.  */
+
+  loc->pc = pc + 1;
 
   /* The libbacktrace library says that these strings might disappear,
      but with the current implementation they won't.  We can't easily

Reply via email to