summaryrefslogtreecommitdiff
path: root/src/cmd/go/test.bash
diff options
context:
space:
mode:
authorErik Westrup <erik.westrup@gmail.com>2014-03-26 15:23:31 -0700
committerErik Westrup <erik.westrup@gmail.com>2014-03-26 15:23:31 -0700
commit9adde271d16cf7d4f0817a9ab390c30b13a7e809 (patch)
tree712f098b8d56d56ae21343a5f234cc5088656589 /src/cmd/go/test.bash
parentc5c81b939fd3c6645b4d4f376a7654dec24fe1d1 (diff)
downloadgo-9adde271d16cf7d4f0817a9ab390c30b13a7e809.tar.gz
cmd/go: Use exported CgoLDFlags when compiler=gccgo
If you compile a program that has cgo LDFLAGS directives, those are exported to an environment variable to be used by subsequent compiler tool invocations. The linking phase when using the gccgo toolchain did not consider the envvar CGO_LDFLAGS's linking directives resulting in undefined references when using cgo+gccgo. Fixes issue 7573 LGTM=iant R=golang-codereviews, iant CC=golang-codereviews https://codereview.appspot.com/80780043 Committer: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/cmd/go/test.bash')
-rwxr-xr-xsrc/cmd/go/test.bash25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/cmd/go/test.bash b/src/cmd/go/test.bash
index fe00df9e2..1091695b3 100755
--- a/src/cmd/go/test.bash
+++ b/src/cmd/go/test.bash
@@ -669,6 +669,31 @@ if ! ./testgo test -c -test.bench=XXX fmt; then
fi
rm -f fmt.test
+TEST 'Issue 7573: cmd/cgo: undefined reference when linking a C-library using gccgo'
+d=$(mktemp -d -t testgoXXX)
+export GOPATH=$d
+mkdir -p $d/src/cgoref
+ldflags="-L alibpath -lalib"
+echo "
+package main
+// #cgo LDFLAGS: $ldflags
+// void f(void) {}
+import \"C\"
+
+func main() { C.f() }
+" >$d/src/cgoref/cgoref.go
+go_cmds="$(./testgo build -n -compiler gccgo cgoref 2>&1 1>/dev/null)"
+ldflags_count="$(echo "$go_cmds" | egrep -c "^gccgo.*$(echo $ldflags | sed -e 's/-/\\-/g')" || true)"
+if [ "$ldflags_count" -lt 1 ]; then
+ echo "No Go-inline "#cgo LDFLAGS:" (\"$ldflags\") passed to gccgo linking stage."
+ ok=false
+fi
+rm -rf $d
+unset ldflags_count
+unset go_cmds
+unset ldflags
+unset GOPATH
+
# clean up
if $started; then stop; fi
rm -rf testdata/bin testdata/bin1