Skip to content
New issue

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

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

Already on GitHub? # to your account

forcing internal link mode on macOS causes "unexpected reloc for dynamic symbol" link errors #84

Closed
efritz opened this issue Jun 19, 2024 · 9 comments

Comments

@efritz
Copy link

efritz commented Jun 19, 2024

I tried to compile an existing project that uses go-gl/glfw/v3.2 and saw link-time errors on MacOS which did not occur previously on the same version.

Running the gl21-cube example has the same link error.

$pwd
~/example/gl21-cube

$ go run .
go: downloading github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb
go: downloading github.com/go-gl/gl v0.0.0-20210426225639-a3bfa832c8aa
# github.com/go-gl/example/gl21-cube
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_METACLASS_$_NSObject
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_METACLASS_$_NSObject
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol _objc_empty_cache
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_CLASS_$_NSObject
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol _objc_empty_cache
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_METACLASS_$_NSObject
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_METACLASS_$_NSObject
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol _objc_empty_cache
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_CLASS_$_NSObject
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol _objc_empty_cache
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_CLASS_$_NSObject
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol _objc_empty_cache
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_METACLASS_$_NSObject
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_METACLASS_$_NSObject
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol _objc_empty_cache
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_CLASS_$_NSView
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol _objc_empty_cache
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_METACLASS_$_NSObject
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_METACLASS_$_NSView
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol _objc_empty_cache
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_METACLASS_$_NSObject
/usr/local/go/pkg/tool/darwin_arm64/link: too many errors

$ go version
go version go1.21.3 darwin/arm64

$ sw_vers
ProductName:		macOS
ProductVersion:		14.5
BuildVersion:		23F79

Any advise on how to help diagnose this?

@dmitshur
Copy link
Member

dmitshur commented Jun 19, 2024

v0.0.0-20210410170116-ea3d685f79fb is a pretty old version of glfw/v3.3. Can you try the latest and see if that fixes it?

go get github.com/go-gl/glfw/v3.3/glfw
go run .

If so, we should update the dependency versions in the go.mod.

@efritz
Copy link
Author

efritz commented Jun 20, 2024

 -       github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb
 +       github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a

Same issue with head of master. The project I originally noticed this on doesn't seem to work with any versions v3.2/v3.3.

I'm not sure if an OS update has caused some headers to become mis-aligned. Is there any other system information I can gather to help get more of a handle on where the issue is?

@dmitshur
Copy link
Member

Thanks for trying. That's unexpected. I have a similar setup but I can't reproduce the problem so far. A few more ideas to try:

  1. What's your Xcode version (xcodebuild -version)?
  2. To confirm, since your go version output includes darwin/arm64, this is an Apple silicon Mac and not an Intel one, right?
  3. Can you also try with Go 1.22.4 by running GOTOOLCHAIN=go1.22.4 go run .?

@efritz
Copy link
Author

efritz commented Jun 21, 2024

  1. xcodebuild -version doesn't directly give me a version, but xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance. I blew away this directory and re-installed via xcode-select --install. I see no updates.
  2. Yes, I'm having this error on an M1.
  3. Same output:
$ GOTOOLCHAIN=go1.22.4 go run .
go: downloading go1.22.4 (darwin/arm64)
# github.com/go-gl/example/gl21-cube
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_METACLASS_$_NSObject
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_METACLASS_$_NSObject
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol _objc_empty_cache
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_CLASS_$_NSObject
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol _objc_empty_cache
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_METACLASS_$_NSObject
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_METACLASS_$_NSObject
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol _objc_empty_cache
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_CLASS_$_NSObject
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol _objc_empty_cache
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_CLASS_$_NSObject
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol _objc_empty_cache
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_METACLASS_$_NSObject
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_METACLASS_$_NSObject
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol _objc_empty_cache
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_CLASS_$_NSView
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol _objc_empty_cache
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_METACLASS_$_NSObject
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_METACLASS_$_NSView
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol _objc_empty_cache
github.com/go-gl/glfw/v3.3/glfw(__DATA/__objc_data): unexpected reloc for dynamic symbol OBJC_METACLASS_$_NSObject
/Users/efritz/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.darwin-arm64/pkg/tool/darwin_arm64/link: too many errors

@dmitshur
Copy link
Member

That's quite odd. I'm finding similar errors in issues like mattn/go-sqlite3#112, mattn/go-sqlite3#404. They suggest this might be caused by something being wrong with the Xcode installation.

Can you also post go env output? It's possible one of the flags there has a non-default value that might be contributing to this.

@efritz
Copy link
Author

efritz commented Jun 21, 2024

GO111MODULE=''
GOARCH='arm64'
GOBIN='/Users/efritz/go/bin'
GOCACHE='/Users/efritz/Library/Caches/go-build'
GOENV='/Users/efritz/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS='-ldflags=-linkmode=internal'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/efritz/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/efritz/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.3'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/66/wf1z3g5x05jd2hfrwvkdly140000gn/T/go-build3004369193=/tmp/go-build -gno-record-gcc-switches -fno-common'

@efritz
Copy link
Author

efritz commented Jun 21, 2024

Ah! go run -ldflags -linkmode=external . fixes it!

@dmitshur
Copy link
Member

dmitshur commented Jun 21, 2024

GOFLAGS='-ldflags=-linkmode=internal'

That looks relevant! Please try without forcing internal link mode (which isn't supported with cgo, see golang/go#38918). The go command should default to external automatically (see mattn/go-sqlite3#404 (comment)).

@efritz
Copy link
Author

efritz commented Jun 21, 2024

Thanks so much for your help (and sorry but glad that it was user error)! I had added the linkmode flag to my dotfiles on a different computer and didn't even remember the change.

@efritz efritz closed this as completed Jun 21, 2024
@dmitshur dmitshur changed the title Failure to compile on MacOS Sonoma forcing internal link mode on macOS causes "unexpected reloc for dynamic symbol" link errors Jun 21, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants