]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: fix Macho-O X86_64_RELOC_SUBTRACTOR in internal linking
authorqmuntal <quimmuntal@gmail.com>
Mon, 15 Sep 2025 12:23:44 +0000 (14:23 +0200)
committerQuim Muntal <quimmuntal@gmail.com>
Tue, 23 Sep 2025 18:48:39 +0000 (11:48 -0700)
X86_64_RELOC_SUBTRACTOR is handled as a generic R_PCREL relocations,
which gets the relocation size subtracted from the relocated value.

This is not supposed to happen for this particular relocation, so
compensate by adding the size to the addend.

Cq-Include-Trybots: luci.golang.try:gotip-darwin-amd64-race
Change-Id: I6e6889d63bb03b8076e3e409722601dfebec57e5
Reviewed-on: https://go-review.googlesource.com/c/go/+/703776
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
src/cmd/link/internal/amd64/asm.go

index b8127a2538ea18382aaa7aba6f3000a81db31d80..5424de800cac9fc12efb2e0f074e3edb825a98ca 100644 (file)
@@ -208,7 +208,7 @@ func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loade
                }
                // The second relocation has the target symbol we want
                su.SetRelocType(rIdx+1, objabi.R_PCREL)
-               su.SetRelocAdd(rIdx+1, r.Add()+int64(r.Off())-off)
+               su.SetRelocAdd(rIdx+1, r.Add()+int64(r.Off())+int64(r.Siz())-off)
                // Remove the other relocation
                su.SetRelocSiz(rIdx, 0)
                return true