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/script
Daniel Martí 2ee9cf7a43 support go:linkname directives pointing at methods
This is not common, but it is done by a few projects.
Namely, github.com/goccy/go-json reached into reflect's guts,
which included a number of methods:

	internal/runtime/rtype.go
	11://go:linkname rtype_Align reflect.(*rtype).Align
	19://go:linkname rtype_FieldAlign reflect.(*rtype).FieldAlign
	27://go:linkname rtype_Method reflect.(*rtype).Method
	35://go:linkname rtype_MethodByName reflect.(*rtype).MethodByName
	[...]

Add tests for such go:linkname directives pointing at methods.
Note that there are two possible symbol string variants;
"pkg/path.(*Receiver).method" for methods with pointer receivers,
and "pkg/path.Receiver.method" for the rest.

We can't assume that the presence of two dots means a method either.
For example, a package path may be "pkg/path.with.dots",
and so "pkg/path.with.dots.SomeFunc" is the function "SomeFunc"
rather than the method "SomeFunc" on a type "dots".
To account for this ambiguity, rather than splitting on the last dot
like we used to, try to find a package path prefix by splitting on an
increasing number of first dots.

This can in theory still be ambiguous. For example,
we could have the package "pkg/path" expose the method "foo.bar",
and the package "pkg/path.foo" expose the func "bar".
Then, the symbol string "pkg/path.foo.bar" could mean either of them.
However, this seems extremely unlikely to happen in practice,
and I'm not sure that Go's toolchain would support it either.

I also noticed that goccy/go-json still failed to build after the fix.
The reason was that the type reflect.rtype wasn't being obfuscated.
We could, and likely should, teach our assembly and linkname
transformers about which names we chose not to obfuscate due to the use
of reflection. However, in this particular case, reflect's own types
can be obfuscated safely, so just do that.

Fixes #656.
2 years ago
..
asm.txtar support assembly references to package names 2 years ago
basic.txtar drop support for Go 1.18.x 3 years ago
cgo.txtar default to GOGARBLE=*, stop using GOPRIVATE 2 years ago
crossbuild.txtar avoid breaking intrinsics when obfuscating names 2 years ago
debugdir.txtar default to GOGARBLE=*, stop using GOPRIVATE 2 years ago
embed.txtar default to GOGARBLE=*, stop using GOPRIVATE 2 years ago
goenv.txtar drop support for Go 1.18.x 3 years ago
gogarble.txtar default to GOGARBLE=*, stop using GOPRIVATE 2 years ago
goversion.txtar drop support for Go 1.18.x 3 years ago
help.txtar default to GOGARBLE=*, stop using GOPRIVATE 2 years ago
implement.txtar default to GOGARBLE=*, stop using GOPRIVATE 2 years ago
imports.txtar default to GOGARBLE=*, stop using GOPRIVATE 2 years ago
init.txtar drop support for Go 1.18.x 3 years ago
ldflags.txtar default to GOGARBLE=*, stop using GOPRIVATE 2 years ago
linker.txtar patch and rebuild cmd/link to modify the magic value in pclntab 2 years ago
linkname.txtar support go:linkname directives pointing at methods 2 years ago
literals.txtar ensure that all imports are used after obfuscation 2 years ago
modinfo.txtar default to GOGARBLE=*, stop using GOPRIVATE 2 years ago
plugin.txtar default to GOGARBLE=*, stop using GOPRIVATE 2 years ago
position.txtar default to GOGARBLE=*, stop using GOPRIVATE 2 years ago
reflect.txtar avoid reflect method call panics with GOGARBLE=* 2 years ago
reverse.txtar CI: bump gotip to December 2022 2 years ago
seed-cache.txtar default to GOGARBLE=*, stop using GOPRIVATE 2 years ago
seed.txtar make seed.txtar less likely to flake 2 years ago
syntax.txtar default to GOGARBLE=*, stop using GOPRIVATE 2 years ago
test.txtar support `garble test` in main packages 3 years ago
tiny.txtar remove all unexported func names with -tiny via the linker 2 years ago
typeparams.txtar default to GOGARBLE=*, stop using GOPRIVATE 2 years ago