Skip to content

Commit 3a76627

Browse files
committed
cmd/link: use internal linking for -race mode on darwin/arm64
The code I wrote in ldmacho.go in CL 266373 was plainly wrong. It didn't carry rAdd over correctly. Fixed. Also added sign extension (as ld64 does). Internal linking with -race mode now works. Enable it. Updates #38485. Change-Id: I78aa949687bf6a0987913059059160b018c7560e Reviewed-on: https://go-review.googlesource.com/c/go/+/267097 Trust: Cherry Zhang <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
1 parent 39a5ee5 commit 3a76627

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/cmd/link/internal/ld/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func mustLinkExternal(ctxt *Link) (res bool, reason string) {
206206
// When the race flag is set, the LLVM tsan relocatable file is linked
207207
// into the final binary, which means external linking is required because
208208
// internal linking does not support it.
209-
if *flagRace && (ctxt.Arch.InFamily(sys.PPC64) || ctxt.IsDarwin() && ctxt.IsARM64()) {
209+
if *flagRace && ctxt.Arch.InFamily(sys.PPC64) {
210210
return true, "race on " + objabi.GOARCH
211211
}
212212

src/cmd/link/internal/loadmacho/ldmacho.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,10 +724,8 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
724724

725725
if arch.Family == sys.ARM64 && rel.type_ == MACHO_ARM64_RELOC_ADDEND {
726726
// Two relocations. This addend will be applied to the next one.
727-
rAdd = int64(rel.symnum)
727+
rAdd = int64(rel.symnum) << 40 >> 40 // convert unsigned 24-bit to signed 24-bit
728728
continue
729-
} else {
730-
rAdd = 0
731729
}
732730

733731
rSize = rel.length
@@ -789,6 +787,8 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
789787
r.SetSiz(rSize)
790788
r.SetSym(rSym)
791789
r.SetAdd(rAdd)
790+
791+
rAdd = 0 // clear rAdd for next iteration
792792
}
793793

794794
sb.SortRelocs()

0 commit comments

Comments
 (0)