Skip to content

Commit 612b119

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
1 parent e61d17d commit 612b119

File tree

1 file changed

+5
-4
lines changed
  • src/cmd/link/internal/ld

1 file changed

+5
-4
lines changed

src/cmd/link/internal/ld/lib.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,8 @@ func (ctxt *Link) hostlink() {
12401240

12411241
switch ctxt.HeadType {
12421242
case objabi.Hdarwin:
1243-
if machoPlatform == PLATFORM_MACOS {
1243+
if machoPlatform == PLATFORM_MACOS && ctxt.IsAMD64() {
1244+
// Leave room for DWARF combining.
12441245
// -headerpad is incompatible with -fembed-bitcode.
12451246
argv = append(argv, "-Wl,-headerpad,1144")
12461247
}
@@ -1280,7 +1281,7 @@ func (ctxt *Link) hostlink() {
12801281
switch ctxt.BuildMode {
12811282
case BuildModeExe:
12821283
if ctxt.HeadType == objabi.Hdarwin {
1283-
if machoPlatform == PLATFORM_MACOS {
1284+
if machoPlatform == PLATFORM_MACOS && ctxt.IsAMD64() {
12841285
argv = append(argv, "-Wl,-no_pie")
12851286
argv = append(argv, "-Wl,-pagezero_size,4000000")
12861287
}
@@ -1517,7 +1518,7 @@ func (ctxt *Link) hostlink() {
15171518
// does not work, the resulting programs will not run. See
15181519
// issue #17847. To avoid this problem pass -no-pie to the
15191520
// toolchain if it is supported.
1520-
if ctxt.BuildMode == BuildModeExe && !ctxt.linkShared {
1521+
if ctxt.BuildMode == BuildModeExe && !ctxt.linkShared && !(ctxt.IsDarwin() && ctxt.IsARM64()) {
15211522
// GCC uses -no-pie, clang uses -nopie.
15221523
for _, nopie := range []string{"-no-pie", "-nopie"} {
15231524
if linkerFlagSupported(argv[0], altLinker, nopie) {
@@ -1607,7 +1608,7 @@ func (ctxt *Link) hostlink() {
16071608
Exitf("%s: parsing Mach-O header failed: %v", os.Args[0], err)
16081609
}
16091610
// Only macOS supports unmapped segments such as our __DWARF segment.
1610-
if machoPlatform == PLATFORM_MACOS {
1611+
if machoPlatform == PLATFORM_MACOS && ctxt.IsAMD64() {
16111612
if err := machoCombineDwarf(ctxt, exef, exem, dsym, combinedOutput); err != nil {
16121613
Exitf("%s: combining dwarf failed: %v", os.Args[0], err)
16131614
}

0 commit comments

Comments
 (0)