all: drop support for Go 1.17

Now that we've released v0.6.0, that will be the last feature release to
feature support for Go 1.17. The upcoming v0.7.0 will be Go 1.18+.

Code-wise, the cleanup here isn't super noticeable,
but it will be easier to work on features like VCS-aware version
information and generics support without worrying about Go 1.17.
Plus, now CI is back to being much faster.

Note how "go 1.18" in go.mod makes "go mod tidy" more aggressive.
pull/514/head
lu4p 2 years ago
parent d555639657
commit 1a0b028db7

@ -22,7 +22,7 @@ jobs:
test: test:
strategy: strategy:
matrix: matrix:
go-version: [1.17.x, 1.18.x] go-version: [1.18.x]
os: [ubuntu-latest, macos-latest, windows-latest] os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
@ -44,8 +44,8 @@ jobs:
run: diff <(echo -n) <(gofmt -d .) run: diff <(echo -n) <(gofmt -d .)
- if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.18.x' - if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.18.x'
run: go vet ./... run: go vet ./...
# TODO: bump to Go 1.18 once staticcheck supports it # TODO: reenable once staticcheck supports Go 1.18
- if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.17.x' - if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.18.x' && false
uses: dominikh/staticcheck-action@v1 uses: dominikh/staticcheck-action@v1
with: with:
version: "2021.1.2" version: "2021.1.2"

@ -2,7 +2,7 @@
go install mvdan.cc/garble@latest go install mvdan.cc/garble@latest
Obfuscate Go code by wrapping the Go toolchain. Requires Go 1.17 or later. Obfuscate Go code by wrapping the Go toolchain. Requires Go 1.18 or later.
garble build [build flags] [packages] garble build [build flags] [packages]

