burrowers / garble

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

garble v0.9.3 w/ go1.20 produces panic builds #676

Closed theaog closed 1 year ago

theaog commented 1 year ago

What version of Garble and Go are you using?

$ garble version
mvdan.cc/garble v0.9.3-0.20230207225213-95ef0357da3b

Build settings:
      -buildmode exe
       -compiler gc
     CGO_ENABLED 1
          GOARCH amd64
            GOOS darwin
         GOAMD64 v1

$ go version
go version go1.20 darwin/amd64

What environment are you running Garble on?

MacOS 12.2.1 (21D62)

What did you do?

GOOS=linux GOARCH=amd64 garble build

What did you expect to see?

working program

What did you see instead?

panic: reflect.Value has no flag field

goroutine 1 [running]:
InZWXriRs.glob..func1()
    rHWtOeBBZo7_.go:1 +0x165
InZWXriRs.init()
    rHWtOeBBZo7_.go:4 +0x1d
mvdan commented 1 year ago

Thanks for the report. This is the cause:

https://github.com/davecgh/go-spew/blob/d8f796af33cc11cb798c1aaeb27a4ebc5099927d/spew/bypass.go#L72-L76

Welp, I guess we can't obfuscate types inside the reflect package after all. I'll have to revert that bit. FYI @lu4p

theaog commented 1 year ago

you're welcome, any workaround comes to mind?

mvdan commented 1 year ago

Revert to a slightly older garble release. We'll have a fix soon, but not right away.

theaog commented 1 year ago

same result w/ v0.8.0, how old should I go?

theaog commented 1 year ago

go install mvdan.cc/garble@v0.7.2 will panic w/o completing the build

# runtime
panic: runtime listed a std package we can't find: arena

goroutine 1 [running]:
main.listPackage({0xc0002e035d, 0x5})
        /usr/local/root/go/pkg/mod/mvdan.cc/garble@v0.7.2/shared.go:389 +0x6f9
main.(*transformer).handleDirectives(0x12e13e6?, {0xc0002a5400, 0x69, 0x25fe?})
        /usr/local/root/go/pkg/mod/mvdan.cc/garble@v0.7.2/main.go:952 +0x305
main.transformCompile({0xc0000b4030?, 0x1d3b?, 0xc000111e58?})
        /usr/local/root/go/pkg/mod/mvdan.cc/garble@v0.7.2/main.go:839 +0x745
main.mainErr({0xc0000b4010, 0xa2, 0xa7})
        /usr/local/root/go/pkg/mod/mvdan.cc/garble@v0.7.2/main.go:424 +0x7cd
main.main1()
        /usr/local/root/go/pkg/mod/mvdan.cc/garble@v0.7.2/main.go:228 +0x16e
main.main()
        /usr/local/root/go/pkg/mod/mvdan.cc/garble@v0.7.2/main.go:135 +0x19
exit status 1
theaog commented 1 year ago

shall I downgrade to go 1.19?

mvdan commented 1 year ago

The regression is https://github.com/burrowers/garble/commit/2ee9cf7a43b50d4ed97112e9c6cd3ae2a22f6ef8 I'm pretty sure, so v0.9.1 should work with either Go 1.19 or 1.20, I think.

theaog commented 1 year ago

weird as I still get the same result w/ mvdan.cc/garble v0.9.1 even w/ v0.8.0

panic: reflect.Value has no flag field

goroutine 1 [running]:
sIsD_BqV1_w.glob..func1()
    DoOA8ljZ.go:1 +0x165
sIsD_BqV1_w.init()
    DoOA8ljZ.go:4 +0x1d
theaog commented 1 year ago

if I use go1.19.4 w/ garble v0.9.1, then I get a different issue

# github.com/golang/protobuf/proto
BnrvHi1G.go:2: unknown field 'YU06vztEX1' in struct literal of type DBY547b.CKFyRc9
exit status 2
exit status 2
mvdan commented 1 year ago

Then perhaps we've been broken with that package for a while. I'll try to have a fix by tomorrow.

theaog commented 1 year ago

to get a workable build I had to revert to go19 w/ garble 0.7

mvdan commented 1 year ago

The fix is in master, if you want to give that a try.

theaog commented 1 year ago

thank you @mvdan

theaog commented 1 year ago

works like a charm!

theaog commented 1 year ago

the issue is back :/

./program
panic: reflect.Value read-only flag has changed semantics

goroutine 1 [running]:
xdXmgWO.init.0()
    mgFK8DGAHh.go:1 +0x5b5

go version go1.20.5 linux/amd64 mvdan.cc/garble v0.10.0

Build settings: -buildmode exe -compiler gc CGO_ENABLED 1 GOARCH amd64 GOOS linux GOAMD64 v1

@mvdan what do you suggest to try?

compiled using:

GOOS=linux GOARCH=amd64 CGO_ENABLED=0 garble build -trimpath
lu4p commented 1 year ago

@theaog can you try to isolate which commit reintroduced the issue?

go install mvdan.cc/garble@commit_hash

mvdan commented 1 year ago

Bisected to 0f2b59d79404f5be6725c24170fa2fad94e2b7fb, so it looks like it's my fault :)

theaog commented 1 year ago

going a commit before 0f2b won't compile.

go install mvdan.cc/garble@7d1bd13778a9ceafe17bd13615beee9d769094af
mvdan.cc/garble v0.9.4-0.20230530172756-7d1bd13778a9

build...
# os
//go:linkname refers to net.newUnixFile - add `import _ "net"` for garble to find the package
# program/program
bfTscLd.(*vhcbOL).uTiJS3pqYbRb: relocation target bfTscLd.fQcsIjgz8oFM not defined
exit status 2
exit status 1
theaog commented 1 year ago

hi guys, could I get any help on this please? which go version / garble version could I use to have a working bin?

lu4p commented 1 year ago

I guess reverting to the commit where it got fixed should work or some commit after that.

We will fix this, but we're doing this in our free time so it might get fixed fast or take a while. Consider sponsoring us if you need a fix urgently.

lu4p commented 1 year ago

Closing in favor of #765