if strings.Contains(p.gccName(), "clang") {
c = append(c,
"-ferror-limit=0",
+ // Apple clang version 1.7 (tags/Apple/clang-77) (based on LLVM 2.9svn)
+ // doesn't have -Wno-unneeded-internal-declaration, so we need yet another
+ // flag to disable the warning. Yes, really good diagnostics, clang.
+ "-Wno-unknown-warning-option",
"-Wno-unneeded-internal-declaration",
+ "-Wno-unused-function",
+ "-Qunused-arguments",
)
}
return t
}
+ // clang won't generate DW_AT_byte_size for pointer types,
+ // so we have to fix it here.
+ if dt, ok := base(dtype).(*dwarf.PtrType); ok && dt.ByteSize == -1 {
+ dt.ByteSize = c.ptrSize
+ }
+
t := new(Type)
t.Size = dtype.Size()
t.Align = -1
func (b *builder) libgcc(p *Package) (string, error) {
var buf bytes.Buffer
+ gccCmd := b.gccCmd(p.Dir)
+
prev := b.print
if buildN {
// In -n mode we temporarily swap out the builder's
return fmt.Fprint(&buf, a...)
}
}
- f, err := b.runOut(p.Dir, p.ImportPath, b.gccCmd(p.Dir), "-print-libgcc-file-name")
+ f, err := b.runOut(p.Dir, p.ImportPath, gccCmd, "-print-libgcc-file-name")
if err != nil {
return "", fmt.Errorf("gcc -print-libgcc-file-name: %v (%s)", err, f)
}
b.print(s)
return "$LIBGCC", nil
}
+
+ // clang might not be able to find libgcc, and in that case,
+ // it will simply return "libgcc.a", which is of no use to us.
+ if strings.Contains(gccCmd[0], "clang") && !filepath.IsAbs(string(f)) {
+ return "", nil
+ }
+
return strings.Trim(string(f), "\r\n"), nil
}
}
a = append(a, b.gccArchArgs()...)
// gcc-4.5 and beyond require explicit "-pthread" flag
- // for multithreading with pthread library, but clang whines
- // about unused arguments if we pass it.
+ // for multithreading with pthread library.
if buildContext.CgoEnabled {
switch goos {
case "windows":
a = append(a, "-mthreads")
default:
- if !strings.Contains(a[0], "clang") {
- a = append(a, "-pthread")
- }
+ a = append(a, "-pthread")
}
}
+ // clang is too smart about command-line arguments
+ if strings.Contains(a[0], "clang") {
+ a = append(a, "-Qunused-arguments")
+ }
+
// On OS X, some of the compilers behave as if -fno-common
// is always set, and the Mach-O linker in 6l/8l assumes this.
// See http://golang.org/issue/3253.
var (
cgoLibGccFile string
+ cgoLibGccErr error
cgoLibGccFileOnce sync.Once
)
}
cgoLibGccFileOnce.Do(func() {
- cgoLibGccFile, err = b.libgcc(p)
+ cgoLibGccFile, cgoLibGccErr = b.libgcc(p)
})
- if cgoLibGccFile == "" {
- if err == nil {
- err = errors.New("failed to get libgcc filename")
- }
+ if cgoLibGccFile == "" && cgoLibGccErr != nil {
return nil, nil, err
}
var staticLibs []string
if goos == "windows" {
// libmingw32 and libmingwex might also use libgcc, so libgcc must come last
- staticLibs = []string{"-lmingwex", "-lmingw32", cgoLibGccFile}
- } else {
- staticLibs = []string{cgoLibGccFile}
+ staticLibs = []string{"-lmingwex", "-lmingw32"}
+ }
+ if cgoLibGccFile != "" {
+ staticLibs = append(staticLibs, cgoLibGccFile)
}
for _, cfile := range cfiles {
# Race detector only supported on Linux and OS X,
# and only on amd64, and only when cgo is enabled.
-# Also, clang can't seem to link the .syso files, so only
-# run if we're using gcc.
-case "$GOHOSTOS-$GOOS-$GOARCH-$CGO_ENABLED-${CC:-gcc}" in
-linux-linux-amd64-1-*gcc* | darwin-darwin-amd64-1-*gcc*)
+case "$GOHOSTOS-$GOOS-$GOARCH-$CGO_ENABLED" in
+linux-linux-amd64-1 | darwin-darwin-amd64-1)
echo
echo '# Testing race detector.'
go test -race -i flag