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

buildmode plugin issue of package not found #19

Closed
cytown opened this issue May 19, 2020 · 24 comments
Closed

buildmode plugin issue of package not found #19

cytown opened this issue May 19, 2020 · 24 comments

Comments

@cytown
Copy link

cytown commented May 19, 2020

The files as follows:

go.mod

module test.com/plugin

go 1.14

dll/dll.go

package dll

import (
	"fmt"
)

type DllInfo struct {
	Name string `json:"name"`
	Id   int32  `json:"id"`
}

func TestDll(name string, id int32) {
	fmt.Printf("check : %v\n", &DllInfo{name, id})
}

main.go

package main

import (
	"test.com/plugin/dll"
)

var TestDll = dll.TestDll

func main() {
	TestDll("asdasfas %v", 111)
}

Then run command:

garble build -buildmode=plugin -o dll.so main.go

Get the errors:

# command-line-arguments
main.go:7:15: undefined: dll.TestDll
exit status 2
exit status 2

It really weird... Seems can not find the package.

@cytown
Copy link
Author

cytown commented May 19, 2020

@mvdan Another strange issue was:
When I run command:

go build -buildmode=plugin -o dll.so main.go

# command-line-arguments
main.go:7:15: undefined: dll.TestDll

it will run garble as well, just like I run garble directly, but it's way faster...

Yes it didn't have:

exit status 2
exit status 2

But in another clean machine without garble installed, it looks fine without any issue.

@mvdan
Copy link
Member

mvdan commented May 19, 2020

I cannot reproduce this at all:

$ go version
go version go1.14.3 linux/amd64
$ cat go.mod
module test.com/plugin

go 1.14
$ cat main.go 
package main

import (
	"test.com/plugin/dll"
)

var TestDll = dll.TestDll

func main() {
	TestDll("asdasfas %v", 111)
}
$ cat dll/dll.go 
package dll

import (
	"fmt"
)

type DllInfo struct {
	Name string `json:"name"`
	Id   int32  `json:"id"`
}

func TestDll(name string, id int32) {
	fmt.Printf("check : %v\n", &DllInfo{name, id})
}
$ garble build -buildmode=plugin -o dll.so main.go

@cytown
Copy link
Author

cytown commented May 19, 2020

Confirm again in LInux. Before was in MacOS.

p.s. garble version is retrieved from https://github.com/mvdan/garble and build with "go build .".

$ go version
go version go1.14.2 linux/amd64
$ garble build -buildmode=plugin -o dll.so main.go
# command-line-arguments
./main.go:8:15: undefined: dll.TestDll
exit status 2
exit status 2

@mvdan
Copy link
Member

mvdan commented May 19, 2020

Maybe try giving me a script I can run inside a golang Docker image. Otherwise I'll have to spend hours trying to guess what's causing the failure for you.

@cytown
Copy link
Author

cytown commented May 19, 2020

@mvdan OK, I'll try.

@cytown
Copy link
Author

cytown commented May 19, 2020

Please unzip the attached file and then run:

docker run -v $PWD/gotest:/tmp/go --name golang -it golang bash
# cd /tmp/go
# cd garble/
# go build .
# cd ../a
# ../garble/garble build -buildmode=plugin -o dll.so main.go

gotest.zip

@cytown
Copy link
Author

cytown commented May 21, 2020

@mvdan how about the progress?

@mvdan
Copy link
Member

mvdan commented May 21, 2020

This is an open source side project that I do for free on my spare time. If you want me to work faster, consider becoming a sponsor.

@cytown
Copy link
Author

cytown commented May 21, 2020

Can you reproduce the issue now? I just wonder whether my info is enough.

@mvdan
Copy link
Member

mvdan commented May 21, 2020

I haven't tried yet.

@cytown
Copy link
Author

cytown commented May 21, 2020

Got it, if need any further informations, please let me know.

@mvdan
Copy link
Member

mvdan commented May 21, 2020

OK, I was able to repro like so:

docker run -it golang:1.14.3 <<-SCRIPT

        set -ex

        apt update && apt install unzip

        wget https://github.com/mvdan/garble/files/4649834/gotest.zip
        unzip gotest.zip

        GO111MODULE=on go get mvdan.cc/garble@v0.0.0-20200518174757-3c97725ccc06

        cd gotest/a
        garble build -buildmode=plugin -o dll.so main.go

SCRIPT

This seems to be an error on your part; when you build a package, you should specify a package path, not a file. The first command works, but yours does not:

root@14603a165251:/go/gotest/a# garble build -buildmode=plugin -o dll.so
root@14603a165251:/go/gotest/a# garble build -buildmode=plugin -o dll.so main.go
# command-line-arguments
./main.go:8:15: undefined: dll.TestDll
exit status 2
exit status 2

@mvdan
Copy link
Member

mvdan commented May 21, 2020

It's not clear why garble build -buildmode=plugin -o dll.so main.go works on my machine outside Docker. In any case, you should not rely on building lone Go files to work when they import other packages from modules, or when other Go files are involved in the build.

@mvdan
Copy link
Member

mvdan commented May 21, 2020

OK, I can finally reproduce this without Docker. I still think you should be building the entire package instead of a single file, but there's still a weird bug at play here that we should fix.

@mvdan
Copy link
Member

mvdan commented May 21, 2020

Also, the reason I wasn't reproducing this on my laptop is because I had already set GOPRIVATE for a different project, and wasn't actually obfuscating anything. My bad. I've filed #20 for that.

@cytown
Copy link
Author

cytown commented May 21, 2020

Hmm, yes, it's fine to build without specified main.go. But if there are more than one main.go in this package sub-directory the build should be wrong or mixed, so in common we should name the main entry here. Also the pure go will support this kind of build without any problem.

Anyway, it works in your way, thank you.

@cytown
Copy link
Author

cytown commented May 21, 2020

Looks garble won't obfuscate imported 3rd party packages, or just some misconfiguration?

@mvdan
Copy link
Member

mvdan commented May 21, 2020

@cytown
Copy link
Author

cytown commented May 21, 2020

In my test, garble don't obfuscate the sub dir name of package, in above case, "dll" would remain the original name, but the func name and struct name have been obfuscated. Should the sub dir name be obfuscated as well?

@mvdan
Copy link
Member

mvdan commented May 21, 2020

@cytown
Copy link
Author

cytown commented May 21, 2020

Looks garble won't obfuscate imported 3rd party packages, or just some misconfiguration?

Thanks, this question explained.

In my test, garble don't obfuscate the sub dir name of package, in above case, "dll" would remain the original name, but the func name and struct name have been obfuscated. Should the sub dir name be obfuscated as well?

But I don't understand why the sub-dir of GOPRIVATE package remain same?

@mvdan
Copy link
Member

mvdan commented May 21, 2020

That's https://github.com/mvdan/garble/issues/13. Package paths are not obfuscated yet.

@cytown
Copy link
Author

cytown commented May 21, 2020

That's #13. Package paths are not obfuscated yet.

So it's a pending implementation, right?

@mvdan
Copy link
Member

mvdan commented May 21, 2020

Yes, that's why the issue is still open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants