if buildcfg.GOOS == "ios" {
machoPlatform = PLATFORM_IOS
}
- switch ctxt.Arch.Family {
- default:
- if ctxt.LinkMode == LinkInternal {
- // For lldb, must say LC_VERSION_MIN_MACOSX or else
- // it won't know that this Mach-O binary is from OS X
- // (could be iOS or WatchOS instead).
- // Go on iOS uses linkmode=external, and linkmode=external
- // adds this itself. So we only need this code for linkmode=internal
- // and we can assume OS X.
- //
- // See golang.org/issues/12941.
- //
+ if ctxt.LinkMode == LinkInternal && machoPlatform == PLATFORM_MACOS {
+ var version uint32
+ switch ctxt.Arch.Family {
+ case sys.AMD64:
// The version must be at least 10.9; see golang.org/issues/30488.
- ml := newMachoLoad(ctxt.Arch, LC_VERSION_MIN_MACOSX, 2)
- ml.data[0] = 10<<16 | 9<<8 | 0<<0 // OS X version 10.9.0
- ml.data[1] = 10<<16 | 9<<8 | 0<<0 // SDK 10.9.0
+ version = 10<<16 | 9<<8 | 0<<0 // 10.9.0
+ case sys.ARM64:
+ version = 11<<16 | 0<<8 | 0<<0 // 11.0.0
}
- case sys.ARM64:
+ ml := newMachoLoad(ctxt.Arch, LC_BUILD_VERSION, 4)
+ ml.data[0] = uint32(machoPlatform)
+ ml.data[1] = version // OS version
+ ml.data[2] = version // SDK version
+ ml.data[3] = 0 // ntools
}
}
}
}
-var testMacOSVersionSrc = `
+var testMachOBuildVersionSrc = `
package main
func main() { }
`
-func TestMacOSVersion(t *testing.T) {
+func TestMachOBuildVersion(t *testing.T) {
testenv.MustHaveGoBuild(t)
t.Parallel()
tmpdir := t.TempDir()
src := filepath.Join(tmpdir, "main.go")
- err := ioutil.WriteFile(src, []byte(testMacOSVersionSrc), 0666)
+ err := ioutil.WriteFile(src, []byte(testMachOBuildVersionSrc), 0666)
if err != nil {
t.Fatal(err)
}
t.Fatal(err)
}
found := false
- const LC_VERSION_MIN_MACOSX = 0x24
+ const LC_BUILD_VERSION = 0x32
checkMin := func(ver uint32) {
major, minor := (ver>>16)&0xff, (ver>>8)&0xff
if major != 10 || minor < 9 {
- t.Errorf("LC_VERSION_MIN_MACOSX version %d.%d < 10.9", major, minor)
+ t.Errorf("LC_BUILD_VERSION version %d.%d < 10.9", major, minor)
}
}
for _, cmd := range exem.Loads {
raw := cmd.Raw()
type_ := exem.ByteOrder.Uint32(raw)
- if type_ != LC_VERSION_MIN_MACOSX {
+ if type_ != LC_BUILD_VERSION {
continue
}
- osVer := exem.ByteOrder.Uint32(raw[8:])
+ osVer := exem.ByteOrder.Uint32(raw[12:])
checkMin(osVer)
- sdkVer := exem.ByteOrder.Uint32(raw[12:])
+ sdkVer := exem.ByteOrder.Uint32(raw[16:])
checkMin(sdkVer)
found = true
break
}
if !found {
- t.Errorf("no LC_VERSION_MIN_MACOSX load command found")
+ t.Errorf("no LC_BUILD_VERSION load command found")
}
}