Skip to content

Commit 652fbfb

Browse files
internal/bytealg, internal/cpu, internal/poll: portability fixes
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. Change-Id: Ie9e8081499133433027780adc1e1010af4731e01 Reviewed-on: https://go-review.googlesource.com/137256 Reviewed-by: Than McIntosh <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent 1dbc5b8 commit 652fbfb

15 files changed

+34
-53
lines changed

libgo/Makefile.am

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,14 @@ s-version: Makefile
532532
$(SHELL) $(srcdir)/mvifdiff.sh version.go.tmp version.go
533533
$(STAMP) $@
534534

535+
cpugen.go: s-cpu; @true
536+
s-cpu: Makefile
537+
rm -f cpugen.go.tmp
538+
echo "package cpu" > cpugen.go.tmp
539+
echo "const CacheLineSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) cachelinesize`" >> cpugen.go.tmp
540+
$(SHELL) $(srcdir)/mvifdiff.sh cpugen.go.tmp cpugen.go
541+
$(STAMP) $@
542+
535543
objabi.go: s-objabi; @true
536544
s-objabi: Makefile
537545
rm -f objabi.go.tmp
@@ -963,6 +971,9 @@ runtime_pprof_check_GOCFLAGS = -static-libgo -fno-inline
963971
extra_go_files_runtime_internal_sys = version.go
964972
runtime/internal/sys.lo.dep: $(extra_go_files_runtime_internal_sys)
965973

974+
extra_go_files_internal_cpu = cpugen.go
975+
internal/cpu.lo.dep: $(extra_go_files_internal_cpu)
976+
966977
extra_go_files_internal_goroot = zstdpkglist.go
967978
internal/goroot.lo.dep: $(extra_go_files_internal_goroot)
968979

libgo/Makefile.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ runtime_internal_sys_lo_check_GOCFLAGS = -fgo-compiling-runtime
10021002
# Also use -fno-inline to get better results from the memory profiler.
10031003
runtime_pprof_check_GOCFLAGS = -static-libgo -fno-inline
10041004
extra_go_files_runtime_internal_sys = version.go
1005+
extra_go_files_internal_cpu = cpugen.go
10051006
extra_go_files_internal_goroot = zstdpkglist.go
10061007
extra_go_files_go_types = gccgosizes.go
10071008
extra_go_files_cmd_internal_objabi = objabi.go
@@ -2759,6 +2760,14 @@ s-version: Makefile
27592760
$(SHELL) $(srcdir)/mvifdiff.sh version.go.tmp version.go
27602761
$(STAMP) $@
27612762

2763+
cpugen.go: s-cpu; @true
2764+
s-cpu: Makefile
2765+
rm -f cpugen.go.tmp
2766+
echo "package cpu" > cpugen.go.tmp
2767+
echo "const CacheLineSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) cachelinesize`" >> cpugen.go.tmp
2768+
$(SHELL) $(srcdir)/mvifdiff.sh cpugen.go.tmp cpugen.go
2769+
$(STAMP) $@
2770+
27622771
objabi.go: s-objabi; @true
27632772
s-objabi: Makefile
27642773
rm -f objabi.go.tmp
@@ -2957,6 +2966,7 @@ $(foreach package,$(GOTOOL_PACKAGES),$(eval $(call PACKAGE_template,$(package)))
29572966
runtime.lo.dep: $(extra_go_files_runtime)
29582967
syscall.lo.dep: $(extra_go_files_syscall)
29592968
runtime/internal/sys.lo.dep: $(extra_go_files_runtime_internal_sys)
2969+
internal/cpu.lo.dep: $(extra_go_files_internal_cpu)
29602970
internal/goroot.lo.dep: $(extra_go_files_internal_goroot)
29612971
go/types.lo.dep: $(extra_go_files_go_types)
29622972
cmd/internal/objabi.lo.dep: $(extra_go_files_cmd_internal_objabi)

libgo/go/internal/bytealg/indexbyte_generic.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-
// +ignore_for_gccgo
5+
// +build ignore_for_gccgo
66
// +build !386,!amd64,!amd64p32,!s390x,!arm,!arm64,!ppc64,!ppc64le,!mips,!mipsle,!mips64,!mips64le,!wasm
77

88
package bytealg

libgo/go/internal/cpu/cpu_arm.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

libgo/go/internal/cpu/cpu_arm64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
package cpu
66

7-
const CacheLineSize = 64
8-
97
// arm64 doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2.
108
// These are initialized by archauxv in runtime/os_linux_arm64.go.
119
// These should not be changed after they are initialized.

libgo/go/internal/cpu/cpu_mips.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

libgo/go/internal/cpu/cpu_mips64.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

libgo/go/internal/cpu/cpu_mips64le.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

libgo/go/internal/cpu/cpu_mipsle.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

libgo/go/internal/cpu/cpu_ppc64x.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
package cpu
88

9-
const CacheLineSize = 128
10-
119
// ppc64x doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2.
1210
// These are initialized by archauxv in runtime/os_linux_ppc64x.go.
1311
// These should not be changed after they are initialized.

libgo/go/internal/cpu/cpu_s390x.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
package cpu
66

7-
const CacheLineSize = 256
8-
97
// bitIsSet reports whether the bit at index is set. The bit index
108
// is in big endian order, so bit index 0 is the leftmost bit.
119
func bitIsSet(bits []uint64, index uint) bool {

libgo/go/internal/cpu/cpu_wasm.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

libgo/go/internal/cpu/cpu_x86.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
package cpu
88

9-
const CacheLineSize = 64
10-
119
// cpuid is implemented in cpu_x86.s.
1210
func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32)
1311

libgo/go/internal/poll/splice_linux.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,15 @@ func newTempPipe() (prfd, pwfd int, sc string, err error) {
162162
defer atomic.StorePointer(&disableSplice, unsafe.Pointer(p))
163163

164164
// F_GETPIPE_SZ was added in 2.6.35, which does not have the -EAGAIN bug.
165-
if _, _, errno := syscall.Syscall(syscall.SYS_FCNTL, uintptr(fds[0]), syscall.F_GETPIPE_SZ, 0); errno != 0 {
165+
if syscall.F_GETPIPE_SZ == 0 {
166166
*p = true
167167
destroyTempPipe(fds[0], fds[1])
168-
return -1, -1, "fcntl", errno
168+
return -1, -1, "fcntl", syscall.EINVAL
169+
}
170+
if _, errno := fcntl(uintptr(fds[0]), syscall.F_GETPIPE_SZ, 0); errno != 0 {
171+
*p = true
172+
destroyTempPipe(fds[0], fds[1])
173+
return -1, -1, "fcntl", syscall.Errno(errno)
169174
}
170175
}
171176

libgo/mksysinfo.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ if ! grep '^const F_DUPFD_CLOEXEC' ${OUT} >/dev/null 2>&1; then
7373
echo "const F_DUPFD_CLOEXEC = 0" >> ${OUT}
7474
fi
7575

76+
# The internal/poll package requires F_GETPIPE_SZ to be defined.
77+
if ! grep '^const F_GETPIPE_SZ' ${OUT} >/dev/null 2>&1; then
78+
echo "const F_GETPIPE_SZ = 0" >> ${OUT}
79+
fi
80+
7681
# AIX 7.1 is a 64 bits value for _FCLOEXEC (referenced by O_CLOEXEC)
7782
# which leads to a constant overflow when using O_CLOEXEC in some
7883
# go code. Issue wan not present in 6.1 (no O_CLOEXEC) and is no

0 commit comments

Comments
 (0)