Commit 3e80f9ce authored by Shenghou Ma's avatar Shenghou Ma

cmd/go: invoke gcc -print-libgcc-file-name only once

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6741051
parent 882eb608
...@@ -1541,6 +1541,8 @@ func envList(key string) []string { ...@@ -1541,6 +1541,8 @@ func envList(key string) []string {
var cgoRe = regexp.MustCompile(`[/\\:]`) var cgoRe = regexp.MustCompile(`[/\\:]`)
var cgoLibGccFile string
func (b *builder) cgo(p *Package, cgoExe, obj string, gccfiles []string) (outGo, outObj []string, err error) { func (b *builder) cgo(p *Package, cgoExe, obj string, gccfiles []string) (outGo, outObj []string, err error) {
if goos != toolGOOS { if goos != toolGOOS {
return nil, nil, errors.New("cannot use cgo when compiling for a different operating system") return nil, nil, errors.New("cannot use cgo when compiling for a different operating system")
...@@ -1630,16 +1632,19 @@ func (b *builder) cgo(p *Package, cgoExe, obj string, gccfiles []string) (outGo, ...@@ -1630,16 +1632,19 @@ func (b *builder) cgo(p *Package, cgoExe, obj string, gccfiles []string) (outGo,
bareLDFLAGS = append(bareLDFLAGS, f) bareLDFLAGS = append(bareLDFLAGS, f)
} }
} }
libgcc, err := b.libgcc(p) if cgoLibGccFile == "" {
var err error
cgoLibGccFile, err = b.libgcc(p)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
}
var staticLibs []string var staticLibs []string
if goos == "windows" { if goos == "windows" {
// libmingw32 and libmingwex might also use libgcc, so libgcc must come last // libmingw32 and libmingwex might also use libgcc, so libgcc must come last
staticLibs = []string{"-lmingwex", "-lmingw32", libgcc} staticLibs = []string{"-lmingwex", "-lmingw32", cgoLibGccFile}
} else { } else {
staticLibs = []string{libgcc} staticLibs = []string{cgoLibGccFile}
} }
for _, cfile := range cfiles { for _, cfile := range cfiles {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment