]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link/internal/ld, syscall: use libc based msync on darwin for Go ≥ 1.20
authorTobias Klauser <tklauser@distanz.ch>
Tue, 13 Sep 2022 09:23:50 +0000 (11:23 +0200)
committerGopher Robot <gobot@golang.org>
Tue, 13 Sep 2022 15:50:02 +0000 (15:50 +0000)
Direct syscalls should no longer be used on darwin. Instead, directly
call libc's msync when using Go ≥ 1.20 for bootstrap.

For #54265

Change-Id: Ie3f1e6ccd1a06e7f0ddd88cdef5067393a69e8db
Reviewed-on: https://go-review.googlesource.com/c/go/+/430336
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>

src/cmd/link/internal/ld/msync_darwin_libc.go [new file with mode: 0644]
src/cmd/link/internal/ld/msync_darwin_syscall.go [new file with mode: 0644]
src/cmd/link/internal/ld/outbuf_darwin.go
src/syscall/syscall_darwin.go
src/syscall/zsyscall_darwin_amd64.go
src/syscall/zsyscall_darwin_amd64.s
src/syscall/zsyscall_darwin_arm64.go
src/syscall/zsyscall_darwin_arm64.s

diff --git a/src/cmd/link/internal/ld/msync_darwin_libc.go b/src/cmd/link/internal/ld/msync_darwin_libc.go
new file mode 100644 (file)
index 0000000..eb2a526
--- /dev/null
@@ -0,0 +1,12 @@
+// Copyright 2022 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build darwin && go1.20
+
+package ld
+
+import _ "unsafe" // for go:linkname
+
+//go:linkname msync syscall.msync
+func msync(b []byte, flags int) (err error)
diff --git a/src/cmd/link/internal/ld/msync_darwin_syscall.go b/src/cmd/link/internal/ld/msync_darwin_syscall.go
new file mode 100644 (file)
index 0000000..270d9f3
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright 2022 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build darwin && !go1.20
+
+package ld
+
+import (
+       "syscall"
+       "unsafe"
+)
+
+func msync(b []byte, flags int) (err error) {
+       var p unsafe.Pointer
+       if len(b) > 0 {
+               p = unsafe.Pointer(&b[0])
+       }
+       _, _, errno := syscall.Syscall(syscall.SYS_MSYNC, uintptr(p), uintptr(len(b)), uintptr(flags))
+       if errno != 0 {
+               return errno
+       }
+       return nil
+}
index c0d994ea61df449e8842351e67946c8000ab7c5c..17f7e2a65fc7d94c0ca0cc13916f241df16d80cd 100644 (file)
@@ -43,6 +43,6 @@ func (out *OutBuf) purgeSignatureCache() {
        // When we mmap the output buffer, it doesn't have a code signature
        // (as we haven't generated one). Invalidate the kernel cache now that
        // we have generated the signature. See issue #42684.
-       syscall.Syscall(syscall.SYS_MSYNC, uintptr(unsafe.Pointer(&out.buf[0])), uintptr(len(out.buf)), syscall.MS_INVALIDATE)
+       msync(out.buf, syscall.MS_INVALIDATE)
        // Best effort. Ignore error.
 }
index 663ac4e94c3b07bf63e3b6089f71667fa9633fc6..cf9b0e98091ef517cc31402837e176bd11fed45c 100644 (file)
@@ -171,6 +171,7 @@ func Kill(pid int, signum Signal) (err error) { return kill(pid, int(signum), 1)
 //sys  Mlock(b []byte) (err error)
 //sys  Mlockall(flags int) (err error)
 //sys  Mprotect(b []byte, prot int) (err error)
+//sys  msync(b []byte, flags int) (err error)
 //sys  Munlock(b []byte) (err error)
 //sys  Munlockall() (err error)
 //sys  Open(path string, mode int, perm uint32) (fd int, err error)
index ee78a572fcbebbdff0030238130251b5df1378e4..6b3fff3f3726a224ad1c6bbdc856eec18e73fdfe 100644 (file)
@@ -1063,6 +1063,26 @@ func libc_mprotect_trampoline()
 
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
+func msync(b []byte, flags int) (err error) {
+       var _p0 unsafe.Pointer
+       if len(b) > 0 {
+               _p0 = unsafe.Pointer(&b[0])
+       } else {
+               _p0 = unsafe.Pointer(&_zero)
+       }
+       _, _, e1 := syscall(abi.FuncPCABI0(libc_msync_trampoline), uintptr(_p0), uintptr(len(b)), uintptr(flags))
+       if e1 != 0 {
+               err = errnoErr(e1)
+       }
+       return
+}
+
+func libc_msync_trampoline()
+
+//go:cgo_import_dynamic libc_msync msync "/usr/lib/libSystem.B.dylib"
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
 func Munlock(b []byte) (err error) {
        var _p0 unsafe.Pointer
        if len(b) > 0 {
index 563083d441a17c7600c4265e4104adc9498bc60b..90e51fb9a4f43a63b4fff6150a47626b4d6c1135 100644 (file)
@@ -143,6 +143,8 @@ TEXT ·libc_mlockall_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_mlockall(SB)
 TEXT ·libc_mprotect_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_mprotect(SB)
+TEXT ·libc_msync_trampoline(SB),NOSPLIT,$0-0
+       JMP     libc_msync(SB)
 TEXT ·libc_munlock_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_munlock(SB)
 TEXT ·libc_munlockall_trampoline(SB),NOSPLIT,$0-0
index ac1eccf755978cd6446b0bc754dabd723528760b..61601449a04043f185cd640cd3599af492d565cd 100644 (file)
@@ -1063,6 +1063,26 @@ func libc_mprotect_trampoline()
 
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
+func msync(b []byte, flags int) (err error) {
+       var _p0 unsafe.Pointer
+       if len(b) > 0 {
+               _p0 = unsafe.Pointer(&b[0])
+       } else {
+               _p0 = unsafe.Pointer(&_zero)
+       }
+       _, _, e1 := syscall(abi.FuncPCABI0(libc_msync_trampoline), uintptr(_p0), uintptr(len(b)), uintptr(flags))
+       if e1 != 0 {
+               err = errnoErr(e1)
+       }
+       return
+}
+
+func libc_msync_trampoline()
+
+//go:cgo_import_dynamic libc_msync msync "/usr/lib/libSystem.B.dylib"
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
 func Munlock(b []byte) (err error) {
        var _p0 unsafe.Pointer
        if len(b) > 0 {
index 0567a42fa337985c3b5d0115cf27299c9ebe04d4..f00747939efa36d38d2f920b79169fe31eab8e64 100644 (file)
@@ -143,6 +143,8 @@ TEXT ·libc_mlockall_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_mlockall(SB)
 TEXT ·libc_mprotect_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_mprotect(SB)
+TEXT ·libc_msync_trampoline(SB),NOSPLIT,$0-0
+       JMP     libc_msync(SB)
 TEXT ·libc_munlock_trampoline(SB),NOSPLIT,$0-0
        JMP     libc_munlock(SB)
 TEXT ·libc_munlockall_trampoline(SB),NOSPLIT,$0-0