diff --git a/main.go b/main.go index d3815df..1899ed5 100644 --- a/main.go +++ b/main.go @@ -455,7 +455,7 @@ This command wraps "go %s". Below is its help: } cache.BinaryContentID = decodeHash(splitContentID(binaryBuildID)) - if err := appendListedPackages(args...); err != nil { + if err := appendListedPackages(args, true); err != nil { return nil, err } diff --git a/scripts/runtime-linknamed-nodeps.sh b/scripts/runtime-linknamed-nodeps.sh index 9ee9b64..98cf853 100755 --- a/scripts/runtime-linknamed-nodeps.sh +++ b/scripts/runtime-linknamed-nodeps.sh @@ -1,21 +1,11 @@ #!/bin/bash -# The list of all packages the runtime source linknames to. -linked="$(sed -rn 's@//go:linkname .* ([^.]*)\.[^.]*@\1@p' $(go env GOROOT)/src/runtime/*.go | grep -vE '^main|^runtime\.' | sort -u)" - -# The list of all implied dependencies of the packages above, -# across all main GOOS targets. -implied="$(for GOOS in linux darwin windows js; do - for pkg in $linked; do - GOOS=$GOOS GOARCH=$GOARCH go list -e -deps $pkg | grep -v '^'$pkg'$' - done -done | sort -u)" - -# All packages in linked, except those implied by others already. +# All packages that the runtime linknames to, except runtime and its dependencies. # This resulting list is what we need to "go list" when obfuscating the runtime, # as they are the packages that we may be missing. comm -23 <( - echo "$linked" + sed -rn 's@//go:linkname .* ([^.]*)\.[^.]*@\1@p' $(go env GOROOT)/src/runtime/*.go | grep -vE '^main|^runtime\.' | sort -u ) <( - echo "$implied" + # Note that we assume this is constant across platforms. + go list -deps runtime | sort -u ) diff --git a/shared.go b/shared.go index c581094..0f6f24f 100644 --- a/shared.go +++ b/shared.go @@ -160,14 +160,17 @@ func (p *listedPackage) obfuscatedImportPath() string { // appendListedPackages gets information about the current package // and all of its dependencies -func appendListedPackages(patterns ...string) error { +func appendListedPackages(packages []string, withDeps bool) error { startTime := time.Now() // TODO: perhaps include all top-level build flags set by garble, // including -buildvcs=false. // They shouldn't affect "go list" here, but might as well be consistent. - args := []string{"list", "-json", "-deps", "-export", "-trimpath"} + args := []string{"list", "-json", "-export", "-trimpath"} + if withDeps { + args = append(args, "-deps") + } args = append(args, cache.ForwardBuildFlags...) - args = append(args, patterns...) + args = append(args, packages...) cmd := exec.Command("go", args...) defer func() { @@ -260,16 +263,24 @@ func listPackage(path string) (*listedPackage, error) { // Obtained via scripts/runtime-linknamed-nodeps.sh as of Go 1.18beta1. runtimeLinknamed := []string{ "crypto/x509/internal/macos", + "internal/poll", + "internal/reflectlite", "net", + "os", "os/signal", "plugin", + "reflect", "runtime/debug", "runtime/metrics", "runtime/pprof", "runtime/trace", + "sync", + "sync/atomic", + "syscall", "syscall/js", + "time", } - var missing []string + missing := make([]string, 0, len(runtimeLinknamed)) for _, linknamed := range runtimeLinknamed { switch { case cache.ListedPackages[linknamed] != nil: @@ -282,7 +293,8 @@ func listPackage(path string) (*listedPackage, error) { missing = append(missing, linknamed) } } - if err := appendListedPackages(missing...); err != nil { + // We don't need any information about their dependencies, in this case. + if err := appendListedPackages(missing, false); err != nil { panic(err) // should never happen } pkg, ok := cache.ListedPackages[path]