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: expose padding fields on s390x or hide them on other architectures #18632

Closed
mundaym opened this issue Jan 12, 2017 · 16 comments
Closed

Comments

@mundaym
Copy link
Member

mundaym commented Jan 12, 2017

When the s390x port was upstreamed it was decided that 'to try and stop the bleeding' we would avoid exposing 'internal' fields (usually prefixed with X__) in structs in the syscall package, instead replacing them with blank identifiers. This work then also made its way into x/sys/unix.

Unfortunately every now and again it turns out that someone is using a field we blanked out, for example: #18628 and #17298. This is annoying because while the code in question is probably doing something unpleasant it makes the process of enabling a package on s390x harder than it needs to be.

I would like to propose that we either expose these fields on s390x (only where they exist on other architectures already of course) OR we use blank identifiers for them on other architectures too. Exposing them on s390x is easy, but maybe removing them from the API is more desirable in the long run.

@bradfitz bradfitz added this to the Unreleased milestone Jan 12, 2017
@bradfitz
Copy link
Contributor

Sorry we made you the guinea pig, but I do think it was for the best.

It let us find and clean stuff like pkg/sftp@4d0e916.

I'd like to see if we could remove those fields from all architectures if we can fix all projects depending on them first.

/cc @davecheney @ianlancetaylor @minux

@bradfitz
Copy link
Contributor

Paging Mr. BigQuery @campoy to grep github.

@mundaym
Copy link
Member Author

mundaym commented Jan 12, 2017

It's probably worth mentioning that both these cases involve the syscall package, not x/sys. It may be worth checking for uses of X__ fields from both packages (assuming that we are hoping syscall users will eventually move to x/sys).

@minux
Copy link
Member

minux commented Jan 13, 2017 via email

@mundaym
Copy link
Member Author

mundaym commented Jan 13, 2017

@minux You're right that fsid is a real part of the API, although the way pkg/sftp was encoding the field was probably incorrect for big endian systems. It's also not clear that it is a useful field, but really that's for the package maintainers to decide, not me.

We could rename the X__val field to Val in x/sys as part of this cleanup, or just expose it as X__val on s390x. Depends on the BigQuery result probably. The syscall version is of course locked down.

As for careful review: I think it would be reasonable (there are 28 blanked out fields across 15 structs) to introduce tests for the structs we modify when they are expected to expose specific fields across every platform. Test coverage for x/sys/unix is currently only about 14% (measured on linux/s390x), we should aim to improve that at least a little as part of addressing this issue.

@minux
Copy link
Member

minux commented Jan 13, 2017 via email

@mundaym
Copy link
Member Author

mundaym commented Jan 13, 2017

FWIW there is an abandoned CL to expose X__val on s390x here: https://go-review.googlesource.com/#/c/30130/.

gopherbot pushed a commit that referenced this issue Jan 13, 2017
mkpost.go replaces all variables prefixed with 'X_' with '_' on s390x
because most of them do not need to be exposed. X__val is being used
by a third party library so it turns out we do need to expose it on
s390x (it is already exposed on all other Linux architectures).

Fixes #17298 and updates #18632.

Change-Id: Ic03463229a5f75ca41a4a4b50300da4b4d892d45
Reviewed-on: https://go-review.googlesource.com/30130
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
@minux
Copy link
Member

minux commented Jan 17, 2017 via email

@mundaym
Copy link
Member Author

mundaym commented Jan 17, 2017

Below is the diff that re-adding the padding fields makes to the syscall package. I would say the ones that should maybe be added to syscall (probably not x/sys) for 1.8 are:

