From: Shenghou Ma Date: Sat, 23 Feb 2013 12:24:38 +0000 (+0800) Subject: cmd/cgo, cmd/dist, cmd/go: cgo with clang fixes X-Git-Tag: go1.1rc2~881 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=eec961470fc38a253b46b4004f9acb72741e93d7;p=gostls13.git cmd/cgo, cmd/dist, cmd/go: cgo with clang fixes 1. Workaround the smart clang diagnostics with -Qunused-arguments: clang: error: argument unused during compilation: '-XXX' 2. if "clang -print-libgcc-file-name" returns non-absolute path, don't provide that on linker command line. 3. Fix dwarf.PtrType.Size() in cmd/cgo as clang doesn't generate DW_AT_byte_size for pointer types. 4. Workaround warnings for -Wno-unneeded-internal-declaration with -Wno-unknown-warning-option. 5. Add -Wno-unused-function. 6. enable race detector test on darwin with clang (at least Apple clang version 1.7 (tags/Apple/clang-77) works). Requires CL 7354043. Update #4829 This should fix most parts of the problem, but one glitch still remains. DWARF generated by newer clang doesn't differentiate these two function types: void *malloc(size_t); void *malloc(unsigned long int); so you might need to do this to make make.bash pass: sed -i -e 's/C.malloc(C.size_t/C.malloc(C.ulong/' pkg/os/user/lookup_unix.go R=golang-dev, dave, iant, rsc CC=golang-dev https://golang.org/cl/7351044 --- diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index ad28ec18cb..4b0a521a87 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -783,7 +783,13 @@ func (p *Package) gccCmd() []string { 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", ) } @@ -1049,6 +1055,12 @@ func (c *typeConv) Type(dtype dwarf.Type, pos token.Pos) *Type { 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 diff --git a/src/cmd/dist/build.c b/src/cmd/dist/build.c index eb72074ec8..cf754a4103 100644 --- a/src/cmd/dist/build.c +++ b/src/cmd/dist/build.c @@ -409,6 +409,7 @@ static char *proto_gccargs[] = { "-Wno-comment", "-Werror", "-fno-common", + "-ggdb", "-pipe", "-O2", }; @@ -604,10 +605,10 @@ install(char *dir) splitfields(&gccargs, bstr(&b)); for(i=0; i