Skip to content

Commit ce3f3e2

Browse files
committed
cmd/link/internal/ld, internal/syscall/unix: use posix_fallocate on netbsd
The posix_fallocate system call is available since NetBSD 7.0, see https://man.netbsd.org/posix_fallocate.2 Re-use the syscall wrappers already in place for freebsd. Note that posix_fallocate on netbsd also returns the result in r1 rather than in errno: > If successful, posix_fallocate() returns zero. It returns an error on failure, without > setting errno. Source: https://man.netbsd.org/posix_fallocate.2#RETURN%20VALUES Cq-Include-Trybots: luci.golang.try:gotip-netbsd-arm64 Change-Id: Iaa1f6a805d511645da7f1d2737235bfd42da3407 Reviewed-on: https://go-review.googlesource.com/c/go/+/480475 Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Benny Siegert <[email protected]> Auto-Submit: Tobias Klauser <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 3dbef65 commit ce3f3e2

File tree

8 files changed

+23
-15
lines changed

8 files changed

+23
-15
lines changed

src/cmd/link/internal/ld/fallocate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build darwin || (freebsd && go1.21) || linux
5+
//go:build darwin || (freebsd && go1.21) || linux || (netbsd && go1.25)
66

77
package ld
88

src/cmd/link/internal/ld/outbuf_freebsd.go renamed to src/cmd/link/internal/ld/outbuf_bsd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build freebsd && go1.21
5+
//go:build (freebsd && go1.21) || (netbsd && go1.25)
66

77
package ld
88

src/cmd/link/internal/ld/outbuf_mmap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (out *OutBuf) Mmap(filesize uint64) (err error) {
2828
// Some file systems do not support fallocate. We ignore that error as linking
2929
// can still take place, but you might SIGBUS when you write to the mmapped
3030
// area.
31-
if err != syscall.ENOTSUP && err != syscall.EPERM && err != errNoFallocate {
31+
if err != syscall.ENOTSUP && err != syscall.EOPNOTSUPP && err != syscall.EPERM && err != errNoFallocate {
3232
return err
3333
}
3434
}

src/cmd/link/internal/ld/outbuf_nofallocate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !darwin && !(freebsd && go1.21) && !linux
5+
//go:build !darwin && !(freebsd && go1.21) && !linux && !(netbsd && go1.25)
66

77
package ld
88

src/internal/syscall/unix/at_sysnum_netbsd.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ package unix
77
import "syscall"
88

99
const (
10-
unlinkatTrap uintptr = syscall.SYS_UNLINKAT
11-
openatTrap uintptr = syscall.SYS_OPENAT
12-
fstatatTrap uintptr = syscall.SYS_FSTATAT
13-
readlinkatTrap uintptr = syscall.SYS_READLINKAT
14-
mkdiratTrap uintptr = syscall.SYS_MKDIRAT
15-
fchmodatTrap uintptr = syscall.SYS_FCHMODAT
16-
fchownatTrap uintptr = syscall.SYS_FCHOWNAT
17-
renameatTrap uintptr = syscall.SYS_RENAMEAT
18-
linkatTrap uintptr = syscall.SYS_LINKAT
19-
symlinkatTrap uintptr = syscall.SYS_SYMLINKAT
10+
unlinkatTrap uintptr = syscall.SYS_UNLINKAT
11+
openatTrap uintptr = syscall.SYS_OPENAT
12+
fstatatTrap uintptr = syscall.SYS_FSTATAT
13+
readlinkatTrap uintptr = syscall.SYS_READLINKAT
14+
mkdiratTrap uintptr = syscall.SYS_MKDIRAT
15+
fchmodatTrap uintptr = syscall.SYS_FCHMODAT
16+
fchownatTrap uintptr = syscall.SYS_FCHOWNAT
17+
renameatTrap uintptr = syscall.SYS_RENAMEAT
18+
linkatTrap uintptr = syscall.SYS_LINKAT
19+
symlinkatTrap uintptr = syscall.SYS_SYMLINKAT
20+
posixFallocateTrap uintptr = 479
2021
)
2122

2223
const (

src/internal/syscall/unix/fallocate_freebsd_386.go renamed to src/internal/syscall/unix/fallocate_bsd_386.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build (freebsd || netbsd) && 386
6+
57
package unix
68

79
import "syscall"
810

911
func PosixFallocate(fd int, off int64, size int64) error {
1012
// If successful, posix_fallocate() returns zero. It returns an error on failure, without
1113
// setting errno. See https://man.freebsd.org/cgi/man.cgi?query=posix_fallocate&sektion=2&n=1
14+
// and https://man.netbsd.org/posix_fallocate.2#RETURN%20VALUES
1215
r1, _, _ := syscall.Syscall6(posixFallocateTrap, uintptr(fd), uintptr(off), uintptr(off>>32), uintptr(size), uintptr(size>>32), 0)
1316
if r1 != 0 {
1417
return syscall.Errno(r1)

src/internal/syscall/unix/fallocate_freebsd_64bit.go renamed to src/internal/syscall/unix/fallocate_bsd_64bit.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build freebsd && (amd64 || arm64 || riscv64)
5+
//go:build (freebsd || netbsd) && (amd64 || arm64 || riscv64)
66

77
package unix
88

@@ -11,6 +11,7 @@ import "syscall"
1111
func PosixFallocate(fd int, off int64, size int64) error {
1212
// If successful, posix_fallocate() returns zero. It returns an error on failure, without
1313
// setting errno. See https://man.freebsd.org/cgi/man.cgi?query=posix_fallocate&sektion=2&n=1
14+
// and https://man.netbsd.org/posix_fallocate.2#RETURN%20VALUES
1415
r1, _, _ := syscall.Syscall(posixFallocateTrap, uintptr(fd), uintptr(off), uintptr(size))
1516
if r1 != 0 {
1617
return syscall.Errno(r1)

src/internal/syscall/unix/fallocate_freebsd_arm.go renamed to src/internal/syscall/unix/fallocate_bsd_arm.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build (freebsd || netbsd) && arm
6+
57
package unix
68

79
import "syscall"
810

911
func PosixFallocate(fd int, off int64, size int64) error {
1012
// If successful, posix_fallocate() returns zero. It returns an error on failure, without
1113
// setting errno. See https://man.freebsd.org/cgi/man.cgi?query=posix_fallocate&sektion=2&n=1
14+
// and https://man.netbsd.org/posix_fallocate.2#RETURN%20VALUES
1215
//
1316
// The padding 0 argument is needed because the ARM calling convention requires that if an
1417
// argument (off in this case) needs double-word alignment (8-byte), the NCRN (next core

0 commit comments

Comments
 (0)