Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: C.malloc expects ulong on OS X 10.9 (Mavericks) #5926

Closed
gopherbot opened this issue Jul 21, 2013 · 28 comments
Closed

cmd/cgo: C.malloc expects ulong on OS X 10.9 (Mavericks) #5926

gopherbot opened this issue Jul 21, 2013 · 28 comments
Milestone

Comments

@gopherbot
Copy link

by mazdak@chango.com:

1. Download src (tip) -- currently 17342:3bf9ffdcca1f
2.  Build using src ./all.bash
3. Fails with cannot find 'libgcc.a'

Output:

# Building C bootstrap tool.
cmd/dist

# Building compilers and Go bootstrap tool for host, darwin/amd64.
lib9
libbio
libmach
misc/pprof
cmd/addr2line
....
image/png
image/gif
# runtime/cgo
clang: warning: argument unused during compilation: '-pthread'
testing/quick
# runtime/cgo
clang: error: no such file or directory: 'libgcc.a'

Which compiler are you using (5g, 6g, 8g, gccgo)?

clang --version
Apple LLVM version 5.0 (clang-500.1.61) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix

Which operating system are you using?

OS X 10.9

Darwin AirBook.local 13.0.0 Darwin Kernel Version 13.0.0: Tue Jul  2 15:57:48 PDT 2013;
root:xnu-2422.1.35~2/RELEASE_X86_64 x86_64
@rsc
Copy link
Contributor

rsc commented Jul 25, 2013

Comment 1:

Why is all.bash using clang?

Labels changed: added priority-accepted, go1.2maybe, removed priority-triage.

Status changed to WaitingForReply.

@gopherbot
Copy link
Author

Comment 2 by mazdak@chango.com:

OS X Mavericks does not ship with gcc or llvm-gcc. Clang is the only option.

@rsc
Copy link
Contributor

rsc commented Jul 25, 2013

Comment 3:

OS X never ships with a compiler. Are you saying that the copy of Xcode you
are using has no gcc?

@gopherbot
Copy link
Author

Comment 4 by mazdak@chango.com:

Well, yes. Xcode 5 does not have GCC. It simply is an alias for clang. I believe they
previously deprecated GCC and llvm-GCC and now completely removed them. Clang no longer
supports the fno-eliminate-unused-debug-types flag which breaks everything even further.

@rsc
Copy link
Contributor

rsc commented Jul 25, 2013

Comment 5:

Does it work better if you do
CC=clang ./all.bash
?
If the tools know they are running a program called clang they try to compensate better.

@gopherbot
Copy link
Author

Comment 6 by kenferry:

It gets further with CC=clang, but doesn't complete.
Also: Xcode 5 drops a tool called gcc, but it looks like it's really clang:
% gcc -v
Configured with:
--prefix=/Volumes/Data/Users/ken/Applications/Xcode5-DP3.app/Contents/Developer/usr
--with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.1.65) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
The gcc binary isn't a symlink, it's its own thing. Anyway.
%  ./all.bash
# Building C bootstrap tool.
cmd/dist
# Building compilers and Go bootstrap tool for host, darwin/amd64.
lib9
libbio
libmach
misc/pprof
cmd/addr2line
cmd/cov
cmd/nm
cmd/objdump
cmd/pack
cmd/prof
cmd/cc
cmd/gc
cmd/6l
cmd/6a
cmd/6c
cmd/6g
pkg/runtime
pkg/errors
pkg/sync/atomic
pkg/sync
pkg/io
pkg/unicode
pkg/unicode/utf8
pkg/unicode/utf16
pkg/bytes
pkg/math
pkg/strings
pkg/strconv
pkg/bufio
pkg/sort
pkg/container/heap
pkg/encoding/base64
pkg/syscall
pkg/time
pkg/os
pkg/reflect
pkg/fmt
pkg/encoding/json
pkg/flag
pkg/path/filepath
pkg/path
pkg/io/ioutil
pkg/log
pkg/regexp/syntax
pkg/regexp
pkg/go/token
pkg/go/scanner
pkg/go/ast
pkg/go/parser
pkg/os/exec
pkg/os/signal
pkg/net/url
pkg/text/template/parse
pkg/text/template
pkg/go/doc
pkg/go/build
cmd/go
# Building packages and commands for darwin/amd64.
runtime
errors
sync/atomic
unicode
unicode/utf8
math
sort
unicode/utf16
crypto/subtle
container/list
container/ring
sync
image/color
runtime/race
container/heap
io
syscall
hash
crypto/cipher
crypto
hash/crc32
crypto/hmac
hash/adler32
hash/crc64
hash/fnv
crypto/md5
crypto/sha1
crypto/sha256
crypto/sha512
bytes
strings
time
path
bufio
text/tabwriter
html
compress/bzip2
strconv
math/rand
math/cmplx
os
reflect
regexp/syntax
net/url
encoding/base64
crypto/aes
crypto/rc4
encoding/ascii85
encoding/base32
image
encoding/pem
path/filepath
os/exec
os/signal
io/ioutil
image/draw
image/jpeg
regexp
fmt
encoding/binary
debug/dwarf
crypto/des
index/suffixarray
flag
go/token
text/template/parse
log
debug/elf
debug/macho
debug/pe
encoding/json
go/scanner
encoding/xml
compress/flate
math/big
encoding/hex
go/ast
mime
encoding/gob
runtime/pprof
text/template
compress/gzip
archive/zip
text/scanner
cmd/yacc
crypto/elliptic
crypto/rand
crypto/dsa
encoding/asn1
crypto/rsa
crypto/ecdsa
archive/tar
html/template
go/doc
go/parser
go/printer
compress/lzw
compress/zlib
crypto/x509/pkix
database/sql/driver
debug/gosym
encoding/csv
database/sql
image/gif
image/png
runtime/debug
go/build
testing
testing/iotest
cmd/cgo
go/format
cmd/gofmt
testing/quick
cmd/fix
cmd/api
cmd/vet
runtime/cgo
net
os/user
# os/user
lookup_unix.go:64: cannot use _Ctype_size_t(bufSize) (type C.size_t) as type C.ulong in
function argument
crypto/x509
net/textproto
log/syslog
mime/multipart
net/mail
crypto/tls
net/http
net/smtp
cmd/go
expvar
net/http/pprof
net/http/cgi
net/http/cookiejar
net/http/httptest
net/http/httputil
net/rpc
cmd/godoc
net/http/fcgi
net/rpc/jsonrpc