IfInfomsg.X__ifi_pad (which would fix #17298)
Sysinfo_t.X_f (probably not, _f is in the man page but I can't think of any need for it and it isn't typed correctly by cgo: it is typed as [0]byte or similar on all 64-bit architectures)

Everything else looks ok to me, but please take a look.

@@ -31,13 +31,13 @@ type Timeval struct {
 
 type Timex struct {
 	Modes     uint32
-	_         [4]byte
+	Pad_cgo_0 [4]byte
 	Offset    int64
 	Freq      int64
 	Maxerror  int64
 	Esterror  int64
 	Status    int32
-	_         [4]byte
+	Pad_cgo_1 [4]byte
 	Constant  int64
 	Precision int64
 	Tolerance int64
@@ -46,14 +46,14 @@ type Timex struct {
 	Ppsfreq   int64
 	Jitter    int64
 	Shift     int32
-	_         [4]byte
+	Pad_cgo_2 [4]byte
 	Stabil    int64
 	Jitcnt    int64
 	Calcnt    int64
 	Errcnt    int64
 	Stbcnt    int64
 	Tai       int32
-	_         [44]byte
+	Pad_cgo_3 [44]byte
 }
 
 type Time_t int64
@@ -103,7 +103,7 @@ type Stat_t struct {
 	Mode               uint32
 	Uid                uint32
 	Gid                uint32
-	_       int32
+	X__glibc_reserved0 int32
 	Rdev               uint64
 	Size               int64
 	Atim               Timespec
@@ -111,7 +111,7 @@ type Stat_t struct {
 	Ctim               Timespec
 	Blksize            int64
 	Blocks             int64
-	_       [3]int64
+	X__glibc_reserved  [3]int64
 }
 
 type Statfs_t struct {
@@ -127,7 +127,7 @@ type Statfs_t struct {
 	Frsize    uint32
 	Flags     uint32
 	Spare     [4]uint32
-	_       [4]byte
+	Pad_cgo_0 [4]byte
 }
 
 type Dirent struct {
@@ -136,7 +136,7 @@ type Dirent struct {
 	Reclen    uint16
 	Type      uint8
 	Name      [256]uint8
-	_      [5]byte
+	Pad_cgo_0 [5]byte
 }
 
 type Fsid struct {
@@ -146,11 +146,11 @@ type Fsid struct {
 type Flock_t struct {
 	Type      int16
 	Whence    int16
-	_      [4]byte
+	Pad_cgo_0 [4]byte
 	Start     int64
 	Len       int64
 	Pid       int32
-	_      [4]byte
+	Pad_cgo_1 [4]byte
 }
 
 type RawSockaddrInet4 struct {
@@ -231,13 +231,13 @@ type IPv6Mreq struct {
 type Msghdr struct {
 	Name       *byte
 	Namelen    uint32
-	_          [4]byte
+	Pad_cgo_0  [4]byte
 	Iov        *Iovec
 	Iovlen     uint64
 	Control    *byte
 	Controllen uint64
 	Flags      int32
-	_          [4]byte
+	Pad_cgo_1  [4]byte
 }
 
 type Cmsghdr struct {
@@ -279,7 +279,7 @@ type TCPInfo struct {
 	Probes         uint8
 	Backoff        uint8
 	Options        uint8
-	_              [2]byte
+	Pad_cgo_0      [2]byte
 	Rto            uint32
 	Ato            uint32
 	Snd_mss        uint32
@@ -450,7 +450,7 @@ type RtAttr struct {
 
 type IfInfomsg struct {
 	Family     uint8
-	_      uint8
+	X__ifi_pad uint8
 	Type       uint16
 	Index      int32
 	Flags      uint32
@@ -498,7 +498,7 @@ type SockFilter struct {
 
 type SockFprog struct {
 	Len       uint16
-	_      [6]byte
+	Pad_cgo_0 [6]byte
 	Filter    *SockFilter
 }
 
@@ -528,21 +528,21 @@ type PtracePsw struct {
 
 type PtraceFpregs struct {
 	Fpc       uint32
-	_    [4]byte
+	Pad_cgo_0 [4]byte
 	Fprs      [16]float64
 }
 
 type PtracePer struct {
 	Control_regs  [0]uint64
-	_             [24]byte
-	_             [8]byte
+	Pad_cgo_0     [24]byte
+	Pad_cgo_1     [8]byte
 	Starting_addr uint64
 	Ending_addr   uint64
 	Perc_atmid    uint16
-	_             [6]byte
+	Pad_cgo_2     [6]byte
 	Address       uint64
 	Access_id     uint8
-	_             [7]byte
+	Pad_cgo_3     [7]byte
 }
 
 type FdSet struct {
@@ -560,12 +560,12 @@ type Sysinfo_t struct {
 	Freeswap  uint64
 	Procs     uint16
 	Pad       uint16
-	_         [4]byte
+	Pad_cgo_0 [4]byte
 	Totalhigh uint64
 	Freehigh  uint64
 	Unit      uint32
-	_         [0]uint8
-	_         [4]byte
+	X_f       [0]uint8
+	Pad_cgo_1 [4]byte
 }
 
 type Utsname struct {
@@ -579,16 +579,16 @@ type Utsname struct {
 
 type Ustat_t struct {
 	Tfree     int32
-	_      [4]byte
+	Pad_cgo_0 [4]byte
 	Tinode    uint64
 	Fname     [6]uint8
 	Fpack     [6]uint8
-	_      [4]byte
+	Pad_cgo_1 [4]byte
 }
 
 type EpollEvent struct {
 	Events  uint32
-	_      int32
+	X_padFd int32
 	Fd      int32
 	Pad     int32
 }
@@ -606,7 +606,7 @@ type Termios struct {
 	Lflag     uint32
 	Line      uint8
 	Cc        [32]uint8
-	_      [3]byte
+	Pad_cgo_0 [3]byte
 	Ispeed    uint32
 	Ospeed    uint32
 }

@gopherbot
Copy link

CL https://golang.org/cl/35262 mentions this issue.

@bradfitz
Copy link
Contributor

@mundaym, can we close this?

@mundaym
Copy link
Member Author

mundaym commented Jan 12, 2018

Yeah I think we can close it if we're happy to maintain the status quo and leave the padding fields in the API exposed on non-s390x platforms. I certainly don't think it is worth adding them wholesale to the s390x API at this point.

@mundaym mundaym closed this as completed Jan 12, 2018
@gopherbot
Copy link

Change https://golang.org/cl/89495 mentions this issue: unix: don't export padding fields on all platforms

gopherbot pushed a commit to golang/sys that referenced this issue Jan 24, 2018
Fixes golang/go#18632.

Change-Id: I9d07937dc93f860b09a99a86fe517b85f4dcd1b2
Reviewed-on: https://go-review.googlesource.com/89495
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@gopherbot
Copy link

Change https://golang.org/cl/100556 mentions this issue: unix: don't export padding fields on Solaris

@gopherbot
Copy link

Change https://golang.org/cl/100595 mentions this issue: unix: don't export padding fields on DragonflyBSD

gopherbot pushed a commit to golang/sys that referenced this issue Mar 14, 2018
Re-run ./mkall.sh to avoid exporting Pad_cgo* fields on solaris/amd64.
Akin to CL 89495.

Updates golang/go#18632

Change-Id: Ib80bf6376d0b7c0a5efd0f5d4a0f27e8e37d8abe
Reviewed-on: https://go-review.googlesource.com/100556
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
gopherbot pushed a commit to golang/sys that referenced this issue Mar 14, 2018
Re-run ./mkall.sh to avoid exporting Pad_cgo* fields on dragonfly/amd64.
This also adds some additional RLIMIT_* constants.

Updates golang/go#18632

Change-Id: I7969d8ab12c07befd7b1ff0d1dbc67f6622c39b1
Reviewed-on: https://go-review.googlesource.com/100595
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@gopherbot
Copy link

Change https://golang.org/cl/102075 mentions this issue: unix: don't export padding fields on Darwin

gopherbot pushed a commit to golang/sys that referenced this issue Mar 22, 2018
Re-run ./mkall.sh to avoid exporting Pad_cgo* fields on Darwin.

Updates golang/go#18632

Change-Id: Id9d264293d0b1f1c5581aff289c6e826d63e71ef
Reviewed-on: https://go-review.googlesource.com/102075
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
@golang golang locked and limited conversation to collaborators Mar 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants