internal/bytealg, internal/cpu, internal/poll: portability fixes
authorIan Lance Taylor <ian@gcc.gnu.org>
Tue, 25 Sep 2018 14:31:57 +0000 (14:31 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Tue, 25 Sep 2018 14:31:57 +0000 (14:31 +0000)
    In internal/bytealg correct a +build tag to never build indexbyte_generic.go
    for the gofrontend, where we always use indexbyte_native.go.

    For internal/cpu let the Makefile define CacheLineSize using goarch.sh,
    rather than trying to enumerate all the possibilities in cpu_ARCH.go files.

    In internal/poll call the C fcntl function rather than using SYS_FCNTL.
    Change mksysinfo.sh to ensure that F_GETPIPE_SZ is always defined,
    and check that in internal/poll.

    Reviewed-on: https://go-review.googlesource.com/137256

From-SVN: r264572

16 files changed:
gcc/go/gofrontend/MERGE
libgo/Makefile.am
libgo/Makefile.in
libgo/go/internal/bytealg/indexbyte_generic.go
libgo/go/internal/cpu/cpu_arm.go [deleted file]
libgo/go/internal/cpu/cpu_arm64.go
libgo/go/internal/cpu/cpu_mips.go [deleted file]
libgo/go/internal/cpu/cpu_mips64.go [deleted file]
libgo/go/internal/cpu/cpu_mips64le.go [deleted file]
libgo/go/internal/cpu/cpu_mipsle.go [deleted file]
libgo/go/internal/cpu/cpu_ppc64x.go
libgo/go/internal/cpu/cpu_s390x.go
libgo/go/internal/cpu/cpu_wasm.go [deleted file]
libgo/go/internal/cpu/cpu_x86.go
libgo/go/internal/poll/splice_linux.go
libgo/mksysinfo.sh

index 65693ffebbc88c90764114e6732ec0302d22eb69..485906f78b5270c2923d084dd4b83f43b5774b2a 100644 (file)
@@ -1,4 +1,4 @@
-1dbc5b805a1665079008d1ce341991c3554c1eeb
+652fbfb7acfd81ceffe28e20984464aa7bb6024d
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index 373dd0cf73cff1b959ef75af694bd21d8f74954c..699e10d60aff620ae1ae1357cdd8cc6980ed79b4 100644 (file)
@@ -532,6 +532,14 @@ s-version: Makefile
        $(SHELL) $(srcdir)/mvifdiff.sh version.go.tmp version.go
        $(STAMP) $@
 
+cpugen.go: s-cpu; @true
+s-cpu: Makefile
+       rm -f cpugen.go.tmp
+       echo "package cpu" > cpugen.go.tmp
+       echo "const CacheLineSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) cachelinesize`" >> cpugen.go.tmp
+       $(SHELL) $(srcdir)/mvifdiff.sh cpugen.go.tmp cpugen.go
+       $(STAMP) $@
+
 objabi.go: s-objabi; @true
 s-objabi: Makefile
        rm -f objabi.go.tmp
@@ -963,6 +971,9 @@ runtime_pprof_check_GOCFLAGS = -static-libgo -fno-inline
 extra_go_files_runtime_internal_sys = version.go
 runtime/internal/sys.lo.dep: $(extra_go_files_runtime_internal_sys)
 
+extra_go_files_internal_cpu = cpugen.go
+internal/cpu.lo.dep: $(extra_go_files_internal_cpu)
+
 extra_go_files_internal_goroot = zstdpkglist.go
 internal/goroot.lo.dep: $(extra_go_files_internal_goroot)
 
index dfc2c66199b17bebf84f56843bab312b12617100..10b11e0104db0168d116b502f0b57a369b02ee9b 100644 (file)
@@ -1002,6 +1002,7 @@ runtime_internal_sys_lo_check_GOCFLAGS = -fgo-compiling-runtime
 # Also use -fno-inline to get better results from the memory profiler.
 runtime_pprof_check_GOCFLAGS = -static-libgo -fno-inline
 extra_go_files_runtime_internal_sys = version.go
+extra_go_files_internal_cpu = cpugen.go
 extra_go_files_internal_goroot = zstdpkglist.go
 extra_go_files_go_types = gccgosizes.go
 extra_go_files_cmd_internal_objabi = objabi.go
@@ -2759,6 +2760,14 @@ s-version: Makefile
        $(SHELL) $(srcdir)/mvifdiff.sh version.go.tmp version.go
        $(STAMP) $@
 
+cpugen.go: s-cpu; @true
+s-cpu: Makefile
+       rm -f cpugen.go.tmp
+       echo "package cpu" > cpugen.go.tmp
+       echo "const CacheLineSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) cachelinesize`" >> cpugen.go.tmp
+       $(SHELL) $(srcdir)/mvifdiff.sh cpugen.go.tmp cpugen.go
+       $(STAMP) $@
+
 objabi.go: s-objabi; @true
 s-objabi: Makefile
        rm -f objabi.go.tmp
@@ -2957,6 +2966,7 @@ $(foreach package,$(GOTOOL_PACKAGES),$(eval $(call PACKAGE_template,$(package)))
 runtime.lo.dep: $(extra_go_files_runtime)
 syscall.lo.dep: $(extra_go_files_syscall)
 runtime/internal/sys.lo.dep: $(extra_go_files_runtime_internal_sys)
+internal/cpu.lo.dep: $(extra_go_files_internal_cpu)
 internal/goroot.lo.dep: $(extra_go_files_internal_goroot)
 go/types.lo.dep: $(extra_go_files_go_types)
 cmd/internal/objabi.lo.dep: $(extra_go_files_cmd_internal_objabi)
index 890cd42d2b6039149b55687b02d061e70e841565..6e59fd1e72e372d964fc44ef21350266efe52e65 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +ignore_for_gccgo
+// +build ignore_for_gccgo
 // +build !386,!amd64,!amd64p32,!s390x,!arm,!arm64,!ppc64,!ppc64le,!mips,!mipsle,!mips64,!mips64le,!wasm
 
 package bytealg
diff --git a/libgo/go/internal/cpu/cpu_arm.go b/libgo/go/internal/cpu/cpu_arm.go
deleted file mode 100644 (file)
index 078a6c3..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-// Copyright 2017 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 cpu
-
-const CacheLineSize = 32
index 009f2a28e20a474588ec11ef6fe276bef6a7931e..c4d6b8155abbeea0e5df14f5198fd2cbff60b8d1 100644 (file)
@@ -4,8 +4,6 @@
 
 package cpu
 
-const CacheLineSize = 64
-
 // arm64 doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2.
 // These are initialized by archauxv in runtime/os_linux_arm64.go.
 // These should not be changed after they are initialized.
diff --git a/libgo/go/internal/cpu/cpu_mips.go b/libgo/go/internal/cpu/cpu_mips.go
deleted file mode 100644 (file)
index 078a6c3..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-// Copyright 2017 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 cpu
-
-const CacheLineSize = 32
diff --git a/libgo/go/internal/cpu/cpu_mips64.go b/libgo/go/internal/cpu/cpu_mips64.go
deleted file mode 100644 (file)
index 078a6c3..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-// Copyright 2017 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 cpu
-
-const CacheLineSize = 32
diff --git a/libgo/go/internal/cpu/cpu_mips64le.go b/libgo/go/internal/cpu/cpu_mips64le.go
deleted file mode 100644 (file)
index 078a6c3..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-// Copyright 2017 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 cpu
-
-const CacheLineSize = 32
diff --git a/libgo/go/internal/cpu/cpu_mipsle.go b/libgo/go/internal/cpu/cpu_mipsle.go
deleted file mode 100644 (file)
index 078a6c3..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-// Copyright 2017 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 cpu
-
-const CacheLineSize = 32
index d3f02efa7ff615cd2db190fa29dfd3796c9f93dd..5c4bed7982c0bb25a1117b655b1e07a55684dc6e 100644 (file)
@@ -6,8 +6,6 @@
 
 package cpu
 
-const CacheLineSize = 128
-
 // ppc64x doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2.
 // These are initialized by archauxv in runtime/os_linux_ppc64x.go.
 // These should not be changed after they are initialized.
index 9dedb4cb2a25bddc652ae2cb2c6a99decfb5d459..43fa4ad632c9a56f90c0daded733a49362f93785 100644 (file)
@@ -4,8 +4,6 @@
 
 package cpu
 
-const CacheLineSize = 256
-
 // bitIsSet reports whether the bit at index is set. The bit index
 // is in big endian order, so bit index 0 is the leftmost bit.
 func bitIsSet(bits []uint64, index uint) bool {
diff --git a/libgo/go/internal/cpu/cpu_wasm.go b/libgo/go/internal/cpu/cpu_wasm.go
deleted file mode 100644 (file)
index 1107a7a..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-// Copyright 2018 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 cpu
-
-const CacheLineSize = 64
index 7d9d3aaf76028c28d658a61aae2af04bd6ae6a39..5f159651d88473e944029449a687221269e0c081 100644 (file)
@@ -6,8 +6,6 @@
 
 package cpu
 
-const CacheLineSize = 64
-
 // cpuid is implemented in cpu_x86.s.
 func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32)
 
index aa237e587adabf45945f8841c78966a755053f9c..4265b429d14278ab8a3bd60b295b6a8b01d2151d 100644 (file)
@@ -162,10 +162,15 @@ func newTempPipe() (prfd, pwfd int, sc string, err error) {
                defer atomic.StorePointer(&disableSplice, unsafe.Pointer(p))
 
                // F_GETPIPE_SZ was added in 2.6.35, which does not have the -EAGAIN bug.
-               if _, _, errno := syscall.Syscall(syscall.SYS_FCNTL, uintptr(fds[0]), syscall.F_GETPIPE_SZ, 0); errno != 0 {
+               if syscall.F_GETPIPE_SZ == 0 {
                        *p = true
                        destroyTempPipe(fds[0], fds[1])
-                       return -1, -1, "fcntl", errno
+                       return -1, -1, "fcntl", syscall.EINVAL
+               }
+               if _, errno := fcntl(uintptr(fds[0]), syscall.F_GETPIPE_SZ, 0); errno != 0 {
+                       *p = true
+                       destroyTempPipe(fds[0], fds[1])
+                       return -1, -1, "fcntl", syscall.Errno(errno)
                }
        }
 
index 48bc71dbe986b77635072a3c467be7e20985dcaa..b9436ef1e83404a7772f5f24620e529e47bd4533 100755 (executable)
@@ -73,6 +73,11 @@ if ! grep '^const F_DUPFD_CLOEXEC' ${OUT} >/dev/null 2>&1; then
   echo "const F_DUPFD_CLOEXEC = 0" >> ${OUT}
 fi
 
+# The internal/poll package requires F_GETPIPE_SZ to be defined.
+if ! grep '^const F_GETPIPE_SZ' ${OUT} >/dev/null 2>&1; then
+  echo "const F_GETPIPE_SZ = 0" >> ${OUT}
+fi
+
 # AIX 7.1 is a 64 bits value for _FCLOEXEC (referenced by O_CLOEXEC)
 # which leads to a constant overflow when using O_CLOEXEC in some
 # go code. Issue wan not present in 6.1 (no O_CLOEXEC) and is no