start working on Go 1.16 support (#244)

There are three minor bugs breaking Go 1.16 with the current version of
garble, after the import path obfuscation refactor:

1) Stripping the runtime results in an unused import error. This PR
   fixes that.

2) The asm.txt test seems to be broken; something to do with the export
   data not being right for the exported assembly func.

3) The obfuscated build of std fails, since our runtimeRelated table was
   generated for Go 1.15, not 1.16.

This PR fixes the first issue, adds conditional skip lines for 1.16 for
the other two issues, and enables 1.16 on CI.

Note that 1.16 support is not here just yet, because of the other two
issues. As such, no doc changes.

Updates #124.
pull/246/head
Daniel Martí 3 years ago committed by GitHub
parent 180d64236a
commit 89dbdb69a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,7 +10,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.15.x]
go-version: [1.15.x, 1.16.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:

@ -119,7 +119,20 @@ func stripRuntime(filename string, file *ast.File) {
}
}
if filename == "print.go" {
switch filename {
case "runtime1.go":
// On Go 1.16.x, the code above results in runtime1.go having an
// unused import. Mark it as used via "var _ = pkg.Func".
// Note that the file in Go 1.15.x does not import bytealg.
// If this is a recurring problem, we could go for a more
// generic solution like x/tools/imports.
for _, imp := range file.Imports {
if imp.Path.Value == `"internal/bytealg"` {
file.Decls = append(file.Decls, markUsedBytealg)
break
}
}
case "print.go":
file.Decls = append(file.Decls, hidePrintDecl)
return
}
@ -142,6 +155,17 @@ func removeImport(importPath string, specs []ast.Spec) []ast.Spec {
return specs
}
var markUsedBytealg = &ast.GenDecl{
Tok: token.VAR,
Specs: []ast.Spec{&ast.ValueSpec{
Names: []*ast.Ident{{Name: "_"}},
Values: []ast.Expr{&ast.SelectorExpr{
X: &ast.Ident{Name: "bytealg"},
Sel: &ast.Ident{Name: "IndexByteString"},
}},
}},
}
var hidePrintDecl = &ast.FuncDecl{
Name: ast.NewIdent("hidePrint"),
Type: &ast.FuncType{Params: &ast.FieldList{

@ -1,3 +1,5 @@
[go1.16] skip 'TODO(mvdan): fix for Go 1.16'
env GOPRIVATE=test/main
garble build

@ -8,6 +8,8 @@ stderr '^public package "test/main/importer" can''t depend on obfuscated package
[short] stop
[go1.16] skip 'TODO(mvdan): fix for Go 1.16'
# Try garbling all of std, given some std packages.
# No need for a main package here; building the std packages directly works the
# same, and is faster as we don't need to link a binary.

Loading…
Cancel
Save