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

Invalid syntax when using garble to build #812

Closed
coremedic opened this issue Nov 20, 2023 · 4 comments · Fixed by #823
Closed

Invalid syntax when using garble to build #812

coremedic opened this issue Nov 20, 2023 · 4 comments · Fixed by #823
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@coremedic
Copy link

What version of Garble and Go are you using?

$ garble version
mvdan.cc/garble v0.10.1

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

$ go version
go version go1.21.4 linux/amd64

What environment are you running Garble on?

go env Output
$ go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/ben/.cache/go-build'
GOENV='/home/ben/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/ben/.go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/ben/.go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.4'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/ben/xShell/badger/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build987332042=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I have some go assembly code that I am trying to obfuscate, getting an "invalid syntax" error when building. When I build with "go build" my build works fine. Here are some relevant parts of the debug output:

# badger/asm
[garble] transforming asm with args: -p badger/asm -trimpath asm=>badger/asm;/tmp/go-build3214285344/b050=> -I $WORK/b050/ -I /usr/local/go/pkg/include -D GOOS_windows -D GOARCH_amd64 -D GOAMD64_v1 -gensymabis -o $WORK/b050/symabis asm/parser_asm_x64_windows.s asm/syscall_asm_x64_windows.s asm/trampoline_asm_x64_windows.s asm/util_asm_x64_windows.s
[garble] shared cache loaded in 860µs from /tmp/garble-shared2640033168/main-cache.gob
[garble] import path "badger/asm" hashed with 26a2a52d7fc9accf418cde02e0135913eac9c1e8ee188f0514e27cf7af84ec56 to "gsPjuhBO"
invalid syntax

[...]

[garble] transformed args for compile in 4.36ms: -o $WORK/b002/_pkg_.a -trimpath /tmp/garble-shared2640033168=>;/home/ben/xShell/badger/cmd/whoami=>badger/cmd/whoami;/tmp/go-build3214285344/b002=> -p vHMvj_Nzn -lang=go1.21 -complete -buildid MmSW_M4DMY_TAYsT-AKF/MmSW_M4DMY_TAYsT-AKF -goversion go1.21.4 -c=4 -nolocalimports -importcfg /tmp/garble-shared2640033168/importcfg3258481374 -pack -dwarf=false /tmp/garble-shared2640033168/vHMvj_Nzn/whoami.go /tmp/garble-shared2640033168/vHMvj_Nzn/whoami_windows.go
exit status 1
@coremedic
Copy link
Author

Resolved my own issue. I had a comment on the same line as my #include

@lu4p
Copy link
Member

lu4p commented Nov 21, 2023

Still if it builds with go and not garble we should fix it. Can you send in your code so we can reproduce?

@lu4p lu4p reopened this Nov 21, 2023
@lu4p lu4p added the needs info Requires extra information to be solved label Nov 21, 2023
@coremedic
Copy link
Author

Sorry for the late response, I cant provide the whole context but here is how you could recreate the issue:

Assembly in go program

#include "textflag.h" // THIS COMMENT BREAKS GARBLE

// func ReadByteAtOffset(start uintptr, offset uint32) uint8
TEXT ·readByteAtOffset(SB), NOSPLIT, $0-24
    MOVQ start+0(FP), AX       // Load start into AX
    MOVL offset+8(FP), CX      // Load offset into CX
    ADDQ CX, AX                // Add offset to start
    MOVB (AX), CL              // Read byte from the address in AX
    MOVB CL, ret+16(FP)        // Store the byte in return value
    RET

Comments on the same line as #include will cause an invalid syntax error when building with garble, but is fine with go build

@lu4p lu4p added bug Something isn't working good first issue Good for newcomers and removed needs info Requires extra information to be solved labels Dec 14, 2023
mvdan added a commit to mvdan/garble-fork that referenced this issue Dec 25, 2023
That is, the assembly line

    #include "foo.h" // bar

would make garble run into an error, as we would try to parse
the #include directive before we stripped comments,
effectively trying to unquote the string

    "foo.h" // bar

rather than just the included filename

    "foo.h"

Add test cases for asm but also cgo, while at it.

Fixes burrowers#812.
@mvdan
Copy link
Member

mvdan commented Dec 25, 2023

Thanks @coremedic - that is enough for me to reproduce.

mvdan added a commit that referenced this issue Dec 25, 2023
That is, the assembly line

    #include "foo.h" // bar

would make garble run into an error, as we would try to parse
the #include directive before we stripped comments,
effectively trying to unquote the string

    "foo.h" // bar

rather than just the included filename

    "foo.h"

Add test cases for asm but also cgo, while at it.

Fixes #812.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Development

Successfully merging a pull request may close this issue.

3 participants