syscall, internal/syscall: adjust use of largefile functions

Consistently call __go_openat for openat.  Use fstatat64, creat64,
sendfile64, and getdents64 where needed.

Based on patch by Rainer Orth.

Fixes https://gcc.gnu.org/PR89447

Change-Id: I5c7e9144c6239a969eb561997ef6d5931d984d1a
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/166420
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/libgo/go/internal/syscall/unix/at.go b/libgo/go/internal/syscall/unix/at.go
index b57b791..a602d3a 100644
--- a/libgo/go/internal/syscall/unix/at.go
+++ b/libgo/go/internal/syscall/unix/at.go
@@ -13,12 +13,9 @@
 //extern unlinkat
 func unlinkat(int32, *byte, int32) int32
 
-//extern openat
+//extern __go_openat
 func openat(int32, *byte, int32, syscall.Mode_t) int32
 
-//extern fstatat
-func fstatat(int32, *byte, *syscall.Stat_t, int32) int32
-
 func Unlinkat(dirfd int, path string, flags int) error {
 	var p *byte
 	p, err := syscall.BytePtrFromString(path)
diff --git a/libgo/go/internal/syscall/unix/at_largefile.go b/libgo/go/internal/syscall/unix/at_largefile.go
new file mode 100644
index 0000000..5318d23
--- /dev/null
+++ b/libgo/go/internal/syscall/unix/at_largefile.go
@@ -0,0 +1,14 @@
+// Copyright 2019 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.
+
+// +build aix hurd linux solaris,386 solaris,sparc
+
+package unix
+
+import (
+	"syscall"
+)
+
+//extern fstatat64
+func fstatat(int32, *byte, *syscall.Stat_t, int32) int32
diff --git a/libgo/go/internal/syscall/unix/at_regfile.go b/libgo/go/internal/syscall/unix/at_regfile.go
new file mode 100644
index 0000000..004c801
--- /dev/null
+++ b/libgo/go/internal/syscall/unix/at_regfile.go
@@ -0,0 +1,18 @@
+// Copyright 2019 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.
+
+// +build !aix
+// +build !hurd
+// +build !linux
+// +build !solaris !386
+// +build !solaris !sparc
+
+package unix
+
+import (
+	"syscall"
+)
+
+//extern fstatat
+func fstatat(int32, *byte, *syscall.Stat_t, int32) int32
diff --git a/libgo/go/syscall/libcall_bsd.go b/libgo/go/syscall/libcall_bsd.go
index 9a4b2d6..93f5710 100644
--- a/libgo/go/syscall/libcall_bsd.go
+++ b/libgo/go/syscall/libcall_bsd.go
@@ -13,8 +13,6 @@
 	"unsafe"
 )
 
