cmd/link/internal/ld: use libc based fcntl for (*OutBuf).fallocate on darwin
Direct syscalls are no longer supported on darwin. Instead, use libc
fcntl go:linkname'd from the syscall package.
Change-Id: Ieeec64810452455faedd200f661a8b5839ca1fa0
Reviewed-on: https://go-review.googlesource.com/c/go/+/255260
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
diff --git a/src/cmd/link/internal/ld/outbuf_darwin.go b/src/cmd/link/internal/ld/outbuf_darwin.go
index 9444b65..6920a0a 100644
--- a/src/cmd/link/internal/ld/outbuf_darwin.go
+++ b/src/cmd/link/internal/ld/outbuf_darwin.go
@@ -9,6 +9,10 @@
"unsafe"
)
+// Implemented in the syscall package.
+//go:linkname fcntl syscall.fcntl
+func fcntl(fd int, cmd int, arg int) (int, error)
+
func (out *OutBuf) fallocate(size uint64) error {
stat, err := out.f.Stat()
if err != nil {
@@ -29,12 +33,8 @@
Length: int64(size - cursize),
}
- _, _, errno := syscall.Syscall(syscall.SYS_FCNTL, uintptr(out.f.Fd()), syscall.F_PREALLOCATE, uintptr(unsafe.Pointer(store)))
- if errno != 0 {
- return errno
- }
-
- return nil
+ _, err = fcntl(int(out.f.Fd()), syscall.F_PREALLOCATE, int(uintptr(unsafe.Pointer(store))))
+ return err
}
func (out *OutBuf) purgeSignatureCache() {