]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix cgo linking on netbsd
authorJoel Sing <jsing@google.com>
Wed, 22 Aug 2012 12:23:56 +0000 (22:23 +1000)
committerJoel Sing <jsing@google.com>
Wed, 22 Aug 2012 12:23:56 +0000 (22:23 +1000)
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

src/cmd/go/build.go

index e12698f9f01623c65d271e4685646660af261519..fd11a4dcbabf6257f92304902b84ad2e9ba82b04 100644 (file)
@@ -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")
        }