aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/internal/ld/data.go
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2023-06-15 17:25:08 -0400
committerCherry Mui <cherryyz@google.com>2023-07-31 17:02:24 +0000
commitbe910bf2fd6dee75bfb15aab567dc94b126bde29 (patch)
tree1d36b70e31dd00806630f2febd97eabb2e912e83 /src/cmd/link/internal/ld/data.go
parentbad9ca8a612f6fae85cfc25e07e69ed30384fc84 (diff)
downloadgo-be910bf2fd6dee75bfb15aab567dc94b126bde29.tar.xz
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, 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 <thanm@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/link/internal/ld/data.go')
-rw-r--r--src/cmd/link/internal/ld/data.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go
index 21b2e9a9d4..95fc8b5a42 100644
--- a/src/cmd/link/internal/ld/data.go
+++ b/src/cmd/link/internal/ld/data.go
@@ -368,9 +368,11 @@ func (st *relocSymState) relocsym(s loader.Sym, P []byte) {
o = 0
}
} else if target.IsDarwin() {
- 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.
+ if ldr.SymType(s).IsDWARF() {
+ // We generally use symbol-targeted relocations.
+ // DWARF tools seem to only handle section-targeted relocations,
+ // so generate section-targeted relocations in DWARF sections.
+ // See also machoreloc1.
o += ldr.SymValue(rs)
}
} else if target.IsWindows() {