Commit 0829e1b7 authored by Ian Lance Taylor's avatar Ian Lance Taylor

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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent cd7cb86d
...@@ -14,6 +14,7 @@ import ( ...@@ -14,6 +14,7 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"regexp" "regexp"
"runtime"
"strings" "strings"
"syscall" "syscall"
"testing" "testing"
...@@ -83,13 +84,17 @@ func init() { ...@@ -83,13 +84,17 @@ func init() {
cc = append(cc, []string{"-framework", "CoreFoundation", "-framework", "Foundation"}...) cc = append(cc, []string{"-framework", "CoreFoundation", "-framework", "Foundation"}...)
} }
libgodir = GOOS + "_" + GOARCH libgodir = GOOS + "_" + GOARCH
switch GOOS { if runtime.Compiler == "gccgo" {
case "darwin": libgodir = "gccgo_" + libgodir + "_fPIC"
if GOARCH == "arm" || GOARCH == "arm64" { } else {
switch GOOS {
case "darwin":
if GOARCH == "arm" || GOARCH == "arm64" {
libgodir += "_shared"
}
case "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "solaris":
libgodir += "_shared" libgodir += "_shared"
} }
case "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "solaris":
libgodir += "_shared"
} }
cc = append(cc, "-I", filepath.Join("pkg", libgodir)) cc = append(cc, "-I", filepath.Join("pkg", libgodir))
...@@ -155,6 +160,9 @@ func testInstall(t *testing.T, exe, libgoa, libgoh string, buildcmd ...string) { ...@@ -155,6 +160,9 @@ func testInstall(t *testing.T, exe, libgoa, libgoh string, buildcmd ...string) {
} else { } else {
ccArgs = append(ccArgs, "main_unix.c", libgoa) ccArgs = append(ccArgs, "main_unix.c", libgoa)
} }
if runtime.Compiler == "gccgo" {
ccArgs = append(ccArgs, "-lgo")
}
t.Log(ccArgs) t.Log(ccArgs)
if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil { if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
t.Logf("%s", out) t.Logf("%s", out)
...@@ -163,7 +171,11 @@ func testInstall(t *testing.T, exe, libgoa, libgoh string, buildcmd ...string) { ...@@ -163,7 +171,11 @@ func testInstall(t *testing.T, exe, libgoa, libgoh string, buildcmd ...string) {
defer os.Remove(exe) defer os.Remove(exe)
binArgs := append(cmdToRun(exe), "arg1", "arg2") 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.Logf("%s", out)
t.Fatal(err) t.Fatal(err)
} }
...@@ -194,8 +206,13 @@ func checkLineComments(t *testing.T, hdrname string) { ...@@ -194,8 +206,13 @@ func checkLineComments(t *testing.T, hdrname string) {
func TestInstall(t *testing.T) { func TestInstall(t *testing.T) {
defer os.RemoveAll("pkg") defer os.RemoveAll("pkg")
libgoa := "libgo.a"
if runtime.Compiler == "gccgo" {
libgoa = "liblibgo.a"
}
testInstall(t, "./testp1"+exeSuffix, testInstall(t, "./testp1"+exeSuffix,
filepath.Join("pkg", libgodir, "libgo.a"), filepath.Join("pkg", libgodir, libgoa),
filepath.Join("pkg", libgodir, "libgo.h"), filepath.Join("pkg", libgodir, "libgo.h"),
"go", "install", "-i", "-buildmode=c-archive", "libgo") "go", "install", "-i", "-buildmode=c-archive", "libgo")
...@@ -235,6 +252,9 @@ func TestEarlySignalHandler(t *testing.T) { ...@@ -235,6 +252,9 @@ func TestEarlySignalHandler(t *testing.T) {
checkLineComments(t, "libgo2.h") checkLineComments(t, "libgo2.h")
ccArgs := append(cc, "-o", "testp"+exeSuffix, "main2.c", "libgo2.a") 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 { if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
t.Logf("%s", out) t.Logf("%s", out)
t.Fatal(err) t.Fatal(err)
...@@ -265,6 +285,9 @@ func TestSignalForwarding(t *testing.T) { ...@@ -265,6 +285,9 @@ func TestSignalForwarding(t *testing.T) {
checkLineComments(t, "libgo2.h") checkLineComments(t, "libgo2.h")
ccArgs := append(cc, "-o", "testp"+exeSuffix, "main5.c", "libgo2.a") 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 { if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
t.Logf("%s", out) t.Logf("%s", out)
t.Fatal(err) t.Fatal(err)
...@@ -306,6 +329,9 @@ func TestSignalForwardingExternal(t *testing.T) { ...@@ -306,6 +329,9 @@ func TestSignalForwardingExternal(t *testing.T) {
checkLineComments(t, "libgo2.h") checkLineComments(t, "libgo2.h")
ccArgs := append(cc, "-o", "testp"+exeSuffix, "main5.c", "libgo2.a") 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 { if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
t.Logf("%s", out) t.Logf("%s", out)
t.Fatal(err) t.Fatal(err)
...@@ -419,6 +445,9 @@ func TestOsSignal(t *testing.T) { ...@@ -419,6 +445,9 @@ func TestOsSignal(t *testing.T) {
checkLineComments(t, "libgo3.h") checkLineComments(t, "libgo3.h")
ccArgs := append(cc, "-o", "testp"+exeSuffix, "main3.c", "libgo3.a") 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 { if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
t.Logf("%s", out) t.Logf("%s", out)
t.Fatal(err) t.Fatal(err)
...@@ -452,6 +481,9 @@ func TestSigaltstack(t *testing.T) { ...@@ -452,6 +481,9 @@ func TestSigaltstack(t *testing.T) {
checkLineComments(t, "libgo4.h") checkLineComments(t, "libgo4.h")
ccArgs := append(cc, "-o", "testp"+exeSuffix, "main4.c", "libgo4.a") 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 { if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
t.Logf("%s", out) t.Logf("%s", out)
t.Fatal(err) t.Fatal(err)
...@@ -476,6 +508,9 @@ func TestExtar(t *testing.T) { ...@@ -476,6 +508,9 @@ func TestExtar(t *testing.T) {
case "windows": case "windows":
t.Skip("skipping signal test on Windows") t.Skip("skipping signal test on Windows")
} }
if runtime.Compiler == "gccgo" {
t.Skip("skipping -extar test when using gccgo")
}
defer func() { defer func() {
os.Remove("libgo4.a") os.Remove("libgo4.a")
...@@ -530,14 +565,26 @@ func TestPIE(t *testing.T) { ...@@ -530,14 +565,26 @@ func TestPIE(t *testing.T) {
t.Fatal(err) 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 { if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
t.Logf("%s", out) t.Logf("%s", out)
t.Fatal(err) t.Fatal(err)
} }
binArgs := append(bin, "arg1", "arg2") 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.Logf("%s", out)
t.Fatal(err) t.Fatal(err)
} }
...@@ -605,6 +652,9 @@ func TestSIGPROF(t *testing.T) { ...@@ -605,6 +652,9 @@ func TestSIGPROF(t *testing.T) {
checkLineComments(t, "libgo6.h") checkLineComments(t, "libgo6.h")
ccArgs := append(cc, "-o", "testp6"+exeSuffix, "main6.c", "libgo6.a") 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 { if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
t.Logf("%s", out) t.Logf("%s", out)
t.Fatal(err) t.Fatal(err)
...@@ -648,6 +698,9 @@ func TestCompileWithoutShared(t *testing.T) { ...@@ -648,6 +698,9 @@ func TestCompileWithoutShared(t *testing.T) {
// In some cases, -no-pie is needed here, but not accepted everywhere. First try // In some cases, -no-pie is needed here, but not accepted everywhere. First try
// if -no-pie is accepted. See #22126. // if -no-pie is accepted. See #22126.
ccArgs := append(cc, "-o", exe, "-no-pie", "main5.c", "libgo2.a") ccArgs := append(cc, "-o", exe, "-no-pie", "main5.c", "libgo2.a")
if runtime.Compiler == "gccgo" {
ccArgs = append(ccArgs, "-lgo")
}
t.Log(ccArgs) t.Log(ccArgs)
out, err = exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput() out, err = exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput()
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <signal.h> #include <signal.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
struct sigaction sa; struct sigaction sa;
...@@ -30,7 +31,12 @@ int install_handler() { ...@@ -30,7 +31,12 @@ int install_handler() {
perror("sigaction"); perror("sigaction");
return 2; 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"); fprintf(stderr, "Go runtime did not install signal handler\n");
return 2; return 2;
} }
......
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