code review 80780043: cmd/go: Use exported CgoLDFlags when compiler=gccgo (issue 80780043)

62 views
Skip to first unread message

erik.w...@gmail.com

unread,
Mar 26, 2014, 12:13:55 PM3/26/14
to golang-co...@googlegroups.com, re...@codereview-hr.appspotmail.com
Reviewers: golang-codereviews,

Message:
Hello golang-co...@googlegroups.com,

I'd like you to review this change to
https://code.google.com/p/go


Description:
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.

Please review this at https://codereview.appspot.com/80780043/

Affected files (+26, -0 lines):
M src/cmd/go/build.go
M src/cmd/go/test.bash


Index: src/cmd/go/build.go
===================================================================
--- a/src/cmd/go/build.go
+++ b/src/cmd/go/build.go
@@ -1905,6 +1905,7 @@
ldflags = append(ldflags, afiles...)
ldflags = append(ldflags, sfiles...)
ldflags = append(ldflags, cgoldflags...)
+ ldflags = append(ldflags, p.CgoLDFLAGS...)
if usesCgo && goos == "linux" {
ldflags = append(ldflags, "-Wl,-E")
}
Index: src/cmd/go/test.bash
===================================================================
--- a/src/cmd/go/test.bash
+++ b/src/cmd/go/test.bash
@@ -669,6 +669,31 @@
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


ia...@golang.org

unread,
Mar 26, 2014, 3:53:09 PM3/26/14
to erik.w...@gmail.com, golang-co...@googlegroups.com, re...@codereview-hr.appspotmail.com

ia...@golang.org

unread,
Mar 26, 2014, 3:53:32 PM3/26/14
to erik.w...@gmail.com, golang-co...@googlegroups.com, re...@codereview-hr.appspotmail.com
Have you signed the copyright license agreement?

https://codereview.appspot.com/80780043/

Ian Lance Taylor

unread,
Mar 26, 2014, 6:22:38 PM3/26/14
to Erik Westrup, golang-co...@googlegroups.com, re...@codereview-hr.appspotmail.com
On Wed, Mar 26, 2014 at 3:17 PM, Erik Westrup <erik.w...@gmail.com> wrote:
> On Wed 2014-03-26, ia...@golang.org wrote:
>> Have you signed the copyright license agreement?
>>
>> https://codereview.appspot.com/80780043/
>
> I did that a few hours ago! But I've not received a confirmation email though.

Thanks, it's there.

Ian

ia...@golang.org

unread,
Mar 26, 2014, 6:23:39 PM3/26/14
to erik.w...@gmail.com, golang-co...@googlegroups.com, re...@codereview-hr.appspotmail.com
*** Submitted as
https://code.google.com/p/go/source/detail?r=0134c7020c40 ***

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 <ia...@golang.org>


https://codereview.appspot.com/80780043/

go...@golang.org

unread,
Mar 26, 2014, 6:39:03 PM3/26/14
to erik.w...@gmail.com, golang-co...@googlegroups.com, ia...@golang.org, re...@codereview-hr.appspotmail.com
Reply all
Reply to author
Forward
Message has been deleted
0 new messages