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

cmd/cgo: Invalid code generation when using go 1.15 #40126

Closed
abdelrahman-t opened this issue Jul 9, 2020 · 1 comment
Closed

cmd/cgo: Invalid code generation when using go 1.15 #40126

abdelrahman-t opened this issue Jul 9, 2020 · 1 comment

Comments

@abdelrahman-t
Copy link

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

$ go version > go version go1.15beta1 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env >

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user/.cache/go-build"
GOENV="/home/user/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/user/golib/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/user/golib:/home/user/Desktop/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-build080754714=/tmp/go-build -gno-record-gcc-switches"

What did you do?

// tuntap_c.go
// Author: @danderson https://code.google.com/archive/p/tuntap/
package tuntap

/*
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <linux/if.h>
#include <linux/if_tun.h>

#define IFREQ_SIZE sizeof(struct ifreq)
*/
import "C"

const (
	flagTruncated = C.TUN_PKT_STRIP

	iffTun      = C.IFF_TUN
	iffTap      = C.IFF_TAP
	iffnopi     = C.IFF_NO_PI
	iffOneQueue = C.IFF_ONE_QUEUE
)

type ifReq struct {
	Name  [C.IFNAMSIZ]byte
	Flags uint16
	pad   [C.IFREQ_SIZE - C.IFNAMSIZ - 2]byte
}

What did you expect to see?

// tuntap.go
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs=true src/tuntap_c.go
// ...
type ifReq struct {
	Name  [0x10]byte
	Flags uint16
	pad   [0x28 - 0x10 - 2]byte
}

This works as expected when using go 1.14

What did you see instead?

// tuntap.go
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs=true src/tuntap_c.go
// ...
type ifReq struct {
	Name  [0x10]byte
	Flags uint16
	pad   [uint64 - 0x10 - 2]byte // compiler: uint64 (type) is not an expression
}
@ianlancetaylor
Copy link
Contributor

Thanks for the bug report. This has already been fixed on tip. I didn't test it, but I think it was fixed by the fix to #39534.

@golang golang locked and limited conversation to collaborators Jul 9, 2021
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

3 participants