diff --git a/main.go b/main.go index 4383d42..64b1384 100644 --- a/main.go +++ b/main.go @@ -718,13 +718,6 @@ func transformCompile(args []string) ([]string, error) { return nil, err } - // We can't obfuscate literals in the runtime and its dependencies, - // because obfuscated literals sometimes escape to heap, - // and that's not allowed in the runtime itself. - if runtimeAndDeps[curPkg.ImportPath] { - flagLiterals = false - } - // Literal obfuscation uses math/rand, so seed it deterministically. randSeed := flagSeed.bytes if len(randSeed) == 0 { @@ -1361,6 +1354,10 @@ func (tf *transformer) recordType(t types.Type) { func (tf *transformer) transformGo(file *ast.File) *ast.File { // Only obfuscate the literals here if the flag is on // and if the package in question is to be obfuscated. + // + // We can't obfuscate literals in the runtime and its dependencies, + // because obfuscated literals sometimes escape to heap, + // and that's not allowed in the runtime itself. if flagLiterals && curPkg.ToObfuscate { file = literals.Obfuscate(file, tf.info, fset) } diff --git a/testdata/scripts/literals.txt b/testdata/scripts/literals.txt index 09a578d..4be97f4 100644 --- a/testdata/scripts/literals.txt +++ b/testdata/scripts/literals.txt @@ -1,4 +1,4 @@ -env GOGARBLE=test/main +env GOGARBLE=* garble -literals build exec ./main$exe @@ -61,7 +61,11 @@ go 1.17 -- main.go -- package main -import "test/main/imported" +import ( + _ "runtime/debug" + + "test/main/imported" +) type structTest struct { field string