Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/sys/unix: offs2lohi is incorrect, causing Pwritev to fail on linux/arm #57291

Closed
elagergren-spideroak opened this issue Dec 13, 2022 · 2 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@elagergren-spideroak
Copy link

elagergren-spideroak commented Dec 13, 2022

What version of Go are you using (go version)?

$ go version
go version go1.19.3 linux/arm

But for sys/unix:

golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

Does this issue reproduce with the latest release?

n/a

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="arm"
GOBIN=""
GOCACHE="/home/pi/.cache/go-build"
GOENV="/home/pi/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/pi/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/pi/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_arm"
GOVCS=""
GOVERSION="go1.19.3"
GCCGO="gccgo"
GOARM="6"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -marm -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1026506967=/tmp/go-build -gno-record-gcc-switches"

What did you do?

https://go.dev/play/p/Q97xfv0JM07

What did you expect to see?

writing 1 bytes at 10
before pwritev(2): 0
after pwritev(2): 11

writing 1 bytes at 15
before pwritev(2): 0
after pwritev(2): 16

writing 1 bytes at 16
before pwritev(2): 0
after pwritev(2): 17

writing 1 bytes at 20
before pwritev(2): 0
after pwritev(2): 21

writing 1 bytes at 30
before pwritev(2): 0
after pwritev(2): 31

writing 1 bytes at 40
before pwritev(2): 0
after pwritev(2): 41

What did you see instead?


writing 1 bytes at 10
before pwritev(2): 0
after pwritev(2): 11

writing 1 bytes at 15
before pwritev(2): 0
after pwritev(2): 16

writing 1 bytes at 16
before pwritev(2): 0
after pwritev(2): 4294967313

writing 1 bytes at 20
before pwritev(2): 0
after pwritev(2): 4294967317

writing 1 bytes at 30
before pwritev(2): 0
after pwritev(2): 4294967327

writing 1 bytes at 40
before pwritev(2): 0
after pwritev(2): 8589934633

The problem is that offs2lohi shifts by unix.SizeofLong which is the size in bytes, not bits. So it's shifting by 4 or 8, not 32 or 64. But we actually don't need to use SizeofLong because the man pages state that we simply split the 64-bit offset into its 32-bit halves.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Dec 13, 2022
@gopherbot gopherbot added this to the Unreleased milestone Dec 13, 2022
@elagergren-spideroak
Copy link
Author

elagergren-spideroak commented Dec 13, 2022

This means that Preadv, Preadv2, Pwritev, and Pwritev2 are all broken since they all use offs2lohi.

@gopherbot
Copy link

Change https://go.dev/cl/457315 mentions this issue: unix: offs2lohi should shift by bits, not bytes

@thanm thanm added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 14, 2022
@golang golang locked and limited conversation to collaborators Dec 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants