]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/cgo, cmd/dist: turn off exc_bad_access handler by default
authorDavid Crawshaw <crawshaw@golang.org>
Thu, 30 Apr 2015 20:38:10 +0000 (16:38 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Fri, 1 May 2015 13:19:39 +0000 (13:19 +0000)
App Store policy requires programs do not reference the exc_server
symbol. (Some public forum threads show that Unity ran into this
several years ago and it is a hard policy rule.) While some research
suggests that I could write my own version of exc_server, the
expedient course is to disable the exception handler by default.

Go programs only need it when running under lldb, which is primarily
used by tests. So enable the exception handler in cmd/dist when we
are running the tests.

Fixes #10646

Change-Id: I853905254894b5367edb8abd381d45585a78ee8b
Reviewed-on: https://go-review.googlesource.com/9549
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/dist/test.go
src/runtime/cgo/gcc_signal_darwin_armx.c
src/runtime/cgo/gcc_signal_darwin_lldb.c

index 6c52693d5b36e4a7e505c96c3ba4bd771087732d..1ed099583e63e1c8e0d7e72065ad6d9e63a03581 100644 (file)
@@ -94,6 +94,29 @@ func (t *tester) run() {
                }
        }
 
+       if t.iOS() {
+               // Install the Mach exception handler used to intercept
+               // EXC_BAD_ACCESS and convert it into a Go panic. This is
+               // necessary for a Go program running under lldb (the way
+               // we run tests). It is disabled by default because iOS
+               // apps are not allowed to access the exc_server symbol.
+               cmd := exec.Command("go", "install", "-a", "-tags", "lldb", "runtime/cgo")
+               cmd.Stdout = os.Stdout
+               cmd.Stderr = os.Stderr
+               if err := cmd.Run(); err != nil {
+                       log.Fatalf("building mach exception handler: %v", err)
+               }
+
+               defer func() {
+                       cmd := exec.Command("go", "install", "-a", "runtime/cgo")
+                       cmd.Stdout = os.Stdout
+                       cmd.Stderr = os.Stderr
+                       if err := cmd.Run(); err != nil {
+                               log.Fatalf("reverting mach exception handler: %v", err)
+                       }
+               }()
+       }
+
        t.timeoutScale = 1
        if t.goarch == "arm" || t.goos == "windows" {
                t.timeoutScale = 2
@@ -350,6 +373,10 @@ func (t *tester) dirCmd(dir string, bin string, args ...string) *exec.Cmd {
        return cmd
 }
 
+func (t *tester) iOS() bool {
+       return t.goos == "darwin" && (t.goarch == "arm" || t.goarch == "arm64")
+}
+
 func (t *tester) out(v string) {
        if t.banner == "" {
                return
@@ -417,8 +444,7 @@ func (t *tester) supportedBuildmode(mode string) bool {
 func (t *tester) cgoTest() error {
        env := mergeEnvLists([]string{"GOTRACEBACK=2"}, os.Environ())
 
-       iOS := t.goos == "darwin" && (t.goarch == "arm" || t.goarch == "arm64")
-       if t.goos == "android" || iOS {
+       if t.goos == "android" || t.iOS() {
                cmd := t.dirCmd("misc/cgo/test", "go", "test")
                cmd.Env = env
                return cmd.Run()
index 9d572acce3dd4b7432840005194e579f00e30b18..e36fe26bb1041fcfe006314e12d5d7b583e16dbd 100644 (file)
 // chance to resolve exceptions before the task handler, so we can generate
 // the panic and avoid lldb's SIGSEGV handler.
 //
-// If you want to debug a segfault under lldb, compile the standard library
-// with the build tag lldb:
-//
-//     go test -tags lldb -installsuffix lldb
+// The dist tool enables this by build flag when testing.
 
-// +build !lldb
+// +build lldb
 // +build darwin
 // +build arm arm64
 
index d3a3dddadd4fe5d65e38341a1e6f18835b9d5204..b26315f10d7a22b9461092c7e1f01db025e429ad 100644 (file)
@@ -2,9 +2,9 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// +build !lldb
 // +build darwin
 // +build arm arm64
-// +build lldb
 
 #include <stdint.h>