diff options
author | Cherry Zhang <cherryyz@google.com> | 2020-09-02 21:04:12 -0400 |
---|---|---|
committer | Cherry Zhang <cherryyz@google.com> | 2020-09-03 21:50:25 +0000 |
commit | 612b1194475a23760ec502b48a93fea7237f3ae6 (patch) | |
tree | 3733a3936cc40dd231ebae6f2f756b0d0f6e66e1 | |
parent | e61d17d3b9ccf4c3e8ac87add9d74da7afa76488 (diff) | |
download | go-612b1194475a23760ec502b48a93fea7237f3ae6.tar.gz go-612b1194475a23760ec502b48a93fea7237f3ae6.zip |
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 <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
-rw-r--r-- | src/cmd/link/internal/ld/lib.go | 9 |
1 files changed, 5 insertions, 4 deletions
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) } |