Skip to content

Commit 33267e0

Browse files
committed
unix: add s390x support
This commit adds linux/s390x support to the unix package. It is based on the changes made to the syscall package in https://golang.org/cl/20961/. It also adds mkpost.go which is used to cleanup the API generated by cgo -godefs. The biggest departure that is made with the syscall package is the use of the -fsigned-char flag to force signed chars. We couldn't do this in the syscall package because of the need to maintain compatibility with the gccgo implementation of the syscall package (gccgo has supported s390x for a longer time than the Go toolchain). The unix package does not have this constraint. Using the -fsigned-char flag makes the API look more like the one generated on amd64 and arm64 and also more consistent with itself (the syscall package represents chars using both int8 and uint8 types, the sys package will only ever use int8). Unfortunately it also means that applications transitioning from the syscall package to the unix package will see a different API on s390x which might be confusing. I think the tradeoff is worth it though. Change-Id: I40b90c18ed787e74ba7a2ebd004bd6bd1ba6279a Reviewed-on: https://go-review.googlesource.com/23045 Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent e82cb4d commit 33267e0

9 files changed

Lines changed: 5045 additions & 3 deletions

unix/asm_linux_s390x.s

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2016 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+
5+
// +build !gccgo
6+
7+
#include "textflag.h"
8+
9+
//
10+
// System calls for s390x, Linux
11+
//
12+
13+
// Just jump to package syscall's implementation for all these functions.
14+
// The runtime may know about them.
15+
16+
TEXT ·Syscall(SB),NOSPLIT,$0-56
17+
BR syscall·Syscall(SB)
18+
19+
TEXT ·Syscall6(SB),NOSPLIT,$0-80
20+
BR syscall·Syscall6(SB)
21+
22+
TEXT ·RawSyscall(SB),NOSPLIT,$0-56
23+
BR syscall·RawSyscall(SB)
24+
25+
TEXT ·RawSyscall6(SB),NOSPLIT,$0-80
26+
BR syscall·RawSyscall6(SB)

unix/mkall.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@ linux_ppc64le)
212212
mksysnum="./mksysnum_linux.pl $unistd_h"
213213
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
214214
;;
215+
linux_s390x)
216+
GOOSARCH_in=syscall_linux_s390x.go
217+
unistd_h=/usr/include/asm/unistd.h
218+
mkerrors="$mkerrors -m64"
219+
mksysnum="./mksysnum_linux.pl $unistd_h"
220+
# Let the type of C char be signed to make the bare sys
221+
# API more consistent between platforms.
222+
# This is a deliberate departure from the way the syscall
223+
# package generates its version of the types file.
224+
mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
225+
;;
215226
netbsd_386)
216227
mkerrors="$mkerrors -m32"
217228
mksyscall="./mksyscall.pl -l32 -netbsd"
@@ -269,6 +280,6 @@ esac
269280
if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
270281
if [ -n "$mktypes" ]; then
271282
echo "echo // +build $GOARCH,$GOOS > ztypes_$GOOSARCH.go";
272-
echo "$mktypes types_$GOOS.go | gofmt >>ztypes_$GOOSARCH.go";
283+
echo "$mktypes types_$GOOS.go | go run mkpost.go >>ztypes_$GOOSARCH.go";
273284
fi
274285
) | $run

unix/mkpost.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2016 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+
5+
// +build ignore
6+
7+
// mkpost processes the output of cgo -godefs to
8+
// modify the generated types. It is used to clean up
9+
// the sys API in an architecture specific manner.
10+
//
11+
// mkpost is run after cgo -godefs by mkall.sh.
12+
package main
13+
14+
import (
15+
"fmt"
16+
"go/format"
17+
"io/ioutil"
18+
"log"
19+
"os"
20+
"regexp"
21+
)
22+
23+
func main() {
24+
b, err := ioutil.ReadAll(os.Stdin)
25+
if err != nil {
26+
log.Fatal(err)
27+
}
28+
s := string(b)
29+
30+
goarch := os.Getenv("GOARCH")
31+
goos := os.Getenv("GOOS")
32+
if goarch == "s390x" && goos == "linux" {
33+
// Export the types of PtraceRegs fields.
34+
re := regexp.MustCompile("ptrace(Psw|Fpregs|Per)")
35+
s = re.ReplaceAllString(s, "Ptrace$1")
36+
37+
// Replace padding fields inserted by cgo with blank identifiers.
38+
re = regexp.MustCompile("Pad_cgo[A-Za-z0-9_]*")
39+
s = re.ReplaceAllString(s, "_")
40+
41+
// Replace other unwanted fields with blank identifiers.
42+
re = regexp.MustCompile("X_[A-Za-z0-9_]*")
43+
s = re.ReplaceAllString(s, "_")
44+
45+
// Replace the control_regs union with a blank identifier for now.
46+
re = regexp.MustCompile("(Control_regs)\\s+\\[0\\]uint64")
47+
s = re.ReplaceAllString(s, "_ [0]uint64")
48+
}
49+
50+
// gofmt
51+
b, err = format.Source([]byte(s))
52+
if err != nil {
53+
log.Fatal(err)
54+
}
55+
56+
// Append this command to the header to show where the new file
57+
// came from.
58+
re := regexp.MustCompile("(cgo -godefs [a-zA-Z0-9_]+\\.go.*)")
59+
b = re.ReplaceAll(b, []byte("$1 | go run mkpost.go"))
60+
61+
fmt.Printf("%s", b)
62+
}

0 commit comments

Comments
 (0)