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

cgo const error on OS X 10.7 #1881

Closed
gopherbot opened this issue May 25, 2011 · 18 comments
Closed

cgo const error on OS X 10.7 #1881

gopherbot opened this issue May 25, 2011 · 18 comments

Comments

@gopherbot
Copy link

by kballard@apple.com:

When attempting to compile Go on OS X 10.7 Developer Preview 3 (11A459e), on a Mac Pro
running the 64-bit kernel, with an appropriate version of the pre-release Lion dev tools
installed, go fails to compile the net package.


INSTALL FAIL net
CGOPKGPATH= cgo --  cgo_bsd.go cgo_unix.go 
touch _obj/_cgo_run
6g  -o _go_.6 dial.go dnsmsg.go fd_darwin.go hosts.go ip.go ipsock.go iprawsock.go
lookup.go net.go parse.go pipe.go sock.go tcpsock.go udpsock.go unixsock.go 
dnsclient.go dnsconfig.go fd.go file.go newpollserver.go port.go sendfile_stub.go
sock_bsd.go  _obj/cgo_bsd.cgo1.go _obj/cgo_unix.cgo1.go _obj/_cgo_gotypes.go
6c -FVw -I/Volumes/Greenholm/Users/kevin/go/pkg/darwin_amd64 -I . -o
"_cgo_defun.6" _obj/_cgo_defun.c
gcc -m64 -I . -g -fPIC -O2 -o _cgo_main.o -c   _obj/_cgo_main.c
gcc -m64 -I . -g -fPIC -O2 -o cgo_bsd.cgo2.o -c   _obj/cgo_bsd.cgo2.c
gcc -m64 -I . -g -fPIC -O2 -o cgo_unix.cgo2.o -c   _obj/cgo_unix.cgo2.c
gcc -m64 -I . -g -fPIC -O2 -o _cgo_export.o -c   _obj/_cgo_export.c
gcc -m64 -g -fPIC -O2 -o _cgo1_.o _cgo_main.o cgo_bsd.cgo2.o cgo_unix.cgo2.o
_cgo_export.o  
cgo -dynimport _cgo1_.o >_obj/_cgo_import.c_ && mv -f _obj/_cgo_import.c_
_obj/_cgo_import.c
6c -FVw -I . -o "_cgo_import.6" _obj/_cgo_import.c
cgo_bsd.go:5[_obj/cgo_bsd.cgo1.go:8]: undefined: _Cconst_AI_MASK
cgo_unix.go:69[_obj/cgo_unix.cgo1.go:72]: undefined: _Cconst_AI_ALL
cgo_unix.go:69[_obj/cgo_unix.cgo1.go:72]: undefined: _Cconst_AI_V4MAPPED
cgo_unix.go:69[_obj/cgo_unix.cgo1.go:72]: undefined: _Cconst_AI_CANONNAME
make[1]: *** [_go_.6] Error 1
make: *** [net.install] Error 1

I've attached the output of

cd $GOROOT/src/pkg/net
make
tar c . | gzip >net.tgz

Oddly enough, on my iMac running the same build of 10.7 with the 32-bit kernel with a
different version of the dev tools installed, go builds without a problem.

Attachments:

  1. net.tgz (73959 bytes)
@gopherbot
Copy link
Author

Comment 1 by kballard@apple.com:

I accidentally filed this with the wrong account. Is there any way to edit it to use my
customary account (kballard@gmail.com)?

@adg
Copy link
Contributor

adg commented May 25, 2011

Comment 2:

You would have to file it again, but you don't need to as this issue has already been
reported.
Please add any additional context to issue #1657 with your gmail account.

Status changed to Duplicate.

Merged into issue #1657.

@gopherbot
Copy link
Author

Comment 3 by kballard:

Is this really the same issue? issue #1657 appears to be a problem that arises in the
test phase. My problem arises when trying to build the net package.

@rsc
Copy link
Contributor

rsc commented May 25, 2011

Comment 4:

undup'ed.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented May 25, 2011

Comment 5:

It looks like cgo assumes const unless it finds other information.
So is AI_MASK even in your system, and can a C program
that does #include <netdb.h> access it?

@gopherbot
Copy link
Author

