burrowers / garble

Obfuscate Go builds
BSD 3-Clause "New" or "Revised" License
3.73k stars 239 forks source link

CGO-related structs are not obfuscated while their usage is obfuscated #857

Open chkp-orad opened 1 month ago

chkp-orad commented 1 month ago

What version of Garble and Go are you using?

$ garble version
mvdan.cc/garble v0.12.1

Build settings:
      -buildmode exe
       -compiler gc
  DefaultGODEBUG httplaxcontentlength=1,httpmuxgo121=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1
     CGO_ENABLED 1
          GOARCH amd64
            GOOS windows
         GOAMD64 v1

$ go version
go version go1.22.0 windows/amd64

What environment are you running Garble on?

go env Output
$ go env
set GO111MODULE=on
set GOARCH=amd64  
set GOBIN=                                      
set GOCACHE=C:\Users\orad\AppData\Local\go-build
set GOENV=C:\Users\orad\AppData\Roaming\go\env  
set GOEXE=.exe                                  
set GOEXPERIMENT=                               
set GOFLAGS=                                    
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\orad\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\orad\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:/Program Files/Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.22.0
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\orad\development\my-project\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\orad\AppData\Local\Temp\go-build127147288=/tmp/go-b
uild -gno-record-gcc-switches

What did you do?

I try to run garble on a project I'm working on in Go. This project also uses CGO to call some C libraries I need for my project. I have some struct that is being created from a custom type in C which is imported in my project. so, In another Go package I create the Go-struct that incorporates the CGO logic, however, it looks like garble is obfuscating calls to this struct fields while not obfuscating the fields in the file that defines the struct causing the build to fail (same as described here: https://github.com/burrowers/garble/issues/843). This raises the following questions:

  1. What could be the root of this? Are there any features garble doesn't support I should be aware of? (whether it's in general or specifically related to CGO)
  2. Can it be related to using CGO in the project? because I copied the problematic files to a new project with some "hello world" project in CGO (that was importing the problematic struct), and didn't see any issue.

What did you expect to see?

I expected to build successfully my project with garble

What did you see instead?

garble is obfuscating calls to my struct (which contains logic in CGO) while not obfuscating the fields in the file that defines the struct itself, causing the build to fail. same as observed in https://github.com/burrowers/garble/issues/843, the only difference is that I didn't use the problematic go module they used in their ticket or any other 3rd party module.