Browse Source

join runtimeAndDeps into cannotObfuscate

There used to be a reason to keep these maps separate, but ever since we
became better at obfuscating the standard library, that has gone away.

It's still a good idea to keep `go list -deps runtime` as a group,
but we can do that via a comment inside a joint map literal.

I also noticed that one comment still referred to cannotObfuscateNames,
which hasn't existed for some time. Fix that up.

It's also not documented how cachedOutput contains info for all deps,
so clarify that while we're improving the docs.

Finally, the reason we cannot obfuscate the syscall package was out of
date; it's not part of the runtime. It is a go:linkname bug.
Daniel Martí 5 months ago
2 changed files with 10 additions and 9 deletions
  1. 4 1
  2. 6 8

+ 4 - 1

@@ -1028,6 +1028,9 @@ type (
 var knownCannotObfuscateUnexported = map[types.Object]bool{}
 // cachedOutput contains information that will be stored as per garbleExportFile.
+// Note that cachedOutput gets loaded from all direct package dependencies,
+// and gets filled while obfuscating the current package, so it ends up
+// containing entries for the current package and its transitive dependencies.
 var cachedOutput = struct {
 	// KnownReflectAPIs is a static record of what std APIs use reflection on their
 	// parameters, so we can avoid obfuscating types used with them.
@@ -1037,7 +1040,7 @@ var cachedOutput = struct {
 	KnownReflectAPIs map[funcFullName][]reflectParameter
 	// KnownCannotObfuscate is filled with the fully qualified names from each
-	// package that we could not obfuscate as per cannotObfuscateNames.
+	// package that we cannot obfuscate.
 	// This record is necessary for knowing what names from imported packages
 	// weren't obfuscated, so we can obfuscate their local uses accordingly.
 	KnownCannotObfuscate map[objectString]struct{}

+ 6 - 8

@@ -243,7 +243,7 @@ func appendListedPackages(packages []string, withDeps bool) error {
 		// Test main packages like "foo/bar.test" are always obfuscated,
 		// just like main packages.
 		switch {
-		case cannotObfuscate[path], runtimeAndDeps[path]:
+		case cannotObfuscate[path]:
 			// We don't support obfuscating these yet.
 		case pkg.Incomplete:
@@ -268,24 +268,22 @@ func appendListedPackages(packages []string, withDeps bool) error {
 // cannotObfuscate is a list of some standard library packages we currently
-// cannot obfuscate. Note that this list currently sits on top of
-// runtimeAndDeps, which are currently not obfuscated either.
+// cannot obfuscate.
 // TODO: investigate and resolve each one of these
 var cannotObfuscate = map[string]bool{
 	// "undefined reference" errors at link time
 	"time": true,
-	// all kinds of stuff breaks when obfuscating the runtime
+	// "//go:linkname must refer to declared function or variable"
 	"syscall": true,
 	// "unknown pc" crashes on windows in the cgo test otherwise
 	"runtime/cgo": true,
-// Obtained from "go list -deps runtime" as of June 29th.
-// Note that the same command on Go 1.18 results in the same list.
-var runtimeAndDeps = map[string]bool{
+	// We do not support obfuscating the runtime nor its dependencies.
+	// Obtained from "go list -deps runtime" as of June 29th.
+	// Note that the same command on Go 1.18 results in the same list.
 	"internal/goarch":          true,
 	"unsafe":                   true,
 	"internal/abi":             true,