Add two patches to lang/go14.

- patch-syscall

  Use SYSCALL assembly instead of INT 0x80 for syscalls on amd64.
  Using INT 0x80 as syscall gate on amd64 is an accidential and
  undocumented feature of COMPAT_FREEBSD32. It allows to use 64-bit
  ABI, but run syscalls through i386 gate.
  Go used this "feature" to workaround a bug in FreeBSD 8, which is no
  longer relevant.
  The patch is exact e9ce76b0eca8fa95dddb90b0a72aadab58de2ffc from go
  repo.
  Now lang/go14 doesn't need COMPAT_FREEBSD32 to build and run.

- patch-pipe2

  The pipe2 syscall is present in all supported versions of FreeBSD,
  but pipe was removed from FreeBSD 11. With the patch go14 can be
  built and run on a system without COMPAT_FREEBSD10.

Reviewed by:	jlaffaye
This commit is contained in:
Gleb Smirnoff 2017-03-21 16:38:33 +00:00
parent 2e6f356fd4
commit 141e3d8b59
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=436616
3 changed files with 157 additions and 0 deletions

View file

@ -2,6 +2,7 @@
PORTNAME= go14
PORTVERSION= 1.4.3
PORTREVISION= 1
CATEGORIES= lang
MASTER_SITES= http://golang.org/dl/
DISTNAME= go${PORTVERSION}.src

108
lang/go14/files/patch-pipe2 Normal file
View file

