Skip to content

Commit 1c4a2a7

Browse files
4a6f656cgopherbot
authored andcommitted
unix: make mkasm_darwin.go usable with other operating systems
Rename mkasm_darwin.go to mkasm.go and pass the operating system as an argument. This will allow mkasm to be used to generate assembly for OpenBSD. Updates golang/go#36435 Change-Id: I42f54f5c6edc3a18a156e0e8e3c38d07ecf26d0b Reviewed-on: https://go-review.googlesource.com/c/sys/+/421795 Run-TryBot: Joel Sing <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Than McIntosh <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Tobias Klauser <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]>
1 parent 3d627bb commit 1c4a2a7

8 files changed

+55
-27
lines changed

unix/darwin_amd64_test.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/darwin_arm64_test.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/mkall.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ aix_ppc64)
7373
darwin_amd64)
7474
mkerrors="$mkerrors -m64"
7575
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
76-
mkasm="go run mkasm_darwin.go"
76+
mkasm="go run mkasm.go"
7777
;;
7878
darwin_arm64)
7979
mkerrors="$mkerrors -m64"
8080
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
81-
mkasm="go run mkasm_darwin.go"
81+
mkasm="go run mkasm.go"
8282
;;
8383
dragonfly_amd64)
8484
mkerrors="$mkerrors -m64"
@@ -232,5 +232,5 @@ esac
232232
if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
233233
if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
234234
if [ -n "$mktypes" ]; then echo "$mktypes types_$GOOS.go | go run mkpost.go > ztypes_$GOOSARCH.go"; fi
235-
if [ -n "$mkasm" ]; then echo "$mkasm $GOARCH"; fi
235+
if [ -n "$mkasm" ]; then echo "$mkasm $GOOS $GOARCH"; fi
236236
) | $run

unix/mkasm_darwin.go renamed to unix/mkasm.go

+46-18
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//go:build ignore
66
// +build ignore
77

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.
99
// This program must be run after mksyscall.go.
1010
package main
1111

@@ -19,9 +19,19 @@ import (
1919
"strings"
2020
)
2121

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+
}
2333

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 {
2535
trampolines := map[string]bool{}
2636
var orderedTrampolines []string
2737
for _, inFileName := range inFileNames {
@@ -43,19 +53,23 @@ func generateASMFile(inFileNames []string, outFileName string, buildTags string)
4353
}
4454
}
4555

56+
ptrSize := archPtrSize(arch)
57+
4658
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:], " "))
4860
fmt.Fprintf(&out, "// Code generated by the command above; DO NOT EDIT.\n")
4961
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+
}
5367
fmt.Fprintf(&out, "#include \"textflag.h\"\n")
5468
for _, fn := range orderedTrampolines {
5569
fmt.Fprintf(&out, "\nTEXT %s_trampoline<>(SB),NOSPLIT,$0-0\n", fn)
5670
fmt.Fprintf(&out, "\tJMP\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)
5973
}
6074

6175
if err := ioutil.WriteFile(outFileName, out.Bytes(), 0644); err != nil {
@@ -65,7 +79,7 @@ func generateASMFile(inFileNames []string, outFileName string, buildTags string)
6579
return trampolines
6680
}
6781

68-
const darwinTestTemplate = `// go run mkasm_darwin.go %s
82+
const darwinTestTemplate = `// go run mkasm.go %s
6983
// Code generated by the command above; DO NOT EDIT.
7084
7185
//go:build darwin && go1.12
@@ -102,23 +116,37 @@ func writeDarwinTest(trampolines map[string]bool, fileName, arch string) {
102116
}
103117

104118
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])
107121
}
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)
109129

110130
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
114143
}
115-
trampolines := generateASMFile(inFileNames, fmt.Sprintf("zsyscall_darwin_%s.s", arch), "go1.12")
116144

117145
inFileNames = []string{
118146
"syscall_darwin.1_13.go",
119147
fmt.Sprintf("zsyscall_darwin_%s.1_13.go", arch),
120148
}
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")
122150

123151
// merge trampolines
124152
for trampoline := range trampolines2 {

unix/zsyscall_darwin_amd64.1_13.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// go run mkasm_darwin.go amd64
1+
// go run mkasm.go darwin amd64
22
// Code generated by the command above; DO NOT EDIT.
33

44
//go:build go1.13

unix/zsyscall_darwin_amd64.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// go run mkasm_darwin.go amd64
1+
// go run mkasm.go darwin amd64
22
// Code generated by the command above; DO NOT EDIT.
33

44
//go:build go1.12

unix/zsyscall_darwin_arm64.1_13.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// go run mkasm_darwin.go arm64
1+
// go run mkasm.go darwin arm64
22
// Code generated by the command above; DO NOT EDIT.
33

44
//go:build go1.13

unix/zsyscall_darwin_arm64.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// go run mkasm_darwin.go arm64
1+
// go run mkasm.go darwin arm64
22
// Code generated by the command above; DO NOT EDIT.
33

44
//go:build go1.12

0 commit comments

Comments
 (0)