wireguard-go-bridge: use boottime instead of monotonic

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2018-11-01 23:39:06 +01:00
parent b21de2e398
commit 6676e557f1
2 changed files with 86 additions and 7 deletions

View File

@ -26,6 +26,26 @@ export CGO_ENABLED := 1
build: $(DESTDIR)/libwg-go.a build: $(DESTDIR)/libwg-go.a
version-header: $(DESTDIR)/wireguard-go-version.h version-header: $(DESTDIR)/wireguard-go-version.h
GOBUILDARCH := $(GOARCH_$(shell uname -m))
GOBUILDOS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
GOBUILDVERSION := 1.11.1
GOBUILDTARBALL := https://dl.google.com/go/go$(GOBUILDVERSION).$(GOBUILDOS)-$(GOBUILDARCH).tar.gz
GOBUILDVERSION_NEEDED := go version go$(GOBUILDVERSION) $(GOBUILDOS)/$(GOBUILDARCH)
export GOROOT := $(BUILDDIR)/goroot
export GOPATH := $(BUILDDIR)/gopath
export PATH := $(GOROOT)/bin:$(PATH)
GOBUILDVERSION_CURRENT := $(shell $(GOROOT)/bin/go version 2>/dev/null)
ifneq ($(GOBUILDVERSION_NEEDED),$(GOBUILDVERSION_CURRENT))
$(shell rm -f $(GOROOT)/bin/go)
endif
$(GOROOT)/bin/go:
rm -rf "$(GOROOT)"
mkdir -p "$(GOROOT)"
curl "$(GOBUILDTARBALL)" | tar -C "$(GOROOT)" --strip-components=1 -xzf - || { rm -rf "$(GOROOT)"; exit 1; }
patch -p1 -f -N -r- -d "$(GOROOT)" < goruntime-boottime-over-monotonic.diff || { rm -rf "$(GOROOT)"; exit 1; }
$(shell test "$$(cat "$(BUILDDIR)/.gobuildversion" 2>/dev/null)" = "$(GOBUILDVERSION_CURRENT)" || rm -f "$(DESTDIR)/libwg-go.a")
define copy-src-to-build define copy-src-to-build
$(subst $(1),$(BUILDDIR)/,$(2)): $(2) $(subst $(1),$(BUILDDIR)/,$(2)): $(2)
@mkdir -vp "$$(dir $$@)" @mkdir -vp "$$(dir $$@)"
@ -36,20 +56,19 @@ endef
$(foreach FILE,$(UPSTREAM_FILES),$(eval $(call copy-src-to-build,../wireguard-go/,$(FILE)))) $(foreach FILE,$(UPSTREAM_FILES),$(eval $(call copy-src-to-build,../wireguard-go/,$(FILE))))
$(foreach FILE,$(DOWNSTREAM_FILES),$(eval $(call copy-src-to-build,src/,$(FILE)))) $(foreach FILE,$(DOWNSTREAM_FILES),$(eval $(call copy-src-to-build,src/,$(FILE))))
$(BUILDDIR)/.prepared: $(BUILDDIR)/.prepared: $(GOROOT)/bin/go
@touch "$@" cd "$(BUILDDIR)" || exit $$?; $(foreach ARCH,$(ARCHS),CC="$(CC_$(ARCH))" CGO_CFLAGS="$(CGO_FLAGS_$(ARCH))" CGO_LDFLAGS="$(CGO_FLAGS_$(ARCH))" GOARCH="$(GOARCH_$(ARCH))" go get -tags ios || { ret=$$?; chmod -fR +w "$(GOPATH)/pkg/mod"; rm -rf "$(GOPATH)/pkg/mod"; exit $$ret; };)
chmod -fR +w "$(GOPATH)/pkg/mod"
touch "$@"
define libwg-go-a define libwg-go-a
$(BUILDDIR)/libwg-go-$(1).a: $(BUILDDIR)/.prepared $(BUILDDIR)/libwg-go-$(1).a: $(BUILDDIR)/.prepared
cd "$(BUILDDIR)" || exit $$$$?; \ cd "$(BUILDDIR)" || exit $$$$?; \
export CC="$(CC_$(1))" \ CC="$(CC_$(1))" \
CGO_CFLAGS="$(CGO_FLAGS_$(1))" \ CGO_CFLAGS="$(CGO_FLAGS_$(1))" \
CGO_LDFLAGS="$(CGO_FLAGS_$(1))" \ CGO_LDFLAGS="$(CGO_FLAGS_$(1))" \
GOARCH="$(GOARCH_$(1))" \ GOARCH="$(GOARCH_$(1))" \
GOPATH="$(BUILDDIR)/gopath"; \ go build -tags ios -v -o "$(BUILDDIR)/libwg-go-$(1).a" -buildmode c-archive && go version > "$(BUILDDIR)/.gobuildversion"; \
go get -tags ios || { ret=$$$$?; chmod -fR +w "$(BUILDDIR)/gopath/pkg/mod"; rm -rf "$(BUILDDIR)/gopath/pkg/mod"; exit $$$$ret; }; \
chmod -fR +w "$(BUILDDIR)/gopath/pkg/mod"; \
go build -tags ios -v -o "$(BUILDDIR)/libwg-go-$(1).a" -buildmode c-archive; \
ret=$$$$?; \ ret=$$$$?; \
rm -f "$(BUILDDIR)/libwg-go-$(1).h"; \ rm -f "$(BUILDDIR)/libwg-go-$(1).h"; \
exit $$$$ret exit $$$$ret

