1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 // mkasm_darwin.go generates assembly trampolines to call libSystem routines from Go.
8 //This program must be run after mksyscall.go.
21 in1, err := ioutil.ReadFile("syscall_darwin.go")
23 log.Fatalf("can't open syscall_darwin.go: %s", err)
26 in2, err := ioutil.ReadFile(fmt.Sprintf("syscall_darwin_%s.go", arch))
28 log.Fatalf("can't open syscall_darwin_%s.go: %s", arch, err)
30 in3, err := ioutil.ReadFile(fmt.Sprintf("zsyscall_darwin_%s.go", arch))
32 log.Fatalf("can't open zsyscall_darwin_%s.go: %s", arch, err)
34 in := string(in1) + string(in2) + string(in3)
36 trampolines := map[string]bool{}
40 fmt.Fprintf(&out, "// go run mkasm_darwin.go %s\n", strings.Join(os.Args[1:], " "))
41 fmt.Fprintf(&out, "// Code generated by the command above; DO NOT EDIT.\n")
42 fmt.Fprintf(&out, "\n")
43 fmt.Fprintf(&out, "// +build go1.12\n")
44 fmt.Fprintf(&out, "\n")
45 fmt.Fprintf(&out, "#include \"textflag.h\"\n")
46 for _, line := range strings.Split(in, "\n") {
47 if !strings.HasPrefix(line, "func ") || !strings.HasSuffix(line, "_trampoline()") {
50 fn := line[5 : len(line)-13]
52 trampolines[fn] = true
53 fmt.Fprintf(&out, "TEXT ยท%s_trampoline(SB),NOSPLIT,$0-0\n", fn)
54 fmt.Fprintf(&out, "\tJMP\t%s(SB)\n", fn)
57 err = ioutil.WriteFile(fmt.Sprintf("zsyscall_darwin_%s.s", arch), out.Bytes(), 0644)
59 log.Fatalf("can't write zsyscall_darwin_%s.s: %s", arch, err)