]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: support plugin on macOS/ARM64
authorCherry Zhang <cherryyz@google.com>
Sat, 3 Oct 2020 20:26:37 +0000 (16:26 -0400)
committerCherry Zhang <cherryyz@google.com>
Tue, 6 Oct 2020 22:55:23 +0000 (22:55 +0000)
Updates #38485.

Change-Id: I8295f7fad55b1f9701162f9d2902b3499137c64d
Reviewed-on: https://go-review.googlesource.com/c/go/+/259441
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/dist/test.go
src/cmd/internal/sys/supported.go
src/cmd/link/internal/arm64/asm.go
src/cmd/link/internal/ld/config.go
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/ld/macho.go

index abe496fdeed0515f5f5b63dba00db365901fe2ff..4b07501b6dc6773935a2a79312df394c9848fd18 100644 (file)
@@ -1011,7 +1011,7 @@ func (t *tester) supportedBuildmode(mode string) bool {
                switch pair {
                case "linux-386", "linux-amd64", "linux-arm", "linux-s390x", "linux-ppc64le":
                        return true
-               case "darwin-amd64":
+               case "darwin-amd64", "darwin-arm64":
                        return true
                case "freebsd-amd64":
                        return true
index b2b3b02bf6e9b9444e5760b619b208a3f9b11698..94fc92146cea34300b9fdf5f0774ced4953a62ba 100644 (file)
@@ -104,7 +104,7 @@ func BuildModeSupported(compiler, buildmode, goos, goarch string) bool {
                switch platform {
                case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/s390x", "linux/ppc64le",
                        "android/amd64", "android/arm", "android/arm64", "android/386",
-                       "darwin/amd64",
+                       "darwin/amd64", "darwin/arm64",
                        "freebsd/amd64":
                        return true
                }
index 945b83822cb3ace6149010e7b4baddde8a5f84da..1d2aa591d70b379e54cae8379f1b669411a6a598 100644 (file)
@@ -371,7 +371,7 @@ func machoreloc1(arch *sys.Arch, out *ld.OutBuf, ldr *loader.Loader, s loader.Sy
        rt := r.Type
        siz := r.Size
 
-       if ldr.SymType(rs) == sym.SHOSTOBJ || rt == objabi.R_CALLARM64 || rt == objabi.R_ADDRARM64 {
+       if ldr.SymType(rs) == sym.SHOSTOBJ || rt == objabi.R_CALLARM64 || rt == objabi.R_ADDRARM64 || rt == objabi.R_ARM64_GOTPCREL {
                if ldr.SymDynid(rs) < 0 {
                        ldr.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", rt, sym.RelocName(arch, rt), ldr.SymName(rs), ldr.SymType(rs), ldr.SymType(rs))
                        return false
@@ -415,6 +415,22 @@ func machoreloc1(arch *sys.Arch, out *ld.OutBuf, ldr *loader.Loader, s loader.Sy
                }
                v |= 1 << 24 // pc-relative bit
                v |= ld.MACHO_ARM64_RELOC_PAGE21 << 28
+       case objabi.R_ARM64_GOTPCREL:
+               siz = 4
+               // Two relocation entries: MACHO_ARM64_RELOC_GOT_LOAD_PAGEOFF12 MACHO_ARM64_RELOC_GOT_LOAD_PAGE21
+               // if r.Xadd is non-zero, add two MACHO_ARM64_RELOC_ADDEND.
+               if r.Xadd != 0 {
+                       out.Write32(uint32(sectoff + 4))
+                       out.Write32((ld.MACHO_ARM64_RELOC_ADDEND << 28) | (2 << 25) | uint32(r.Xadd&0xffffff))
+               }
+               out.Write32(uint32(sectoff + 4))
+               out.Write32(v | (ld.MACHO_ARM64_RELOC_GOT_LOAD_PAGEOFF12 << 28) | (2 << 25))
+               if r.Xadd != 0 {
+                       out.Write32(uint32(sectoff))
+                       out.Write32((ld.MACHO_ARM64_RELOC_ADDEND << 28) | (2 << 25) | uint32(r.Xadd&0xffffff))
+               }
+               v |= 1 << 24 // pc-relative bit
+               v |= ld.MACHO_ARM64_RELOC_GOT_LOAD_PAGE21 << 28
        }
 
        switch siz {
@@ -457,7 +473,7 @@ func archreloc(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, r loade
                        }
 
                        nExtReloc = 2 // need two ELF/Mach-O relocations. see elfreloc1/machoreloc1
-                       if target.IsDarwin() && rt == objabi.R_ADDRARM64 && xadd != 0 {
+                       if target.IsDarwin() && xadd != 0 {
                                nExtReloc = 4 // need another two relocations for non-zero addend
                        }
 
index 9aa59fa3e37e50333da0f803f8bd069328a43aad..a3ed5f23075a22a28e6e2163957d026a2e4f7ff0 100644 (file)
@@ -95,7 +95,13 @@ func (mode *BuildMode) Set(s string) error {
                        default:
                                return badmode()
                        }
-               case "darwin", "freebsd":
+               case "darwin":
+                       switch objabi.GOARCH {
+                       case "amd64", "arm64":
+                       default:
+                               return badmode()
+                       }
+               case "freebsd":
                        switch objabi.GOARCH {
                        case "amd64":
                        default:
index cd630e9eae5f77c077fc4274507e4828fbb2d632..9fb85becec93187ff36bb8b1db6d2d115eaa505b 100644 (file)
@@ -1254,7 +1254,9 @@ func (ctxt *Link) hostlink() {
                        // -headerpad is incompatible with -fembed-bitcode.
                        argv = append(argv, "-Wl,-headerpad,1144")
                }
-               if ctxt.DynlinkingGo() && !ctxt.Arch.InFamily(sys.ARM, sys.ARM64) {
+               if ctxt.DynlinkingGo() && objabi.GOOS != "ios" {
+                       // -flat_namespace is deprecated on iOS.
+                       // It is useful for supporting plugins. We don't support plugins on iOS.
                        argv = append(argv, "-Wl,-flat_namespace")
                }
                if !combineDwarf {
index 9765ce18d366edb6c86fd6696af3f77e8450a80e..80a753438e9ac7d8bde2ac5f3d5199a2927246c5 100644 (file)
@@ -76,36 +76,38 @@ const (
 )
 
 const (
-       MACHO_CPU_AMD64               = 1<<24 | 7
-       MACHO_CPU_386                 = 7
-       MACHO_SUBCPU_X86              = 3
-       MACHO_CPU_ARM                 = 12
-       MACHO_SUBCPU_ARM              = 0
-       MACHO_SUBCPU_ARMV7            = 9
-       MACHO_CPU_ARM64               = 1<<24 | 12
-       MACHO_SUBCPU_ARM64_ALL        = 0
-       MACHO32SYMSIZE                = 12
-       MACHO64SYMSIZE                = 16
-       MACHO_X86_64_RELOC_UNSIGNED   = 0
-       MACHO_X86_64_RELOC_SIGNED     = 1
-       MACHO_X86_64_RELOC_BRANCH     = 2
-       MACHO_X86_64_RELOC_GOT_LOAD   = 3
-       MACHO_X86_64_RELOC_GOT        = 4
-       MACHO_X86_64_RELOC_SUBTRACTOR = 5
-       MACHO_X86_64_RELOC_SIGNED_1   = 6
-       MACHO_X86_64_RELOC_SIGNED_2   = 7
-       MACHO_X86_64_RELOC_SIGNED_4   = 8
-       MACHO_ARM_RELOC_VANILLA       = 0
-       MACHO_ARM_RELOC_PAIR          = 1
-       MACHO_ARM_RELOC_SECTDIFF      = 2
-       MACHO_ARM_RELOC_BR24          = 5
-       MACHO_ARM64_RELOC_UNSIGNED    = 0
-       MACHO_ARM64_RELOC_BRANCH26    = 2
-       MACHO_ARM64_RELOC_PAGE21      = 3
-       MACHO_ARM64_RELOC_PAGEOFF12   = 4
-       MACHO_ARM64_RELOC_ADDEND      = 10
-       MACHO_GENERIC_RELOC_VANILLA   = 0
-       MACHO_FAKE_GOTPCREL           = 100
+       MACHO_CPU_AMD64                      = 1<<24 | 7
+       MACHO_CPU_386                        = 7
+       MACHO_SUBCPU_X86                     = 3
+       MACHO_CPU_ARM                        = 12
+       MACHO_SUBCPU_ARM                     = 0
+       MACHO_SUBCPU_ARMV7                   = 9
+       MACHO_CPU_ARM64                      = 1<<24 | 12
+       MACHO_SUBCPU_ARM64_ALL               = 0
+       MACHO32SYMSIZE                       = 12
+       MACHO64SYMSIZE                       = 16
+       MACHO_X86_64_RELOC_UNSIGNED          = 0
+       MACHO_X86_64_RELOC_SIGNED            = 1
+       MACHO_X86_64_RELOC_BRANCH            = 2
+       MACHO_X86_64_RELOC_GOT_LOAD          = 3
+       MACHO_X86_64_RELOC_GOT               = 4
+       MACHO_X86_64_RELOC_SUBTRACTOR        = 5
+       MACHO_X86_64_RELOC_SIGNED_1          = 6
+       MACHO_X86_64_RELOC_SIGNED_2          = 7
+       MACHO_X86_64_RELOC_SIGNED_4          = 8
+       MACHO_ARM_RELOC_VANILLA              = 0
+       MACHO_ARM_RELOC_PAIR                 = 1
+       MACHO_ARM_RELOC_SECTDIFF             = 2
+       MACHO_ARM_RELOC_BR24                 = 5
+       MACHO_ARM64_RELOC_UNSIGNED           = 0
+       MACHO_ARM64_RELOC_BRANCH26           = 2
+       MACHO_ARM64_RELOC_PAGE21             = 3
+       MACHO_ARM64_RELOC_PAGEOFF12          = 4
+       MACHO_ARM64_RELOC_GOT_LOAD_PAGE21    = 5
+       MACHO_ARM64_RELOC_GOT_LOAD_PAGEOFF12 = 6
+       MACHO_ARM64_RELOC_ADDEND             = 10
+       MACHO_GENERIC_RELOC_VANILLA          = 0
+       MACHO_FAKE_GOTPCREL                  = 100
 )
 
 const (