aboutsummaryrefslogtreecommitdiff
path: root/libgo/misc
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2018-09-24 21:46:21 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2018-09-24 21:46:21 +0000
commitdd931d9b48647e898dc80927c532ae93cc09e192 (patch)
tree71be2295cd79b8a182f6130611658db8628772d5 /libgo/misc
parent779d8a5ad09b01428726ea5a0e6c87bd9ac3c0e4 (diff)
downloadgcc-dd931d9b48647e898dc80927c532ae93cc09e192.zip
gcc-dd931d9b48647e898dc80927c532ae93cc09e192.tar.gz
gcc-dd931d9b48647e898dc80927c532ae93cc09e192.tar.bz2
libgo: update to Go 1.11
Reviewed-on: https://go-review.googlesource.com/136435 gotools/: * Makefile.am (mostlyclean-local): Run chmod on check-go-dir to make sure it is writable. (check-go-tools): Likewise. (check-vet): Copy internal/objabi to check-vet-dir. * Makefile.in: Rebuild. From-SVN: r264546
Diffstat (limited to 'libgo/misc')
-rw-r--r--libgo/misc/cgo/life/main.go2
-rw-r--r--libgo/misc/cgo/stdio/chain.go2
-rw-r--r--libgo/misc/cgo/stdio/fib.go2
-rw-r--r--libgo/misc/cgo/stdio/hello.go2
-rw-r--r--libgo/misc/cgo/test/basic.go14
-rw-r--r--libgo/misc/cgo/test/cgo_test.go8
-rw-r--r--libgo/misc/cgo/test/issue18146.go8
-rw-r--r--libgo/misc/cgo/test/issue21897.go11
-rw-r--r--libgo/misc/cgo/test/issue21897b.go2
-rw-r--r--libgo/misc/cgo/test/issue23356.go19
-rw-r--r--libgo/misc/cgo/test/issue23555.go11
-rw-r--r--libgo/misc/cgo/test/issue23555a/a.go12
-rw-r--r--libgo/misc/cgo/test/issue23555b/a.go12
-rw-r--r--libgo/misc/cgo/test/issue23720.go22
-rw-r--r--libgo/misc/cgo/test/issue24161_darwin_test.go39
-rw-r--r--libgo/misc/cgo/test/issue24161arg/def.go17
-rw-r--r--libgo/misc/cgo/test/issue24161arg/use.go19
-rw-r--r--libgo/misc/cgo/test/issue24161e0/main.go29
-rw-r--r--libgo/misc/cgo/test/issue24161e1/main.go38
-rw-r--r--libgo/misc/cgo/test/issue24161e2/main.go40
-rw-r--r--libgo/misc/cgo/test/issue24161res/restype.go23
-rw-r--r--libgo/misc/cgo/test/issue24206.go54
-rw-r--r--libgo/misc/cgo/test/issue24206_generic.go13
-rw-r--r--libgo/misc/cgo/test/issue25143.go22
-rw-r--r--libgo/misc/cgo/test/issue26066.go19
-rw-r--r--libgo/misc/cgo/test/issue26213/jni.h29
-rw-r--r--libgo/misc/cgo/test/issue26213/test26213.go46
-rw-r--r--libgo/misc/cgo/test/issue26430.go10
-rw-r--r--libgo/misc/cgo/test/issue26430/a.go13
-rw-r--r--libgo/misc/cgo/test/issue26430/b.go13
-rw-r--r--libgo/misc/cgo/test/issue26517.go23
-rw-r--r--libgo/misc/cgo/test/issue26743.go10
-rw-r--r--libgo/misc/cgo/test/issue26743/a.go11
-rw-r--r--libgo/misc/cgo/test/issue26743/b.go9
-rw-r--r--libgo/misc/cgo/test/issue4029.c2
-rw-r--r--libgo/misc/cgo/test/issue4029.go2
-rw-r--r--libgo/misc/cgo/test/issue4029w.go2
-rw-r--r--libgo/misc/cgo/test/issue9400/asm_arm.s2
-rw-r--r--libgo/misc/cgo/test/issue9400/asm_arm64.s2
-rw-r--r--libgo/misc/cgo/test/issue9400/asm_mipsx.s2
-rw-r--r--libgo/misc/cgo/test/issue9400/stubs.go2
-rw-r--r--libgo/misc/cgo/test/sigprocmask.c21
-rw-r--r--libgo/misc/cgo/test/sigprocmask.go2
-rw-r--r--libgo/misc/cgo/test/test26213.go15
-rw-r--r--libgo/misc/cgo/testcarchive/carchive_test.go36
-rw-r--r--libgo/misc/cgo/testcarchive/main5.c2
-rw-r--r--libgo/misc/cgo/testcarchive/src/libgo3/libgo3.go4
-rw-r--r--libgo/misc/cgo/testcshared/cshared_test.go22
-rw-r--r--libgo/misc/cgo/testcshared/main2.c4
-rw-r--r--libgo/misc/cgo/testgodefs/fieldtypedef.go18
-rw-r--r--libgo/misc/cgo/testgodefs/test.bash2
-rw-r--r--libgo/misc/cgo/testplugin/src/issue25756/main.go52
-rw-r--r--libgo/misc/cgo/testplugin/src/issue25756/plugin/c-life.c56
-rw-r--r--libgo/misc/cgo/testplugin/src/issue25756/plugin/life.go39
-rw-r--r--libgo/misc/cgo/testplugin/src/issue25756/plugin/life.h7
-rw-r--r--libgo/misc/cgo/testplugin/test.bash11
-rw-r--r--libgo/misc/cgo/testsanitizers/cc_test.go5
-rw-r--r--libgo/misc/cgo/testsanitizers/msan_test.go1
-rw-r--r--libgo/misc/cgo/testsanitizers/src/msan6.go72
-rw-r--r--libgo/misc/cgo/testsanitizers/tsan_test.go4
-rw-r--r--libgo/misc/cgo/testshared/shared_test.go6
-rw-r--r--libgo/misc/cgo/testshared/src/depBase/asm.s2
-rw-r--r--libgo/misc/cgo/testshared/src/depBase/dep.go4
-rw-r--r--libgo/misc/cgo/testshared/src/depBase/gccgo.go6
-rw-r--r--libgo/misc/cgo/testshared/src/depBase/stubs.go6
-rw-r--r--libgo/misc/cgo/testshared/src/trivial/trivial.go5
66 files changed, 983 insertions, 37 deletions
diff --git a/libgo/misc/cgo/life/main.go b/libgo/misc/cgo/life/main.go
index 45376fd..145a273b 100644
--- a/libgo/misc/cgo/life/main.go
+++ b/libgo/misc/cgo/life/main.go
@@ -1,4 +1,4 @@
-// cmpout -tags=use_go_run
+// run -tags=use_go_run
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
diff --git a/libgo/misc/cgo/stdio/chain.go b/libgo/misc/cgo/stdio/chain.go
index 0fa813c..cdc3852 100644
--- a/libgo/misc/cgo/stdio/chain.go
+++ b/libgo/misc/cgo/stdio/chain.go
@@ -1,4 +1,4 @@
-// cmpout -tags=use_go_run
+// run -tags=use_go_run
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
diff --git a/libgo/misc/cgo/stdio/fib.go b/libgo/misc/cgo/stdio/fib.go
index 56e3255..58f185c 100644
--- a/libgo/misc/cgo/stdio/fib.go
+++ b/libgo/misc/cgo/stdio/fib.go
@@ -1,4 +1,4 @@
-// cmpout -tags=use_go_run
+// run -tags=use_go_run
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
diff --git a/libgo/misc/cgo/stdio/hello.go b/libgo/misc/cgo/stdio/hello.go
index 63bff4c..56220d3 100644
--- a/libgo/misc/cgo/stdio/hello.go
+++ b/libgo/misc/cgo/stdio/hello.go
@@ -1,4 +1,4 @@
-// cmpout -tags=use_go_run
+// run -tags=use_go_run
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
diff --git a/libgo/misc/cgo/test/basic.go b/libgo/misc/cgo/test/basic.go
index 3ceb4ce..2655a66 100644
--- a/libgo/misc/cgo/test/basic.go
+++ b/libgo/misc/cgo/test/basic.go
@@ -31,6 +31,8 @@ struct S {
int x;
};
+const char *cstr = "abcefghijklmnopqrstuvwxyzABCEFGHIJKLMNOPQRSTUVWXYZ1234567890";
+
extern enum E myConstFunc(struct S* const ctx, int const id, struct S **const filter);
enum E myConstFunc(struct S *const ctx, int const id, struct S **const filter) { return 0; }
@@ -149,6 +151,18 @@ func benchCgoCall(b *testing.B) {
}
}
+var sinkString string
+
+func benchGoString(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ sinkString = C.GoString(C.cstr)
+ }
+ const want = "abcefghijklmnopqrstuvwxyzABCEFGHIJKLMNOPQRSTUVWXYZ1234567890"
+ if sinkString != want {
+ b.Fatalf("%q != %q", sinkString, want)
+ }
+}
+
// Issue 2470.
func testUnsignedInt(t *testing.T) {
a := (int64)(C.UINT32VAL)
diff --git a/libgo/misc/cgo/test/cgo_test.go b/libgo/misc/cgo/test/cgo_test.go
index cfacb9c..ccacc50 100644
--- a/libgo/misc/cgo/test/cgo_test.go
+++ b/libgo/misc/cgo/test/cgo_test.go
@@ -87,5 +87,11 @@ func Test6907(t *testing.T) { test6907(t) }
func Test6907Go(t *testing.T) { test6907Go(t) }
func Test21897(t *testing.T) { test21897(t) }
func Test22906(t *testing.T) { test22906(t) }
+func Test24206(t *testing.T) { test24206(t) }
+func Test25143(t *testing.T) { test25143(t) }
+func Test23356(t *testing.T) { test23356(t) }
+func Test26066(t *testing.T) { test26066(t) }
+func Test26213(t *testing.T) { test26213(t) }
-func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) }
+func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) }
+func BenchmarkGoString(b *testing.B) { benchGoString(b) }
diff --git a/libgo/misc/cgo/test/issue18146.go b/libgo/misc/cgo/test/issue18146.go
index a58aa1b..8b7bb77 100644
--- a/libgo/misc/cgo/test/issue18146.go
+++ b/libgo/misc/cgo/test/issue18146.go
@@ -22,6 +22,10 @@ import (
)
func test18146(t *testing.T) {
+ if testing.Short() {
+ t.Skip("skipping in short mode")
+ }
+
if runtime.GOOS == "darwin" {
t.Skipf("skipping flaky test on %s; see golang.org/issue/18202", runtime.GOOS)
}
@@ -33,10 +37,6 @@ func test18146(t *testing.T) {
attempts := 1000
threads := 4
- if testing.Short() {
- attempts = 100
- }
-
// Restrict the number of attempts based on RLIMIT_NPROC.
// Tediously, RLIMIT_NPROC was left out of the syscall package,
// probably because it is not in POSIX.1, so we define it here.
diff --git a/libgo/misc/cgo/test/issue21897.go b/libgo/misc/cgo/test/issue21897.go
index d13246b..454a141 100644
--- a/libgo/misc/cgo/test/issue21897.go
+++ b/libgo/misc/cgo/test/issue21897.go
@@ -2,7 +2,16 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin,cgo,!internal
+// We skip this test in race mode because, for unknown reasons,
+// linking against CoreFoundation on macOS 10.10 causes mmap to ignore
+// the hint address, which makes the Go allocator incompatible with
+// TSAN. See golang.org/issue/26475.
+//
+// TODO(austin): Once support for macOS 10.10 is dropped, remove the
+// race constraint (and the one in issue21897b.go). See
+// golang.org/issue/26513.
+
+// +build darwin,cgo,!internal,!race
package cgotest
diff --git a/libgo/misc/cgo/test/issue21897b.go b/libgo/misc/cgo/test/issue21897b.go
index 08b5f4d..e143bad 100644
--- a/libgo/misc/cgo/test/issue21897b.go
+++ b/libgo/misc/cgo/test/issue21897b.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build !darwin !cgo internal
+// +build !darwin !cgo internal race
package cgotest
diff --git a/libgo/misc/cgo/test/issue23356.go b/libgo/misc/cgo/test/issue23356.go
new file mode 100644
index 0000000..1c39012
--- /dev/null
+++ b/libgo/misc/cgo/test/issue23356.go
@@ -0,0 +1,19 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package cgotest
+
+// int a(void) { return 5; };
+// int r(void) { return 3; };
+import "C"
+import "testing"
+
+func test23356(t *testing.T) {
+ if got, want := C.a(), C.int(5); got != want {
+ t.Errorf("C.a() == %v, expected %v", got, want)
+ }
+ if got, want := C.r(), C.int(3); got != want {
+ t.Errorf("C.r() == %v, expected %v", got, want)
+ }
+}
diff --git a/libgo/misc/cgo/test/issue23555.go b/libgo/misc/cgo/test/issue23555.go
new file mode 100644
index 0000000..5fa44e6
--- /dev/null
+++ b/libgo/misc/cgo/test/issue23555.go
@@ -0,0 +1,11 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Test that we can have two identical cgo packages in a single binary.
+// No runtime test; just make sure it compiles.
+
+package cgotest
+
+import _ "./issue23555a"
+import _ "./issue23555b"
diff --git a/libgo/misc/cgo/test/issue23555a/a.go b/libgo/misc/cgo/test/issue23555a/a.go
new file mode 100644
index 0000000..cb6626b
--- /dev/null
+++ b/libgo/misc/cgo/test/issue23555a/a.go
@@ -0,0 +1,12 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package issue23555
+
+// #include <stdlib.h>
+import "C"
+
+func X() {
+ C.free(C.malloc(10))
+}
diff --git a/libgo/misc/cgo/test/issue23555b/a.go b/libgo/misc/cgo/test/issue23555b/a.go
new file mode 100644
index 0000000..cb6626b
--- /dev/null
+++ b/libgo/misc/cgo/test/issue23555b/a.go
@@ -0,0 +1,12 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package issue23555
+
+// #include <stdlib.h>
+import "C"
+
+func X() {
+ C.free(C.malloc(10))
+}
diff --git a/libgo/misc/cgo/test/issue23720.go b/libgo/misc/cgo/test/issue23720.go
new file mode 100644
index 0000000..934fff3
--- /dev/null
+++ b/libgo/misc/cgo/test/issue23720.go
@@ -0,0 +1,22 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Test that we can pass compatible typedefs.
+// No runtime test; just make sure it compiles.
+
+package cgotest
+
+/*
+typedef int *issue23720A;
+
+typedef const int *issue23720B;
+
+void issue23720F(issue23720B a) {}
+*/
+import "C"
+
+func Issue23720F() {
+ var x C.issue23720A
+ C.issue23720F(x)
+}
diff --git a/libgo/misc/cgo/test/issue24161_darwin_test.go b/libgo/misc/cgo/test/issue24161_darwin_test.go
new file mode 100644
index 0000000..48072ff
--- /dev/null
+++ b/libgo/misc/cgo/test/issue24161_darwin_test.go
@@ -0,0 +1,39 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// See issue21897.go and golang.org/issue/26475 for why this is
+// skipped in race mode.
+//
+// TODO(austin): Once support for macOS 10.10 is dropped, remove the
+// race constraint. See golang.org/issue/26513.
+
+// +build !race
+
+package cgotest
+
+import (
+ "testing"
+
+ "./issue24161arg"
+ "./issue24161e0"
+ "./issue24161e1"
+ "./issue24161e2"
+ "./issue24161res"
+)
+
+func Test24161Arg(t *testing.T) {
+ issue24161arg.Test(t)
+}
+func Test24161Res(t *testing.T) {
+ issue24161res.Test(t)
+}
+func Test24161Example0(t *testing.T) {
+ issue24161e0.Test(t)
+}
+func Test24161Example1(t *testing.T) {
+ issue24161e1.Test(t)
+}
+func Test24161Example2(t *testing.T) {
+ issue24161e2.Test(t)
+}
diff --git a/libgo/misc/cgo/test/issue24161arg/def.go b/libgo/misc/cgo/test/issue24161arg/def.go
new file mode 100644
index 0000000..d33479a
--- /dev/null
+++ b/libgo/misc/cgo/test/issue24161arg/def.go
@@ -0,0 +1,17 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build darwin
+
+package issue24161arg
+
+/*
+#cgo LDFLAGS: -framework CoreFoundation
+#include <CoreFoundation/CoreFoundation.h>
+*/
+import "C"
+
+func test24161array() C.CFArrayRef {
+ return C.CFArrayCreate(0, nil, 0, nil)
+}
diff --git a/libgo/misc/cgo/test/issue24161arg/use.go b/libgo/misc/cgo/test/issue24161arg/use.go
new file mode 100644
index 0000000..3e74944
--- /dev/null
+++ b/libgo/misc/cgo/test/issue24161arg/use.go
@@ -0,0 +1,19 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build darwin
+
+package issue24161arg
+
+/*
+#cgo LDFLAGS: -framework CoreFoundation
+#include <CoreFoundation/CoreFoundation.h>
+*/
+import "C"
+import "testing"
+
+func Test(t *testing.T) {
+ a := test24161array()
+ C.CFArrayCreateCopy(0, a)
+}
diff --git a/libgo/misc/cgo/test/issue24161e0/main.go b/libgo/misc/cgo/test/issue24161e0/main.go
new file mode 100644
index 0000000..cbc1dee
--- /dev/null
+++ b/libgo/misc/cgo/test/issue24161e0/main.go
@@ -0,0 +1,29 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build darwin
+
+package issue24161e0
+
+/*
+#cgo CFLAGS: -x objective-c
+#cgo LDFLAGS: -framework CoreFoundation -framework Security
+#include <TargetConditionals.h>
+#include <CoreFoundation/CoreFoundation.h>
+#include <Security/Security.h>
+#if TARGET_OS_IPHONE == 0 && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200
+ typedef CFStringRef SecKeyAlgorithm;
+ static CFDataRef SecKeyCreateSignature(SecKeyRef key, SecKeyAlgorithm algorithm, CFDataRef dataToSign, CFErrorRef *error){return NULL;}
+ #define kSecKeyAlgorithmECDSASignatureDigestX962SHA1 foo()
+ static SecKeyAlgorithm foo(void){return NULL;}
+#endif
+*/
+import "C"
+import "testing"
+
+func f1() {
+ C.SecKeyCreateSignature(0, C.kSecKeyAlgorithmECDSASignatureDigestX962SHA1, 0, nil)
+}
+
+func Test(t *testing.T) {}
diff --git a/libgo/misc/cgo/test/issue24161e1/main.go b/libgo/misc/cgo/test/issue24161e1/main.go
new file mode 100644
index 0000000..eb48fc0
--- /dev/null
+++ b/libgo/misc/cgo/test/issue24161e1/main.go
@@ -0,0 +1,38 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build darwin
+
+package issue24161e1
+
+/*
+#cgo CFLAGS: -x objective-c
+#cgo LDFLAGS: -framework CoreFoundation -framework Security
+#include <TargetConditionals.h>
+#include <CoreFoundation/CoreFoundation.h>
+#include <Security/Security.h>
+#if TARGET_OS_IPHONE == 0 && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200
+ typedef CFStringRef SecKeyAlgorithm;
+ static CFDataRef SecKeyCreateSignature(SecKeyRef key, SecKeyAlgorithm algorithm, CFDataRef dataToSign, CFErrorRef *error){return NULL;}
+ #define kSecKeyAlgorithmECDSASignatureDigestX962SHA1 foo()
+ static SecKeyAlgorithm foo(void){return NULL;}
+#endif
+*/
+import "C"
+import (
+ "fmt"
+ "testing"
+)
+
+func f1() {
+ C.SecKeyCreateSignature(0, C.kSecKeyAlgorithmECDSASignatureDigestX962SHA1, 0, nil)
+}
+
+func f2(e C.CFErrorRef) {
+ if desc := C.CFErrorCopyDescription(e); desc != 0 {
+ fmt.Println(desc)
+ }
+}
+
+func Test(t *testing.T) {}
diff --git a/libgo/misc/cgo/test/issue24161e2/main.go b/libgo/misc/cgo/test/issue24161e2/main.go
new file mode 100644
index 0000000..1951c86
--- /dev/null
+++ b/libgo/misc/cgo/test/issue24161e2/main.go
@@ -0,0 +1,40 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build darwin
+
+package issue24161e2
+
+/*
+#cgo CFLAGS: -x objective-c
+#cgo LDFLAGS: -framework CoreFoundation -framework Security
+#include <TargetConditionals.h>
+#include <CoreFoundation/CoreFoundation.h>
+#include <Security/Security.h>
+#if TARGET_OS_IPHONE == 0 && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200
+ typedef CFStringRef SecKeyAlgorithm;
+ static CFDataRef SecKeyCreateSignature(SecKeyRef key, SecKeyAlgorithm algorithm, CFDataRef dataToSign, CFErrorRef *error){return NULL;}
+ #define kSecKeyAlgorithmECDSASignatureDigestX962SHA1 foo()
+ static SecKeyAlgorithm foo(void){return NULL;}
+#endif
+*/
+import "C"
+import (
+ "fmt"
+ "testing"
+)
+
+var _ C.CFStringRef
+
+func f1() {
+ C.SecKeyCreateSignature(0, C.kSecKeyAlgorithmECDSASignatureDigestX962SHA1, 0, nil)
+}
+
+func f2(e C.CFErrorRef) {
+ if desc := C.CFErrorCopyDescription(e); desc != 0 {
+ fmt.Println(desc)
+ }
+}
+
+func Test(t *testing.T) {}
diff --git a/libgo/misc/cgo/test/issue24161res/restype.go b/libgo/misc/cgo/test/issue24161res/restype.go
new file mode 100644
index 0000000..e5719f2
--- /dev/null
+++ b/libgo/misc/cgo/test/issue24161res/restype.go
@@ -0,0 +1,23 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build darwin
+
+package issue24161res
+
+/*
+#cgo LDFLAGS: -framework CoreFoundation
+#include <CoreFoundation/CoreFoundation.h>
+*/
+import "C"
+import (
+ "reflect"
+ "testing"
+)
+
+func Test(t *testing.T) {
+ if k := reflect.TypeOf(C.CFArrayCreate(0, nil, 0, nil)).Kind(); k != reflect.Uintptr {
+ t.Fatalf("bad kind %s\n", k)
+ }
+}
diff --git a/libgo/misc/cgo/test/issue24206.go b/libgo/misc/cgo/test/issue24206.go
new file mode 100644
index 0000000..5fec68e
--- /dev/null
+++ b/libgo/misc/cgo/test/issue24206.go
@@ -0,0 +1,54 @@
+// +build amd64,linux
+
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package cgotest
+
+// Test that C.GoString uses IndexByte in safe manner.
+
+/*
+#include <sys/mman.h>
+
+// Returns string with null byte at the last valid address
+char* dangerousString1() {
+ int pageSize = 4096;
+ char *data = mmap(0, 2 * pageSize, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, 0, 0);
+ mprotect(data + pageSize,pageSize,PROT_NONE);
+ int start = pageSize - 123 - 1; // last 123 bytes of first page + 1 null byte
+ int i = start;
+ for (; i < pageSize; i++) {
+ data[i] = 'x';
+ }
+ data[pageSize -1 ] = 0;
+ return data+start;
+}
+
+char* dangerousString2() {
+ int pageSize = 4096;
+ char *data = mmap(0, 3 * pageSize, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, 0, 0);
+ mprotect(data + 2 * pageSize,pageSize,PROT_NONE);
+ int start = pageSize - 123 - 1; // last 123 bytes of first page + 1 null byte
+ int i = start;
+ for (; i < 2 * pageSize; i++) {
+ data[i] = 'x';
+ }
+ data[2*pageSize -1 ] = 0;
+ return data+start;
+}
+*/
+import "C"
+
+import (
+ "testing"
+)
+
+func test24206(t *testing.T) {
+ if l := len(C.GoString(C.dangerousString1())); l != 123 {
+ t.Errorf("Incorrect string length - got %d, want 123", l)
+ }
+ if l := len(C.GoString(C.dangerousString2())); l != 4096+123 {
+ t.Errorf("Incorrect string length - got %d, want %d", l, 4096+123)
+ }
+}
diff --git a/libgo/misc/cgo/test/issue24206_generic.go b/libgo/misc/cgo/test/issue24206_generic.go
new file mode 100644
index 0000000..27c4d65
--- /dev/null
+++ b/libgo/misc/cgo/test/issue24206_generic.go
@@ -0,0 +1,13 @@
+// +build !amd64 !linux
+
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package cgotest
+
+import "testing"
+
+func test24206(t *testing.T) {
+ t.Skip("Skipping on non-amd64 or non-linux system")
+}
diff --git a/libgo/misc/cgo/test/issue25143.go b/libgo/misc/cgo/test/issue25143.go
new file mode 100644
index 0000000..607bfe4
--- /dev/null
+++ b/libgo/misc/cgo/test/issue25143.go
@@ -0,0 +1,22 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package cgotest
+
+import "C"
+import "testing"
+
+func issue25143sum(ns ...C.int) C.int {
+ total := C.int(0)
+ for _, n := range ns {
+ total += n
+ }
+ return total
+}
+
+func test25143(t *testing.T) {
+ if got, want := issue25143sum(1, 2, 3), C.int(6); got != want {
+ t.Errorf("issue25143sum(1, 2, 3) == %v, expected %v", got, want)
+ }
+}
diff --git a/libgo/misc/cgo/test/issue26066.go b/libgo/misc/cgo/test/issue26066.go
new file mode 100644
index 0000000..21028e7
--- /dev/null
+++ b/libgo/misc/cgo/test/issue26066.go
@@ -0,0 +1,19 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Wrong type of constant with GCC 8 and newer.
+
+package cgotest
+
+// const unsigned long long int issue26066 = (const unsigned long long) -1;
+import "C"
+
+import "testing"
+
+func test26066(t *testing.T) {
+ var i = int64(C.issue26066)
+ if i != -1 {
+ t.Errorf("got %d, want -1", i)
+ }
+}
diff --git a/libgo/misc/cgo/test/issue26213/jni.h b/libgo/misc/cgo/test/issue26213/jni.h
new file mode 100644
index 0000000..0c76979
--- /dev/null
+++ b/libgo/misc/cgo/test/issue26213/jni.h
@@ -0,0 +1,29 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// It's going to be hard to include a whole real JVM to test this.
+// So we'll simulate a really easy JVM using just the parts we need.
+
+// This is the relevant part of jni.h.
+
+// On Android NDK16, jobject is defined like this in C and C++
+typedef void* jobject;
+
+typedef jobject jclass;
+typedef jobject jthrowable;
+typedef jobject jstring;
+typedef jobject jarray;
+typedef jarray jbooleanArray;
+typedef jarray jbyteArray;
+typedef jarray jcharArray;
+typedef jarray jshortArray;
+typedef jarray jintArray;
+typedef jarray jlongArray;
+typedef jarray jfloatArray;
+typedef jarray jdoubleArray;
+typedef jarray jobjectArray;
+
+typedef jobject jweak;
+
+// Note: jvalue is already a non-pointer type due to it being a C union.
diff --git a/libgo/misc/cgo/test/issue26213/test26213.go b/libgo/misc/cgo/test/issue26213/test26213.go
new file mode 100644
index 0000000..5d1f637
--- /dev/null
+++ b/libgo/misc/cgo/test/issue26213/test26213.go
@@ -0,0 +1,46 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package issue26213
+
+/*
+#include "jni.h"
+*/
+import "C"
+import (
+ "testing"
+)
+
+func Test26213(t *testing.T) {
+ var x1 C.jobject = 0 // Note: 0, not nil. That makes sure we use uintptr for these types.
+ _ = x1
+ var x2 C.jclass = 0
+ _ = x2
+ var x3 C.jthrowable = 0
+ _ = x3
+ var x4 C.jstring = 0
+ _ = x4
+ var x5 C.jarray = 0
+ _ = x5
+ var x6 C.jbooleanArray = 0
+ _ = x6
+ var x7 C.jbyteArray = 0
+ _ = x7
+ var x8 C.jcharArray = 0
+ _ = x8
+ var x9 C.jshortArray = 0
+ _ = x9
+ var x10 C.jintArray = 0
+ _ = x10
+ var x11 C.jlongArray = 0
+ _ = x11
+ var x12 C.jfloatArray = 0
+ _ = x12
+ var x13 C.jdoubleArray = 0
+ _ = x13
+ var x14 C.jobjectArray = 0
+ _ = x14
+ var x15 C.jweak = 0
+ _ = x15
+}
diff --git a/libgo/misc/cgo/test/issue26430.go b/libgo/misc/cgo/test/issue26430.go
new file mode 100644
index 0000000..3ad5420
--- /dev/null
+++ b/libgo/misc/cgo/test/issue26430.go
@@ -0,0 +1,10 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Issue 26430: incomplete typedef leads to inconsistent typedefs error.
+// No runtime test; just make sure it compiles.
+
+package cgotest
+
+import _ "./issue26430"
diff --git a/libgo/misc/cgo/test/issue26430/a.go b/libgo/misc/cgo/test/issue26430/a.go
new file mode 100644
index 0000000..fbaa46b
--- /dev/null
+++ b/libgo/misc/cgo/test/issue26430/a.go
@@ -0,0 +1,13 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package a
+
+// typedef struct S ST;
+// static ST* F() { return 0; }
+import "C"
+
+func F1() {
+ C.F()
+}
diff --git a/libgo/misc/cgo/test/issue26430/b.go b/libgo/misc/cgo/test/issue26430/b.go
new file mode 100644
index 0000000..a7c527c
--- /dev/null
+++ b/libgo/misc/cgo/test/issue26430/b.go
@@ -0,0 +1,13 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package a
+
+// typedef struct S ST;
+// struct S { int f; };
+import "C"
+
+func F2(p *C.ST) {
+ p.f = 1
+}
diff --git a/libgo/misc/cgo/test/issue26517.go b/libgo/misc/cgo/test/issue26517.go
new file mode 100644
index 0000000..c1bf1c9
--- /dev/null
+++ b/libgo/misc/cgo/test/issue26517.go
@@ -0,0 +1,23 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package cgotest
+
+// Introduce two pointer types which are distinct, but have the same
+// base type. Make sure that both of those pointer types get resolved
+// correctly. Before the fix for 26517 if one of these pointer types
+// was resolved before the other one was processed, the second one
+// would never be resolved.
+// Before this issue was fixed this test failed on Windows,
+// where va_list expands to a named char* type.
+
+/*
+#include <stdarg.h>
+typedef va_list TypeOne;
+typedef char *TypeTwo;
+*/
+import "C"
+
+var a C.TypeOne
+var b C.TypeTwo
diff --git a/libgo/misc/cgo/test/issue26743.go b/libgo/misc/cgo/test/issue26743.go
new file mode 100644
index 0000000..35c8473
--- /dev/null
+++ b/libgo/misc/cgo/test/issue26743.go
@@ -0,0 +1,10 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Issue 26743: typedef of uint leads to inconsistent typedefs error.
+// No runtime test; just make sure it compiles.
+
+package cgotest
+
+import _ "./issue26743"
diff --git a/libgo/misc/cgo/test/issue26743/a.go b/libgo/misc/cgo/test/issue26743/a.go
new file mode 100644
index 0000000..a3df179
--- /dev/null
+++ b/libgo/misc/cgo/test/issue26743/a.go
@@ -0,0 +1,11 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package issue26743
+
+// typedef unsigned int uint;
+// int C1(uint x) { return x; }
+import "C"
+
+var V1 = C.C1(0)
diff --git a/libgo/misc/cgo/test/issue26743/b.go b/libgo/misc/cgo/test/issue26743/b.go
new file mode 100644
index 0000000..c5f1ae4
--- /dev/null
+++ b/libgo/misc/cgo/test/issue26743/b.go
@@ -0,0 +1,9 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package issue26743
+
+import "C"
+
+var V2 C.uint
diff --git a/libgo/misc/cgo/test/issue4029.c b/libgo/misc/cgo/test/issue4029.c
index 7205c5a..30646ad 100644
--- a/libgo/misc/cgo/test/issue4029.c
+++ b/libgo/misc/cgo/test/issue4029.c
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build !windows
+// +build !windows,!static
#include <stdint.h>
#include <dlfcn.h>
diff --git a/libgo/misc/cgo/test/issue4029.go b/libgo/misc/cgo/test/issue4029.go
index 8e468d3..1bf029d 100644
--- a/libgo/misc/cgo/test/issue4029.go
+++ b/libgo/misc/cgo/test/issue4029.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build !windows
+// +build !windows,!static
package cgotest
diff --git a/libgo/misc/cgo/test/issue4029w.go b/libgo/misc/cgo/test/issue4029w.go
index 18c7201..eee33f7 100644
--- a/libgo/misc/cgo/test/issue4029w.go
+++ b/libgo/misc/cgo/test/issue4029w.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build windows
+// +build windows static
package cgotest
diff --git a/libgo/misc/cgo/test/issue9400/asm_arm.s b/libgo/misc/cgo/test/issue9400/asm_arm.s
index 166d53f..96c2785 100644
--- a/libgo/misc/cgo/test/issue9400/asm_arm.s
+++ b/libgo/misc/cgo/test/issue9400/asm_arm.s
@@ -9,7 +9,7 @@
TEXT cas<>(SB),NOSPLIT,$0
MOVW $0xffff0fc0, R15 // R15 is PC
-TEXT ·RewindAndSetgid(SB),NOSPLIT,$-4-0
+TEXT ·RewindAndSetgid(SB),NOSPLIT|NOFRAME,$0-0
// Save link register
MOVW R14, R4
diff --git a/libgo/misc/cgo/test/issue9400/asm_arm64.s b/libgo/misc/cgo/test/issue9400/asm_arm64.s
index 9bb5081..2ebbfcc 100644
--- a/libgo/misc/cgo/test/issue9400/asm_arm64.s
+++ b/libgo/misc/cgo/test/issue9400/asm_arm64.s
@@ -6,7 +6,7 @@
#include "textflag.h"
-TEXT ·RewindAndSetgid(SB),NOSPLIT,$-8-0
+TEXT ·RewindAndSetgid(SB),NOSPLIT|NOFRAME,$0-0
// Save link register
MOVD R30, R9
diff --git a/libgo/misc/cgo/test/issue9400/asm_mipsx.s b/libgo/misc/cgo/test/issue9400/asm_mipsx.s
index ddf33e9..7a92735 100644
--- a/libgo/misc/cgo/test/issue9400/asm_mipsx.s
+++ b/libgo/misc/cgo/test/issue9400/asm_mipsx.s
@@ -7,7 +7,7 @@
#include "textflag.h"
-TEXT ·RewindAndSetgid(SB),NOSPLIT,$-4-0
+TEXT ·RewindAndSetgid(SB),NOSPLIT|NOFRAME,$0-0
// Rewind stack pointer so anything that happens on the stack
// will clobber the test pattern created by the caller
ADDU $(1024*8), R29
diff --git a/libgo/misc/cgo/test/issue9400/stubs.go b/libgo/misc/cgo/test/issue9400/stubs.go
index 7b50cef..e431c5a 100644
--- a/libgo/misc/cgo/test/issue9400/stubs.go
+++ b/libgo/misc/cgo/test/issue9400/stubs.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build !gccgo
+// +build gc
package issue9400
diff --git a/libgo/misc/cgo/test/sigprocmask.c b/libgo/misc/cgo/test/sigprocmask.c
index bd99647..e77ba5b 100644
--- a/libgo/misc/cgo/test/sigprocmask.c
+++ b/libgo/misc/cgo/test/sigprocmask.c
@@ -4,10 +4,12 @@
// +build !windows
+#include <errno.h>
#include <signal.h>
#include <stdlib.h>
#include <pthread.h>
#include <stdio.h>
+#include <time.h>
#include <unistd.h>
extern void IntoGoAndBack();
@@ -28,11 +30,22 @@ static void* sigthreadfunc(void* unused) {
}
int RunSigThread() {
+ int tries;
pthread_t thread;
int r;
+ struct timespec ts;
- r = pthread_create(&thread, NULL, &sigthreadfunc, NULL);
- if (r != 0)
- return r;
- return pthread_join(thread, NULL);
+ for (tries = 0; tries < 20; tries++) {
+ r = pthread_create(&thread, NULL, &sigthreadfunc, NULL);
+ if (r == 0) {
+ return pthread_join(thread, NULL);
+ }
+ if (r != EAGAIN) {
+ return r;
+ }
+ ts.tv_sec = 0;
+ ts.tv_nsec = (tries + 1) * 1000 * 1000; // Milliseconds.
+ nanosleep(&ts, NULL);
+ }
+ return EAGAIN;
}
diff --git a/libgo/misc/cgo/test/sigprocmask.go b/libgo/misc/cgo/test/sigprocmask.go
index 39b658e..e2b939f 100644
--- a/libgo/misc/cgo/test/sigprocmask.go
+++ b/libgo/misc/cgo/test/sigprocmask.go
@@ -32,7 +32,7 @@ func IntoGoAndBack() {
func testSigprocmask(t *testing.T) {
if r := C.RunSigThread(); r != 0 {
- t.Error("pthread_create/pthread_join failed")
+ t.Errorf("pthread_create/pthread_join failed: %d", r)
}
if !blocked {
t.Error("Go runtime unblocked SIGIO")
diff --git a/libgo/misc/cgo/test/test26213.go b/libgo/misc/cgo/test/test26213.go
new file mode 100644
index 0000000..176a7ec
--- /dev/null
+++ b/libgo/misc/cgo/test/test26213.go
@@ -0,0 +1,15 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package cgotest
+
+import (
+ "testing"
+
+ "./issue26213"
+)
+
+func test26213(t *testing.T) {
+ issue26213.Test26213(t)
+}
diff --git a/libgo/misc/cgo/testcarchive/carchive_test.go b/libgo/misc/cgo/testcarchive/carchive_test.go
index 4a8cc0f..457ac0d 100644
--- a/libgo/misc/cgo/testcarchive/carchive_test.go
+++ b/libgo/misc/cgo/testcarchive/carchive_test.go
@@ -13,6 +13,7 @@ import (
"os"
"os/exec"
"path/filepath"
+ "regexp"
"runtime"
"strings"
"syscall"
@@ -178,6 +179,28 @@ func testInstall(t *testing.T, exe, libgoa, libgoh string, buildcmd ...string) {
t.Logf("%s", out)
t.Fatal(err)
}
+
+ checkLineComments(t, libgoh)
+}
+
+var badLineRegexp = regexp.MustCompile(`(?m)^#line [0-9]+ "/.*$`)
+
+// checkLineComments checks that the export header generated by
+// -buildmode=c-archive doesn't have any absolute paths in the #line
+// comments. We don't want those paths because they are unhelpful for
+// the user and make the files change based on details of the location
+// of GOPATH.
+func checkLineComments(t *testing.T, hdrname string) {
+ hdr, err := ioutil.ReadFile(hdrname)
+ if err != nil {
+ if !os.IsNotExist(err) {
+ t.Error(err)
+ }
+ return
+ }
+ if line := badLineRegexp.Find(hdr); line != nil {
+ t.Errorf("bad #line directive with absolute path in %s: %q", hdrname, line)
+ }
}
func TestInstall(t *testing.T) {
@@ -226,6 +249,7 @@ func TestEarlySignalHandler(t *testing.T) {
t.Logf("%s", out)
t.Fatal(err)
}
+ checkLineComments(t, "libgo2.h")
ccArgs := append(cc, "-o", "testp"+exeSuffix, "main2.c", "libgo2.a")
if runtime.Compiler == "gccgo" {
@@ -258,6 +282,7 @@ func TestSignalForwarding(t *testing.T) {
t.Logf("%s", out)
t.Fatal(err)
}
+ checkLineComments(t, "libgo2.h")
ccArgs := append(cc, "-o", "testp"+exeSuffix, "main5.c", "libgo2.a")
if runtime.Compiler == "gccgo" {
@@ -283,6 +308,9 @@ func TestSignalForwarding(t *testing.T) {
}
func TestSignalForwardingExternal(t *testing.T) {
+ if GOOS == "freebsd" {
+ t.Skipf("skipping on %s/%s; signal always goes to the Go runtime", GOOS, GOARCH)
+ }
checkSignalForwardingTest(t)
defer func() {
@@ -298,6 +326,7 @@ func TestSignalForwardingExternal(t *testing.T) {
t.Logf("%s", out)
t.Fatal(err)
}
+ checkLineComments(t, "libgo2.h")
ccArgs := append(cc, "-o", "testp"+exeSuffix, "main5.c", "libgo2.a")
if runtime.Compiler == "gccgo" {
@@ -413,6 +442,7 @@ func TestOsSignal(t *testing.T) {
t.Logf("%s", out)
t.Fatal(err)
}
+ checkLineComments(t, "libgo3.h")
ccArgs := append(cc, "-o", "testp"+exeSuffix, "main3.c", "libgo3.a")
if runtime.Compiler == "gccgo" {
@@ -448,6 +478,7 @@ func TestSigaltstack(t *testing.T) {
t.Logf("%s", out)
t.Fatal(err)
}
+ checkLineComments(t, "libgo4.h")
ccArgs := append(cc, "-o", "testp"+exeSuffix, "main4.c", "libgo4.a")
if runtime.Compiler == "gccgo" {
@@ -465,7 +496,7 @@ func TestSigaltstack(t *testing.T) {
}
const testar = `#!/usr/bin/env bash
-while expr $1 : '[-]' >/dev/null; do
+while [[ $1 == -* ]] >/dev/null; do
shift
done
echo "testar" > $1
@@ -505,6 +536,7 @@ func TestExtar(t *testing.T) {
t.Logf("%s", out)
t.Fatal(err)
}
+ checkLineComments(t, "libgo4.h")
if _, err := os.Stat("testar.ran"); err != nil {
if os.IsNotExist(err) {
@@ -617,6 +649,7 @@ func TestSIGPROF(t *testing.T) {
t.Logf("%s", out)
t.Fatal(err)
}
+ checkLineComments(t, "libgo6.h")
ccArgs := append(cc, "-o", "testp6"+exeSuffix, "main6.c", "libgo6.a")
if runtime.Compiler == "gccgo" {
@@ -658,6 +691,7 @@ func TestCompileWithoutShared(t *testing.T) {
if err != nil {
t.Fatal(err)
}
+ checkLineComments(t, "libgo2.h")
exe := "./testnoshared" + exeSuffix
diff --git a/libgo/misc/cgo/testcarchive/main5.c b/libgo/misc/cgo/testcarchive/main5.c
index 2437bf0..897b70d 100644
--- a/libgo/misc/cgo/testcarchive/main5.c
+++ b/libgo/misc/cgo/testcarchive/main5.c
@@ -85,6 +85,8 @@ int main(int argc, char** argv) {
printf("write(2) unexpectedly succeeded\n");
return 0;
}
+ printf("did not receieve SIGPIPE\n");
+ return 0;
}
default:
printf("Unknown test: %d\n", test);
diff --git a/libgo/misc/cgo/testcarchive/src/libgo3/libgo3.go b/libgo/misc/cgo/testcarchive/src/libgo3/libgo3.go
index e276a3c..3725f7a 100644
--- a/libgo/misc/cgo/testcarchive/src/libgo3/libgo3.go
+++ b/libgo/misc/cgo/testcarchive/src/libgo3/libgo3.go
@@ -29,13 +29,13 @@ func ResetSIGIO() {
signal.Reset(syscall.SIGIO)
}
-// SawSIGIO returns whether we saw a SIGIO within a brief pause.
+// SawSIGIO reports whether we saw a SIGIO.
//export SawSIGIO
func SawSIGIO() C.int {
select {
case <-sigioChan:
return 1
- case <-time.After(100 * time.Millisecond):
+ case <-time.After(5 * time.Second):
return 0
}
}
diff --git a/libgo/misc/cgo/testcshared/cshared_test.go b/libgo/misc/cgo/testcshared/cshared_test.go
index e43422d..89b19d6 100644
--- a/libgo/misc/cgo/testcshared/cshared_test.go
+++ b/libgo/misc/cgo/testcshared/cshared_test.go
@@ -201,6 +201,16 @@ func run(t *testing.T, env []string, args ...string) string {
t.Helper()
cmd := exec.Command(args[0], args[1:]...)
cmd.Env = env
+
+ if GOOS != "windows" {
+ // TestUnexportedSymbols relies on file descriptor 30
+ // being closed when the program starts, so enforce
+ // that in all cases. (The first three descriptors are
+ // stdin/stdout/stderr, so we just need to make sure
+ // that cmd.ExtraFiles[27] exists and is nil.)
+ cmd.ExtraFiles = make([]*os.File, 28)
+ }
+
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("command failed: %v\n%v\n%s\n", args, err, out)
@@ -322,7 +332,11 @@ func TestExportedSymbolsWithDynamicLoad(t *testing.T) {
createHeadersOnce(t)
- runCC(t, "-o", cmd, "main1.c", "-ldl")
+ if GOOS != "freebsd" {
+ runCC(t, "-o", cmd, "main1.c", "-ldl")
+ } else {
+ runCC(t, "-o", cmd, "main1.c")
+ }
adbPush(t, cmd)
defer os.Remove(bin)
@@ -411,7 +425,11 @@ func testSignalHandlers(t *testing.T, pkgname, cfile, cmd string) {
"-o", libname, pkgname,
)
adbPush(t, libname)
- runCC(t, "-pthread", "-o", cmd, cfile, "-ldl")
+ if GOOS != "freebsd" {
+ runCC(t, "-pthread", "-o", cmd, cfile, "-ldl")
+ } else {
+ runCC(t, "-pthread", "-o", cmd, cfile)
+ }
adbPush(t, cmd)
bin := cmdToRun(cmd)
diff --git a/libgo/misc/cgo/testcshared/main2.c b/libgo/misc/cgo/testcshared/main2.c
index 1a3f1d7..f89bcca 100644
--- a/libgo/misc/cgo/testcshared/main2.c
+++ b/libgo/misc/cgo/testcshared/main2.c
@@ -21,7 +21,7 @@ int main(void) {
// The descriptor will be initialized in a thread, so we have to
// give a chance to get opened.
- for (i = 0; i < 1000; i++) {
+ for (i = 0; i < 200; i++) {
n = read(fd, buf, sizeof buf);
if (n >= 0)
break;
@@ -33,7 +33,7 @@ int main(void) {
// An EBADF error means that the shared library has not opened the
// descriptor yet.
ts.tv_sec = 0;
- ts.tv_nsec = 1000000;
+ ts.tv_nsec = 10000000;
nanosleep(&ts, NULL);
}
diff --git a/libgo/misc/cgo/testgodefs/fieldtypedef.go b/libgo/misc/cgo/testgodefs/fieldtypedef.go
new file mode 100644
index 0000000..45c0bf8
--- /dev/null
+++ b/libgo/misc/cgo/testgodefs/fieldtypedef.go
@@ -0,0 +1,18 @@
+// Copyright 2018 The Go Authors. All rights reserve d.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+//
+// +build ignore
+
+package main
+
+/*
+struct S1 { int f1; };
+struct S2 { struct S1 s1; };
+typedef struct S1 S1Type;
+typedef struct S2 S2Type;
+*/
+import "C"
+
+type S1 C.S1Type
+type S2 C.S2Type
diff --git a/libgo/misc/cgo/testgodefs/test.bash b/libgo/misc/cgo/testgodefs/test.bash
index a82ff93..012d007 100644
--- a/libgo/misc/cgo/testgodefs/test.bash
+++ b/libgo/misc/cgo/testgodefs/test.bash
@@ -7,7 +7,7 @@
# We are testing cgo -godefs, which translates Go files that use
# import "C" into Go files with Go definitions of types defined in the
# import "C" block. Add more tests here.
-FILE_PREFIXES="anonunion issue8478"
+FILE_PREFIXES="anonunion issue8478 fieldtypedef"
RM=
for FP in $FILE_PREFIXES
diff --git a/libgo/misc/cgo/testplugin/src/issue25756/main.go b/libgo/misc/cgo/testplugin/src/issue25756/main.go
new file mode 100644
index 0000000..817daf4
--- /dev/null
+++ b/libgo/misc/cgo/testplugin/src/issue25756/main.go
@@ -0,0 +1,52 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Run the game of life in C using Go for parallelization.
+
+package main
+
+import (
+ "flag"
+ "fmt"
+ "plugin"
+)
+
+const MAXDIM = 100
+
+var dim = flag.Int("dim", 16, "board dimensions")
+var gen = flag.Int("gen", 10, "generations")
+
+func main() {
+ flag.Parse()
+
+ var a [MAXDIM * MAXDIM]int32
+ for i := 2; i < *dim; i += 8 {
+ for j := 2; j < *dim-3; j += 8 {
+ for y := 0; y < 3; y++ {
+ a[i**dim+j+y] = 1
+ }
+ }
+ }
+
+ p, err := plugin.Open("life.so")
+ if err != nil {
+ panic(err)
+ }
+ f, err := p.Lookup("Run")
+ if err != nil {
+ panic(err)
+ }
+ f.(func(int, int, int, []int32))(*gen, *dim, *dim, a[:])
+
+ for i := 0; i < *dim; i++ {
+ for j := 0; j < *dim; j++ {
+ if a[i**dim+j] == 0 {
+ fmt.Print(" ")
+ } else {
+ fmt.Print("X")
+ }
+ }
+ fmt.Print("\n")
+ }
+}
diff --git a/libgo/misc/cgo/testplugin/src/issue25756/plugin/c-life.c b/libgo/misc/cgo/testplugin/src/issue25756/plugin/c-life.c
new file mode 100644
index 0000000..f853163
--- /dev/null
+++ b/libgo/misc/cgo/testplugin/src/issue25756/plugin/c-life.c
@@ -0,0 +1,56 @@
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+#include <assert.h>
+#include "life.h"
+#include "_cgo_export.h"
+
+const int MYCONST = 0;
+
+// Do the actual manipulation of the life board in C. This could be
+// done easily in Go, we are just using C for demonstration
+// purposes.
+void
+Step(int x, int y, int *a, int *n)
+{
+ struct GoStart_return r;
+
+ // Use Go to start 4 goroutines each of which handles 1/4 of the
+ // board.
+ r = GoStart(0, x, y, 0, x / 2, 0, y / 2, a, n);
+ assert(r.r0 == 0 && r.r1 == 100); // test multiple returns
+ r = GoStart(1, x, y, x / 2, x, 0, y / 2, a, n);
+ assert(r.r0 == 1 && r.r1 == 101); // test multiple returns
+ GoStart(2, x, y, 0, x / 2, y / 2, y, a, n);
+ GoStart(3, x, y, x / 2, x, y / 2, y, a, n);
+ GoWait(0);
+ GoWait(1);
+ GoWait(2);
+ GoWait(3);
+}
+
+// The actual computation. This is called in parallel.
+void
+DoStep(int xdim, int ydim, int xstart, int xend, int ystart, int yend, int *a, int *n)
+{
+ int x, y, c, i, j;
+
+ for(x = xstart; x < xend; x++) {
+ for(y = ystart; y < yend; y++) {
+ c = 0;
+ for(i = -1; i <= 1; i++) {
+ for(j = -1; j <= 1; j++) {
+ if(x+i >= 0 && x+i < xdim &&
+ y+j >= 0 && y+j < ydim &&
+ (i != 0 || j != 0))
+ c += a[(x+i)*xdim + (y+j)] != 0;
+ }
+ }
+ if(c == 3 || (c == 2 && a[x*xdim + y] != 0))
+ n[x*xdim + y] = 1;
+ else
+ n[x*xdim + y] = 0;
+ }
+ }
+}
diff --git a/libgo/misc/cgo/testplugin/src/issue25756/plugin/life.go b/libgo/misc/cgo/testplugin/src/issue25756/plugin/life.go
new file mode 100644
index 0000000..675a192
--- /dev/null
+++ b/libgo/misc/cgo/testplugin/src/issue25756/plugin/life.go
@@ -0,0 +1,39 @@
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+// #include "life.h"
+import "C"
+
+import "unsafe"
+
+func Run(gen, x, y int, a []int32) {
+ n := make([]int32, x*y)
+ for i := 0; i < gen; i++ {
+ C.Step(C.int(x), C.int(y), (*C.int)(unsafe.Pointer(&a[0])), (*C.int)(unsafe.Pointer(&n[0])))
+ copy(a, n)
+ }
+}
+
+// Keep the channels visible from Go.
+var chans [4]chan bool
+
+//export GoStart
+// Double return value is just for testing.
+func GoStart(i, xdim, ydim, xstart, xend, ystart, yend C.int, a *C.int, n *C.int) (int, int) {
+ c := make(chan bool, int(C.MYCONST))
+ go func() {
+ C.DoStep(xdim, ydim, xstart, xend, ystart, yend, a, n)
+ c <- true
+ }()
+ chans[i] = c
+ return int(i), int(i + 100)
+}
+
+//export GoWait
+func GoWait(i C.int) {
+ <-chans[i]
+ chans[i] = nil
+}
diff --git a/libgo/misc/cgo/testplugin/src/issue25756/plugin/life.h b/libgo/misc/cgo/testplugin/src/issue25756/plugin/life.h
new file mode 100644
index 0000000..11d2b97
--- /dev/null
+++ b/libgo/misc/cgo/testplugin/src/issue25756/plugin/life.h
@@ -0,0 +1,7 @@
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+extern void Step(int, int, int *, int *);
+extern void DoStep(int, int, int, int, int, int, int *, int *);
+extern const int MYCONST;
diff --git a/libgo/misc/cgo/testplugin/test.bash b/libgo/misc/cgo/testplugin/test.bash
index df38204..bf8ed3c 100644
--- a/libgo/misc/cgo/testplugin/test.bash
+++ b/libgo/misc/cgo/testplugin/test.bash
@@ -15,7 +15,7 @@ goos=$(go env GOOS)
goarch=$(go env GOARCH)
function cleanup() {
- rm -f plugin*.so unnamed*.so iface*.so issue*
+ rm -f plugin*.so unnamed*.so iface*.so life.so issue*
rm -rf host pkg sub iface
}
trap cleanup EXIT
@@ -90,3 +90,12 @@ GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -o issue22295 src/issue22295.pkg/m
GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o issue24351.so src/issue24351/plugin.go
GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -o issue24351 src/issue24351/main.go
./issue24351
+
+# Test for issue 25756
+GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o life.so issue25756/plugin
+GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -o issue25756 src/issue25756/main.go
+# Fails intermittently, but 20 runs should cause the failure
+for i in `seq 1 20`;
+do
+ ./issue25756 > /dev/null
+done
diff --git a/libgo/misc/cgo/testsanitizers/cc_test.go b/libgo/misc/cgo/testsanitizers/cc_test.go
index 306844b..f09ad52 100644
--- a/libgo/misc/cgo/testsanitizers/cc_test.go
+++ b/libgo/misc/cgo/testsanitizers/cc_test.go
@@ -381,12 +381,13 @@ func (c *config) checkRuntime() (skip bool, err error) {
return false, err
}
cmd.Args = append(cmd.Args, "-dM", "-E", "../../../src/runtime/cgo/libcgo.h")
+ cmdStr := strings.Join(cmd.Args, " ")
out, err := cmd.CombinedOutput()
if err != nil {
- return false, fmt.Errorf("%#q exited with %v\n%s", strings.Join(cmd.Args, " "), err, out)
+ return false, fmt.Errorf("%#q exited with %v\n%s", cmdStr, err, out)
}
if !bytes.Contains(out, []byte("#define CGO_TSAN")) {
- return true, fmt.Errorf("%#q did not define CGO_TSAN")
+ return true, fmt.Errorf("%#q did not define CGO_TSAN", cmdStr)
}
return false, nil
}
diff --git a/libgo/misc/cgo/testsanitizers/msan_test.go b/libgo/misc/cgo/testsanitizers/msan_test.go
index af5afa9..88b90d3 100644
--- a/libgo/misc/cgo/testsanitizers/msan_test.go
+++ b/libgo/misc/cgo/testsanitizers/msan_test.go
@@ -27,6 +27,7 @@ func TestMSAN(t *testing.T) {
{src: "msan3.go"},
{src: "msan4.go"},
{src: "msan5.go"},
+ {src: "msan6.go"},
{src: "msan_fail.go", wantErr: true},
}
for _, tc := range cases {
diff --git a/libgo/misc/cgo/testsanitizers/src/msan6.go b/libgo/misc/cgo/testsanitizers/src/msan6.go
new file mode 100644
index 0000000..003989c
--- /dev/null
+++ b/libgo/misc/cgo/testsanitizers/src/msan6.go
@@ -0,0 +1,72 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+// A C function returning a value on the Go stack could leave the Go
+// stack marked as uninitialized, potentially causing a later error
+// when the stack is used for something else. Issue 26209.
+
+/*
+#cgo LDFLAGS: -fsanitize=memory
+#cgo CPPFLAGS: -fsanitize=memory
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+typedef struct {
+ uintptr_t a[20];
+} S;
+
+S f() {
+ S *p;
+
+ p = (S *)(malloc(sizeof(S)));
+ p->a[0] = 0;
+ return *p;
+}
+*/
+import "C"
+
+// allocateStack extends the stack so that stack copying doesn't
+// confuse the msan data structures.
+//go:noinline
+func allocateStack(i int) int {
+ if i == 0 {
+ return i
+ }
+ return allocateStack(i - 1)
+}
+
+// F1 marks a chunk of stack as uninitialized.
+// C.f returns an uninitialized struct on the stack, so msan will mark
+// the stack as uninitialized.
+//go:noinline
+func F1() uintptr {
+ s := C.f()
+ return uintptr(s.a[0])
+}
+
+// F2 allocates a struct on the stack and converts it to an empty interface,
+// which will call msanread and see that the data appears uninitialized.
+//go:noinline
+func F2() interface{} {
+ return C.S{}
+}
+
+func poisonStack(i int) int {
+ if i == 0 {
+ return int(F1())
+ }
+ F1()
+ r := poisonStack(i - 1)
+ F2()
+ return r
+}
+
+func main() {
+ allocateStack(16384)
+ poisonStack(128)
+}
diff --git a/libgo/misc/cgo/testsanitizers/tsan_test.go b/libgo/misc/cgo/testsanitizers/tsan_test.go
index ec4e003..1d769a9 100644
--- a/libgo/misc/cgo/testsanitizers/tsan_test.go
+++ b/libgo/misc/cgo/testsanitizers/tsan_test.go
@@ -5,11 +5,15 @@
package sanitizers_test
import (
+ "runtime"
"strings"
"testing"
)
func TestTSAN(t *testing.T) {
+ if runtime.GOARCH == "arm64" {
+ t.Skip("skipping test; see https://golang.org/issue/25682")
+ }
t.Parallel()
requireOvercommit(t)
config := configure("thread")
diff --git a/libgo/misc/cgo/testshared/shared_test.go b/libgo/misc/cgo/testshared/shared_test.go
index a296005..846a271 100644
--- a/libgo/misc/cgo/testshared/shared_test.go
+++ b/libgo/misc/cgo/testshared/shared_test.go
@@ -905,3 +905,9 @@ func TestGlobal(t *testing.T) {
AssertIsLinkedTo(t, "./bin/global", soname)
AssertHasRPath(t, "./bin/global", gorootInstallDir)
}
+
+// Run a test using -linkshared of an installed shared package.
+// Issue 26400.
+func TestTestInstalledShared(t *testing.T) {
+ goCmd(nil, "test", "-linkshared", "-test.short", "sync/atomic")
+}
diff --git a/libgo/misc/cgo/testshared/src/depBase/asm.s b/libgo/misc/cgo/testshared/src/depBase/asm.s
index f203f8b..a8acf77f0 100644
--- a/libgo/misc/cgo/testshared/src/depBase/asm.s
+++ b/libgo/misc/cgo/testshared/src/depBase/asm.s
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-//+build !gccgo
+// +build !gccgo
#include "textflag.h"
diff --git a/libgo/misc/cgo/testshared/src/depBase/dep.go b/libgo/misc/cgo/testshared/src/depBase/dep.go
index 569c210..e7cc7c8 100644
--- a/libgo/misc/cgo/testshared/src/depBase/dep.go
+++ b/libgo/misc/cgo/testshared/src/depBase/dep.go
@@ -1,3 +1,7 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
package depBase
import (
diff --git a/libgo/misc/cgo/testshared/src/depBase/gccgo.go b/libgo/misc/cgo/testshared/src/depBase/gccgo.go
index 3e2b69b..2b02a1e 100644
--- a/libgo/misc/cgo/testshared/src/depBase/gccgo.go
+++ b/libgo/misc/cgo/testshared/src/depBase/gccgo.go
@@ -1,4 +1,8 @@
-//+build gccgo
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build gccgo
package depBase
diff --git a/libgo/misc/cgo/testshared/src/depBase/stubs.go b/libgo/misc/cgo/testshared/src/depBase/stubs.go
index 96573c1..04534f3 100644
--- a/libgo/misc/cgo/testshared/src/depBase/stubs.go
+++ b/libgo/misc/cgo/testshared/src/depBase/stubs.go
@@ -1,4 +1,8 @@
-//+build !gccgo
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build !gccgo
package depBase
diff --git a/libgo/misc/cgo/testshared/src/trivial/trivial.go b/libgo/misc/cgo/testshared/src/trivial/trivial.go
index da29a2c..6ade47c 100644
--- a/libgo/misc/cgo/testshared/src/trivial/trivial.go
+++ b/libgo/misc/cgo/testshared/src/trivial/trivial.go
@@ -1,4 +1,9 @@
package main
func main() {
+ // This is enough to make sure that the executable references
+ // a type descriptor, which was the cause of
+ // https://golang.org/issue/25970.
+ c := make(chan int)
+ _ = c
}