5
5
//go:build ignore
6
6
// +build ignore
7
7
8
- // mkasm_darwin .go generates assembly trampolines to call libSystem routines from Go.
8
+ // mkasm .go generates assembly trampolines to call library routines from Go.
9
9
// This program must be run after mksyscall.go.
10
10
package main
11
11
@@ -19,9 +19,19 @@ import (
19
19
"strings"
20
20
)
21
21
22
- const ptrsize = 8 // Pointer size. All supported platforms are 64-bit.
22
+ func archPtrSize (arch string ) int {
23
+ switch arch {
24
+ case "386" , "arm" :
25
+ return 4
26
+ case "amd64" , "arm64" , "mips64" :
27
+ return 8
28
+ default :
29
+ log .Fatalf ("Unknown arch %q" , arch )
30
+ return 0
31
+ }
32
+ }
23
33
24
- func generateASMFile (inFileNames []string , outFileName string , buildTags string ) map [string ]bool {
34
+ func generateASMFile (arch string , inFileNames []string , outFileName , buildTags string ) map [string ]bool {
25
35
trampolines := map [string ]bool {}
26
36
var orderedTrampolines []string
27
37
for _ , inFileName := range inFileNames {
@@ -43,19 +53,23 @@ func generateASMFile(inFileNames []string, outFileName string, buildTags string)
43
53
}
44
54
}
45
55
56
+ ptrSize := archPtrSize (arch )
57
+
46
58
var out bytes.Buffer
47
- fmt .Fprintf (& out , "// go run mkasm_darwin .go %s\n " , strings .Join (os .Args [1 :], " " ))
59
+ fmt .Fprintf (& out , "// go run mkasm .go %s\n " , strings .Join (os .Args [1 :], " " ))
48
60
fmt .Fprintf (& out , "// Code generated by the command above; DO NOT EDIT.\n " )
49
61
fmt .Fprintf (& out , "\n " )
50
- fmt .Fprintf (& out , "//go:build %s\n " , buildTags )
51
- fmt .Fprintf (& out , "// +build %s\n " , buildTags )
52
- fmt .Fprintf (& out , "\n " )
62
+ if buildTags != "" {
63
+ fmt .Fprintf (& out , "//go:build %s\n " , buildTags )
64
+ fmt .Fprintf (& out , "// +build %s\n " , buildTags )
65
+ fmt .Fprintf (& out , "\n " )
66
+ }
53
67
fmt .Fprintf (& out , "#include \" textflag.h\" \n " )
54
68
for _ , fn := range orderedTrampolines {
55
69
fmt .Fprintf (& out , "\n TEXT %s_trampoline<>(SB),NOSPLIT,$0-0\n " , fn )
56
70
fmt .Fprintf (& out , "\t JMP\t %s(SB)\n \n " , fn )
57
- fmt .Fprintf (& out , "GLOBL\t ·%s_trampoline_addr(SB), RODATA, $%d\n " , fn , ptrsize )
58
- fmt .Fprintf (& out , "DATA\t ·%s_trampoline_addr(SB)/%d, $%s_trampoline<>(SB)\n " , fn , ptrsize , fn )
71
+ fmt .Fprintf (& out , "GLOBL\t ·%s_trampoline_addr(SB), RODATA, $%d\n " , fn , ptrSize )
72
+ fmt .Fprintf (& out , "DATA\t ·%s_trampoline_addr(SB)/%d, $%s_trampoline<>(SB)\n " , fn , ptrSize , fn )
59
73
}
60
74
61
75
if err := ioutil .WriteFile (outFileName , out .Bytes (), 0644 ); err != nil {
@@ -65,7 +79,7 @@ func generateASMFile(inFileNames []string, outFileName string, buildTags string)
65
79
return trampolines
66
80
}
67
81
68
- const darwinTestTemplate = `// go run mkasm_darwin .go %s
82
+ const darwinTestTemplate = `// go run mkasm .go %s
69
83
// Code generated by the command above; DO NOT EDIT.
70
84
71
85
//go:build darwin && go1.12
@@ -102,23 +116,37 @@ func writeDarwinTest(trampolines map[string]bool, fileName, arch string) {
102
116
}
103
117
104
118
func main () {
105
- if len (os .Args ) != 2 {
106
- log .Fatalf ("Usage: %s <arch>" , os .Args [0 ])
119
+ if len (os .Args ) != 3 {
120
+ log .Fatalf ("Usage: %s <goos> < arch>" , os .Args [0 ])
107
121
}
108
- arch := os .Args [1 ]
122
+ goos , arch := os .Args [1 ], os .Args [2 ]
123
+
124
+ buildTags := ""
125
+ syscallFilename := fmt .Sprintf ("syscall_%s.go" , goos )
126
+ syscallArchFilename := fmt .Sprintf ("syscall_%s_%s.go" , goos , arch )
127
+ zsyscallArchFilename := fmt .Sprintf ("zsyscall_%s_%s.go" , goos , arch )
128
+ zsyscallASMFileName := fmt .Sprintf ("zsyscall_%s_%s.s" , goos , arch )
109
129
110
130
inFileNames := []string {
111
- "syscall_darwin.go" ,
112
- fmt .Sprintf ("syscall_darwin_%s.go" , arch ),
113
- fmt .Sprintf ("zsyscall_darwin_%s.go" , arch ),
131
+ syscallFilename ,
132
+ syscallArchFilename ,
133
+ zsyscallArchFilename ,
134
+ }
135
+
136
+ if goos == "darwin" {
137
+ buildTags = "go1.12"
138
+ }
139
+ trampolines := generateASMFile (arch , inFileNames , zsyscallASMFileName , buildTags )
140
+
141
+ if goos != "darwin" {
142
+ return
114
143
}
115
- trampolines := generateASMFile (inFileNames , fmt .Sprintf ("zsyscall_darwin_%s.s" , arch ), "go1.12" )
116
144
117
145
inFileNames = []string {
118
146
"syscall_darwin.1_13.go" ,
119
147
fmt .Sprintf ("zsyscall_darwin_%s.1_13.go" , arch ),
120
148
}
121
- trampolines2 := generateASMFile (inFileNames , fmt .Sprintf ("zsyscall_darwin_%s.1_13.s" , arch ), "go1.13" )
149
+ trampolines2 := generateASMFile (arch , inFileNames , fmt .Sprintf ("zsyscall_darwin_%s.1_13.s" , arch ), "go1.13" )
122
150
123
151
// merge trampolines
124
152
for trampoline := range trampolines2 {
0 commit comments