@gopherbot
Copy link
Author

Comment 7 by kenferry:

It got through and passed tests after changing
    buf := C.malloc(C.size_t(bufSize))
to
    buf := C.malloc(C.ulong(bufSize))
at lookup_unix.go:64

@rsc
Copy link
Contributor

rsc commented Jul 30, 2013

Comment 8:

issue #5822 is tracking the switch to invoking clang on OS X.
The remaining issue here is the C.malloc prototype not working right.
It looks like someone changed the definition of malloc on OS X 10.9
from taking size_t to ulong (C doesn't care, if they typedef to the same thing,
but Go does).

@gopherbot
Copy link
Author

Comment 9 by mazdak@chango.com:

I am able to build with the changes above; however, I am getting this error:
# command-line-arguments
xxxx.go:190:12: struct size calculation error off=40 bytesize=32
The same go file (which is actually a cgo file) works on older versions of OS X and
Linux.

@gopherbot
Copy link
Author

Comment 10 by mazdak@chango.com:

To assist, here is a snippet that reproduces the above problem:
package main
/*
#include <stdlib.h>
enum ct { A = 0x00, B = 0x01};
typedef enum ct ct;
typedef struct cobject_s {
  enum ct    type;
  size_t      sz;
  union {
    char    *str; // note for str: sz is strlen (not strlen+1
    void    *blob;
    int64_t   i64;   // easiest to have one large int type
  } u;
  void *free; // if this is set, this must be freed on destructuion
} cobject;
typedef struct cbin_s {
  char    bin_name[32];
  cobject object;
} cbin;
*/
import "C"
func main() {
    var a C.cbin
}

@gopherbot
Copy link
Author

Comment 11 by kenferry:

The prototype for malloc still looks like it wants size_t in the 10.9 headers. Could
something else be keeping go from picking it up correctly?
/Volumes/Data/Users/ken/Applications/Xcode5-DP3.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/stdlib.h:
void    *malloc(size_t);
/Volumes/Data/Users/ken/Applications/Xcode5-DP3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/5.0/include/stddef.h:
#if !defined(_SIZE_T) || __has_feature(modules)
/* Always define size_t when modules are available. */
#if !__has_feature(modules)
#define _SIZE_T
#endif
typedef __SIZE_TYPE__ size_t;
#endif
ken@Nepheli ~> clang -dM -E - < /dev/null | grep SIZE_TYPE
#define __SIZE_TYPE__ long unsigned int

@rsc
Copy link
Contributor

rsc commented Jul 31, 2013

Comment 12:

Re "size calculation error", probably the padding rules are different
somehow.
Re size_t vs ulong, my guess is that the clang DWARF output is not
mentioning size_t but instead saying unsigned long as the type of the
argument to malloc. Clang support for generating DWARF information has been
problematic and is really only barely passable.

@gopherbot
Copy link
Author

Comment 13 by Jens.Alfke:

