From: Tobias Klauser Date: Mon, 27 Mar 2023 18:52:43 +0000 (+0200) Subject: cmd/link/internal/ld, internal/syscall/unix: use posix_fallocate on freebsd X-Git-Tag: go1.21rc1~1143 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ed1cf6ab3ef94c603f9d883aa6806a5a82d2bee3;p=gostls13.git cmd/link/internal/ld, internal/syscall/unix: use posix_fallocate on freebsd The posix_fallocate system call is available since FreeBSD 9.0, see https://man.freebsd.org/cgi/man.cgi?query=posix_fallocate Change-Id: Ie65e0a44341909707617d3b0d9a4f1710c45b935 Reviewed-on: https://go-review.googlesource.com/c/go/+/478035 TryBot-Result: Gopher Robot Auto-Submit: Tobias Klauser Run-TryBot: Tobias Klauser Reviewed-by: Cherry Mui Reviewed-by: Than McIntosh --- diff --git a/src/cmd/dist/buildtool.go b/src/cmd/dist/buildtool.go index 1eeb32afd3..f2228df33d 100644 --- a/src/cmd/dist/buildtool.go +++ b/src/cmd/dist/buildtool.go @@ -68,10 +68,11 @@ var bootstrapDirs = []string{ "internal/goroot", "internal/goversion", "internal/pkgbits", + "internal/platform", "internal/profile", "internal/race", "internal/saferio", - "internal/platform", + "internal/syscall/unix", "internal/types/errors", "internal/unsafeheader", "internal/xcoff", diff --git a/src/cmd/link/internal/ld/fallocate_test.go b/src/cmd/link/internal/ld/fallocate_test.go index 1ed0eb2ca7..ad77be536f 100644 --- a/src/cmd/link/internal/ld/fallocate_test.go +++ b/src/cmd/link/internal/ld/fallocate_test.go @@ -2,8 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build darwin || linux -// +build darwin linux +//go:build darwin || (freebsd && go1.21) || linux package ld diff --git a/src/cmd/link/internal/ld/outbuf_freebsd.go b/src/cmd/link/internal/ld/outbuf_freebsd.go new file mode 100644 index 0000000000..5ff17300c1 --- /dev/null +++ b/src/cmd/link/internal/ld/outbuf_freebsd.go @@ -0,0 +1,13 @@ +// Copyright 2023 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 freebsd && go1.21 + +package ld + +import "internal/syscall/unix" + +func (out *OutBuf) fallocate(size uint64) error { + return unix.PosixFallocate(int(out.f.Fd()), 0, int64(size)) +} diff --git a/src/cmd/link/internal/ld/outbuf_nofallocate.go b/src/cmd/link/internal/ld/outbuf_nofallocate.go index dd5afc61db..435be5e09f 100644 --- a/src/cmd/link/internal/ld/outbuf_nofallocate.go +++ b/src/cmd/link/internal/ld/outbuf_nofallocate.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build !darwin && !linux +//go:build !darwin && !(freebsd && go1.21) && !linux package ld diff --git a/src/cmd/link/internal/ld/outbuf_notdarwin.go b/src/cmd/link/internal/ld/outbuf_notdarwin.go index f9caa413e3..3e5c67a5c2 100644 --- a/src/cmd/link/internal/ld/outbuf_notdarwin.go +++ b/src/cmd/link/internal/ld/outbuf_notdarwin.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build !darwin -// +build !darwin package ld diff --git a/src/internal/syscall/unix/fallocate_freebsd.go b/src/internal/syscall/unix/fallocate_freebsd.go new file mode 100644 index 0000000000..6c3e80118b --- /dev/null +++ b/src/internal/syscall/unix/fallocate_freebsd.go @@ -0,0 +1,18 @@ +// Copyright 2023 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. + +package unix + +import "syscall" + +// FreeBSD posix_fallocate system call number. +const posixFallocateTrap uintptr = 530 + +func PosixFallocate(fd int, off int64, size int64) error { + _, _, errno := syscall.Syscall(posixFallocateTrap, uintptr(fd), uintptr(off), uintptr(size)) + if errno != 0 { + return errno + } + return nil +}