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í 955c24856c properly record when type aliases are embedded as fields
There are two scenarios when it comes to embedding fields.
The first is easy, and we always handled it well:

	type Named struct { Foo int }

	type T struct { Named }

In this scenario, T ends up with an embedded field named "Named",
and a promoted field named "Foo".

Then there's the form with a type alias:

	type Named struct { Foo int }

	type Alias = Named

	type T struct { Alias }

This case is different: T ends up with an embedded field named "Alias",
and a promoted field named "Foo".
Note how the field gets its name from the referenced type,
even if said type is just an alias to another type.

This poses two problems.
First, we must obfuscate the field T.Alias as the name "Alias",
and not as the name "Named" that the alias points to.
Second, we must be careful of cases where Named and Alias are declared
in different packages, as they will obfuscate the same name differently.

Both of those problems compounded in the reported issue.
The actual reason is that quic-go has a type alias in the form of:

	type ConnectionState = qtls.ConnectionState

In other words, the entire problem boils down to a type alias which
points to a named type in a different package, where both types share
the same name. For example:

	package parent

	import "parent/p1"

	type T struct { p1.SameName }

	[...]

	package p1

	import "parent/p2"

	type SameName = p2.SameName

	[...]

	package p2

	type SameName struct { Foo int }

This broke garble because we had a heuristic to detect when an embedded
field was a type alias:

	// Instead, detect such a "foreign alias embed".
	// If we embed a final named type,
	// but the field name does not match its name,
	// then it must have been done via an alias.
	// We dig out the alias's TypeName via locateForeignAlias.
	if named.Obj().Name() != node.Name {

As the reader can deduce, this heuristic would incorrectly assume that
the snippet above does not embed a type alias, when in fact it does.
When obfuscating the field T.SameName, which uses a type alias,
we would correctly obfuscate the name "SameName",
but we would incorrectly obfuscate it with the package p2, not p1.
This would then result in build errors.

To fix this problem for good, we need to get rid of the heuristic.
Instead, we now mimic what was done for KnownCannotObfuscate,
but for embedded fields which use type aliases.
KnownEmbeddedAliasFields is now filled for each package
and stored in the cache as part of cachedOutput.
We can then detect the "embedded alias" case reliably,
even when the field is declared in an imported package.

On the plus side, we get to remove locateForeignAlias.
We also add a couple of TODOs to record further improvements.
Finally, add a test.

Fixes #466.
2 years ago
..
asm.txt CI: test on GOARCH=386 3 years ago
basic.txt fix binsubstr calls to not prepare for a regexp 3 years ago
cgo.txt stop loading obfuscated type information from deps 2 years ago
crossbuild.txt only list missing packages when obfuscating the runtime 3 years ago
debugdir.txt avoid build ID mismatches when using -debugdir 3 years ago
embed.txt deprecate using GOPRIVATE in favor of GOGARBLE (#427) 3 years ago
gogarble.txt only list missing packages when obfuscating the runtime 3 years ago
goversion.txt drop support for Go 1.16.x 3 years ago
help.txt give a useful error for "garble build -tiny" 3 years ago
implement.txt deprecate using GOPRIVATE in favor of GOGARBLE (#427) 3 years ago
imports.txt handle --long build flags properly 3 years ago
init.txt drop support for Go 1.16.x 3 years ago
ldflags.txt avoid obfuscating literals set via -ldflags=-X 3 years ago
linkname.txt deprecate using GOPRIVATE in favor of GOGARBLE (#427) 3 years ago
literals.txt support GOGARBLE=* with -literals again 3 years ago
modinfo.txt testdata: adjust for newer Go 1.18 tip version 3 years ago
plugin.txt deprecate using GOPRIVATE in favor of GOGARBLE (#427) 3 years ago
position.txt deprecate using GOPRIVATE in favor of GOGARBLE (#427) 3 years ago
reflect.txt stop loading obfuscated type information from deps 2 years ago
reverse.txt testdata: make pointer regexp less prone to flakes 3 years ago
seed.txt deprecate using GOPRIVATE in favor of GOGARBLE (#427) 3 years ago
syntax.txt properly record when type aliases are embedded as fields 2 years ago
test.txt drop support for Go 1.16.x 3 years ago
tiny.txt deprecate using GOPRIVATE in favor of GOGARBLE (#427) 3 years ago