I'm running into this not even trying to build Go; I'm just installing the websockets
package and I get the same error:
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -o $WORK/runtime/cgo/_obj/_all.o
$WORK/runtime/cgo/_obj/_cgo_export.o $WORK/runtime/cgo/_obj/cgo.cgo2.o
$WORK/runtime/cgo/_obj/gcc_darwin_amd64.o $WORK/runtime/cgo/_obj/gcc_setenv.o
$WORK/runtime/cgo/_obj/gcc_util.o $WORK/runtime/cgo/_obj/gcc_amd64.o -Wl,-r -nostdlib
libgcc.a
# runtime/cgo
clang: error: no such file or directory: 'libgcc.a'
Xcode 5 is about to ship, assuming it has the same release schedule (9/17) that iOS 7
does. Sounds like a whole lot of Mac-based developers are going to run into this bug
then, since Software Update likes to semi-automatically upgrade stuff...

@gopherbot
Copy link
Author

Comment 14 by Jens.Alfke:

Hang on, I was able to get websockets to build by prefixing the "go build" command with
"CC=clang" as suggested in the above thread. Whew.

@mirtchovski
Copy link
Contributor

Comment 15:

one more data point. attached is CGO_ENABLED=0 compilation with xcode 5.0. all tests
pass.

Attachments:

  1. go.log (6643 bytes)

@mitchellh
Copy link

Comment 16:

To add another data point, I just upgraded to OS X 10.9 DP7 (latest as of this post)
with Xcode 5 DP6 (also latest), and get the above error:
# os/user
lookup_unix.go:64: cannot use _Ctype_size_t(bufSize) (type C.size_t) as type C.ulong in
function argument

@cookieo9
Copy link
Contributor

Comment 17:

Chiming in with my own datapoint:
 - Ubuntu 12.04 (precise) 32-bit (vagrant's precise32.box running in VirtualBox)
 - Binary Clang+LLVM 3.3 from llvm.org (debian 6 package, because no 32-bit ubuntu one)
 - Latest tip
 - CC=clang
Fails exactly the same as #6:
pkg/os/user/lookup_unix.go:64: cannot use _Ctype_size_t(bufSize) (type C.size_t) as type
C.uint in function argument
Looks like this is a clang-3.3 issue, not just a OSX-Mavericks one.

@davecheney
Copy link
Contributor

Comment 18:

As clang 3.3 and OS X 10.9 are likely to land before, or soon after 1.2 ships I think
the priority if this issue should be raised. I've marked it as such, please feel free to
revert this change if it is not appropriate.

Labels changed: added priority-later, go1.2, removed priority-accepted, go1.2maybe.

@rsc
Copy link
Contributor

rsc commented Sep 11, 2013

Comment 19:

Status changed to Started.

@rsc
Copy link
Contributor

rsc commented Sep 11, 2013

Comment 20:

This issue was closed by revision 397ba2c.

Status changed to Fixed.

@mirtchovski
Copy link
Contributor

Comment 21:

all.bash on mavericks on a fresh clone of the repo past revision 46fd4ef6c0de

Attachments:

  1. go.log (6643 bytes)

@mirtchovski
Copy link
Contributor

Comment 22:

(sorry, uploaded incorrect file). 
here's an all.bash log from mavericks on a fresh clone past the above revision.

@rsc
Copy link
Contributor

rsc commented Sep 11, 2013

Comment 24:

lgtm thanks

@gopherbot
Copy link
Author

Comment 25 by mazdak@chango.com:

Any reason why the following snippet doesn't work?
Error:
# command-line-arguments
xxxx.go:190:12: struct size calculation error off=40 bytesize=32
-----
package main
/*
#include <stdlib.h>
enum ct { A = 0x00, B = 0x01};
typedef enum ct ct;
typedef struct cobject_s {
  enum ct    type;
  size_t      sz;
  union {
    char    *str; // note for str: sz is strlen (not strlen+1
    void    *blob;
    int64_t   i64;   // easiest to have one large int type
  } u;
  void *free; // if this is set, this must be freed on destructuion
} cobject;
typedef struct cbin_s {
  char    bin_name[32];
  cobject object;
} cbin;
*/
import "C"
func main() {
    var a C.cbin
}

@ianlancetaylor
Copy link
Contributor

Comment 26:

Please move the discussion about the struct size calculation to a new issue.  Thanks.

@gopherbot
Copy link
Author

Comment 27 by mazdak@chango.com:

Done. Thank you.
New issue: https://golang.org/issue/6368

@gopherbot
Copy link
Author

Comment 28 by brainscott:

I'm simply running go build and running into an error on Mavericks.
# runtime/cgo
clang: warning: argument unused during compilation: '-pthread'
# runtime/cgo
clang: error: no such file or directory: 'libgcc.a'

@davecheney
Copy link
Contributor

Comment 29:

Please do not comment on fixed issues. 
Please open a new issue.

@rsc rsc added this to the Go1.2 milestone Apr 14, 2015
@rsc rsc removed the go1.2 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants