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: missing Msghdr.SetIovlen #34164

Closed
antong opened this issue Sep 7, 2019 · 3 comments
Closed

x/sys/unix: missing Msghdr.SetIovlen #34164

antong opened this issue Sep 7, 2019 · 3 comments

Comments

@antong
Copy link
Contributor

antong commented Sep 7, 2019

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

$ go version
go version go1.13 linux/amd64

Does this issue reproduce with the latest release?

At the time of writing, yes, it reproduces with 1.13, which is the latest release.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build361474088=/tmp/go-build -gno-record-gcc-switches"

Issue

x/sys/unix and syscall have a Msghdr structure that looks like the following on 64-bit GOOS=linux, e.g., GOARCH=amd64:

type Msghdr struct {
        Name       *byte
        Namelen    uint32
        Pad_cgo_0  [4]byte
        Iov        *Iovec
        Iovlen     uint64
        Control    *byte
        Controllen uint64
        Flags      int32
        Pad_cgo_1  [4]byte
}

On 32-bit GOOS=linux like GOARCH=386 it looks like:

type Msghdr struct {
        Name       *byte
        Namelen    uint32
        Iov        *Iovec
        Iovlen     uint32
        Control    *byte
        Controllen uint32
        Flags      int32
}

The Iovlen and Controllen are of type uint64 on 64-bit GOOS=linux and of type uint32 on 32-bit GOOS=linux.

There is a method for setting the Controllen member given an int. Here is the GOARCH=386 version that converts the int length to uint32. There are corresponding versions for 64-bit Linuxes that convert to uint64.

func (msghdr *Msghdr) SetControllen(length int) {
	msghdr.Controllen = uint32(length)
}

However, there is no corresponding method for setting the Iovlen member. In particular, there is no SetIovlen (GOARCH=386):

func (msghdr *Msghdr) SetIovlen(length int) {
	msghdr.Iovlen = uint32(length)
}

This is an inconvenience, as it is difficult to write generic code that fills this structure on any Linux, 32-bit and 64-bit. For the sake of consistency and convenience, I'd expect there to be a setter for the Iovlen member as well.

The missing setter forces to use build tags like the following: internal/socket/msghdr_linux_64bit.go#L5 and maintain lists of which GOARCH are 32-bit and which are 64-bit.

@andig
Copy link
Contributor

andig commented Sep 8, 2019

I've just noticed that the net msghdr struct seems to be not the one from sys (see golang/net#52). In fact, sys has only recently been added as a dependency to net at all. So- the PR is there- but I'm really unsure what good it does.

@gopherbot
Copy link

Change https://golang.org/cl/194077 mentions this issue: unix: add Msghdr.SetIovlen

@gopherbot
Copy link

Change https://golang.org/cl/194099 mentions this issue: unix: add Msghdr.SetIovlen for solaris/amd64

gopherbot pushed a commit to golang/sys that referenced this issue Sep 10, 2019
Follow-up for CL 194077

Updates golang/go#34164

Change-Id: I4bf670dc3e13c483e9087dc3f04973278a09b2f4
Reviewed-on: https://go-review.googlesource.com/c/sys/+/194099
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@golang golang locked and limited conversation to collaborators Sep 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants