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
-literals can still cause unused import errors #658
Comments
Can you provide a way for us to reproduce the bug? If you can't, see #595 as well. |
trying to find you a good excert/way to replicate, in the meantime, it looks like the latest update is what caused the issue. Everything works with 0.9.0
Build settings: |
@pagran does this ring a bell? you did make a change to |
In process, I have one hypothesis |
1: package main
import (
"time"
. "time"
)
const Test = ANSIC
func main() {
println(time.ANSIC)
println(Test)
} 2: package main
import (
"time"
t2 "time"
)
const Test = t2.ANSIC
func main() {
println(time.ANSIC)
println(Test)
} |
I can confirm, both tests successfully reproduced the error |
garble's -literals flag and its patching of the runtime may leave unused imports. We used to try to detect those and remove the imports, but that was still buggy with edge cases like dot imports or renamed imports. Moreover, it was potentially incorrect. Completely removing an import from a package means we don't run its init funcs, which could have side effects changing the behavior of a program. As an example, database/sql drivers are registered at init time. Instead, for each import in an obfuscated Go file, add an unnamed declaration which references the imported package. This may not be necessary for all imported packages, as only a minority become unused due to garble, but it's also relatively harmless to do so. Fixes #658.
What version of Garble and Go are you using?
What environment are you running Garble on?
go env
OutputWhat did you do?
env GOOS=windows GOARCH=amd64 garble -tiny -literals -seed=random build -buildmode=pie -trimpath -ldflags="-w -s"
What did you expect to see?
No error
What did you see instead?
:5: imported and not used: "gCMQFPPui" as time
exit status 2
exit status 2
Notably, the compile works without the -literals flag. I wish I could give you better info, I just dont know what else to give. Code base is custom but i can share more if you need it.
The text was updated successfully, but these errors were encountered: