Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

"duplicate symbol" error when running easyjson on a file in the main package (go1.12) #236

Open
roberth-k opened this issue Jun 21, 2019 · 5 comments

Comments

@roberth-k
Copy link

When running easyjson -all ./path/to/file.go on a file that's in package main, the program fails with the following output:

# command-line-arguments
2019/06/21 22:54:25 duplicate symbol runtime/debug.modinfo (types 30 and 30) in main and $WORK/b002/_pkg_.a(_go_.o)
Bootstrap failed: exit status 2

The ..._easyjson.go file will be present, but generated only up until the type EasyJSON_exporter_ ... declaration. The error disappears if the package is renamed to something other than main.

The issue can be reproduced with a minimal file such as:

package main

type MyStruct struct {
	MyField string `json:"my_field"`
}

I couldn't find caveats in the README about package main limitations, so I assume it's a bug. Running an identical test with go1.11.11 (no error) and go1.12.0 (error) suggests that this is specific to go1.12+. Travis only tests with 1.11, which is why this would not be showing up in CI.

Environment: go1.12.6 on macOS 10.14.5
easyjson version: da37f6c

@rvasily
Copy link
Contributor

rvasily commented Jun 26, 2019

easyjson parser and codegen based on reflection, so it wont works on package main files, because they cant be imported by parser.

I added this note to readme.

Fixing this requires to full rewrite parser from reflection to AST traversal, and this not in plan. See #1 for details

@roberth-k
Copy link
Author

Thanks for the clarification. I couldn't find anything in the go1.12.0 changelog to explain why it would stop working only at that point, but it could have been undefined behaviour to begin with.

It's a wild shot and likely not feasible, but I'm wondering if the package main could be re-written with a randomly generated package name (e.g. into a temporary directory) just for the duration of reflection.

@GoWebProd
Copy link
Collaborator

I think we can copy to separate dir with pkg renaming, this is very good idea. PR welcomed.

adrianlzt added a commit to datadope-io/skydive-plugins that referenced this issue May 19, 2020
easyjson does not work with main packages. Workaround changing the
package name as suggested in mailru/easyjson#236

Some code has been moved from skydive to graffity: common.Getter

Clean and update gomod:
k8s deps should be added with replace, kubernetes/kubernetes#79384
Same problem with networkservicemesh
viper is not being used
add skydive as dep, not local replace

Once compiled it fails to run with skydive because problems with the Go
plugin framework.
The error is: plugin was built with a different version of package golang.org/x/sys/unix

golang/go#20481
golang/go#27751
adrianlzt added a commit to datadope-io/skydive-plugins that referenced this issue May 19, 2020
easyjson does not work with main packages. Workaround changing the
package name as suggested in mailru/easyjson#236

Some code has been moved from skydive to graffity: common.Getter

Clean and update gomod:
k8s deps should be added with replace, kubernetes/kubernetes#79384
Same problem with networkservicemesh
viper is not being used
add skydive as dep, not local replace

Once compiled it fails to run with skydive because problems with the Go
plugin framework.
The error is: plugin was built with a different version of package golang.org/x/sys/unix

golang/go#20481
golang/go#27751

Tested adding to the skydive.yml config file:
plugin:
  plugins_dir: /home/adrian/go/src/github.com/skydive-project/skydive-plugins/memory
  topology:
    probes: memory
@stokito
Copy link

stokito commented Sep 23, 2021

It would be nice to add into error message that main package is not supported.

@rustyx
Copy link

rustyx commented Dec 19, 2021

This is ridiculous; easyjson can't handle main package...

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

5 participants