-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
cmd/link: Go c-archive doesn't work with new Xcode 15 beta ld-prime linker #60694
Comments
cc @golang/compiler |
cc @golang/ios (Does this only affect iOS apps, not macOS?) |
A screenshot of the crash on device (this is an iPhone 13 mini running iOS 17 Developer Beta 1, build number 21a5248v): @prattmic yes, this appears to be iOS-only for now, at least based on the Xcode 15 release notes:
I noticed ld-prime throws this warning out during build time, it is the only warning I could see:
Attached is the crash report from iOS: IPNExtension-crash.ips.zip I'll try to upload a minimal repro Xcode project as soon as possible. |
Thanks for reporting. From the stack trace it just jumps to
This looks like the C linker doesn't like our dynamic symbol table? If possible, could you share the output of |
otool output attached: otool_output.txt Will get you a minimal repro project soon! |
Thanks.
This matches |
Does this patch make any difference? (This is a patch to the Go linker. You'll need to reinstall the linker after applying the patch: |
Thanks for looking into this. I'll give your diff a try soon. Minimal repro app project attached here: LDPrimeRepro.zip It's a SwiftUI app that upon app launch tries to call the SomeFunc() Go function. Install Xcode 15.0 beta 1, then build and run it onto an iPhone (you might need to do it twice). App will crash immediately upon launch. |
@cherrymui applied your patch and rebuilt Go. It got rid of the warning when building the repro project, but I am still hitting the same crash: |
@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. |
I think I understand it now. It seems ld-prime doesn't honor the initializer we set in
which points to
which is the initializer entry symbol to initialize the runtime. (I'm using a macOS AMD64 machine, but the problem looks the same.) Linking with ld64,
We have the same initializer symbol in But linking with ld-prime,
We have I'll see if this is an intentional breaking behavior change or a bug for ld-prime. If we have to work around it, perhaps one possibility is putting the entry symbol (or a jump instruction to the entry symbol) at the start of the text section... ==========
c.c
Build with
|
This hack seems to make it work. Basically, for
|
Great! I’ll try your patch as soon as I get a chance :) |
Change https://go.dev/cl/502617 mentions this issue: |
Change https://go.dev/cl/502616 mentions this issue: |
Change https://go.dev/cl/503935 mentions this issue: |
FYI, I filed #61229 for other issues with the new Apple linker, and included CLs for workarounds there. (This issue is currently specifically c-archive mode.) |
When external linking, the external linker will generate it. Updates #60694. For #61229. Change-Id: I086a7628dd9baa84b46315641746fc3640473f2b Reviewed-on: https://go-review.googlesource.com/c/go/+/502617 Reviewed-by: Than McIntosh <[email protected]> Run-TryBot: Cherry Mui <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
Change https://go.dev/cl/513757 mentions this issue: |
…al linking on Mach-O When external linking, the external linker will generate it. Updates #60694. For #61229. Change-Id: I086a7628dd9baa84b46315641746fc3640473f2b Reviewed-on: https://go-review.googlesource.com/c/go/+/502617 Reviewed-by: Than McIntosh <[email protected]> Run-TryBot: Cherry Mui <[email protected]> TryBot-Result: Gopher Robot <[email protected]> (cherry picked from commit f55e7e1) Reviewed-on: https://go-review.googlesource.com/c/go/+/513757
In Mach-O object files, there are two kinds of relocations: "external" relocation, which targets a symbol, and "non-external" relocation, which targets a section. For targeting symbols not in the current object, we must use symbol-targeted relocations. For targeting symbols defined in the current object, for some relocation types, both kinds can be used. We currently use section-targeted relocations for R_ADDR targeting locally defined symbols. Modern Apple toolchain seems to prefer symbol-targeted relocations. Also, Apple's new linker, ld-prime, seems to not handle section- targeted relocations well in some cases. So this CL switches to always generate symbol-targeted relocations. This also simplifies the code. One exception is that DWARF tools seem to handle only section- targeted relocations. So generate those in DWARF sections. This CL supersedes CL 502616. Fixes #60694. For #61229. Change-Id: I3b74df64f21114635061bcd89114392b3a2d588b Reviewed-on: https://go-review.googlesource.com/c/go/+/503935 Reviewed-by: Than McIntosh <[email protected]> Run-TryBot: Cherry Mui <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
Change https://go.dev/cl/514535 mentions this issue: |
…al linking on Mach-O When external linking, the external linker will generate it. Updates golang#60694. For golang#61229. Change-Id: I086a7628dd9baa84b46315641746fc3640473f2b Reviewed-on: https://go-review.googlesource.com/c/go/+/502617 Reviewed-by: Than McIntosh <[email protected]> Run-TryBot: Cherry Mui <[email protected]> TryBot-Result: Gopher Robot <[email protected]> (cherry picked from commit f55e7e1) Reviewed-on: https://go-review.googlesource.com/c/go/+/513757
So actually which is the way to apply this fix? Do I have to wait for a major release or is there a way to use a specific commit where this is already fixed? |
…initializers on Mach-O Apple's new linker, ld-prime from Xcode 15 beta, when handling initializers in __mod_init_func, drops the offset in the data, resolving the relocation to the beginning of the section. The latest version of ld-prime rejects non-zero addend. We need to use symbol-targeted "external" relocations, so that it doesn't need an addend and can be resolved correctly. This also works fine with ld64. Fixes #60694. For #61229. Change-Id: Ida2be6aa4c91bfcd142b755e2ec63aabfbbd77a6 Reviewed-on: https://go-review.googlesource.com/c/go/+/502616 Run-TryBot: Cherry Mui <[email protected]> Reviewed-by: Than McIntosh <[email protected]> TryBot-Result: Gopher Robot <[email protected]> (cherry picked from commit bad9ca8) Reviewed-on: https://go-review.googlesource.com/c/go/+/514535
@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. |
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)
The text was updated successfully, but these errors were encountered: