Skip to content

Commit b4a75ba

Browse files
committed
unix: generate linux/sparc64 go files using Docker
With cgo supporting sparc64 as of CL 102555 and CL 132155, the Docker based build system can be used to generate file for linux/sparc64 as well. Updates golang/go#15282 Change-Id: I109e55f39d3229b24b0029c42074e439c6c54dc8 Reviewed-on: https://go-review.googlesource.com/c/102655 Run-TryBot: Tobias Klauser <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent a79f1b1 commit b4a75ba

10 files changed

+3867
-1909
lines changed

unix/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ migrating the build system to use containers so the builds are reproducible.
1414
This is being done on an OS-by-OS basis. Please update this documentation as
1515
components of the build system change.
1616

17-
### Old Build System (currently for `GOOS != "Linux" || GOARCH == "sparc64"`)
17+
### Old Build System (currently for `GOOS != "linux"`)
1818

1919
The old build system generates the Go files based on the C header files
2020
present on your system. This means that files
@@ -34,7 +34,7 @@ your specific system. Running `mkall.sh -n` shows the commands that will be run.
3434

3535
Requirements: bash, perl, go
3636

37-
### New Build System (currently for `GOOS == "Linux" && GOARCH != "sparc64"`)
37+
### New Build System (currently for `GOOS == "linux"`)
3838

3939
The new build system uses a Docker container to generate the go files directly
4040
from source checkouts of the kernel and various system libraries. This means

unix/linux/mkall.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ type target struct {
5252
Bits int
5353
}
5454

55-
// List of all Linux targets supported by the go compiler. sparc64 is not
56-
// currently supported, though a port is in progress.
55+
// List of all Linux targets supported by the go compiler. Currently, riscv64
56+
// and sparc64 are not fully supported, but there is enough support already to
57+
// generate Go type and error definitions.
5758
var targets = []target{
5859
{
5960
GoArch: "386",
@@ -133,13 +134,13 @@ var targets = []target{
133134
SignedChar: true,
134135
Bits: 64,
135136
},
136-
// {
137-
// GoArch: "sparc64",
138-
// LinuxArch: "sparc",
139-
// GNUArch: "sparc64-linux-gnu",
140-
// BigEndian: true,
141-
// Bits: 64,
142-
// },
137+
{
138+
GoArch: "sparc64",
139+
LinuxArch: "sparc",
140+
GNUArch: "sparc64-linux-gnu",
141+
BigEndian: true,
142+
Bits: 64,
143+
},
143144
}
144145

145146
// ptracePairs is a list of pairs of targets that can, in some cases,
@@ -532,7 +533,7 @@ func (t *target) mksyscallFlags() (flags []string) {
532533
}
533534
}
534535

535-
// This flag menas a 64-bit value should use (even, odd)-pair.
536+
// This flag means a 64-bit value should use (even, odd)-pair.
536537
if t.GoArch == "arm" || (t.LinuxArch == "mips" && t.Bits == 32) {
537538
flags = append(flags, "-arm")
538539
}

unix/linux/types.go

+21
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,28 @@ package unix
5757
#include <linux/perf_event.h>
5858
#include <linux/rtnetlink.h>
5959
#include <linux/stat.h>
60+
#if defined(__sparc__)
61+
// On sparc{,64}, the kernel defines struct termios2 itself which clashes with the
62+
// definition in glibc. Duplicate the kernel version here.
63+
#if defined(__arch64__)
64+
typedef unsigned int tcflag_t;
65+
#else
66+
typedef unsigned long tcflag_t;
67+
#endif
68+
69+
struct termios2 {
70+
tcflag_t c_iflag;
71+
tcflag_t c_oflag;
72+
tcflag_t c_cflag;
73+
tcflag_t c_lflag;
74+
unsigned char c_line;
75+
unsigned char c_cc[19];
76+
unsigned int c_ispeed;
77+
unsigned int c_ospeed;
78+
};
79+
#else
6080
#include <asm/termbits.h>
81+
#endif
6182
#include <asm/ptrace.h>
6283
#include <time.h>
6384
#include <unistd.h>

unix/mkall.sh

+2-9
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ case "$#" in
4646
exit 2
4747
esac
4848

49-
if [[ "$GOOS" = "linux" ]] && [[ "$GOARCH" != "sparc64" ]]; then
50-
# Use then new build system
49+
if [[ "$GOOS" = "linux" ]]; then
50+
# Use the Docker-based build system
5151
# Files generated through docker (use $cmd so you can Ctl-C the build or run)
5252
$cmd docker build --tag generate:$GOOS $GOOS
5353
$cmd docker run --interactive --tty --volume $(dirname "$(readlink -f "$0")"):/build generate:$GOOS
@@ -121,13 +121,6 @@ freebsd_arm)
121121
# API consistent across platforms.
122122
mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
123123
;;
124-
linux_sparc64)
125-
GOOSARCH_in=syscall_linux_sparc64.go
126-
unistd_h=/usr/include/sparc64-linux-gnu/asm/unistd.h
127-
mkerrors="$mkerrors -m64"
128-
mksysnum="./mksysnum_linux.pl $unistd_h"
129-
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
130-
;;
131124
netbsd_386)
132125
mkerrors="$mkerrors -m32"
133126
mksyscall="go run mksyscall.go -l32 -netbsd"

unix/mkerrors.sh

+12-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ if test -z "$GOARCH" -o -z "$GOOS"; then
1717
fi
1818

1919
# Check that we are using the new build system if we should
20-
if [[ "$GOOS" = "linux" ]] && [[ "$GOARCH" != "sparc64" ]]; then
21-
if [[ "$GOLANG_SYS_BUILD" != "docker" ]]; then
22-
echo 1>&2 "In the new build system, mkerrors should not be called directly."
23-
echo 1>&2 "See README.md"
24-
exit 1
25-
fi
20+
if [[ "$GOOS" = "linux" ]] && [[ "$GOLANG_SYS_BUILD" != "docker" ]]; then
21+
echo 1>&2 "In the Docker based build system, mkerrors should not be called directly."
22+
echo 1>&2 "See README.md"
23+
exit 1
2624
fi
2725

2826
if [[ "$GOOS" = "aix" ]]; then
@@ -223,7 +221,15 @@ struct ltchars {
223221
#include <linux/if_xdp.h>
224222
#include <mtd/ubi-user.h>
225223
#include <net/route.h>
224+
225+
#if defined(__sparc__)
226+
// On sparc{,64}, the kernel defines struct termios2 itself which clashes with the
227+
// definition in glibc. As only the error constants are needed here, include the
228+
// generic termibits.h (which is included by termbits.h on sparc).
229+
#include <asm-generic/termbits.h>
230+
#else
226231
#include <asm/termbits.h>
232+
#endif
227233
228234
#ifndef MSG_FASTOPEN
229235
#define MSG_FASTOPEN 0x20000000

unix/mkpost.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ func main() {
2828
if goarch == "" {
2929
goarch = os.Getenv("GOARCH")
3030
}
31-
// Check that we are using the new build system if we should be.
32-
if goos == "linux" && goarch != "sparc64" {
31+
// Check that we are using the Docker-based build system if we should be.
32+
if goos == "linux" {
3333
if os.Getenv("GOLANG_SYS_BUILD") != "docker" {
34-
os.Stderr.WriteString("In the new build system, mkpost should not be called directly.\n")
34+
os.Stderr.WriteString("In the Docker-based build system, mkpost should not be called directly.\n")
3535
os.Stderr.WriteString("See README.md\n")
3636
os.Exit(1)
3737
}

unix/mksyscall.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ func main() {
9393
goarch = os.Getenv("GOARCH")
9494
}
9595

96-
// Check that we are using the new build system if we should
97-
if goos == "linux" && goarch != "sparc64" {
96+
// Check that we are using the Docker-based build system if we should
97+
if goos == "linux" {
9898
if os.Getenv("GOLANG_SYS_BUILD") != "docker" {
99-
fmt.Fprintf(os.Stderr, "In the new build system, mksyscall should not be called directly.\n")
99+
fmt.Fprintf(os.Stderr, "In the Docker-based build system, mksyscall should not be called directly.\n")
100100
fmt.Fprintf(os.Stderr, "See README.md\n")
101101
os.Exit(1)
102102
}

0 commit comments

Comments
 (0)