1
0
mirror of https://github.com/golang/go synced 2024-11-24 21:10:04 -07:00

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
This commit is contained in:
Joel Sing 2012-08-22 22:23:56 +10:00
parent 2e6d0968e3
commit 2281c3294b

View 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")
}