cmd/link: fix macOS 13 build

Write our own load command for macOS builds,
to make sure we can put the versions in.
Builds on older macOS were seeing an LC_VERSION_MIN instead
and scribbling over fields that didn't exist.

Fixes #78070.

Change-Id: If338d0506b1156b133253e496f29818a29a22a91
Reviewed-on: https://go-review.googlesource.com/c/go/+/754241
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Russ Cox <rsc@golang.org>
This commit is contained in:
Russ Cox
2026-03-11 12:52:44 -04:00
committed by Gopher Robot
parent a8f99ef1f6
commit 3d7681ebab

View File

@@ -461,14 +461,9 @@ func (ctxt *Link) domacho() {
if err != nil {
Exitf("%v", err)
}
if load != nil {
machoPlatform = load.platform
if load != nil && load.platform != PLATFORM_MACOS {
ml := newMachoLoad(ctxt.Arch, load.cmd.type_, uint32(len(load.cmd.data)))
copy(ml.data, load.cmd.data)
if machoPlatform == PLATFORM_MACOS {
ml.data[1] = macOS.version()
ml.data[2] = macSDK.version()
}
break
}
}
@@ -477,7 +472,7 @@ func (ctxt *Link) domacho() {
if buildcfg.GOOS == "ios" {
machoPlatform = PLATFORM_IOS
}
if ctxt.LinkMode == LinkInternal && machoPlatform == PLATFORM_MACOS {
if load == nil && machoPlatform == PLATFORM_MACOS {
ml := newMachoLoad(ctxt.Arch, imacho.LC_BUILD_VERSION, 4)
ml.data[0] = uint32(machoPlatform)
ml.data[1] = macOS.version()