Fix nanotime for macOS Sierra

This commit is contained in:
Jakub Čajka 2016-10-10 15:09:07 +02:00
parent 7e3e63c06c
commit 1ffe9f2d11
3 changed files with 138 additions and 1 deletions

View File

@ -129,7 +129,12 @@ Patch213: go1.5beta1-disable-TestGdbPython.patch
Patch215: ./go1.5-zoneinfo_testing_only.patch
# Backport of https://go-review.googlesource.com/#/c/20471/
Patch216: runtime-use-entire-address-space-on-32-bit.patch
Patch216: runtime-use-entire-address-space-on-32-bit.patch
# Backport of https://github.com/golang/go/issues/16570
# and https://github.com/golang/go/issues/16606
Patch217: macos-01.patch
Patch218: macos-02.patch
# Having documentation separate was broken
Obsoletes: %{name}-docs < 1.1-4
@ -258,6 +263,9 @@ Summary: Golang shared object libraries
%patch216 -p1
%patch217 -p1
%patch218 -p1
%build
# print out system information
uname -a
@ -464,6 +472,7 @@ fi
%changelog
* Tue Sep 27 2016 Jakub Čajka <jcajka@redhat.com> - 1.6.3-3
- Resolves: BZ#1378960 - make possible to use whole address space on 32bit
- Fix nanotime for macOS Sierra
* Mon Aug 08 2016 Jakub Čajka <jcajka@redhat.com> - 1.6.3-2
- Obsolete golang-vet and golang-cover from golang-googlecode-tools package

60
macos-01.patch Normal file
View File

@ -0,0 +1,60 @@
From 2da5633eb9091608047881953f75b489a3134cdc Mon Sep 17 00:00:00 2001
From: Brad Fitzpatrick <bradfitz@golang.org>
Date: Mon, 1 Aug 2016 21:54:40 -0700
Subject: [PATCH] runtime: fix nanotime for macOS Sierra, again.
macOS Sierra beta4 changed the kernel interface for getting time.
DX now optionally points to an address for additional info.
Set it to zero to avoid corrupting memory.
Fixes #16570
Change-Id: I9f537e552682045325cdbb68b7d0b4ddafade14a
Reviewed-on: https://go-review.googlesource.com/25400
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Quentin Smith <quentin@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
---
src/runtime/sys_darwin_386.s | 7 ++++---
src/runtime/sys_darwin_amd64.s | 1 +
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/runtime/sys_darwin_386.s b/src/runtime/sys_darwin_386.s
index 83f4709..b5e65e6 100644
--- a/src/runtime/sys_darwin_386.s
+++ b/src/runtime/sys_darwin_386.s
@@ -196,15 +196,16 @@ timeloop:
systime:
// Fall back to system call (usually first call in this thread)
- LEAL 12(SP), AX // must be non-nil, unused
+ LEAL 16(SP), AX // must be non-nil, unused
MOVL AX, 4(SP)
MOVL $0, 8(SP) // time zone pointer
+ MOVL $0, 12(SP) // required as of Sierra; Issue 16570
MOVL $116, AX
INT $0x80
CMPL AX, $0
JNE inreg
- MOVL 12(SP), AX
- MOVL 16(SP), DX
+ MOVL 16(SP), AX
+ MOVL 20(SP), DX
inreg:
// sec is in AX, usec in DX
// convert to DX:AX nsec
diff --git a/src/runtime/sys_darwin_amd64.s b/src/runtime/sys_darwin_amd64.s
index e4837ce..ea2cc06 100644
--- a/src/runtime/sys_darwin_amd64.s
+++ b/src/runtime/sys_darwin_amd64.s
@@ -157,6 +157,7 @@ systime:
// Fall back to system call (usually first call in this thread).
MOVQ SP, DI
MOVQ $0, SI
+ MOVQ $0, DX // required as of Sierra; Issue 16570
MOVL $(0x2000000+116), AX
SYSCALL
CMPQ AX, $0

68
macos-02.patch Normal file
View File

@ -0,0 +1,68 @@
diff --git a/src/syscall/syscall_darwin_386.go b/src/syscall/syscall_darwin_386.go
index 2074e7a..286ca98 100644
--- a/src/syscall/syscall_darwin_386.go
+++ b/src/syscall/syscall_darwin_386.go
@@ -26,14 +26,22 @@ func NsecToTimeval(nsec int64) (tv Timeval) {
}
//sysnb gettimeofday(tp *Timeval) (sec int32, usec int32, err error)
-func Gettimeofday(tv *Timeval) (err error) {
- // The tv passed to gettimeofday must be non-nil
- // but is otherwise unused. The answers come back
- // in the two registers.
+func Gettimeofday(tv *Timeval) error {
+ // The tv passed to gettimeofday must be non-nil.
+ // Before macOS Sierra (10.12), tv was otherwise unused and
+ // the answers came back in the two registers.
+ // As of Sierra, gettimeofday return zeros and populates
+ // tv itself.
sec, usec, err := gettimeofday(tv)
- tv.Sec = int32(sec)
- tv.Usec = int32(usec)
- return err
+ if err != nil {
+ return err
+ }
+ if sec != 0 || usec != 0 {
+ tv.Sec = int32(sec)
+ tv.Usec = int32(usec)
+ }
+ return nil
+
}
func SetKevent(k *Kevent_t, fd, mode, flags int) {
diff --git a/src/syscall/syscall_darwin_amd64.go b/src/syscall/syscall_darwin_amd64.go
index 70b53b8..e2565ba 100644
--- a/src/syscall/syscall_darwin_amd64.go
+++ b/src/syscall/syscall_darwin_amd64.go
@@ -26,14 +26,22 @@ func NsecToTimeval(nsec int64) (tv Timeval) {
}
//sysnb gettimeofday(tp *Timeval) (sec int64, usec int32, err error)
-func Gettimeofday(tv *Timeval) (err error) {
- // The tv passed to gettimeofday must be non-nil
- // but is otherwise unused. The answers come back
- // in the two registers.
+func Gettimeofday(tv *Timeval) error {
+ // The tv passed to gettimeofday must be non-nil.
+ // Before macOS Sierra (10.12), tv was otherwise unused and
+ // the answers came back in the two registers.
+ // As of Sierra, gettimeofday return zeros and populates
+ // tv itself.
sec, usec, err := gettimeofday(tv)
- tv.Sec = sec
- tv.Usec = usec
- return err
+ if err != nil {
+ return err
+ }
+ if sec != 0 || usec != 0 {
+ tv.Sec = sec
+ tv.Usec = usec
+ }
+ return nil
+
}
func SetKevent(k *Kevent_t, fd, mode, flags int) {