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

Missing struct fields when using CGO on macOS #35640

Closed
t0rr3sp3dr0 opened this issue Nov 16, 2019 · 1 comment · May be fixed by zephyr-im/krb5-go#5

Comments

@t0rr3sp3dr0
Copy link

@t0rr3sp3dr0 t0rr3sp3dr0 commented Nov 16, 2019

When importing MIT Kerberos krb5.h on macOS some struct fields are not defined, while on Linux the same header causes the structs to have these fields as expected. This behavior can be replicated by trying to use github.com/zephyr-im/krb5-go library on macOS Catalina 10.15 (19A603).

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

$ go version
go version go1.13.4 darwin/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="/Users/pedro/Library/Caches/go-build"
GOENV="/Users/pedro/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/pedro/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13.4/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13.4/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/h8/24ggm1b922xdhz91lg7krpqh0000gn/T/go-build346701707=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

go test github.com/zephyr-im/krb5-go

What did you expect to see?

# github.com/zephyr-im/krb5-go
../go/src/github.com/zephyr-im/krb5-go/krb5.go:241:58: princ.data undefined (type _Ctype_krb5_principal has no field or method data)
../go/src/github.com/zephyr-im/krb5-go/krb5.go:248:33: princ.realm undefined (type _Ctype_krb5_principal has no field or method realm)
../go/src/github.com/zephyr-im/krb5-go/krb5.go:269:3: unknown field 'realm' in struct literal of type _Ctype_struct_krb5_principal_data
../go/src/github.com/zephyr-im/krb5-go/krb5.go:270:3: unknown field 'data' in struct literal of type _Ctype_struct_krb5_principal_data
../go/src/github.com/zephyr-im/krb5-go/krb5.go:276:17: p.realm undefined (type *_Ctype_struct_krb5_principal_data has no field or method realm)
../go/src/github.com/zephyr-im/krb5-go/krb5.go:277:54: p.data undefined (type *_Ctype_struct_krb5_principal_data has no field or method data)
../go/src/github.com/zephyr-im/krb5-go/krb5.go:332:43: cksum.contents undefined (type *_Ctype_struct__krb5_checksum has no field or method contents)
../go/src/github.com/zephyr-im/krb5-go/krb5.go:339:3: unknown field 'contents' in struct literal of type _Ctype_struct__krb5_checksum
../go/src/github.com/zephyr-im/krb5-go/krb5.go:352:39: k.contents undefined (type *_Ctype_struct__krb5_keyblock has no field or method contents)
../go/src/github.com/zephyr-im/krb5-go/krb5.go:359:3: unknown field 'contents' in struct literal of type _Ctype_struct__krb5_keyblock
../go/src/github.com/zephyr-im/krb5-go/krb5.go:359:3: too many errors
FAIL	github.com/zephyr-im/krb5-go [build failed]
FAIL

What did you see instead?

ok  	github.com/zephyr-im/krb5-go	0.009s
@t0rr3sp3dr0

This comment has been minimized.

Copy link
Author

@t0rr3sp3dr0 t0rr3sp3dr0 commented Nov 16, 2019

The problem actually was that the structs were packed on macOS.

#if defined(TARGET_OS_MAC) && TARGET_OS_MAC
#    pragma pack(push,2)
#endif

…

#if defined(TARGET_OS_MAC) && TARGET_OS_MAC
#    pragma pack(pop)
#endif

https://github.com/golang/go/wiki/cgo#struct-alignment-issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.