summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2017-02-24 15:46:40 -0800
committerIan Lance Taylor <iant@golang.org>2018-08-21 15:03:10 +0000
commit0829e1b757969cc5e22df6c5b5a45cff8f073a38 (patch)
tree40bb9b3adb8c3285155baddf5d59d69275c98ce5 /misc
parentcd7cb86d8e56d28bfe9bd522baa44c95127028d7 (diff)
downloadgo-git-0829e1b757969cc5e22df6c5b5a45cff8f073a38.tar.gz
misc/cgo/testcarchive: make the tests work when using gccgo
Change-Id: I62a7a8ebbbc1f1a266234b53680768da157b2df5 Reviewed-on: https://go-review.googlesource.com/130416 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'misc')
-rw-r--r--misc/cgo/testcarchive/carchive_test.go71
-rw-r--r--misc/cgo/testcarchive/main_unix.c8
2 files changed, 69 insertions, 10 deletions
diff --git a/misc/cgo/testcarchive/carchive_test.go b/misc/cgo/testcarchive/carchive_test.go
index 71232305f6..457ac0db09 100644
--- a/misc/cgo/testcarchive/carchive_test.go
+++ b/misc/cgo/testcarchive/carchive_test.go
@@ -14,6 +14,7 @@ import (
"os/exec"
"path/filepath"
"regexp"
+ "runtime"
"strings"
"syscall"
"testing"
@@ -83,13 +84,17 @@ func init() {
cc = append(cc, []string{"-framework", "CoreFoundation", "-framework", "Foundation"}...)
}
libgodir = GOOS + "_" + GOARCH
- switch GOOS {
- case "darwin":
- if GOARCH == "arm" || GOARCH == "arm64" {
+ if runtime.Compiler == "gccgo" {
+ libgodir = "gccgo_" + libgodir + "_fPIC"
+ } else {
+ switch GOOS {
+ case "darwin":
+ if GOARCH == "arm" || GOARCH == "arm64" {
+ libgodir += "_shared"
+ }
+ case "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "solaris":
libgodir += "_shared"
}
- case "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "solaris":
- libgodir += "_shared"
}
cc = append(cc, "-I", filepath.Join("pkg", libgodir))
@@ -155,6 +160,9 @@ func testInstall(t *testing.T, exe, libgoa, libgoh string, buildcmd ...string) {
} else {
ccArgs = append(ccArgs, "main_unix.c", libgoa)
}
+ if runtime.Compiler == "gccgo" {
+ ccArgs = append(ccArgs, "-lgo")
+ }
t.Log(ccArgs)
if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
t.Logf("%s", out)
@@ -163,7 +171,11 @@ func testInstall(t *testing.T, exe, libgoa, libgoh string, buildcmd ...string) {
defer os.Remove(exe)
binArgs := append(cmdToRun(exe), "arg1", "arg2")
- if out, err := exec.Command(binArgs[0], binArgs[1:]...).CombinedOutput(); err != nil {
+ cmd = exec.Command(binArgs[0], binArgs[1:]...)
+ if runtime.Compiler == "gccgo" {
+ cmd.Env = append(os.Environ(), "GCCGO=1")
+ }
+ if out, err := cmd.CombinedOutput(); err != nil {
t.Logf("%s", out)
t.Fatal(err)
}
@@ -194,8 +206,13 @@ func checkLineComments(t *testing.T, hdrname string) {
func TestInstall(t *testing.T) {
defer os.RemoveAll("pkg")
+ libgoa := "libgo.a"
+ if runtime.Compiler == "gccgo" {
+ libgoa = "liblibgo.a"
+ }
+
testInstall(t, "./testp1"+exeSuffix,
- filepath.Join("pkg", libgodir, "libgo.a"),
+ filepath.Join("pkg", libgodir, libgoa),
filepath.Join("pkg", libgodir, "libgo.h"),
"go", "install", "-i", "-buildmode=c-archive", "libgo")
@@ -235,6 +252,9 @@ func TestEarlySignalHandler(t *testing.T) {
checkLineComments(t, "libgo2.h")
ccArgs := append(cc, "-o", "testp"+exeSuffix, "main2.c", "libgo2.a")
+ if runtime.Compiler == "gccgo" {
+ ccArgs = append(ccArgs, "-lgo")
+ }
if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
t.Logf("%s", out)
t.Fatal(err)
@@ -265,6 +285,9 @@ func TestSignalForwarding(t *testing.T) {
checkLineComments(t, "libgo2.h")
ccArgs := append(cc, "-o", "testp"+exeSuffix, "main5.c", "libgo2.a")
+ if runtime.Compiler == "gccgo" {
+ ccArgs = append(ccArgs, "-lgo")
+ }
if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
t.Logf("%s", out)
t.Fatal(err)
@@ -306,6 +329,9 @@ func TestSignalForwardingExternal(t *testing.T) {
checkLineComments(t, "libgo2.h")
ccArgs := append(cc, "-o", "testp"+exeSuffix, "main5.c", "libgo2.a")
+ if runtime.Compiler == "gccgo" {
+ ccArgs = append(ccArgs, "-lgo")
+ }
if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
t.Logf("%s", out)
t.Fatal(err)
@@ -419,6 +445,9 @@ func TestOsSignal(t *testing.T) {
checkLineComments(t, "libgo3.h")
ccArgs := append(cc, "-o", "testp"+exeSuffix, "main3.c", "libgo3.a")
+ if runtime.Compiler == "gccgo" {
+ ccArgs = append(ccArgs, "-lgo")
+ }
if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
t.Logf("%s", out)
t.Fatal(err)
@@ -452,6 +481,9 @@ func TestSigaltstack(t *testing.T) {
checkLineComments(t, "libgo4.h")
ccArgs := append(cc, "-o", "testp"+exeSuffix, "main4.c", "libgo4.a")
+ if runtime.Compiler == "gccgo" {
+ ccArgs = append(ccArgs, "-lgo")
+ }
if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
t.Logf("%s", out)
t.Fatal(err)
@@ -476,6 +508,9 @@ func TestExtar(t *testing.T) {
case "windows":
t.Skip("skipping signal test on Windows")
}
+ if runtime.Compiler == "gccgo" {
+ t.Skip("skipping -extar test when using gccgo")
+ }
defer func() {
os.Remove("libgo4.a")
@@ -530,14 +565,26 @@ func TestPIE(t *testing.T) {
t.Fatal(err)
}
- ccArgs := append(cc, "-fPIE", "-pie", "-o", "testp"+exeSuffix, "main.c", "main_unix.c", filepath.Join("pkg", libgodir, "libgo.a"))
+ libgoa := "libgo.a"
+ if runtime.Compiler == "gccgo" {
+ libgoa = "liblibgo.a"
+ }
+
+ ccArgs := append(cc, "-fPIE", "-pie", "-o", "testp"+exeSuffix, "main.c", "main_unix.c", filepath.Join("pkg", libgodir, libgoa))
+ if runtime.Compiler == "gccgo" {
+ ccArgs = append(ccArgs, "-lgo")
+ }
if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
t.Logf("%s", out)
t.Fatal(err)
}
binArgs := append(bin, "arg1", "arg2")
- if out, err := exec.Command(binArgs[0], binArgs[1:]...).CombinedOutput(); err != nil {
+ cmd = exec.Command(binArgs[0], binArgs[1:]...)
+ if runtime.Compiler == "gccgo" {
+ cmd.Env = append(os.Environ(), "GCCGO=1")
+ }
+ if out, err := cmd.CombinedOutput(); err != nil {
t.Logf("%s", out)
t.Fatal(err)
}
@@ -605,6 +652,9 @@ func TestSIGPROF(t *testing.T) {
checkLineComments(t, "libgo6.h")
ccArgs := append(cc, "-o", "testp6"+exeSuffix, "main6.c", "libgo6.a")
+ if runtime.Compiler == "gccgo" {
+ ccArgs = append(ccArgs, "-lgo")
+ }
if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
t.Logf("%s", out)
t.Fatal(err)
@@ -648,6 +698,9 @@ func TestCompileWithoutShared(t *testing.T) {
// In some cases, -no-pie is needed here, but not accepted everywhere. First try
// if -no-pie is accepted. See #22126.
ccArgs := append(cc, "-o", exe, "-no-pie", "main5.c", "libgo2.a")
+ if runtime.Compiler == "gccgo" {
+ ccArgs = append(ccArgs, "-lgo")
+ }
t.Log(ccArgs)
out, err = exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput()
diff --git a/misc/cgo/testcarchive/main_unix.c b/misc/cgo/testcarchive/main_unix.c
index 4d9d16f03b..b23ac1c242 100644
--- a/misc/cgo/testcarchive/main_unix.c
+++ b/misc/cgo/testcarchive/main_unix.c
@@ -5,6 +5,7 @@
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
struct sigaction sa;
@@ -30,7 +31,12 @@ int install_handler() {
perror("sigaction");
return 2;
}
- if (osa.sa_handler == SIG_DFL || (osa.sa_flags&SA_ONSTACK) == 0) {
+ if (osa.sa_handler == SIG_DFL) {
+ fprintf(stderr, "Go runtime did not install signal handler\n");
+ return 2;
+ }
+ // gccgo does not set SA_ONSTACK for SIGSEGV.
+ if (getenv("GCCGO") == "" && (osa.sa_flags&SA_ONSTACK) == 0) {
fprintf(stderr, "Go runtime did not install signal handler\n");
return 2;
}