testDWARF(t, "c-archive", true, cc, "CGO_ENABLED=1", "GOOS=darwin", "GOARCH=arm", "GOARM=7")
testDWARF(t, "c-archive", true, cc, "CGO_ENABLED=1", "GOOS=darwin", "GOARCH=arm64")
}
+
+func TestBuildFortvOS(t *testing.T) {
+ testenv.MustHaveCGO(t)
+ testenv.MustHaveGoBuild(t)
+
+ // Only run this on darwin/amd64, where we can cross build for tvOS.
+ if runtime.GOARCH != "amd64" || runtime.GOOS != "darwin" {
+ t.Skip("skipping on non-darwin/amd64 platform")
+ }
+ if err := exec.Command("xcrun", "--help").Run(); err != nil {
+ t.Skipf("error running xcrun, required for iOS cross build: %v", err)
+ }
+
+ sdkPath, err := exec.Command("xcrun", "--sdk", "appletvos", "--show-sdk-path").Output()
+ if err != nil {
+ t.Fatalf("xcrun --sdk appletvos --show-sdk-path failed: %v", err)
+ }
+ CC := []string{
+ "clang",
+ "-arch",
+ "arm64",
+ "-isysroot", strings.TrimSpace(string(sdkPath)),
+ "-mtvos-version-min=12.0",
+ "-fembed-bitcode",
+ "-framework", "CoreFoundation",
+ }
+ lib := filepath.Join("testdata", "lib.go")
+ tmpDir, err := ioutil.TempDir("", "go-link-TestBuildFortvOS")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer os.RemoveAll(tmpDir)
+
+ ar := filepath.Join(tmpDir, "lib.a")
+ cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode=c-archive", "-o", ar, lib)
+ cmd.Env = append(os.Environ(),
+ "CGO_ENABLED=1",
+ "GOOS=darwin",
+ "GOARCH=arm64",
+ "CC="+strings.Join(CC, " "),
+ )
+ if out, err := cmd.CombinedOutput(); err != nil {
+ t.Fatalf("%v: %v:\n%s", cmd.Args, err, out)
+ }
+
+ link := exec.Command(CC[0], CC[1:]...)
+ link.Args = append(link.Args, ar, filepath.Join("testdata", "main.m"))
+ if out, err := link.CombinedOutput(); err != nil {
+ t.Fatalf("%v: %v:\n%s", link.Args, err, out)
+ }
+}
"cmd/link/internal/sym"
"debug/macho"
"encoding/binary"
+ "fmt"
+ "io"
+ "os"
"sort"
"strings"
)
}
}
}
-
- if ctxt.LinkMode == LinkInternal {
+ load, err := hostobjMachoPlatform(hostobj)
+ if err != nil {
+ Exitf("%v", err)
+ }
+ if load != nil {
+ ml := newMachoLoad(ctxt.Arch, load.cmd.type_, uint32(len(load.cmd.data)))
+ copy(ml.data, load.cmd.data)
+ } else 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).
}
}
+// hostobjMachoPlatform returns the first platform load command found
+// in the host objects, if any.
+func hostobjMachoPlatform(hostobj []Hostobj) (*MachoPlatformLoad, error) {
+ for _, h := range hostobj {
+ f, err := os.Open(h.file)
+ if err != nil {
+ return nil, fmt.Errorf("%s: failed to open host object: %v\n", h.file, err)
+ }
+ defer f.Close()
+ sr := io.NewSectionReader(f, h.off, h.length)
+ m, err := macho.NewFile(sr)
+ if err != nil {
+ // Not a valid Mach-O file.
+ return nil, nil
+ }
+ load, err := peekMachoPlatform(m)
+ if err != nil {
+ return nil, err
+ }
+ if load != nil {
+ return load, nil
+ }
+ }
+ return nil, nil
+}
+
// peekMachoPlatform returns the first LC_VERSION_MIN_* or LC_BUILD_VERSION
// load command found in the Mach-O file, if any.
func peekMachoPlatform(m *macho.File) (*MachoPlatformLoad, error) {