diff --git a/go_std_tables.go b/go_std_tables.go index c412a4c..9ca4818 100644 --- a/go_std_tables.go +++ b/go_std_tables.go @@ -87,8 +87,10 @@ var runtimeAndLinknamed = []string{ "unique", // go1.25 "weak", // go1.25 // The net package linknames to the runtime, not the other way around. - // TODO: support this automatically via our script. "net", + // The testing package uses a //go:linkname directive pointing to testing/synctest, + // but it doesn't import the package, presumably to avoid an import cycle. + "testing/synctest", } var compilerIntrinsics = map[string]map[string]bool{ diff --git a/scripts/gen_go_std_tables.go b/scripts/gen_go_std_tables.go index 0e94700..a057722 100644 --- a/scripts/gen_go_std_tables.go +++ b/scripts/gen_go_std_tables.go @@ -53,8 +53,10 @@ var runtimeAndLinknamed = []string{ "{{ $path.String }}", // {{ $path.GoVersionLang }} {{- end }} // The net package linknames to the runtime, not the other way around. - // TODO: support this automatically via our script. "net", + // The testing package uses a //go:linkname directive pointing to testing/synctest, + // but it doesn't import the package, presumably to avoid an import cycle. + "testing/synctest", } var compilerIntrinsics = map[string]map[string]bool{ diff --git a/shared.go b/shared.go index c986d9a..a42ed1c 100644 --- a/shared.go +++ b/shared.go @@ -279,23 +279,12 @@ func appendListedPackages(packages []string, mainBuild bool) error { // Similar flags to what go/packages uses. "-json", "-export", "-compiled", "-e", } - if len(packages) == 0 { - // As we may append to the packages slice below, - // ensure that zero packages still means "the current directory". - packages = append(packages, ".") - } if mainBuild { // When loading the top-level packages we are building, // we want to transitively load all their dependencies as well. // That is not the case when loading standard library packages, // as runtimeAndLinknamed already contains transitive dependencies. args = append(args, "-deps") - if slices.Contains(sharedCache.ForwardBuildFlags, "-test") { - // The testing package uses a //go:linkname directive pointing to testing/synctest, - // but it doesn't import the package, presumably to avoid an import cycle. - // For the linkname to obfuscate correctly, we need to list both when using `go test`. - packages = append(packages, "testing/synctest") - } } args = append(args, garbleBuildFlags...) args = append(args, sharedCache.ForwardBuildFlags...) diff --git a/testdata/script/gogarble.txtar b/testdata/script/gogarble.txtar index 984392e..eba6f6d 100644 --- a/testdata/script/gogarble.txtar +++ b/testdata/script/gogarble.txtar @@ -91,6 +91,7 @@ import ( "runtime" "runtime/debug" "syscall" + "testing" "time" ) @@ -107,6 +108,7 @@ func main() { debug.WriteHeapDump(1) time.Now() syscall.Listen(0, 1) + testing.MainStart(nil, nil, nil, nil, nil) } }