You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
garble/testdata/scripts
Daniel Martí 68f07389b2 fix a number of issues involving types from indirect imports
obfuscatedTypesPackage is used to figure out if a name in a dependency
package was obfuscated or not. For example, if that package used
reflection on a named type, it wasn't obfuscated, so we must have the
same information to not obfuscate the same name downstream.

obfuscatedTypesPackage could return nil if the package was indirectly
imported, though. This can happen if a direct import has a function that
returns an indirect type, or if a direct import exposes a name that's a
type alias to an indirect type.

We sort of dealt with this in two pieces of code by checking for
obfPkg!=nil, but a third one did not have this check and caused a panic
in the added test case:

	--- FAIL: TestScripts/reflect (0.81s)
	    testscript.go:397:
	        > env GOPRIVATE=test/main
	        > garble build
	        [stderr]
	        # test/main
	        panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	        	panic: runtime error: invalid memory address or nil pointer dereference
	        [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x8a5e39]

More importantly though, the nil check only avoids panics. It doesn't
fix the root cause of the problem: that importcfg does not contain
indirectly imported packages. The added test case would still fail, as
we would obfuscate a type in the main package, but not in the indirectly
imported package where the type is defined.

To fix this, resurrect a bit of code from earlier garble versions, which
uses "go list -toolexec=garble" to fetch a package's export file. This
lets us fill the indirect import gaps in importcfg, working around the
problem entirely.

This solution is still not particularly great, so we add a TODO about
possibly rethinking this in the future. It does add some overhead and
complexity, though thankfully indirect imports should be uncommon.

This fixes a few panics while building the protobuf module.
4 years ago
..
asm.txt obfuscate asm function names as well (#273) 5 years ago
basic.txt testdata: reduce the cost of short tests 5 years ago
cgo.txt all: drop support for Go 1.15.x (#265) 5 years ago
crossbuild.txt fix windows/arm cross-build linking 5 years ago
debugdir.txt refactor "current package" with TOOLEXEC_IMPORTPATH (#266) 5 years ago
embed.txt don't obfuscate the "embed" import path 5 years ago
goprivate.txt avoid reproducibility issues with full rebuilds 5 years ago
goversion.txt use "go env -json" to collect env info all at once 5 years ago
help.txt make "help" refuse arguments for now 5 years ago
implement.txt remove tinyfmt implementation from a test script 4 years ago
imports.txt testdata: split reflection test cases into reflect.txt 5 years ago
init.txt all: drop support for Go 1.15.x (#265) 5 years ago
ldflags.txt testdata: remove some unnecessary execs (#267) 5 years ago
linkname.txt fix obfuscating linkname directives that where the package name contained a dot 5 years ago
literals.txt make -literals succeed on all of std 5 years ago
modinfo.txt testdata: remove some unnecessary execs (#267) 5 years ago
plugin.txt all: drop support for Go 1.15.x (#265) 5 years ago
position.txt hopefully fix position test on Windows by not matching on 'main.go' 5 years ago
reflect.txt fix a number of issues involving types from indirect imports 4 years ago
reverse.txt reverse lone filenames as well 4 years ago
seed.txt make flags like -literals and GOPRIVATE affect hashing (#288) 5 years ago
syntax.txt testdata: split reflection test cases into reflect.txt 5 years ago
test.txt testdata: reduce the cost of short tests 5 years ago
tiny.txt testdata: scope GODEBUG to a single test case 5 years ago