View File

@ -0,0 +1,60 @@
diff -r -u go/src/runtime/sys_darwin_386.s go-modified/src/runtime/sys_darwin_386.s
--- go/src/runtime/sys_darwin_386.s 2018-10-01 23:02:54.000000000 +0200
+++ go-modified/src/runtime/sys_darwin_386.s 2018-11-01 23:18:04.383055355 +0100
@@ -184,7 +184,7 @@
PUSHL BP
MOVL SP, BP
SUBL $8+(machTimebaseInfo__size+15)/16*16, SP
- CALL libc_mach_absolute_time(SB)
+ CALL libc_mach_continuous_time(SB)
MOVL 16+(machTimebaseInfo__size+15)/16*16(SP), CX
MOVL AX, 0(CX)
MOVL DX, 4(CX)
diff -r -u go/src/runtime/sys_darwin_amd64.s go-modified/src/runtime/sys_darwin_amd64.s
--- go/src/runtime/sys_darwin_amd64.s 2018-10-01 23:02:54.000000000 +0200
+++ go-modified/src/runtime/sys_darwin_amd64.s 2018-11-01 23:18:04.382055360 +0100
@@ -85,7 +85,7 @@
PUSHQ BP
MOVQ SP, BP
MOVQ DI, BX
- CALL libc_mach_absolute_time(SB)
+ CALL libc_mach_continuous_time(SB)
MOVQ AX, 0(BX)
MOVL timebase<>+machTimebaseInfo_numer(SB), SI
MOVL timebase<>+machTimebaseInfo_denom(SB), DI // atomic read
diff -r -u go/src/runtime/sys_darwin_arm64.s go-modified/src/runtime/sys_darwin_arm64.s
--- go/src/runtime/sys_darwin_arm64.s 2018-10-01 23:02:54.000000000 +0200
+++ go-modified/src/runtime/sys_darwin_arm64.s 2018-11-01 23:18:04.380055369 +0100
@@ -110,7 +110,7 @@
TEXT runtime·nanotime_trampoline(SB),NOSPLIT,$40
MOVD R0, R19
- BL libc_mach_absolute_time(SB)
+ BL libc_mach_continuous_time(SB)
MOVD R0, 0(R19)
MOVW timebase<>+machTimebaseInfo_numer(SB), R20
MOVD $timebase<>+machTimebaseInfo_denom(SB), R21
diff -r -u go/src/runtime/sys_darwin_arm.s go-modified/src/runtime/sys_darwin_arm.s
--- go/src/runtime/sys_darwin_arm.s 2018-10-01 23:02:54.000000000 +0200
+++ go-modified/src/runtime/sys_darwin_arm.s 2018-11-01 23:18:04.381055364 +0100
@@ -118,7 +118,7 @@
TEXT runtime·nanotime_trampoline(SB),NOSPLIT,$0
MOVW R0, R8
- BL libc_mach_absolute_time(SB)
+ BL libc_mach_continuous_time(SB)
MOVW R0, 0(R8)
MOVW R1, 4(R8)
MOVW timebase<>+machTimebaseInfo_numer(SB), R6
diff -r -u go/src/runtime/sys_darwin.go go-modified/src/runtime/sys_darwin.go
--- go/src/runtime/sys_darwin.go 2018-10-01 23:02:54.000000000 +0200
+++ go-modified/src/runtime/sys_darwin.go 2018-11-01 23:18:04.384055350 +0100
@@ -348,7 +348,7 @@
//go:cgo_import_dynamic libc_usleep usleep "/usr/lib/libSystem.B.dylib"
//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_mach_continuous_time mach_continuous_time "/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"