]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: pass darwin/amd64-specific flags only on AMD64
authorCherry Zhang <cherryyz@google.com>
Thu, 3 Sep 2020 01:04:12 +0000 (21:04 -0400)
committerCherry Zhang <cherryyz@google.com>
Thu, 3 Sep 2020 21:50:25 +0000 (21:50 +0000)
The linker assumed macOS is AMD64 (and 386 in the past). It
passes darwin/amd64-specific flags to the external linker when
building for macOS. They don't work for ARM64-based macOS. So
only pass them on AMD64.

Disable DWARF combining for macOS ARM64 for now. The generated
binary doesn't run. (TODO: fix.)

For macOS ARM64 port. External linking now works.

Change-Id: Iab53bc48f4fadd9b91de8898b4b450ea442667a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/253019
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/link/internal/ld/lib.go

index d6ee437bcac3f36d07c15d03d423002aadde99d3..702c90214276d8da64cee916d0031cb0e4a913cc 100644 (file)
@@ -1240,7 +1240,8 @@ func (ctxt *Link) hostlink() {
 
        switch ctxt.HeadType {
        case objabi.Hdarwin:
-               if machoPlatform == PLATFORM_MACOS {
+               if machoPlatform == PLATFORM_MACOS && ctxt.IsAMD64() {
+                       // Leave room for DWARF combining.
                        // -headerpad is incompatible with -fembed-bitcode.
                        argv = append(argv, "-Wl,-headerpad,1144")
                }
@@ -1280,7 +1281,7 @@ func (ctxt *Link) hostlink() {
        switch ctxt.BuildMode {
        case BuildModeExe:
                if ctxt.HeadType == objabi.Hdarwin {
-                       if machoPlatform == PLATFORM_MACOS {
+                       if machoPlatform == PLATFORM_MACOS && ctxt.IsAMD64() {
                                argv = append(argv, "-Wl,-no_pie")
                                argv = append(argv, "-Wl,-pagezero_size,4000000")
                        }
@@ -1517,7 +1518,7 @@ func (ctxt *Link) hostlink() {
        // does not work, the resulting programs will not run. See
        // issue #17847. To avoid this problem pass -no-pie to the
        // toolchain if it is supported.
-       if ctxt.BuildMode == BuildModeExe && !ctxt.linkShared {
+       if ctxt.BuildMode == BuildModeExe && !ctxt.linkShared && !(ctxt.IsDarwin() && ctxt.IsARM64()) {
                // GCC uses -no-pie, clang uses -nopie.
                for _, nopie := range []string{"-no-pie", "-nopie"} {
                        if linkerFlagSupported(argv[0], altLinker, nopie) {
@@ -1607,7 +1608,7 @@ func (ctxt *Link) hostlink() {
                        Exitf("%s: parsing Mach-O header failed: %v", os.Args[0], err)
                }
                // Only macOS supports unmapped segments such as our __DWARF segment.
-               if machoPlatform == PLATFORM_MACOS {
+               if machoPlatform == PLATFORM_MACOS && ctxt.IsAMD64() {
                        if err := machoCombineDwarf(ctxt, exef, exem, dsym, combinedOutput); err != nil {
                                Exitf("%s: combining dwarf failed: %v", os.Args[0], err)
                        }