go: cmd/link: Go c-archive doesn't work with new Xcode 15 beta ld-prime linker
We found that Go libraries (-buildmode=c-archive
) linked into iOS apps crash on startup (during the dynamic loader?) when using the new Xcode 15 beta’s “ld-prime” linker.
The workaround for now is to force the old linker with LDFLAGS=-ld64
, so filing this issue for people to find.
/cc @agottardo (who figured out the workaround and can probably provide more details)
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 5
- Comments: 21 (10 by maintainers)
Commits related to this issue
- cmd/link: don't generate DYSYMTAB when external linking on Mach-O When external linking, the external linker will generate it. Updates #60694. For #61229. Change-Id: I086a7628dd9baa84b46315641746fc... — committed to golang/go by cherrymui a year ago
- [release-branch.go1.21] cmd/link: don't generate DYSYMTAB when external linking on Mach-O When external linking, the external linker will generate it. Updates #60694. For #61229. Change-Id: I086a76... — committed to golang/go by cherrymui a year ago
- cmd/link: always use symbol-targeted relocations on Mach-O In Mach-O object files, there are two kinds of relocations: "external" relocation, which targets a symbol, and "non-external" relocation, wh... — committed to golang/go by cherrymui a year ago
- [release-branch.go1.21] cmd/link: don't generate DYSYMTAB when external linking on Mach-O When external linking, the external linker will generate it. Updates #60694. For #61229. Change-Id: I086a76... — committed to tailscale/go by cherrymui a year ago
- [release-branch.go1.21] cmd/link: use symbol-targeted relocation for initializers on Mach-O Apple's new linker, ld-prime from Xcode 15 beta, when handling initializers in __mod_init_func, drops the o... — committed to golang/go by cherrymui a year ago
This hack seems to make it work. Basically, for
__mod_init_func
, we need to use symbol-targeted relocation, instead of section+offset-targeted relocation (ld-prime just drops the offset, making it point to the start of the section…)… This seems to work for both ld64 and ld-prime.@albertoAround the fix will be included in Go 1.21, which is to be released next week. You could also checkout the master branch and build the Go toolchain (you could also cherry-pick CL https://golang.org/cl/502616 but it is probably better and simpler to just use the master branch). Thanks.
@agottardo Thanks for sharing. I’ll look into it.
Also, I downloaded Xcode 15 beta, ran it on a macOS ARM64 machine using ld-prime with Go, and found a number of issues. While some of them are minor, I got SIGILL for the c-shared and plugin mode, which may also be related. I’ll look into them. Thanks.