aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/internal/ld
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2023-06-12 13:42:30 -0400
committerCherry Mui <cherryyz@google.com>2023-07-31 17:01:57 +0000
commitbad9ca8a612f6fae85cfc25e07e69ed30384fc84 (patch)
treea1596d501f2255a8def3b698d60960923a71bdcc /src/cmd/link/internal/ld
parent9eb1d5317b2b87c379797edf0dea48e59c9ebc7d (diff)
downloadgo-bad9ca8a612f6fae85cfc25e07e69ed30384fc84.tar.xz
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 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 <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/link/internal/ld')
-rw-r--r--src/cmd/link/internal/ld/data.go4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go
index d651e2e346..21b2e9a9d4 100644
--- a/src/cmd/link/internal/ld/data.go
+++ b/src/cmd/link/internal/ld/data.go
@@ -368,7 +368,9 @@ func (st *relocSymState) relocsym(s loader.Sym, P []byte) {
o = 0
}
} else if target.IsDarwin() {
- if ldr.SymType(rs) != sym.SHOSTOBJ {
+ if ldr.SymType(rs) != sym.SHOSTOBJ && ldr.SymType(s) != sym.SINITARR {
+ // ld-prime drops the offset in data for SINITARR. We need to use
+ // symbol-targeted relocation. See also machoreloc1.
o += ldr.SymValue(rs)
}
} else if target.IsWindows() {