Skip to content

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

@elagergren-spideroak

Description

@elagergren-spideroak

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions