Commit 8ff22ea5 by Ian Lance Taylor

misc/cgo/testcarchive: fix test to work for gccgo

    
    This test is not yet run, but it will be soon.
    
    Reviewed-on: https://go-review.googlesource.com/47038

From-SVN: r249795
parent 1a7ad6ad
8c4d6fd19f6d5dc9b41be384c60507f2236f05ec 12c65e8310956eb3cc412d9dc9f9e88cbd928c8e
The first line of this file holds the git revision number of the last The first line of this file holds the git revision number of the last
merge done from the gofrontend repository. merge done from the gofrontend repository.
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime"
"strings" "strings"
"syscall" "syscall"
"testing" "testing"
...@@ -81,13 +82,17 @@ func init() { ...@@ -81,13 +82,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))
...@@ -149,6 +154,9 @@ func testInstall(t *testing.T, exe, libgoa, libgoh string, buildcmd ...string) { ...@@ -149,6 +154,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)
...@@ -157,7 +165,11 @@ func testInstall(t *testing.T, exe, libgoa, libgoh string, buildcmd ...string) { ...@@ -157,7 +165,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)
} }
...@@ -166,8 +178,13 @@ func testInstall(t *testing.T, exe, libgoa, libgoh string, buildcmd ...string) { ...@@ -166,8 +178,13 @@ func testInstall(t *testing.T, exe, libgoa, libgoh string, buildcmd ...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", "-buildmode=c-archive", "libgo") "go", "install", "-buildmode=c-archive", "libgo")
...@@ -206,6 +223,9 @@ func TestEarlySignalHandler(t *testing.T) { ...@@ -206,6 +223,9 @@ func TestEarlySignalHandler(t *testing.T) {
} }
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)
...@@ -243,6 +263,9 @@ func TestSignalForwarding(t *testing.T) { ...@@ -243,6 +263,9 @@ func TestSignalForwarding(t *testing.T) {
} }
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)
...@@ -293,6 +316,9 @@ func TestSignalForwardingExternal(t *testing.T) { ...@@ -293,6 +316,9 @@ func TestSignalForwardingExternal(t *testing.T) {
} }
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)
...@@ -380,6 +406,9 @@ func TestOsSignal(t *testing.T) { ...@@ -380,6 +406,9 @@ func TestOsSignal(t *testing.T) {
} }
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)
...@@ -412,6 +441,9 @@ func TestSigaltstack(t *testing.T) { ...@@ -412,6 +441,9 @@ func TestSigaltstack(t *testing.T) {
} }
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)
...@@ -436,6 +468,9 @@ func TestExtar(t *testing.T) { ...@@ -436,6 +468,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")
...@@ -489,14 +524,26 @@ func TestPIE(t *testing.T) { ...@@ -489,14 +524,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)
} }
......
...@@ -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