garble icon indicating copy to clipboard operation
garble copied to clipboard

"unknown field in struct literal" errors with cgo-exported struct type

Open sintanial opened this issue 2 years ago • 11 comments

What version of Garble and Go are you using?

$ garble version
v0.4.0

$ go version
go version go1.17.1 darwin/arm64

What environment are you running Garble on?

go env Output
$ go env
go env
GO111MODULE="on"
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/sintanial/Library/Caches/go-build"
GOENV="/Users/sintanial/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/sintanial/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/sintanial/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.17.1"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/sintanial/Projects/proxy-lite-go-sdk/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/yr/5mf2fdkx2zs4wc_k8kvlrb980000gn/T/go-build4061621286=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

garble build -v main.go

What did you expect to see?

build binary file

What did you see instead?

errors

garble build -v main.go                    
command-line-arguments
# command-line-arguments
:23: unknown field 'UniqId' in struct literal of type EOPsYxXp.DeviceInfo
:24: unknown field 'DebugRemoteAddr' in struct literal of type EOPsYxXp.DeviceInfo
:25: unknown field 'ConnType' in struct literal of type EOPsYxXp.DeviceInfo
:27: unknown field 'UserAgent' in struct literal of type EOPsYxXp.DeviceInfo
:30: unknown field 'DeviceType' in struct literal of type EOPsYxXp.DeviceInfo
:32: unknown field 'DeviceModel' in struct literal of type EOPsYxXp.DeviceInfo
:35: unknown field 'OsType' in struct literal of type EOPsYxXp.DeviceInfo
:37: unknown field 'OsVersion' in struct literal of type EOPsYxXp.DeviceInfo
:40: unknown field 'SdkType' in struct literal of type EOPsYxXp.DeviceInfo
:42: unknown field 'SdkBuild' in struct literal of type EOPsYxXp.DeviceInfo
:42: too many errors
exit status 2
exit status 2

sintanial avatar Sep 28 '21 08:09 sintanial

Can you try garble master?

mvdan avatar Sep 28 '21 08:09 mvdan

@mvdan the same errors on version v0.4.1-0.20210923110939-7ede21c981cf

sintanial avatar Sep 28 '21 09:09 sintanial

OK. Can you provide a way for us to reproduce the error? Unfortunately this is not enough for us to investigate what's going on.

mvdan avatar Sep 28 '21 09:09 mvdan

I think problem in export structs and methods !

When i delete //export DeviceInfo from code than garble work fine ! :)

//export DeviceInfo
type DeviceInfo struct {
	UserAgent   string
	UniqId      string
	DeviceType  string
	DeviceModel string
	OsType      string
	OsVersion   string
	SdkType     string
	SdkBuild    float64
	SdkHash     string
	SdkSettings string
	SdkMethod   string
	SdkTag      string
	AppType     string
	AppName     string
	ConnType    string
	NetType     string
	NetGen      string
	ProtoVers   int64

	LoadedAt    int64
	InstalledAt int64
	LocalTime   int64
	UnixTime    int64

	DebugRemoteAddr string
}

sintanial avatar Sep 29 '21 06:09 sintanial

Hmm. Are the error lines in the same package where you define that type? What do the lines look like?

mvdan avatar Sep 29 '21 08:09 mvdan

Previously i report what exactly error looks like )). If you means line number then they are different ....

sintanial avatar Sep 29 '21 10:09 sintanial

image

sintanial avatar Sep 29 '21 10:09 sintanial

I think, i found something. I run command garble -debugdir obfuscator build main.go and then in debug files i see that my struct looks like that:

type DeviceInfo struct {
	QzQoPkUe	string
	Z2RUufd7	string
	MtOFtXKm	string
	ZUBlOcUQ	string
	ZCbJAQ_p	string
	JBvbLDBg	string
	QZ7Wzzv4	string
	D1dZrba1	float64
	CvYqz8bI	string
	GLgkqmDu	string
	Arjq4m5X	string
	VKAtEaWm	string
	ZISMvP4d	string
	DxvpBRfz	string
	TTh6d6_y	string
	Y37OytXl	string
	EiXCyzIm	string
	K7hLfzxj	int64

	Y_OChjaQ	int64
	YKdP9Ytc	int64
	BJLPQeQh	int64
	LW02xcnv	int64

	RwGFcknH	string
}

So as you can see, garble keep name only for struct, but rename all fields inside

sintanial avatar Sep 29 '21 10:09 sintanial

Thanks for the info! I assume you're exporting these types for cgo?

I think this should be enough detail for us to investigate.

mvdan avatar Sep 29 '21 10:09 mvdan

yes, for cgo

sintanial avatar Sep 29 '21 10:09 sintanial

@sintanial out of curiosity, does https://github.com/burrowers/garble/pull/384 fix or change the resulting error for you? We weren't able to review or merge that PR as we were never able to reproduce the problem the author was trying to fix. It was also related to cgo struct fields, so I wonder if it's the same bug.

mvdan avatar Nov 17 '21 22:11 mvdan

I was never able to reproduce or figure out this bug, and it's been 18 months without anyone else bringing it up, so I'm going to close this for the time being since we can't do much else here.

It's entirely possible that the bug was valid and still exists, in which case I'll be more than happy to reopen if someone can provide more details or a way to reproduce the bug.

mvdan avatar Mar 11 '23 18:03 mvdan