From: Joel Sing Date: Wed, 22 Aug 2012 12:23:56 +0000 (+1000) Subject: cmd/go: fix cgo linking on netbsd X-Git-Tag: go1.1rc2~2611 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2281c3294b01501b177670e21d571ca7d5074cbf;p=gostls13.git cmd/go: fix cgo linking on netbsd NetBSD's built-in linker script for 'ld -r' does not provide a SEARCH_DIR. As a result libgcc.a is not found when -lgcc is used. Work around this by determining the path to libgcc (by invoking gcc with the -print-libgcc-file-name option) and explicitly referencing the resulting library. R=golang-dev, iant, aram, lucio.dere, minux.ma CC=golang-dev https://golang.org/cl/6470044 --- diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go index e12698f9f0..fd11a4dcba 100644 --- a/src/cmd/go/build.go +++ b/src/cmd/go/build.go @@ -1427,6 +1427,16 @@ func gccgoPrefix(p *Package) string { return "go_" + p.ImportPath } +// libgcc returns the filename for libgcc, as determined by invoking gcc with +// the -print-libgcc-file-name option. +func (b *builder) libgcc(p *Package) (string, error) { + f, err := b.runOut(p.Dir, p.ImportPath, b.gccCmd(p.Dir), "-print-libgcc-file-name") + if err != nil { + return "", nil + } + return strings.Trim(string(f), "\r\n"), nil +} + // gcc runs the gcc C compiler to create an object from a single C file. func (b *builder) gcc(p *Package, out string, flags []string, cfile string) error { cfile = mkAbs(p.Dir, cfile) @@ -1571,7 +1581,11 @@ func (b *builder) cgo(p *Package, cgoExe, obj string, gccfiles []string) (outGo, bareLDFLAGS = append(bareLDFLAGS, f) } } - staticLibs := []string{"-lgcc"} + libgcc, err := b.libgcc(p) + if err != nil { + return nil, nil, err + } + staticLibs := []string{libgcc} if goos == "windows" { staticLibs = append(staticLibs, "-lmingwex", "-lmingw32") }