aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/crash_cgo_test.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2016-09-21 09:44:40 -0700
committerIan Lance Taylor <iant@golang.org>2016-09-22 23:37:17 +0000
commit9d8522fdc72ecc8eaa2d318a2cc04abde9beeb42 (patch)
treee528995a166f8b6ae8140f3fe4d2150e5a1f1085 /src/runtime/crash_cgo_test.go
parent88d2f9112a0a8afd3a29ac1479d4f17847f16803 (diff)
downloadgo-9d8522fdc72ecc8eaa2d318a2cc04abde9beeb42.tar.gz
go-9d8522fdc72ecc8eaa2d318a2cc04abde9beeb42.zip
cmd/compile: don't instrument copy and append in runtime
Instrumenting copy and append for the race detector changes them to call different functions. In the runtime package the alternate functions are not marked as nosplit. This caused a crash in the SIGPROF handler when invoked on a non-Go thread in a program built with the race detector. In some cases the handler can call copy, the race detector changed that to a call to a non-nosplit function, the function tried to check the stack guard, and crashed because it was running on a non-Go thread. The SIGPROF handler is written carefully to avoid such problems, but hidden function calls are difficult to avoid. Fix this by changing the compiler to not instrument copy and append when compiling the runtime package. Change the runtime package to add explicit race checks for the only code I could find where copy is used to write to user data (append is never used). Change-Id: I11078a66c0aaa459a7d2b827b49f4147922050af Reviewed-on: https://go-review.googlesource.com/29472 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Diffstat (limited to 'src/runtime/crash_cgo_test.go')
-rw-r--r--src/runtime/crash_cgo_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/runtime/crash_cgo_test.go b/src/runtime/crash_cgo_test.go
index 3de07280de..1e509c113a 100644
--- a/src/runtime/crash_cgo_test.go
+++ b/src/runtime/crash_cgo_test.go
@@ -291,3 +291,31 @@ func TestCgoPprofPIE(t *testing.T) {
func TestCgoPprofThread(t *testing.T) {
testCgoPprof(t, "", "CgoPprofThread")
}
+
+func TestRaceProf(t *testing.T) {
+ if runtime.GOOS != "linux" || runtime.GOARCH != "amd64" {
+ t.Skipf("not yet supported on %s/%s", runtime.GOOS, runtime.GOARCH)
+ }
+
+ testenv.MustHaveGoRun(t)
+
+ // This test requires building various packages with -race, so
+ // it's somewhat slow.
+ if testing.Short() {
+ t.Skip("skipping test in -short mode")
+ }
+
+ exe, err := buildTestProg(t, "testprogcgo", "-race")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ got, err := testEnv(exec.Command(exe, "CgoRaceprof")).CombinedOutput()
+ if err != nil {
+ t.Fatal(err)
+ }
+ want := "OK\n"
+ if string(got) != want {
+ t.Errorf("expected %q got %s", want, got)
+ }
+}