From: Cherry Zhang Date: Sun, 1 Nov 2020 20:28:21 +0000 (-0500) Subject: cmd/link: use internal linking for -race mode on darwin/arm64 X-Git-Tag: go1.16beta1~349 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3a76627df4f6bd38a3cfa21aeddcb871f6df1881;p=gostls13.git 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 Reviewed-by: Than McIntosh --- diff --git a/src/cmd/link/internal/ld/config.go b/src/cmd/link/internal/ld/config.go index cd64d86a4a..0cb3cc25c0 100644 --- a/src/cmd/link/internal/ld/config.go +++ b/src/cmd/link/internal/ld/config.go @@ -206,7 +206,7 @@ func mustLinkExternal(ctxt *Link) (res bool, reason string) { // When the race flag is set, the LLVM tsan relocatable file is linked // into the final binary, which means external linking is required because // internal linking does not support it. - if *flagRace && (ctxt.Arch.InFamily(sys.PPC64) || ctxt.IsDarwin() && ctxt.IsARM64()) { + if *flagRace && ctxt.Arch.InFamily(sys.PPC64) { return true, "race on " + objabi.GOARCH } diff --git a/src/cmd/link/internal/loadmacho/ldmacho.go b/src/cmd/link/internal/loadmacho/ldmacho.go index d26869e23a..6d1d9bb29e 100644 --- a/src/cmd/link/internal/loadmacho/ldmacho.go +++ b/src/cmd/link/internal/loadmacho/ldmacho.go @@ -724,10 +724,8 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader, if arch.Family == sys.ARM64 && rel.type_ == MACHO_ARM64_RELOC_ADDEND { // Two relocations. This addend will be applied to the next one. - rAdd = int64(rel.symnum) + rAdd = int64(rel.symnum) << 40 >> 40 // convert unsigned 24-bit to signed 24-bit continue - } else { - rAdd = 0 } rSize = rel.length @@ -789,6 +787,8 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader, r.SetSiz(rSize) r.SetSym(rSym) r.SetAdd(rAdd) + + rAdd = 0 // clear rAdd for next iteration } sb.SortRelocs()