Comment 6 by kballard:

In /usr/include/netdb.h I find
#define AI_MASK \
    (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | \
    AI_ADDRCONFIG)

@gopherbot
Copy link
Author

Comment 7 by kballard:

If it makes a difference, this is inside an #if block
#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)

@rsc
Copy link
Contributor

rsc commented May 25, 2011

Comment 8:

That doesn't necessarily mean anything.
If you write
#include <netdb.h>
int main() {
    return AI_MASK;
}
does it compile?

@gopherbot
Copy link
Author

Comment 9 by kballard:

I take it back. I just looked up that value on the wrong system, still running 10.6.
Similarly, my comment about one system actually compiling above, that was this system.
That part should be completely ignored. And I obviously need more sleep.

@gopherbot
Copy link
Author

Comment 10 by kballard:

Ok, now I've looked in /usr/include/netdb.h on an actual 10.7 system, and I find the
exact same thing.
/* valid flags for addrinfo (not a standard def, apps should not use it) */
#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
#define AI_MASK \
    (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | \
    AI_ADDRCONFIG)
#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */

@rsc
Copy link
Contributor

rsc commented May 25, 2011

Comment 11:

Never try to read include files.  Only compile code.

@gopherbot
Copy link
Author

Comment 12 by kballard:

I compiled the following program with clang:
#include <stdlib.h>
#include <netdb.h>
#include <stdio.h>
int main() {
    printf("AI_MASK: %d\n", AI_MASK);
    return 0;
}
and got as output
AI_MASK: 5127

@gopherbot
Copy link
Author

Comment 13 by kwal@google.com:

I'm running the same build of OS X at home.
As far as I can tell, the version of GCC that ships with the Lion dev tools either
doesn't produce any EnumerationType DWARF entries, or is producing them in a way that
debug/dwarf doesn't recognize.  The dwarf.TagEnumerationType case in loadDWARF in
cgo/gcc.go doesn't ever seem to get run.  Without seeing these tags, cgo can determine
the value for simple const defines (e.g. #define FOO 23) but not more complicated
defines like AI_MASK.

@gopherbot
Copy link
Author

Comment 14 by dmwright:

FYI, I'm seeing exactly this issue on OS X 10.6.7  I've attached my go/src/pkg/net as
well.
I compiled and ran the same test program as Kevin above, and got the same result:
AI_MASK: 5127

Attachments:

  1. net.tgz (69481 bytes)

@gopherbot
Copy link
Author

Comment 15 by briandorsey:

Compiling go worked fine for me a few weeks ago, but crashes with this same error now.
I've recently updated Xcode to the 4C104 build, version 4.2, released on June 6. I'm
running OS/X 10.6.7. It seems likely that something changed in this release of Xcode. 
I also ran the AI_MASK test code:
spark:golang$ cat test.c 
#include <stdlib.h>
#include <netdb.h>
#include <stdio.h>
int main() {
    printf("AI_MASK: %d\n", AI_MASK);
    return 0;
}
spark:golang$ clang test.c -o test.o
spark:golang$ ./test.o 
AI_MASK: 5127
I don't have a sense for where to start troubleshooting, but I'd be happy to try any
experiments which would help diagnose the issue.

@rsc
Copy link
Contributor

rsc commented Jun 13, 2011

Comment 16:

Reproduced with new Xcode on Snow Leopard.
Thanks for the tip.

@rsc
Copy link
Contributor

rsc commented Jun 13, 2011

Comment 17:

This issue was closed by revision 9968090.

Status changed to Fixed.

@rsc
Copy link
Contributor

rsc commented Jul 12, 2011

Comment 18:

This issue was closed by revision d292bc788668.

rsc added a commit that referenced this issue May 11, 2015
««« CL 4607045 / 142f0bc0d6e7
cgo: handle new Apple LLVM-based gcc from Xcode 4.2

That gcc does not include enumerator names and values
in its DWARF debug output.  Create a data block from which
we can read the values instead.

Fixes #1881.

R=iant
CC=golang-dev
https://golang.org/cl/4607045
»»»

R=adg
CC=golang-dev
https://golang.org/cl/4708042
@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

3 participants