Skip to content

Commit 4cd6c3b

Browse files
committed
cmd/link/internal/ld: bump macOS and macOS SDK version to 10.9
Satisfies the Apple Notary. Fixes #30488 Change-Id: I91cf2d706a3ebe79bafdb759a0d32266ed6b9096 Reviewed-on: https://go-review.googlesource.com/c/go/+/175918 Run-TryBot: Elias Naur <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent bc0c077 commit 4cd6c3b

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,11 @@ func (ctxt *Link) domacho() {
414414
// and we can assume OS X.
415415
//
416416
// See golang.org/issues/12941.
417+
//
418+
// The version must be at least 10.9; see golang.org/issues/30488.
417419
ml := newMachoLoad(ctxt.Arch, LC_VERSION_MIN_MACOSX, 2)
418-
ml.data[0] = 10<<16 | 7<<8 | 0<<0 // OS X version 10.7.0
419-
ml.data[1] = 10<<16 | 7<<8 | 0<<0 // SDK 10.7.0
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
420422
}
421423
}
422424

src/cmd/link/link_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"debug/macho"
45
"internal/testenv"
56
"io/ioutil"
67
"os"
@@ -257,3 +258,67 @@ func TestXFlag(t *testing.T) {
257258
t.Errorf("%v: %v:\n%s", cmd.Args, err, out)
258259
}
259260
}
261+
262+
var testMacOSVersionSrc = `
263+
package main
264+
func main() { }
265+
`
266+
267+
func TestMacOSVersion(t *testing.T) {
268+
testenv.MustHaveGoBuild(t)
269+
270+
tmpdir, err := ioutil.TempDir("", "TestMacOSVersion")
271+
if err != nil {
272+
t.Fatal(err)
273+
}
274+
defer os.RemoveAll(tmpdir)
275+
276+
src := filepath.Join(tmpdir, "main.go")
277+
err = ioutil.WriteFile(src, []byte(testMacOSVersionSrc), 0666)
278+
if err != nil {
279+
t.Fatal(err)
280+
}
281+
282+
exe := filepath.Join(tmpdir, "main")
283+
cmd := exec.Command(testenv.GoToolPath(t), "build", "-ldflags=-linkmode=internal", "-o", exe, src)
284+
cmd.Env = append(os.Environ(),
285+
"CGO_ENABLED=0",
286+
"GOOS=darwin",
287+
"GOARCH=amd64",
288+
)
289+
if out, err := cmd.CombinedOutput(); err != nil {
290+
t.Fatalf("%v: %v:\n%s", cmd.Args, err, out)
291+
}
292+
exef, err := os.Open(exe)
293+
if err != nil {
294+
t.Fatal(err)
295+
}
296+
exem, err := macho.NewFile(exef)
297+
if err != nil {
298+
t.Fatal(err)
299+
}
300+
found := false
301+
const LC_VERSION_MIN_MACOSX = 0x24
302+
checkMin := func(ver uint32) {
303+
major, minor := (ver>>16)&0xff, (ver>>8)&0xff
304+
if major != 10 || minor < 9 {
305+
t.Errorf("LC_VERSION_MIN_MACOSX version %d.%d < 10.9", major, minor)
306+
}
307+
}
308+
for _, cmd := range exem.Loads {
309+
raw := cmd.Raw()
310+
type_ := exem.ByteOrder.Uint32(raw)
311+
if type_ != LC_VERSION_MIN_MACOSX {
312+
continue
313+
}
314+
osVer := exem.ByteOrder.Uint32(raw[8:])
315+
checkMin(osVer)
316+
sdkVer := exem.ByteOrder.Uint32(raw[12:])
317+
checkMin(sdkVer)
318+
found = true
319+
break
320+
}
321+
if !found {
322+
t.Errorf("no LC_VERSION_MIN_MACOSX load command found")
323+
}
324+
}

0 commit comments

Comments
 (0)