You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mkasm_darwin.go 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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.
  4. // +build ignore
  5. // mkasm_darwin.go generates assembly trampolines to call libSystem routines from Go.
  6. //This program must be run after mksyscall.go.
  7. package main
  8. import (
  9. "bytes"
  10. "fmt"
  11. "io/ioutil"
  12. "log"
  13. "os"
  14. "strings"
  15. )
  16. func main() {
  17. in1, err := ioutil.ReadFile("syscall_darwin.go")
  18. if err != nil {
  19. log.Fatalf("can't open syscall_darwin.go: %s", err)
  20. }
  21. arch := os.Args[1]
  22. in2, err := ioutil.ReadFile(fmt.Sprintf("syscall_darwin_%s.go", arch))
  23. if err != nil {
  24. log.Fatalf("can't open syscall_darwin_%s.go: %s", arch, err)
  25. }
  26. in3, err := ioutil.ReadFile(fmt.Sprintf("zsyscall_darwin_%s.go", arch))
  27. if err != nil {
  28. log.Fatalf("can't open zsyscall_darwin_%s.go: %s", arch, err)
  29. }
  30. in := string(in1) + string(in2) + string(in3)
  31. trampolines := map[string]bool{}
  32. var out bytes.Buffer
  33. fmt.Fprintf(&out, "// go run mkasm_darwin.go %s\n", strings.Join(os.Args[1:], " "))
  34. fmt.Fprintf(&out, "// Code generated by the command above; DO NOT EDIT.\n")
  35. fmt.Fprintf(&out, "\n")
  36. fmt.Fprintf(&out, "// +build go1.12\n")
  37. fmt.Fprintf(&out, "\n")
  38. fmt.Fprintf(&out, "#include \"textflag.h\"\n")
  39. for _, line := range strings.Split(in, "\n") {
  40. if !strings.HasPrefix(line, "func ") || !strings.HasSuffix(line, "_trampoline()") {
  41. continue
  42. }
  43. fn := line[5 : len(line)-13]
  44. if !trampolines[fn] {
  45. trampolines[fn] = true
  46. fmt.Fprintf(&out, "TEXT ·%s_trampoline(SB),NOSPLIT,$0-0\n", fn)
  47. fmt.Fprintf(&out, "\tJMP\t%s(SB)\n", fn)
  48. }
  49. }
  50. err = ioutil.WriteFile(fmt.Sprintf("zsyscall_darwin_%s.s", arch), out.Bytes(), 0644)
  51. if err != nil {
  52. log.Fatalf("can't write zsyscall_darwin_%s.s: %s", arch, err)
  53. }
  54. }