Commit 467a6d28 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

runtime: adopt race detector for runtime written in Go

Ignore memory access on g0/gsignal.
See the issue for context and explanation.
Fixes #8627.

LGTM=khr
R=golang-codereviews, mdempsky, khr
CC=golang-codereviews, rsc
https://golang.org/cl/137070043
parent 56bd176e
...@@ -239,9 +239,7 @@ Assoc: ...@@ -239,9 +239,7 @@ Assoc:
// Reuse the newly evicted entry. // Reuse the newly evicted entry.
e.depth = uintptr(len(pc)) e.depth = uintptr(len(pc))
e.count = 1 e.count = 1
for i := range pc { copy(e.stack[:], pc)
e.stack[i] = pc[i]
}
} }
// evict copies the given entry's data into the log, so that // evict copies the given entry's data into the log, so that
...@@ -266,10 +264,8 @@ func (p *cpuProfile) evict(e *cpuprofEntry) bool { ...@@ -266,10 +264,8 @@ func (p *cpuProfile) evict(e *cpuprofEntry) bool {
q++ q++
log[q] = d log[q] = d
q++ q++
for i := uintptr(0); i < d; i++ { copy(log[q:], e.stack[:d])
log[q] = e.stack[i] q += d
q++
}
p.nlog = q p.nlog = q
e.count = 0 e.count = 0
return true return true
......
...@@ -215,6 +215,10 @@ runtime·main(void) ...@@ -215,6 +215,10 @@ runtime·main(void)
{ {
Defer d; Defer d;
// Racectx of m0->g0 is used only as the parent of the main goroutine.
// It must not be used for anything else.
g->m->g0->racectx = 0;
// Max stack size is 1 GB on 64-bit, 250 MB on 32-bit. // Max stack size is 1 GB on 64-bit, 250 MB on 32-bit.
// Using decimal instead of binary GB and MB because // Using decimal instead of binary GB and MB because
// they look nicer in the stack overflow failure message. // they look nicer in the stack overflow failure message.
...@@ -1166,8 +1170,6 @@ newm(void(*fn)(void), P *p) ...@@ -1166,8 +1170,6 @@ newm(void(*fn)(void), P *p)
mp = runtime·allocm(p); mp = runtime·allocm(p);
mp->nextp = p; mp->nextp = p;
mp->mstartfn = fn; mp->mstartfn = fn;
if(raceenabled)
mp->g0->racectx = runtime·racegostart(newm);
if(runtime·iscgo) { if(runtime·iscgo) {
CgoThreadStart ts; CgoThreadStart ts;
......
...@@ -153,6 +153,11 @@ runtime·racegoend(void) ...@@ -153,6 +153,11 @@ runtime·racegoend(void)
void void
runtime·racewriterangepc(void *addr, uintptr sz, void *callpc, void *pc) runtime·racewriterangepc(void *addr, uintptr sz, void *callpc, void *pc)
{ {
if(g != g->m->curg) {
// The call is coming from manual instrumentation of Go code running on g0/gsignal.
// Not interesting.
return;
}
if(callpc != nil) if(callpc != nil)
runtime·racefuncenter(callpc); runtime·racefuncenter(callpc);
runtime·racewriterangepc1(addr, sz, pc); runtime·racewriterangepc1(addr, sz, pc);
...@@ -163,6 +168,11 @@ runtime·racewriterangepc(void *addr, uintptr sz, void *callpc, void *pc) ...@@ -163,6 +168,11 @@ runtime·racewriterangepc(void *addr, uintptr sz, void *callpc, void *pc)
void void
runtime·racereadrangepc(void *addr, uintptr sz, void *callpc, void *pc) runtime·racereadrangepc(void *addr, uintptr sz, void *callpc, void *pc)
{ {
if(g != g->m->curg) {
// The call is coming from manual instrumentation of Go code running on g0/gsignal.
// Not interesting.
return;
}
if(callpc != nil) if(callpc != nil)
runtime·racefuncenter(callpc); runtime·racefuncenter(callpc);
runtime·racereadrangepc1(addr, sz, pc); runtime·racereadrangepc1(addr, sz, pc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment