Skip to content

cmd/ld: Objective-C dynamic relocation link failure with internal linker on Mac OS X 10.6 with Xcode 4.2 #8009

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

Closed
andlabs opened this issue May 16, 2014 · 5 comments

Comments

@andlabs
Copy link
Contributor

andlabs commented May 16, 2014

(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:

  1. newerr.386 (10200 bytes)
  2. newerr.amd64 (17599 bytes)
@andlabs
Copy link
Contributor Author

andlabs commented May 16, 2014

Comment 1:

As another example, consider
$ cat b.go
package main; import "fmt"
// #cgo LDFLAGS: -framework Foundation
// extern void *cgoptr(void);
import "C"
func main() { fmt.Printf("pointer from cgo: %p\n", C.cgoptr()) }
$ cat b.m
#include <Foundation/NSObject.h>
void *cgoptr(void) { return [NSObject new]; }
which yields
main(__DATA/__objc_classrefs): unexpected reloc for dynamic symbol OBJC_CLASS_$_NSObject
main(__DATA/__objc_classrefs): unhandled relocation for OBJC_CLASS_$_NSObject (type 32
rtype 1)
I also forgot to say that things work fine with -linkmode external, as with issue #5699.

@ianlancetaylor
Copy link
Contributor

Comment 2:

Labels changed: added repo-main, release-go1.4.

@rsc
Copy link
Contributor

rsc commented Sep 15, 2014

Comment 3:

The real question for me is why this is not using linkmode external in the first place.
Linkmode internal is supposed to be used only for the standard library.
Are you forcing linkmode internal somehow?

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Oct 6, 2014

Comment 4:

Not going to get to this for 1.4. Sorry.

Labels changed: added release-go1.5, removed release-go1.4.

@rsc
Copy link
Contributor

rsc commented Apr 28, 2015

Per #9511, we will not be making any further bug fixes specific to 10.6.

@rsc rsc closed this as completed Apr 28, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
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

6 participants