Skip to content

Instantly share code, notes, and snippets.

@leonklingele
Created February 17, 2021 08:56
Show Gist options
  • Save leonklingele/a221d95d759310a744eec37fc95c4729 to your computer and use it in GitHub Desktop.
Save leonklingele/a221d95d759310a744eec37fc95c4729 to your computer and use it in GitHub Desktop.
0001-Revert-runtime-use-clock_gettime-instead-of-gettimeo.patch
From b27c969f972ae942dba6be33b21f0110adcf7f5f Mon Sep 17 00:00:00 2001
From: Leon Klingele <[email protected]>
Date: Wed, 17 Feb 2021 09:55:58 +0100
Subject: [PATCH] Revert "runtime: use clock_gettime instead of gettimeofday on
darwin"
This reverts commit ae76f6e96216f352cc5021a4c8a7d879c4cb6873.
---
src/runtime/sys_darwin.go | 6 +++---
src/runtime/sys_darwin_amd64.s | 8 +++-----
src/runtime/sys_darwin_arm64.s | 8 +++-----
3 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/src/runtime/sys_darwin.go b/src/runtime/sys_darwin.go
index 4a3f2fc453..d7cc7e1721 100644
--- a/src/runtime/sys_darwin.go
+++ b/src/runtime/sys_darwin.go
@@ -266,9 +266,9 @@ func nanotime_trampoline()
//go:nosplit
//go:cgo_unsafe_args
func walltime1() (int64, int32) {
- var t timespec
+ var t timeval
libcCall(unsafe.Pointer(funcPC(walltime_trampoline)), unsafe.Pointer(&t))
- return t.tv_sec, int32(t.tv_nsec)
+ return int64(t.tv_sec), 1000 * t.tv_usec
}
func walltime_trampoline()
@@ -441,7 +441,7 @@ func setNonblock(fd int32) {
//go:cgo_import_dynamic libc_mach_timebase_info mach_timebase_info "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_mach_absolute_time mach_absolute_time "/usr/lib/libSystem.B.dylib"
-//go:cgo_import_dynamic libc_clock_gettime clock_gettime "/usr/lib/libSystem.B.dylib"
+//go:cgo_import_dynamic libc_gettimeofday gettimeofday "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_sigaction sigaction "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_pthread_sigmask pthread_sigmask "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_sigaltstack sigaltstack "/usr/lib/libSystem.B.dylib"
diff --git a/src/runtime/sys_darwin_amd64.s b/src/runtime/sys_darwin_amd64.s
index 0fe8c7e172..8013db1d31 100644
--- a/src/runtime/sys_darwin_amd64.s
+++ b/src/runtime/sys_darwin_amd64.s
@@ -12,8 +12,6 @@
#include "go_tls.h"
#include "textflag.h"
-#define CLOCK_REALTIME 0
-
// Exit the entire program (like C exit)
TEXT runtime·exit_trampoline<ABIInternal>(SB),NOSPLIT,$0
PUSHQ BP
@@ -144,9 +142,9 @@ initialized:
TEXT runtime·walltime_trampoline<ABIInternal>(SB),NOSPLIT,$0
PUSHQ BP // make a frame; keep stack aligned
MOVQ SP, BP
- MOVQ DI, SI // arg 2 timespec
- MOVL $CLOCK_REALTIME, DI // arg 1 clock_id
- CALL libc_clock_gettime(SB)
+ // DI already has *timeval
+ XORL SI, SI // no timezone needed
+ CALL libc_gettimeofday(SB)
POPQ BP
RET
diff --git a/src/runtime/sys_darwin_arm64.s b/src/runtime/sys_darwin_arm64.s
index 96d2ed1076..b2690f4c37 100644
--- a/src/runtime/sys_darwin_arm64.s
+++ b/src/runtime/sys_darwin_arm64.s
@@ -10,8 +10,6 @@
#include "go_tls.h"
#include "textflag.h"
-#define CLOCK_REALTIME 0
-
TEXT notok<>(SB),NOSPLIT,$0
MOVD $0, R8
MOVD R8, (R8)
@@ -134,9 +132,9 @@ TEXT runtime·setitimer_trampoline(SB),NOSPLIT,$0
RET
TEXT runtime·walltime_trampoline(SB),NOSPLIT,$0
- MOVD R0, R1 // arg 2 timespec
- MOVW $CLOCK_REALTIME, R0 // arg 1 clock_id
- BL libc_clock_gettime(SB)
+ // R0 already has *timeval
+ MOVD $0, R1 // no timezone needed
+ BL libc_gettimeofday(SB)
RET
GLOBL timebase<>(SB),NOPTR,$(machTimebaseInfo__size)
--
2.30.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment