From: Cherry Zhang Date: Thu, 3 Sep 2020 01:04:12 +0000 (-0400) Subject: cmd/link: pass darwin/amd64-specific flags only on AMD64 X-Git-Tag: go1.16beta1~1128 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=612b1194475a23760ec502b48a93fea7237f3ae6;p=gostls13.git cmd/link: pass darwin/amd64-specific flags only on AMD64 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 TryBot-Result: Gobot Gobot Reviewed-by: Than McIntosh --- diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index d6ee437bca..702c902142 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -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) }