]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link/internal/arm64: support Mach-O ARM64_RELOC_POINTER_TO_GOT in internal linking
authorqmuntal <quimmuntal@gmail.com>
Fri, 12 Sep 2025 14:23:40 +0000 (16:23 +0200)
committerQuim Muntal <quimmuntal@gmail.com>
Tue, 30 Sep 2025 14:37:51 +0000 (07:37 -0700)
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>
src/cmd/link/internal/arm64/asm.go
src/cmd/link/internal/ld/macho.go

index 68474b4484f1af289f9f2b3da00c102f15776baf..b2572fd1040b0bdef82c44e88b58e33db53c3728 100644 (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.
index 431dad9d6bcbaa476d833d829cb5b06fe52224a0..6920f42015b344660db31a3f7580339c563c3a6a 100644 (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