@ -0,0 +1,108 @@
--- src/syscall/syscall_freebsd.go.orig 2017-03-17 19:00:39.000000000 +0000
+++ src/syscall/syscall_freebsd.go 2017-03-17 19:00:39.000000000 +0000
@@ -82,13 +82,16 @@
return origlen - len(buf), count, names
}
-//sysnb pipe() (r int, w int, err error)
+//sysnb pipe2(p *[2]_C_int, flags int) (err error)
-func Pipe(p []int) (err error) {
+func Pipe2(p []int, flags int) (err error) {
if len(p) != 2 {
return EINVAL
}
- p[0], p[1], err = pipe()
+ var pp [2]_C_int
+ err = pipe2(&pp, flags)
+ p[0] = int(pp[0])
+ p[1] = int(pp[1])
return
}
--- src/syscall/exec_bsd.go.orig 2017-03-17 18:21:43.000000000 +0000
+++ src/syscall/exec_bsd.go 2017-03-17 18:21:43.000000000 +0000
@@ -233,15 +233,7 @@
}
// Try to open a pipe with O_CLOEXEC set on both file descriptors.
-func forkExecPipe(p []int) error {
- err := Pipe(p)
- if err != nil {
- return err
- }
- _, err = fcntl(p[0], F_SETFD, FD_CLOEXEC)
- if err != nil {
- return err
- }
- _, err = fcntl(p[1], F_SETFD, FD_CLOEXEC)
- return err
+func forkExecPipe(p []int) (err error) {
+ err = Pipe2(p, O_CLOEXEC)
+ return
}
--- src/syscall/zsyscall_freebsd_amd64.go.orig 2017-03-17 19:01:09.000000000 +0000
+++ src/syscall/zsyscall_freebsd_amd64.go 2017-03-17 19:01:09.000000000 +0000
@@ -260,10 +260,8 @@
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-func pipe() (r int, w int, err error) {
- r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0)
- r = int(r0)
- w = int(r1)
+func pipe2(p *[2]_C_int, flags int) (err error) {
+ _, _, e1 := RawSyscall(SYS_PIPE2, uintptr(unsafe.Pointer(p)), uintptr(flags), 0)
if e1 != 0 {
err = e1
}
--- src/syscall/zsyscall_freebsd_arm.go.orig 2017-03-17 20:52:22.000000000 +0000
+++ src/syscall/zsyscall_freebsd_arm.go 2017-03-17 20:52:22.000000000 +0000
@@ -260,10 +260,8 @@
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-func pipe() (r int, w int, err error) {
- r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0)
- r = int(r0)
- w = int(r1)
+func pipe2(p *[2]_C_int, flags int) (err error) {
+ _, _, e1 := RawSyscall(SYS_PIPE2, uintptr(unsafe.Pointer(p)), uintptr(flags), 0)
if e1 != 0 {
err = e1
}
--- src/syscall/zsyscall_freebsd_386.go.orig 2017-03-17 20:53:05.000000000 +0000
+++ src/syscall/zsyscall_freebsd_386.go 2017-03-17 20:53:05.000000000 +0000
@@ -260,10 +260,8 @@
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-func pipe() (r int, w int, err error) {
- r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0)
- r = int(r0)
- w = int(r1)
+func pipe2(p *[2]_C_int, flags int) (err error) {
+ _, _, e1 := RawSyscall(SYS_PIPE2, uintptr(unsafe.Pointer(p)), uintptr(flags), 0)
if e1 != 0 {
err = e1
}
--- src/os/pipe_bsd.go.orig 2017-03-17 20:54:41.000000000 +0000
+++ src/os/pipe_bsd.go 2017-03-17 20:54:41.000000000 +0000
@@ -13,16 +13,10 @@
func Pipe() (r *File, w *File, err error) {
var p [2]int
- // See ../syscall/exec.go for description of lock.
- syscall.ForkLock.RLock()
- e := syscall.Pipe(p[0:])
+ e := syscall.Pipe2(p[0:], syscall.O_CLOEXEC)
if e != nil {
- syscall.ForkLock.RUnlock()
return nil, nil, NewSyscallError("pipe", e)
}
- syscall.CloseOnExec(p[0])
- syscall.CloseOnExec(p[1])
- syscall.ForkLock.RUnlock()
return NewFile(uintptr(p[0]), "|0"), NewFile(uintptr(p[1]), "|1"), nil
}

View file

@ -0,0 +1,48 @@
--- src/runtime/sys_freebsd_amd64.s.orig 2017-03-17 20:08:29.000000000 +0000
+++ src/runtime/sys_freebsd_amd64.s 2017-03-17 20:08:29.000000000 +0000
@@ -9,31 +9,6 @@
#include "zasm_GOOS_GOARCH.h"
#include "textflag.h"
-// FreeBSD 8, FreeBSD 9, and older versions that I have checked
-// do not restore R10 on exit from a "restarted" system call
-// if you use the SYSCALL instruction. This means that, for example,
-// if a signal arrives while the wait4 system call is executing,
-// the wait4 internally returns ERESTART, which makes the kernel
-// back up the PC to execute the SYSCALL instruction a second time.
-// However, since the kernel does not restore R10, the fourth
-// argument to the system call has been lost. (FreeBSD 9 also fails
-// to restore the fifth and sixth arguments, R8 and R9, although
-// some earlier versions did restore those correctly.)
-// The broken code is in fast_syscall in FreeBSD's amd64/amd64/exception.S.
-// It restores only DI, SI, DX, AX, and RFLAGS on system call return.
-// http://fxr.watson.org/fxr/source/amd64/amd64/exception.S?v=FREEBSD91#L399
-//
-// The INT $0x80 system call path (int0x80_syscall in FreeBSD's
-// amd64/ia32/ia32_exception.S) does not have this problem,
-// but it expects the third argument in R10. Instead of rewriting
-// all the assembly in this file, #define SYSCALL to a safe simulation
-// using INT $0x80.
-//
-// INT $0x80 is a little slower than SYSCALL, but correctness wins.
-//
-// See golang.org/issue/6372.
-#define SYSCALL MOVQ R10, CX; INT $0x80
-
TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0
MOVQ addr+0(FP), DI
MOVL mode+8(FP), SI
--- src/syscall/asm_freebsd_amd64.s.orig 2017-03-17 20:20:07.000000000 +0000
+++ src/syscall/asm_freebsd_amd64.s 2017-03-17 20:20:07.000000000 +0000
@@ -12,11 +12,6 @@
// System call support for AMD64, FreeBSD
//
-// The SYSCALL variant for invoking system calls is broken in FreeBSD.
-// See comment at top of ../runtime/sys_freebsd_amd64.c and
-// golang.org/issue/6372.
-#define SYSCALL MOVQ R10, CX; INT $0x80
-
// func Syscall(trap int64, a1, a2, a3 int64) (r1, r2, err int64);
// func Syscall6(trap int64, a1, a2, a3, a4, a5, a6 int64) (r1, r2, err int64);
// func Syscall9(trap int64, a1, a2, a3, a4, a5, a6, a7, a8, a9 int64) (r1, r2, err int64)