cmd/link/internal/arm64: support Mach-O ARM64_RELOC_POINTER_TO_GOT in internal linking

ARM64_RELOC_POINTER_TO_GOT is the arm64 version of X86_64_RELOC_GOT, which has been support
for many years now.

The standard library still doesn't need it, but I've found it necessary
when statically linking against a library I own.

Change-Id: I8eb7bf3c74aed663a1fc00b5dd986057130f7f7a
Reviewed-on: https://go-review.googlesource.com/c/go/+/703315
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
qmuntal 2025-09-12 16:23:40 +02:00 committed by Quim Muntal
parent 742f92063e
commit 6e95748335
2 changed files with 12 additions and 0 deletions

View file

@ -277,6 +277,17 @@ func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loade
su.SetRelocSym(rIdx, syms.GOT)
su.SetRelocAdd(rIdx, int64(ldr.SymGot(targ)))
return true
case objabi.MachoRelocOffset + ld.MACHO_ARM64_RELOC_POINTER_TO_GOT*2 + pcrel:
if targType != sym.SDYNIMPORT {
ldr.Errorf(s, "unexpected GOT reloc for non-dynamic symbol %s", ldr.SymName(targ))
}
ld.AddGotSym(target, ldr, syms, targ, 0)
su := ldr.MakeSymbolUpdater(s)
su.SetRelocType(rIdx, objabi.R_PCREL)
su.SetRelocSym(rIdx, syms.GOT)
su.SetRelocAdd(rIdx, r.Add()+int64(r.Siz())+int64(ldr.SymGot(targ)))
return true
}
// Reread the reloc to incorporate any changes in type above.

View file

@ -111,6 +111,7 @@ const (
MACHO_ARM64_RELOC_PAGEOFF12 = 4
MACHO_ARM64_RELOC_GOT_LOAD_PAGE21 = 5
MACHO_ARM64_RELOC_GOT_LOAD_PAGEOFF12 = 6
MACHO_ARM64_RELOC_POINTER_TO_GOT = 7
MACHO_ARM64_RELOC_ADDEND = 10
MACHO_GENERIC_RELOC_VANILLA = 0
MACHO_FAKE_GOTPCREL = 100