-//sys	sendfile(outfd int, infd int, offset *Offset_t, count int) (written int, err error)
-//sendfile(outfd _C_int, infd _C_int, offset *Offset_t, count Size_t) Ssize_t
 func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
 	if race.Enabled {
 		race.ReleaseMerge(unsafe.Pointer(&ioSync))
diff --git a/libgo/go/syscall/libcall_bsd_largefile.go b/libgo/go/syscall/libcall_bsd_largefile.go
new file mode 100644
index 0000000..c6a336c
--- /dev/null
+++ b/libgo/go/syscall/libcall_bsd_largefile.go
@@ -0,0 +1,10 @@
+// Copyright 2019 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.
+
+// +build solaris,386 solaris,sparc
+
+package syscall
+
+//sys	sendfile(outfd int, infd int, offset *Offset_t, count int) (written int, err error)
+//sendfile64(outfd _C_int, infd _C_int, offset *Offset_t, count Size_t) Ssize_t
diff --git a/libgo/go/syscall/libcall_bsd_regfile.go b/libgo/go/syscall/libcall_bsd_regfile.go
new file mode 100644
index 0000000..388c8a7
--- /dev/null
+++ b/libgo/go/syscall/libcall_bsd_regfile.go
@@ -0,0 +1,10 @@
+// Copyright 2019 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.
+
+// +build darwin dragonfly freebsd netbsd openbsd solaris,amd64 solaris,sparc64
+
+package syscall
+
+//sys	sendfile(outfd int, infd int, offset *Offset_t, count int) (written int, err error)
+//sendfile(outfd _C_int, infd _C_int, offset *Offset_t, count Size_t) Ssize_t
diff --git a/libgo/go/syscall/libcall_posix.go b/libgo/go/syscall/libcall_posix.go
index d2fa0d9..31d6bf1 100644
--- a/libgo/go/syscall/libcall_posix.go
+++ b/libgo/go/syscall/libcall_posix.go
@@ -184,9 +184,6 @@
 //sys	Close(fd int) (err error)
 //close(fd _C_int) _C_int
 
-//sys	Creat(path string, mode uint32) (fd int, err error)
-//creat(path *byte, mode Mode_t) _C_int
-
 //sysnb	Dup(oldfd int) (fd int, err error)
 //dup(oldfd _C_int) _C_int
 
diff --git a/libgo/go/syscall/libcall_posix_largefile.go b/libgo/go/syscall/libcall_posix_largefile.go
index 57a7f5e..bf0f9fe 100644
--- a/libgo/go/syscall/libcall_posix_largefile.go
+++ b/libgo/go/syscall/libcall_posix_largefile.go
@@ -8,6 +8,9 @@
 
 package syscall
 
+//sys	Creat(path string, mode uint32) (fd int, err error)
+//creat64(path *byte, mode Mode_t) _C_int
+
 //sys	Fstat(fd int, stat *Stat_t) (err error)
 //fstat64(fd _C_int, stat *Stat_t) _C_int
 
diff --git a/libgo/go/syscall/libcall_posix_regfile.go b/libgo/go/syscall/libcall_posix_regfile.go
index 5dc6eb6..8ff7213 100644
--- a/libgo/go/syscall/libcall_posix_regfile.go
+++ b/libgo/go/syscall/libcall_posix_regfile.go
@@ -13,6 +13,9 @@
 
 package syscall
 
+//sys	Creat(path string, mode uint32) (fd int, err error)
+//creat(path *byte, mode Mode_t) _C_int
+
 //sys	Fstat(fd int, stat *Stat_t) (err error)
 //fstat(fd _C_int, stat *Stat_t) _C_int
 
diff --git a/libgo/go/syscall/libcall_solaris.go b/libgo/go/syscall/libcall_solaris_largefile.go
similarity index 63%
copy from libgo/go/syscall/libcall_solaris.go
copy to libgo/go/syscall/libcall_solaris_largefile.go
index a026614..757b229 100644
--- a/libgo/go/syscall/libcall_solaris.go
+++ b/libgo/go/syscall/libcall_solaris_largefile.go
@@ -1,11 +1,13 @@
-// Copyright 2017 The Go Authors. All rights reserved.
+// Copyright 2019 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.
 
+// +build solaris,386 solaris,sparc
+
 package syscall
 
 //sys Getdents(fd int, buf []byte) (n int, err error)
-//getdents(fd _C_int, buf *byte, nbyte Size_t) _C_int
+//getdents64(fd _C_int, buf *byte, nbyte Size_t) _C_int
 
 func ReadDirent(fd int, buf []byte) (n int, err error) {
 	return Getdents(fd, buf)
diff --git a/libgo/go/syscall/libcall_solaris.go b/libgo/go/syscall/libcall_solaris_regfile.go
similarity index 89%
rename from libgo/go/syscall/libcall_solaris.go
rename to libgo/go/syscall/libcall_solaris_regfile.go
index a026614..fa5dd8c 100644
--- a/libgo/go/syscall/libcall_solaris.go
+++ b/libgo/go/syscall/libcall_solaris_regfile.go
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// +build solaris,amd64 solaris,sparc64
+
 package syscall
 
 //sys Getdents(fd int, buf []byte) (n int, err error)