]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: adjust program counters in race detector
authorDmitry Vyukov <dvyukov@google.com>
Sat, 14 Feb 2015 12:54:25 +0000 (15:54 +0300)
committerDmitry Vyukov <dvyukov@google.com>
Fri, 20 Feb 2015 18:04:16 +0000 (18:04 +0000)
In most cases we pass return PC to race detector,
and race runtime subtracts one from them.
However, in manual instrumentation in runtime
we pass function start PC to race runtime.
Race runtime can't distinguish these cases
and so it does not subtract one from top PC.
This leads to bogus line numbers in some cases.
Make it consistent and always pass what looks
like a return PC, so that race runtime can
subtract one and still get PC in the same function.

Also delete two unused functions.

Update #8053

Change-Id: I4242dec5e055e460c9a8990eaca1d085ae240ed2
Reviewed-on: https://go-review.googlesource.com/4902
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/race.go
src/runtime/race1.go
src/runtime/race_amd64.s

index e7703ba770b94e6b93310a1fd7f9eb6890ef65d3..923d6113f685e4d6c5b96aa30a2822a7fa109c96 100644 (file)
@@ -23,6 +23,9 @@ func RaceSemrelease(s *uint32)
 // private interface for the runtime
 const raceenabled = true
 
+// For all functions accepting callerpc and pc,
+// callerpc is a return PC of the function that calls this function,
+// pc is start PC of the function that calls this function.
 func raceReadObjectPC(t *_type, addr unsafe.Pointer, callerpc, pc uintptr) {
        kind := t.kind & kindMask
        if kind == kindArray || kind == kindStruct {
index 41f4938e876e13e32a9138f633f2a2a541664f20..4c14d84746eda46471580e227606d16b5bcdecee 100644 (file)
@@ -226,26 +226,6 @@ func racereadrangepc(addr unsafe.Pointer, sz, callpc, pc uintptr) {
        }
 }
 
-//go:nosplit
-func racewriteobjectpc(addr unsafe.Pointer, t *_type, callpc, pc uintptr) {
-       kind := t.kind & _KindMask
-       if kind == _KindArray || kind == _KindStruct {
-               racewriterangepc(addr, t.size, callpc, pc)
-       } else {
-               racewritepc(addr, callpc, pc)
-       }
-}
-
-//go:nosplit
-func racereadobjectpc(addr unsafe.Pointer, t *_type, callpc, pc uintptr) {
-       kind := t.kind & _KindMask
-       if kind == _KindArray || kind == _KindStruct {
-               racereadrangepc(addr, t.size, callpc, pc)
-       } else {
-               racereadpc(addr, callpc, pc)
-       }
-}
-
 //go:nosplit
 func raceacquire(addr unsafe.Pointer) {
        raceacquireg(getg(), addr)
index 267cd6cec4a79767f537662c9f0840bb1636c225..d9e674b61f558dba18b79b4d2c50706d4a88a88c 100644 (file)
@@ -58,6 +58,7 @@ TEXT  runtime·racereadpc(SB), NOSPLIT, $0-24
        MOVQ    addr+0(FP), RARG1
        MOVQ    callpc+8(FP), RARG2
        MOVQ    pc+16(FP), RARG3
+       ADDQ    $1, RARG3 // pc is function start, tsan wants return address
        // void __tsan_read_pc(ThreadState *thr, void *addr, void *callpc, void *pc);
        MOVQ    $__tsan_read_pc(SB), AX
        JMP     racecalladdr<>(SB)
@@ -81,6 +82,7 @@ TEXT  runtime·racewritepc(SB), NOSPLIT, $0-24
        MOVQ    addr+0(FP), RARG1
        MOVQ    callpc+8(FP), RARG2
        MOVQ    pc+16(FP), RARG3
+       ADDQ    $1, RARG3 // pc is function start, tsan wants return address
        // void __tsan_write_pc(ThreadState *thr, void *addr, void *callpc, void *pc);
        MOVQ    $__tsan_write_pc(SB), AX
        JMP     racecalladdr<>(SB)
@@ -105,6 +107,7 @@ TEXT        runtime·racereadrangepc1(SB), NOSPLIT, $0-24
        MOVQ    addr+0(FP), RARG1
        MOVQ    size+8(FP), RARG2
        MOVQ    pc+16(FP), RARG3
+       ADDQ    $1, RARG3 // pc is function start, tsan wants return address
        // void __tsan_read_range(ThreadState *thr, void *addr, uintptr size, void *pc);
        MOVQ    $__tsan_read_range(SB), AX
        JMP     racecalladdr<>(SB)
@@ -129,6 +132,7 @@ TEXT        runtime·racewriterangepc1(SB), NOSPLIT, $0-24
        MOVQ    addr+0(FP), RARG1
        MOVQ    size+8(FP), RARG2
        MOVQ    pc+16(FP), RARG3
+       ADDQ    $1, RARG3 // pc is function start, tsan wants return address
        // void __tsan_write_range(ThreadState *thr, void *addr, uintptr size, void *pc);
        MOVQ    $__tsan_write_range(SB), AX
        JMP     racecalladdr<>(SB)