]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/ld: really import runtime/cgo for external link
authorIan Lance Taylor <iant@golang.org>
Wed, 21 May 2014 04:36:50 +0000 (21:36 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 21 May 2014 04:36:50 +0000 (21:36 -0700)
Fixes #8032.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/95580043

misc/cgo/nocgo/nocgo.go [new file with mode: 0644]
misc/cgo/nocgo/nocgo_test.go [new file with mode: 0644]
src/cmd/ld/lib.c
src/run.bash

diff --git a/misc/cgo/nocgo/nocgo.go b/misc/cgo/nocgo/nocgo.go
new file mode 100644 (file)
index 0000000..00ae5e9
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright 2014 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 -static works when not using cgo.  This test is in
+// misc/cgo to take advantage of the testing framework support for
+// when -static is expected to work.
+
+package nocgo
+
+func NoCgo() int {
+       c := make(chan int)
+
+       // The test is run with external linking, which means that
+       // goroutines will be created via the runtime/cgo package.
+       // Make sure that works.
+       go func() {
+               c <- 42
+       }()
+
+       return <-c
+}
diff --git a/misc/cgo/nocgo/nocgo_test.go b/misc/cgo/nocgo/nocgo_test.go
new file mode 100644 (file)
index 0000000..45d247c
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright 2014 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 nocgo
+
+import "testing"
+
+func TestNop(t *testing.T) {
+       i := NoCgo()
+       if i != 42 {
+               t.Errorf("got %d, want %d", i, 42)
+       }
+}
index 2975b2327ac902c55ec6a58fd6d5db6e2a3f132a..da6194e4ff0ad37708447256f98e4bfaa39b00fe 100644 (file)
@@ -205,6 +205,8 @@ loadlib(void)
                // whether to initialize the TLS.  So give it one.  This could
                // be handled differently but it's an unusual case.
                loadinternal("runtime/cgo");
+               if(i < ctxt->libraryp)
+                       objfile(ctxt->library[i].file, ctxt->library[i].pkg);
 
                // Pretend that we really imported the package.
                s = linklookup(ctxt, "go.importpath.runtime/cgo.", 0);
index 4706c2bc4fdd5e4d05e47594c503204b31ee9cb0..76216ba01043b98b54ab05ff7baf40de5c3918a0 100755 (executable)
@@ -145,6 +145,9 @@ dragonfly-386 | dragonfly-amd64 | freebsd-386 | freebsd-amd64 | freebsd-arm | li
                        echo "No support for static linking found (lacks libc.a?), skip cgo static linking test."
                else
                        go test -ldflags '-linkmode=external -extldflags "-static -pthread"' ../testtls || exit 1
+                       go test ../nocgo || exit 1
+                       go test -ldflags '-linkmode=external' ../nocgo || exit 1
+                       go test -ldflags '-linkmode=external -extldflags "-static -pthread"' ../nocgo || exit 1
                fi
                ;;
        esac