]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: use internal linking for -race mode on darwin/arm64
authorCherry Zhang <cherryyz@google.com>
Sun, 1 Nov 2020 20:28:21 +0000 (15:28 -0500)
committerCherry Zhang <cherryyz@google.com>
Mon, 2 Nov 2020 23:58:08 +0000 (23:58 +0000)
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 <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/link/internal/ld/config.go
src/cmd/link/internal/loadmacho/ldmacho.go

index cd64d86a4afbbc1026a7d9fb1e93270eaa5f0d66..0cb3cc25c06408b96ee3acbddda80e11553623e7 100644 (file)
@@ -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
        }
 
index d26869e23a734180944bb74cdb1797e3be7b04a3..6d1d9bb29edd5646994e454a2b9a5da1dcacc338 100644 (file)
@@ -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()