Issue 1:
What version of Go are you using (go version)?

go version go1.4.2 darwin/amd64

MacOSX-10.6.8

What did you do?

$ cd $GOPATH/src/github.com/sbinet
$ git clone git://github.com/sbinet/test-cgo
$ cd test-cgo
$ make
/bin/rm -f pkg/my/*.so
(cd pkg/my && cc -shared -o libmy.so lib.c)
# github.com/sbinet/test-cgo/pcgo
github.com/sbinet/test-cgo/pkg._Cvar_Global: unsupported relocation for dynamic symbol Global (type=1 stype=32)
github.com/sbinet/test-cgo/pkg._Cvar_Global: unhandled relocation for Global (type 32 rtype 1)
make: *** [install] Error 2

note that if, in test-cgo/pkg/my/lib.h I change:

#define API_DATA(RTYPE) extern RTYPE
//#define API_DATA(RTYPE) RTYPE

to:

//#define API_DATA(RTYPE) extern RTYPE
#define API_DATA(RTYPE) RTYPE

everything compiles and runs:

$ make && (cd ./pkg/my && pcgo)
/bin/rm -f pkg/my/*.so
(cd pkg/my && cc -shared -o libmy.so lib.c)
>>>
Global: 42
Global: 42
<<<

Note that on master, I get instead:

$ go version devel +48469a2 Mon Feb 23 07:54:13 2015 +0000 darwin/amd64
$ make && (cd ./pkg/my && pcgo)
>>>
Global: 42
fatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0xb01dfacedebac1e pc=0x1dbf23]

runtime stack:
runtime.throw(0x126e70, 0x2a)
/Users/binet/dev/go/root/go/src/runtime/panic.go:511 +0xa0
runtime.sigpanic()
/Users/binet/dev/go/root/go/src/runtime/sigpanic_unix.go:12 +0x62

goroutine 1 [syscall, locked to thread]:
runtime.cgocall_errno(0xac120, 0xc208037ed0, 0xc200000000)
/Users/binet/dev/go/root/go/src/runtime/cgocall.go:130 +0x10c fp=0xc208037eb0 sp=0xc208037e88
github.com/sbinet/test-cgo/pkg._Cfunc_Get(0x25ff0000077a25ff, 0x0)
/Users/binet/dev/go/root/path/src/github.com/sbinet/test-cgo/pkg/:24 +0x3c fp=0xc208037ed0 sp=0xc208037eb0
github.com/sbinet/test-cgo/pkg.Print()
/Users/binet/dev/go/root/path/src/github.com/sbinet/test-cgo/pkg/pkg.go:14 +0x10c fp=0xc208037f58 sp=0xc208037ed0
main.main()
/Users/binet/dev/go/root/path/src/github.com/sbinet/test-cgo/pcgo/main.go:11 +0x4e fp=0xc208037fa0 sp=0xc208037f58
runtime.main()
/Users/binet/dev/go/root/go/src/runtime/proc.go:88 +0x1d2 fp=0xc208037fe0 sp=0xc208037fa0
runtime.goexit()
/Users/binet/dev/go/root/go/src/runtime/asm_amd64.s:2466 +0x1 fp=0xc208037fe8 sp=0xc208037fe0

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
/Users/binet/dev/go/root/go/src/runtime/asm_amd64.s:2466 +0x1
zsh: exit 2 (; cd pkg/my && pcgo; )

Such extern global symbols are heavily used in e.g. the CPython API.

To recap: the pkg builds fine, it's when somebody uses that cgo-based package that all hell breaks loose.

Issue 2:
(This is somewhat related to issue #5699 but I was told to file a new one; things got
more interesting since.)

$ cat a.go
package main; import "fmt"
// #cgo LDFLAGS: -framework Foundation -framework AppKit
// extern void *cgoptr;
import "C"
func main() { fmt.Printf("pointer from cgo: %p\n", C.cgoptr) }
$ cat a.m
#include <AppKit/NSKeyValueBinding.h>
void *cgoptr = &NSObservedObjectKey;

All of the following:

$ CC=gcc CGO_ENABLED=1 GOARCH=amd64 go build -x
$ CC=gcc CGO_ENABLED=1 GOARCH=386 go build -x
$ CC=clang CGO_ENABLED=1 GOARCH=amd64 go build -x
$ CC=clang CGO_ENABLED=1 GOARCH=386 go build -x

will yield the following during the final link:

main(__DATA/__data): unexpected reloc for dynamic symbol NSObservedObjectKey
main(__DATA/__data): unhandled relocation for NSObservedObjectKey (type 32 rtype 1)

This happens for any Objective-C anything.

For larger projects, the link failures become more spectacular. Attached are the results
of building
andlabs/ui@93914ec (this
specific commit) with a modified cmd/ld that does not terminate after 20 error messages
(this should probably be an option like it is for the compilers but I'll leave that for
another issue). I don't know why the 386 one has a different error from the rest; it
should probably be a third issue...

go version:
go version devel +b10044024a6d Thu May 15 15:55:31 2014 +1000 darwin/amd64

gcc version:
i686-apple-darwin10-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM
build 2336.1.00)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

clang version:
Apple clang version 3.0 (tags/Apple/clang-211.10.1) (based on LLVM 3.0svn)
Target: x86_64-apple-darwin10.8.0
Thread model: posix

This is with Xcode 4.2 for Snow Leopard.

Thanks.

Attachments:

newerr.386 (10200 bytes)

newerr.amd64 (17599 bytes)