FAQ
Reviewers: dvyukov,

Message:
Hello dvyukov@google.com (cc: golang-dev@googlegroups.com),

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


Description:
cmd/go: fix data race on cgoLibGccFile
Fixes issue 4426.

Please review this at http://codereview.appspot.com/6851099/

Affected files:
M src/cmd/go/build.go


Index: src/cmd/go/build.go
===================================================================
--- a/src/cmd/go/build.go
+++ b/src/cmd/go/build.go
@@ -1478,7 +1478,7 @@
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 "", fmt.Errorf("gcc -print-libgcc-file-name: %v (%s)", err, f)
}
return strings.Trim(string(f), "\r\n"), nil
}
@@ -1542,7 +1542,10 @@

var cgoRe = regexp.MustCompile(`[/\\:]`)

-var cgoLibGccFile string
+var (
+ cgoLibGccFile string
+ cgoLibGccFileOnce sync.Once
+)

func (b *builder) cgo(p *Package, cgoExe, obj string, gccfiles []string)
(outGo, outObj []string, err error) {
if goos != toolGOOS {
@@ -1633,13 +1636,17 @@
bareLDFLAGS = append(bareLDFLAGS, f)
}
}
+
+ cgoLibGccFileOnce.Do(func() {
+ cgoLibGccFile, err = b.libgcc(p)
+ })
if cgoLibGccFile == "" {
- var err error
- cgoLibGccFile, err = b.libgcc(p)
- if err != nil {
- return nil, nil, err
+ if err == nil {
+ err = errors.New("failed to get libgcc filename")
}
+ return nil, nil, err
}
+
var staticLibs []string
if goos == "windows" {
// libmingw32 and libmingwex might also use libgcc, so libgcc must come
last

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedNov 23, '12 at 11:28a
activeNov 23, '12 at 11:59a
posts3
users2
websitegolang.org

2 users in discussion

Minux Ma: 2 posts Dvyukov: 1 post

People

Translate

site design / logo © 2022 Grokbase