Skip to content

Commit d856e05

Browse files
committed
cmd/link/internal/ld: set MachO platform to PLATFORM_IOS on iOS
CL 205340 changed the linker to skip certain flags when linking for iOS. However, for host linking on iOS (such as on the Corellium darwin/arm64 builders) the MachO platform defaults to PLATFORM_MACOS, and the flags are not skipped. Avoids warnings such as ld: warning: -no_pie ignored for arm64 Updates #32963 Change-Id: Ib6b4c2375fd14cf89410bf5ff1537b692b7a1c15 Reviewed-on: https://go-review.googlesource.com/c/go/+/206337 Run-TryBot: Elias Naur <mail@eliasnaur.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
1 parent 4160a71 commit d856e05

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -404,21 +404,26 @@ func (ctxt *Link) domacho() {
404404
}
405405
}
406406
if machoPlatform == 0 {
407-
machoPlatform = PLATFORM_MACOS
408-
if ctxt.LinkMode == LinkInternal {
409-
// For lldb, must say LC_VERSION_MIN_MACOSX or else
410-
// it won't know that this Mach-O binary is from OS X
411-
// (could be iOS or WatchOS instead).
412-
// Go on iOS uses linkmode=external, and linkmode=external
413-
// adds this itself. So we only need this code for linkmode=internal
414-
// and we can assume OS X.
415-
//
416-
// See golang.org/issues/12941.
417-
//
418-
// The version must be at least 10.9; see golang.org/issues/30488.
419-
ml := newMachoLoad(ctxt.Arch, LC_VERSION_MIN_MACOSX, 2)
420-
ml.data[0] = 10<<16 | 9<<8 | 0<<0 // OS X version 10.9.0
421-
ml.data[1] = 10<<16 | 9<<8 | 0<<0 // SDK 10.9.0
407+
switch ctxt.Arch.Family {
408+
default:
409+
machoPlatform = PLATFORM_MACOS
410+
if ctxt.LinkMode == LinkInternal {
411+
// For lldb, must say LC_VERSION_MIN_MACOSX or else
412+
// it won't know that this Mach-O binary is from OS X
413+
// (could be iOS or WatchOS instead).
414+
// Go on iOS uses linkmode=external, and linkmode=external
415+
// adds this itself. So we only need this code for linkmode=internal
416+
// and we can assume OS X.
417+
//
418+
// See golang.org/issues/12941.
419+
//
420+
// The version must be at least 10.9; see golang.org/issues/30488.
421+
ml := newMachoLoad(ctxt.Arch, LC_VERSION_MIN_MACOSX, 2)
422+
ml.data[0] = 10<<16 | 9<<8 | 0<<0 // OS X version 10.9.0
423+
ml.data[1] = 10<<16 | 9<<8 | 0<<0 // SDK 10.9.0
424+
}
425+
case sys.ARM, sys.ARM64:
426+
machoPlatform = PLATFORM_IOS
422427
}
423428
}
424429

0 commit comments

Comments
 (0)