@ -1,6 +1,6 @@
module mvdan.cc/garble module mvdan.cc/garble
go 1.17 go 1.18
require ( require (
github.com/frankban/quicktest v1.14.2 github.com/frankban/quicktest v1.14.2

@ -15,33 +15,11 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg= github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20= golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20=
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

@ -195,8 +195,9 @@ func (w *uniqueLineWriter) Write(p []byte) (n int, err error) {
} }
// debugf is like log.Printf, but it is a no-op by default. // debugf is like log.Printf, but it is a no-op by default.
// TODO(mvdan): remove once we use 1.18: https://github.com/golang/go/issues/47164 // TODO(mvdan): use our own debug logger instead of hijacking the global one,
func debugf(format string, args ...interface{}) { // and drop the "flagDebug" no-op check now that we require Go 1.18 or later.
func debugf(format string, args ...any) {
if !flagDebug { if !flagDebug {
return return
} }
@ -263,8 +264,8 @@ var toolchainVersionSemver string
func goVersionOK() bool { func goVersionOK() bool {
const ( const (
minGoVersionSemver = "v1.17.0" minGoVersionSemver = "v1.18.0"
suggestedGoVersion = "1.17.x" suggestedGoVersion = "1.18.x"
) )
// rxVersion looks for a version like "go1.2" or "go1.2.3" // rxVersion looks for a version like "go1.2" or "go1.2.3"
@ -497,10 +498,7 @@ This command wraps "go %s". Below is its help:
goArgs := []string{ goArgs := []string{
command, command,
"-trimpath", "-trimpath",
} "-buildvcs=false",
if semver.Compare(toolchainVersionSemver, "v1.18.0") >= 0 {
// TODO: remove the conditional once we drop support for 1.17
goArgs = append(goArgs, "-buildvcs=false")
} }
// Pass the garble flags down to each toolexec invocation. // Pass the garble flags down to each toolexec invocation.

@ -15,6 +15,8 @@ import (
) )
func isDirective(text string) bool { func isDirective(text string) bool {
// TODO: can we remove the check for "// +build" now that we require Go 1.18
// or later? we should update the tests too.
return strings.HasPrefix(text, "//go:") || strings.HasPrefix(text, "// +build") return strings.HasPrefix(text, "//go:") || strings.HasPrefix(text, "// +build")
} }

@ -128,8 +128,7 @@ func stripRuntime(filename string, file *ast.File) {
switch filename { switch filename {
case "print.go": case "print.go":
// was used in hexdumpWords // was used in hexdumpWords
x.Specs = removeImport(`"runtime/internal/sys"`, x.Specs) // Before Go 1.18. x.Specs = removeImport(`"internal/goarch"`, x.Specs)
x.Specs = removeImport(`"internal/goarch"`, x.Specs) // Go 1.18.
case "traceback.go": case "traceback.go":
// was used in traceback1 // was used in traceback1
x.Specs = removeImport(`"runtime/internal/atomic"`, x.Specs) x.Specs = removeImport(`"runtime/internal/atomic"`, x.Specs)

@ -113,7 +113,7 @@ func writeFileExclusive(name string, data []byte) error {
return err return err
} }
func writeGobExclusive(name string, val interface{}) error { func writeGobExclusive(name string, val any) error {
f, err := createExclusive(name) f, err := createExclusive(name)
if err != nil { if err != nil {
return err return err

@ -23,7 +23,7 @@ binsubstr main$exe 'privateAdd' 'PublicAdd'
-- go.mod -- -- go.mod --
module test/main module test/main
go 1.17 go 1.18
-- main.go -- -- main.go --
package main package main

@ -58,7 +58,7 @@ binsubstr main$exe 'garble_main.go' 'globalVar' 'globalFunc' $gofullversion
-- go.mod -- -- go.mod --
module test/mainfoo module test/mainfoo
go 1.17 go 1.18
-- garble_main.go -- -- garble_main.go --
package main package main

@ -27,7 +27,7 @@ binsubstr main$exe 'privateAdd'
-- go.mod -- -- go.mod --
module test/main module test/main
go 1.17 go 1.18
-- main.go -- -- main.go --
package main package main

@ -15,7 +15,7 @@ garble build
-- go.mod -- -- go.mod --
module test/main module test/main
go 1.17 go 1.18
-- main.go -- -- main.go --
package main package main

@ -18,7 +18,7 @@ stderr 'test/main' # we force rebuilds with -debugdir
-- go.mod -- -- go.mod --
module test/main module test/main
go 1.17 go 1.18
-- main.go -- -- main.go --
package main package main

@ -14,7 +14,7 @@ cmp stdout main.stdout
-- go.mod -- -- go.mod --
module test/main module test/main
go 1.17 go 1.18
-- main.go -- -- main.go --
package main package main

@ -50,7 +50,7 @@ bincmp out_rebuild out
-- go.mod -- -- go.mod --
module test/main module test/main
go 1.17 go 1.18
-- standalone/main.go -- -- standalone/main.go --
package main package main

@ -7,18 +7,18 @@ env PATH=${WORK}/.bin${:}${PATH}
# An empty go version. # An empty go version.
env TOOLCHAIN_GOVERSION='' env TOOLCHAIN_GOVERSION=''
! garble build ! garble build
stderr 'Go version is too old; please upgrade to Go 1\.17\.x or a newer devel version' stderr 'Go version is too old; please upgrade to Go 1\.18\.x or a newer devel version'
# We should error on a devel version that's too old. # We should error on a devel version that's too old.
# Note that they lacked the "goN.M-" prefix. # Note that they lacked the "goN.M-" prefix.
env TOOLCHAIN_GOVERSION='devel +afb5fca Sun Aug 07 00:00:00 2020 +0000' env TOOLCHAIN_GOVERSION='devel +afb5fca Sun Aug 07 00:00:00 2020 +0000'
! garble build ! garble build
stderr 'Go version is too old; please upgrade to Go 1\.17\.x or a newer devel version' stderr 'Go version is too old; please upgrade to Go 1\.18\.x or a newer devel version'
# Another form of old version; with an old "goN.M-" prefix. # Another form of old version; with an old "goN.M-" prefix.
env TOOLCHAIN_GOVERSION='devel go1.15-afb5fca Sun Aug 07 00:00:00 2020 +0000' env TOOLCHAIN_GOVERSION='devel go1.15-afb5fca Sun Aug 07 00:00:00 2020 +0000'
! garble build ! garble build
stderr 'Go version "devel go1\.15-.*2020.*" is too old; please upgrade to Go 1\.17\.x' stderr 'Go version "devel go1\.15-.*2020.*" is too old; please upgrade to Go 1\.18\.x'
# A current devel version should be fine. # A current devel version should be fine.
# Note that we don't look at devel version timestamps. # Note that we don't look at devel version timestamps.
@ -30,7 +30,7 @@ stderr 'mocking the real build'
# We should error on a stable version that's too old. # We should error on a stable version that's too old.
env TOOLCHAIN_GOVERSION='go1.14' env TOOLCHAIN_GOVERSION='go1.14'
! garble build ! garble build
stderr 'Go version "go1\.14" is too old; please upgrade to Go 1\.17\.x' stderr 'Go version "go1\.14" is too old; please upgrade to Go 1\.18\.x'
! stderr 'or a newer devel version' ! stderr 'or a newer devel version'
# We should accept a future stable version. # We should accept a future stable version.
@ -46,8 +46,8 @@ env TOOLCHAIN_GOVERSION='devel go1.18-somecustomversion'
stderr 'mocking the real build' stderr 'mocking the real build'
# The current toolchain may be older than the one that built garble. # The current toolchain may be older than the one that built garble.
env GARBLE_TEST_GOVERSION='go1.18' env GARBLE_TEST_GOVERSION='go1.19'
env TOOLCHAIN_GOVERSION='go1.17.3' env TOOLCHAIN_GOVERSION='go1.18.3'
! garble build ! garble build
stderr 'mocking the real build' stderr 'mocking the real build'
@ -58,10 +58,10 @@ env TOOLCHAIN_GOVERSION='devel go1.19-6673d5d701 Sun Mar 20 16:05:03 2022 +0000'
stderr 'mocking the real build' stderr 'mocking the real build'
# The current toolchain must not be newer than the one that built garble. # The current toolchain must not be newer than the one that built garble.
env GARBLE_TEST_GOVERSION='go1.17' env GARBLE_TEST_GOVERSION='go1.18'
env TOOLCHAIN_GOVERSION='go1.18.1' env TOOLCHAIN_GOVERSION='go1.19.1'
! garble build ! garble build
stderr 'garble was built with "go1\.17" and is being used with "go1\.18\.1"; please rebuild garble with the newer version' stderr 'garble was built with "go1\.18" and is being used with "go1\.19\.1"; please rebuild garble with the newer version'
# We'll error even if the difference is a minor (bugfix) level. # We'll error even if the difference is a minor (bugfix) level.
# In practice it probably wouldn't matter, but in theory it could still lead to tricky bugs. # In practice it probably wouldn't matter, but in theory it could still lead to tricky bugs.
@ -73,14 +73,14 @@ stderr 'garble was built with "go1\.18\.11" and is being used with "go1\.18\.14"
# If garble builds itself and is then used, it won't know what version built it. # If garble builds itself and is then used, it won't know what version built it.
# As a fallback, we drop the comparison against the toolchain's version. # As a fallback, we drop the comparison against the toolchain's version.
env GARBLE_TEST_GOVERSION='bogus version' env GARBLE_TEST_GOVERSION='bogus version'
env TOOLCHAIN_GOVERSION='go1.17.3' env TOOLCHAIN_GOVERSION='go1.18.3'
! garble build ! garble build
stderr 'mocking the real build' stderr 'mocking the real build'
-- go.mod -- -- go.mod --
module test/main module test/main
go 1.17 go 1.18
-- main.go -- -- main.go --
package main package main

@ -16,7 +16,7 @@ cmp stdout main.stdout
-- go.mod -- -- go.mod --
module test/main module test/main
go 1.17 go 1.18
-- main.go -- -- main.go --
package main package main
@ -91,7 +91,7 @@ type Struct2 struct {
package lib3 package lib3
type StructEmbed struct { type StructEmbed struct {
Baz interface{} Baz any
} }
-- main.stdout -- -- main.stdout --
String method for foo String method for foo

@ -45,7 +45,7 @@ cmp stdout main.stdout
-- go.mod -- -- go.mod --
module test/main module test/main
go 1.17 go 1.18
require ( require (
gopkg.in/garbletest.v2 v2.999.0 gopkg.in/garbletest.v2 v2.999.0
@ -93,7 +93,7 @@ func main() {
garbletest.Test() garbletest.Test()
} }
func printfWithoutPackage(format string, v interface{}) { func printfWithoutPackage(format string, v any) {
fmt.Print(strings.Split(fmt.Sprintf(format, v), ".")[1]) fmt.Print(strings.Split(fmt.Sprintf(format, v), ".")[1])
} }
-- notag_fail.go -- -- notag_fail.go --

@ -13,7 +13,7 @@ cmp stderr main.stderr
-- go.mod -- -- go.mod --
module test/main module test/main
go 1.17 go 1.18
-- main.go -- -- main.go --
package main package main

@ -31,7 +31,7 @@ binsubstr main$exe 'unexportedVersion' 'ExportedUnset' 'v1.22.33' 'garble_replac
-- go.mod -- -- go.mod --
module domain.test/main module domain.test/main
go 1.17 go 1.18
-- main.go -- -- main.go --
package main package main

@ -15,7 +15,7 @@ cmp stderr main.stderr
-- go.mod -- -- go.mod --
module test/main module test/main
go 1.17 go 1.18
replace big.chungus/meme => ./big.chungus/meme replace big.chungus/meme => ./big.chungus/meme
@ -52,7 +52,7 @@ func byteIndex(s string, c byte) int
// A linkname to an external non-obfuscated non-exported func. // A linkname to an external non-obfuscated non-exported func.
//go:linkname interfaceEqual os/exec.interfaceEqual //go:linkname interfaceEqual os/exec.interfaceEqual
func interfaceEqual(a, b interface{}) bool func interfaceEqual(a, b any) bool
// A linkname to an external obfuscated func. // A linkname to an external obfuscated func.
//go:linkname obfuscatedFunc test/main/imported.ObfuscatedFuncImpl //go:linkname obfuscatedFunc test/main/imported.ObfuscatedFuncImpl
@ -99,7 +99,7 @@ func ByteIndex(s string, c byte) int
-- big.chungus/meme/go.mod -- -- big.chungus/meme/go.mod --
module test/main module test/main
go 1.17 go 1.18
-- big.chungus/meme/dante.go -- -- big.chungus/meme/dante.go --
package meme package meme

@ -57,7 +57,7 @@ garble -literals build std
-- go.mod -- -- go.mod --
module test/main module test/main
go 1.17 go 1.18
-- main.go -- -- main.go --
package main package main

@ -18,19 +18,18 @@ stdout -count=1 '^.+$' # expect just one line
[short] stop # no need to verify this with -short [short] stop # no need to verify this with -short
go build -tags veryuniquebuildtag go build -tags veryuniquebuildtag
[!go1.18] binsubstr main$exe '(devel)' binsubstr main$exe '(devel)' 'veryuniquebuildtag' ${HEAD_COMMIT_SHA}
[go1.18] binsubstr main$exe '(devel)' 'veryuniquebuildtag' ${HEAD_COMMIT_SHA}
go version -m main$exe go version -m main$exe
stdout 'path\s*test/main' stdout 'path\s*test/main'
stdout 'mod\s*test/main\s*\(devel\)' stdout 'mod\s*test/main\s*\(devel\)'
[go1.18] stdout 'build\s*-tags=veryuniquebuildtag' stdout 'build\s*-tags=veryuniquebuildtag'
[go1.18] stdout 'build\s*vcs.revision='${HEAD_COMMIT_SHA} stdout 'build\s*vcs.revision='${HEAD_COMMIT_SHA}
-- go.mod -- -- go.mod --
module test/main module test/main
go 1.17 go 1.18
-- main.go -- -- main.go --
package main package main

@ -29,7 +29,7 @@ cmp stderr main.stderr
-- go.mod -- -- go.mod --
module test/main module test/main
go 1.17 go 1.18
-- plugin/main.go -- -- plugin/main.go --
package main package main

@ -19,7 +19,7 @@ stdout 'varPositions is sorted'
-- go.mod -- -- go.mod --
module test/main module test/main
go 1.17 go 1.18
-- garble_main.go -- -- garble_main.go --
package main package main

@ -17,7 +17,7 @@ cmp stdout main.stdout
-- go.mod -- -- go.mod --
module test/main module test/main
go 1.17 go 1.18
-- garble_main.go -- -- garble_main.go --
package main package main
@ -111,7 +111,7 @@ type EmbeddingIndirect struct {
importedpkg.AliasIndirectNamedWithReflect importedpkg.AliasIndirectNamedWithReflect
} }
func printfWithoutPackage(format string, v interface{}) { func printfWithoutPackage(format string, v any) {
s := fmt.Sprintf(format, v) s := fmt.Sprintf(format, v)
if i := strings.IndexByte(s, '.'); i > 0 { if i := strings.IndexByte(s, '.'); i > 0 {
s = s[i+1:] s = s[i+1:]
@ -135,7 +135,7 @@ type IndirectReflection struct {
ReflectionField string ReflectionField string
} }
func indirectReflection(v interface{}) { func indirectReflection(v any) {
fmt.Println(reflect.TypeOf(v).Field(0).Name) fmt.Println(reflect.TypeOf(v).Field(0).Name)
} }

@ -26,9 +26,7 @@ cp stderr build-error.stderr
stdin build-error.stderr stdin build-error.stderr
garble reverse ./build-error garble reverse ./build-error
# Go 1.18 changed the error format slightly. cmp stdout build-error-reverse.stdout
[!go1.18] cmp stdout build-error-reverse.stdout-go1.17
[go1.18] cmp stdout build-error-reverse.stdout-go1.18
[short] stop # no need to verify this with -short [short] stop # no need to verify this with -short
@ -54,7 +52,7 @@ cmp stdout main-literals.stderr
-- go.mod -- -- go.mod --
module test/main module test/main
go 1.17 go 1.18
-- long_main.go -- -- long_main.go --
package main package main
@ -157,12 +155,7 @@ main.main(...)
test/main/long_main.go:11 +0x?? test/main/long_main.go:11 +0x??
main filename: test/main/long_main.go main filename: test/main/long_main.go
-- build-error-reverse.stdout-go1.17 -- -- build-error-reverse.stdout --
# test/main/build-error
test/main/build-error/error.go:18: cannot convert UnobfuscatedStruct{} (type UnobfuscatedStruct) to type struct { SomeField int }
exit status 2
exit status 2
-- build-error-reverse.stdout-go1.18 --
# test/main/build-error # test/main/build-error
test/main/build-error/error.go:18: cannot convert UnobfuscatedStruct{} (value of type UnobfuscatedStruct) to type struct{SomeField int} test/main/build-error/error.go:18: cannot convert UnobfuscatedStruct{} (value of type UnobfuscatedStruct) to type struct{SomeField int}
exit status 2 exit status 2

@ -34,7 +34,7 @@ cd ..
-- mod1/go.mod -- -- mod1/go.mod --
module test/main/mod1 module test/main/mod1
go 1.17 go 1.18
require gopkg.in/garbletest.v2 v2.999.0 require gopkg.in/garbletest.v2 v2.999.0
@ -54,7 +54,7 @@ func main() { garbletest.Test() }
-- mod2/go.mod -- -- mod2/go.mod --
module test/main/mod2 module test/main/mod2
go 1.17 go 1.18
require gopkg.in/garbletest.v2 v2.999.0 require gopkg.in/garbletest.v2 v2.999.0

@ -99,7 +99,7 @@ cmp stderr importedpkg.stderr
-- go.mod -- -- go.mod --
module test/main module test/main
go 1.17 go 1.18
-- main.go -- -- main.go --
package main package main
@ -131,7 +131,7 @@ func mainFunc() {
// A workaround to fool garble's reflect detection, // A workaround to fool garble's reflect detection,
// because we want it to show us the obfuscated NamedType. // because we want it to show us the obfuscated NamedType.
var NamedTypeValue interface{} = NamedType{} var NamedTypeValue any = NamedType{}
type NamedType struct { type NamedType struct {
NamedField int NamedField int
@ -159,7 +159,7 @@ func NamedFunc() string {
return CallerFuncName() return CallerFuncName()
} }
func PrintNames(v interface{}, fn func() string) { func PrintNames(v any, fn func() string) {
typ := reflect.TypeOf(v) typ := reflect.TypeOf(v)
println("path:", typ.PkgPath()) println("path:", typ.PkgPath())
println("type:", typ.Name()) println("type:", typ.Name())

@ -19,7 +19,7 @@ binsubstr main$exe 'globalVar' # 'globalType' matches on some, but not all, plat
-- extra/go.mod -- -- extra/go.mod --
module private.source/extra module private.source/extra
go 1.17 go 1.18
-- extra/extra.go -- -- extra/extra.go --
package extra package extra
@ -29,7 +29,7 @@ func Func() string {
-- go.mod -- -- go.mod --
module test/main module test/main
go 1.17 go 1.18
// We include an extra module to obfuscate, included in the same original source // We include an extra module to obfuscate, included in the same original source
// code via a replace directive. // code via a replace directive.
@ -48,7 +48,7 @@ import (
) )
// This comment contains valuable information. Ensure it's not in the final binary. // This comment contains valuable information. Ensure it's not in the final binary.
var V interface{} var V any
type T struct { type T struct {
ast.Node ast.Node
@ -193,7 +193,7 @@ func Test() {
} }
} }
func noop(...interface{}) {} func noop(...any) {}
// Funcs that almost look like test funcs used to make garble panic. // Funcs that almost look like test funcs used to make garble panic.

@ -41,7 +41,7 @@ stdout 'package bar_test, func name: test/bar\.OriginalFuncName'
-- go.mod -- -- go.mod --
module test/bar module test/bar
go 1.17 go 1.18
-- bar.go -- -- bar.go --
package bar package bar

@ -26,14 +26,14 @@ stderr 'panic: oh noes'
-- go.mod -- -- go.mod --
module test/main module test/main
go 1.17 go 1.18
-- garble_main.go -- -- garble_main.go --
package main package main
import "runtime" import "runtime"
func main() { func main() {
var v interface{} = "tada" var v any = "tada"
println(v) println(v)
defer func() { defer func() {

Loading…
Cancel
Save