mirror of
https://github.com/golang/go.git
synced 2026-02-05 10:25:06 +03:00
cmd/link/internal/arm64: support Mach-O ARM64_RELOC_SUBTRACTOR in internal linking
ARM64_RELOC_SUBTRACTOR is the arm64 version of X86_64_RELOC_SUBTRACTOR, which has been recently implemented in CL 660715. The standard library still doesn't need it, but I've found it necessary when statically linking against a library I own. Change-Id: I138281b12f2304e3673f7dc92f7137e48bf68fdd Reviewed-on: https://go-review.googlesource.com/c/go/+/703316 Reviewed-by: Carlos Amedee <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
@@ -224,6 +224,28 @@ func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loade
|
||||
}
|
||||
return true
|
||||
|
||||
case objabi.MachoRelocOffset + ld.MACHO_ARM64_RELOC_SUBTRACTOR*2:
|
||||
// ARM64_RELOC_SUBTRACTOR must be followed by ARM64_RELOC_UNSIGNED.
|
||||
// The pair of relocations resolves to the difference between two
|
||||
// symbol addresses (each relocation specifies a symbol).
|
||||
outer, off := ld.FoldSubSymbolOffset(ldr, targ)
|
||||
if outer != s {
|
||||
// TODO: support subtracted symbol in different section.
|
||||
ldr.Errorf(s, "unsupported ARM64_RELOC_SUBTRACTOR reloc: target %s, outer %s", ldr.SymName(targ), ldr.SymName(outer))
|
||||
break
|
||||
}
|
||||
su := ldr.MakeSymbolUpdater(s)
|
||||
relocs := su.Relocs()
|
||||
if rIdx+1 >= relocs.Count() || relocs.At(rIdx+1).Type() != objabi.MachoRelocOffset+ld.MACHO_ARM64_RELOC_UNSIGNED*2 || relocs.At(rIdx+1).Off() != r.Off() {
|
||||
ldr.Errorf(s, "unexpected ARM64_RELOC_SUBTRACTOR reloc, must be followed by ARM64_RELOC_UNSIGNED at same offset")
|
||||
break
|
||||
}
|
||||
su.SetRelocType(rIdx+1, objabi.R_PCREL)
|
||||
su.SetRelocAdd(rIdx+1, r.Add()+int64(r.Off())+int64(r.Siz())-off)
|
||||
// Remove the other relocation
|
||||
su.SetRelocSiz(rIdx, 0)
|
||||
return true
|
||||
|
||||
case objabi.MachoRelocOffset + ld.MACHO_ARM64_RELOC_BRANCH26*2 + pcrel:
|
||||
su := ldr.MakeSymbolUpdater(s)
|
||||
su.SetRelocType(rIdx, objabi.R_CALLARM64)
|
||||
|
||||
@@ -106,6 +106,7 @@ const (
|
||||
MACHO_ARM_RELOC_SECTDIFF = 2
|
||||
MACHO_ARM_RELOC_BR24 = 5
|
||||
MACHO_ARM64_RELOC_UNSIGNED = 0
|
||||
MACHO_ARM64_RELOC_SUBTRACTOR = 1
|
||||
MACHO_ARM64_RELOC_BRANCH26 = 2
|
||||
MACHO_ARM64_RELOC_PAGE21 = 3
|
||||
MACHO_ARM64_RELOC_PAGEOFF12 = 4
|
||||
|
||||
Reference in New Issue
Block a user