]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/internal/sys: migrate support.go functions to new internal pkg
authorThan McIntosh <thanm@google.com>
Tue, 4 Oct 2022 13:00:31 +0000 (09:00 -0400)
committerThan McIntosh <thanm@google.com>
Tue, 4 Oct 2022 18:08:15 +0000 (18:08 +0000)
Separate out the functions from cmd/internal/sys/support.go and
migrate them to a new package internal/platform, so that functions such as
"RaceDetectorSupported" can be called from tests in std as well as in
cmd. This isn't a complete move of everything in cmd/internal/sys;
there are still many functions left.

The original version of this CL (patch set 1) called the new package
"internal/sys", but for packages that needed both "internal/sys" and
"cmd/internal/sys" the import of the former had to be done with a
different name, which was confusing and also required a hack in
cmd/dist.

Updates #56006.

Change-Id: I866d62e75adbf3a640a06e2c7386a6e9e2a18d91
Reviewed-on: https://go-review.googlesource.com/c/go/+/438475
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>

19 files changed:
src/cmd/compile/internal/base/flag.go
src/cmd/dist/buildtool.go
src/cmd/dist/test.go
src/cmd/go/go_test.go
src/cmd/go/internal/load/pkg.go
src/cmd/go/internal/test/test.go
src/cmd/go/internal/work/gc.go
src/cmd/go/internal/work/init.go
src/cmd/go/script_test.go
src/cmd/internal/sys/supported_test.go [deleted file]
src/cmd/link/elf_test.go
src/cmd/link/internal/ld/config.go
src/cmd/link/link_test.go
src/cmd/objdump/objdump_test.go
src/go/build/deps_test.go
src/internal/fuzz/counters_unsupported.go
src/internal/fuzz/sys_unimplemented.go
src/internal/platform/supported.go [moved from src/cmd/internal/sys/supported.go with 97% similarity]
src/internal/testenv/testenv.go

index 9b97ce85d23e47e6c8006bda01588e73aaed22b8..42273ea35083d6a15eb1d264994623c035766bd9 100644 (file)
@@ -10,6 +10,7 @@ import (
        "fmt"
        "internal/buildcfg"
        "internal/coverage"
+       "internal/platform"
        "log"
        "os"
        "reflect"
@@ -176,13 +177,13 @@ func ParseFlags() {
        registerFlags()
        objabi.Flagparse(usage)
 
-       if Flag.MSan && !sys.MSanSupported(buildcfg.GOOS, buildcfg.GOARCH) {
+       if Flag.MSan && !platform.MSanSupported(buildcfg.GOOS, buildcfg.GOARCH) {
                log.Fatalf("%s/%s does not support -msan", buildcfg.GOOS, buildcfg.GOARCH)
        }
-       if Flag.ASan && !sys.ASanSupported(buildcfg.GOOS, buildcfg.GOARCH) {
+       if Flag.ASan && !platform.ASanSupported(buildcfg.GOOS, buildcfg.GOARCH) {
                log.Fatalf("%s/%s does not support -asan", buildcfg.GOOS, buildcfg.GOARCH)
        }
-       if Flag.Race && !sys.RaceDetectorSupported(buildcfg.GOOS, buildcfg.GOARCH) {
+       if Flag.Race && !platform.RaceDetectorSupported(buildcfg.GOOS, buildcfg.GOARCH) {
                log.Fatalf("%s/%s does not support -race", buildcfg.GOOS, buildcfg.GOARCH)
        }
        if (*Flag.Shared || *Flag.Dynlink || *Flag.LinkShared) && !Ctxt.Arch.InFamily(sys.AMD64, sys.ARM, sys.ARM64, sys.I386, sys.PPC64, sys.RISCV64, sys.S390X) {
index 755ec61affe51cf412bb7b8015c5a2eefd3e80a5..828e93aa4cf65f4de190561454df33e3a4cac410 100644 (file)
@@ -67,6 +67,7 @@ var bootstrapDirs = []string{
        "internal/pkgbits",
        "internal/race",
        "internal/saferio",
+       "internal/platform",
        "internal/unsafeheader",
        "internal/xcoff",
        "math/big",
index 7f85fc1d2da0f82b0d193f366866d8beac199706..fb0f1e13525afbdef21dc9eb992abab13350f722 100644 (file)
@@ -1711,7 +1711,7 @@ func (t *tester) runPrecompiledStdTest(timeout time.Duration) error {
 }
 
 // raceDetectorSupported is a copy of the function
-// cmd/internal/sys.RaceDetectorSupported, which can't be used here
+// internal/platform.RaceDetectorSupported, which can't be used here
 // because cmd/dist has to be buildable by Go 1.4.
 // The race detector only supports 48-bit VMA on arm64. But we don't have
 // a good solution to check VMA size(See https://golang.org/issue/29948)
index acc4d66fa7c5588e673eecad1c581d928b0fe67b..f1cee5a832ebc883b1070f1f93cedb0ca426cacf 100644 (file)
@@ -14,6 +14,7 @@ import (
        "fmt"
        "go/format"
        "internal/godebug"
+       "internal/platform"
        "internal/testenv"
        "io"
        "io/fs"
@@ -260,17 +261,17 @@ func TestMain(m *testing.M) {
                }
                testGOCACHE = strings.TrimSpace(string(out))
 
-               canMSan = canCgo && sys.MSanSupported(runtime.GOOS, runtime.GOARCH)
-               canASan = canCgo && sys.ASanSupported(runtime.GOOS, runtime.GOARCH)
-               canRace = canCgo && sys.RaceDetectorSupported(runtime.GOOS, runtime.GOARCH)
+               canMSan = canCgo && platform.MSanSupported(runtime.GOOS, runtime.GOARCH)
+               canASan = canCgo && platform.ASanSupported(runtime.GOOS, runtime.GOARCH)
+               canRace = canCgo && platform.RaceDetectorSupported(runtime.GOOS, runtime.GOARCH)
                // The race detector doesn't work on Alpine Linux:
                // golang.org/issue/14481
                // gccgo does not support the race detector.
                if isAlpineLinux() || runtime.Compiler == "gccgo" {
                        canRace = false
                }
-               canFuzz = sys.FuzzSupported(runtime.GOOS, runtime.GOARCH)
-               fuzzInstrumented = sys.FuzzInstrumented(runtime.GOOS, runtime.GOARCH)
+               canFuzz = platform.FuzzSupported(runtime.GOOS, runtime.GOARCH)
+               fuzzInstrumented = platform.FuzzInstrumented(runtime.GOOS, runtime.GOARCH)
        }
 
        // Don't let these environment variables confuse the test.
index 3e110dcd7c6a12463b097567791db90443526441..1e50fdc0a5f0bc032049606ec95816891c2e5007 100644 (file)
@@ -15,6 +15,7 @@ import (
        "go/build"
        "go/scanner"
        "go/token"
+       "internal/platform"
        "io/fs"
        "os"
        "os/exec"
@@ -43,7 +44,6 @@ import (
        "cmd/go/internal/trace"
        "cmd/go/internal/vcs"
        "cmd/internal/pkgpattern"
-       "cmd/internal/sys"
 
        "golang.org/x/mod/modfile"
        "golang.org/x/mod/module"
@@ -2604,7 +2604,7 @@ func externalLinkingForced(p *Package) bool {
        // -ldflags=-linkmode=external. External linking mode forces
        // an import of runtime/cgo.
        // If there are multiple -linkmode options, the last one wins.
-       pieCgo := cfg.BuildBuildmode == "pie" && !sys.InternalLinkPIESupported(cfg.BuildContext.GOOS, cfg.BuildContext.GOARCH)
+       pieCgo := cfg.BuildBuildmode == "pie" && !platform.InternalLinkPIESupported(cfg.BuildContext.GOOS, cfg.BuildContext.GOARCH)
        linkmodeExternal := false
        if p != nil {
                ldflags := BuildLdflags.For(p)
index 9a59bba76132f5595ec6e8ca449b6af491bba780..2b597632113167fe8e05226182f54105be342134 100644 (file)
@@ -9,6 +9,7 @@ import (
        "context"
        "errors"
        "fmt"
+       "internal/platform"
        "io"
        "io/fs"
        "os"
@@ -30,7 +31,6 @@ import (
        "cmd/go/internal/str"
        "cmd/go/internal/trace"
        "cmd/go/internal/work"
-       "cmd/internal/sys"
        "cmd/internal/test2json"
 
        "golang.org/x/mod/module"
@@ -664,7 +664,7 @@ func runTest(ctx context.Context, cmd *base.Command, args []string) {
                base.Fatalf("cannot use -o flag with multiple packages")
        }
        if testFuzz != "" {
-               if !sys.FuzzSupported(cfg.Goos, cfg.Goarch) {
+               if !platform.FuzzSupported(cfg.Goos, cfg.Goarch) {
                        base.Fatalf("-fuzz flag is not supported on %s/%s", cfg.Goos, cfg.Goarch)
                }
                if len(pkgs) != 1 {
index e25f111e1dcaccc228740d7d5566dfcc165580b6..d01a05122326e665146bd7733c434e8fce0f268b 100644 (file)
@@ -8,6 +8,7 @@ import (
        "bufio"
        "bytes"
        "fmt"
+       "internal/platform"
        "io"
        "log"
        "os"
@@ -22,7 +23,6 @@ import (
        "cmd/go/internal/str"
        "cmd/internal/objabi"
        "cmd/internal/quoted"
-       "cmd/internal/sys"
        "crypto/sha1"
 )
 
@@ -640,7 +640,7 @@ func (gcToolchain) ld(b *Builder, root *Action, out, importcfg, mainpkg string)
                // linker's build id, which will cause our build id to not
                // match the next time the tool is built.
                // Rely on the external build id instead.
-               if !sys.MustLinkExternal(cfg.Goos, cfg.Goarch) {
+               if !platform.MustLinkExternal(cfg.Goos, cfg.Goarch) {
                        ldflags = append(ldflags, "-X=cmd/internal/objabi.buildID="+root.buildID)
                }
        }
index d30b9683e297f92a944e2dc4b53737ceb07441ef..458a81bead96321913013f6c264dbca3a9dfce92 100644 (file)
@@ -13,8 +13,8 @@ import (
        "cmd/go/internal/fsys"
        "cmd/go/internal/modload"
        "cmd/internal/quoted"
-       "cmd/internal/sys"
        "fmt"
+       "internal/platform"
        "os"
        "os/exec"
        "path/filepath"
@@ -93,7 +93,7 @@ func BuildInit() {
 // instrumentation is added. 'go test -fuzz' still works without coverage,
 // but it generates random inputs without guidance, so it's much less effective.
 func fuzzInstrumentFlags() []string {
-       if !sys.FuzzInstrumented(cfg.Goos, cfg.Goarch) {
+       if !platform.FuzzInstrumented(cfg.Goos, cfg.Goarch) {
                return nil
        }
        return []string{"-d=libfuzzer"}
@@ -118,17 +118,17 @@ func instrumentInit() {
                base.SetExitStatus(2)
                base.Exit()
        }
-       if cfg.BuildMSan && !sys.MSanSupported(cfg.Goos, cfg.Goarch) {
+       if cfg.BuildMSan && !platform.MSanSupported(cfg.Goos, cfg.Goarch) {
                fmt.Fprintf(os.Stderr, "-msan is not supported on %s/%s\n", cfg.Goos, cfg.Goarch)
                base.SetExitStatus(2)
                base.Exit()
        }
-       if cfg.BuildRace && !sys.RaceDetectorSupported(cfg.Goos, cfg.Goarch) {
+       if cfg.BuildRace && !platform.RaceDetectorSupported(cfg.Goos, cfg.Goarch) {
                fmt.Fprintf(os.Stderr, "-race is not supported on %s/%s\n", cfg.Goos, cfg.Goarch)
                base.SetExitStatus(2)
                base.Exit()
        }
-       if cfg.BuildASan && !sys.ASanSupported(cfg.Goos, cfg.Goarch) {
+       if cfg.BuildASan && !platform.ASanSupported(cfg.Goos, cfg.Goarch) {
                fmt.Fprintf(os.Stderr, "-asan is not supported on %s/%s\n", cfg.Goos, cfg.Goarch)
                base.SetExitStatus(2)
                base.Exit()
@@ -299,12 +299,12 @@ func buildModeInit() {
                base.Fatalf("buildmode=%s not supported", cfg.BuildBuildmode)
        }
 
-       if !sys.BuildModeSupported(cfg.BuildToolchainName, cfg.BuildBuildmode, cfg.Goos, cfg.Goarch) {
+       if !platform.BuildModeSupported(cfg.BuildToolchainName, cfg.BuildBuildmode, cfg.Goos, cfg.Goarch) {
                base.Fatalf("-buildmode=%s not supported on %s/%s\n", cfg.BuildBuildmode, cfg.Goos, cfg.Goarch)
        }
 
        if cfg.BuildLinkshared {
-               if !sys.BuildModeSupported(cfg.BuildToolchainName, "shared", cfg.Goos, cfg.Goarch) {
+               if !platform.BuildModeSupported(cfg.BuildToolchainName, "shared", cfg.Goos, cfg.Goarch) {
                        base.Fatalf("-linkshared not supported on %s/%s\n", cfg.Goos, cfg.Goarch)
                }
                if gccgo {
index 8769aa061ca49d66a9e6a8b5b8abb4d574aaaab2..82af065ac82fd45282dcfb644b95b1a22ba78704 100644 (file)
@@ -15,6 +15,7 @@ import (
        "fmt"
        "go/build"
        "internal/buildcfg"
+       "internal/platform"
        "internal/testenv"
        "internal/txtar"
        "io/fs"
@@ -35,7 +36,6 @@ import (
        "cmd/go/internal/par"
        "cmd/go/internal/robustio"
        "cmd/go/internal/work"
-       "cmd/internal/sys"
 )
 
 var testSum = flag.String("testsum", "", `may be tidy, listm, or listall. If set, TestScript generates a go.sum file at the beginning of each test and updates test files if they pass.`)
@@ -459,7 +459,7 @@ Script:
                                        break
                                }
                                if value, found := strings.CutPrefix(cond.tag, "buildmode:"); found {
-                                       ok = sys.BuildModeSupported(runtime.Compiler, value, runtime.GOOS, runtime.GOARCH)
+                                       ok = platform.BuildModeSupported(runtime.Compiler, value, runtime.GOOS, runtime.GOARCH)
                                        break
                                }
                                if strings.HasPrefix(cond.tag, "GOEXPERIMENT:") {
diff --git a/src/cmd/internal/sys/supported_test.go b/src/cmd/internal/sys/supported_test.go
deleted file mode 100644 (file)
index 1217814..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2020 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package sys
-
-import (
-       "internal/testenv"
-       "runtime"
-       "testing"
-)
-
-func TestMustLinkExternalMatchesTestenv(t *testing.T) {
-       // MustLinkExternal and testenv.CanInternalLink are the exact opposite.
-       if b := MustLinkExternal(runtime.GOOS, runtime.GOARCH); b != !testenv.CanInternalLink() {
-               t.Fatalf("MustLinkExternal() == %v, testenv.CanInternalLink() == %v, don't match", b, testenv.CanInternalLink())
-       }
-}
index 5037f5b6c0d4b12b628f1a839d1e604c32bff95e..a75f35bf5d1ad13724938cad2b8ff7fd62ab1baf 100644 (file)
@@ -10,6 +10,7 @@ package main
 import (
        "debug/elf"
        "fmt"
+       "internal/platform"
        "internal/testenv"
        "os"
        "os/exec"
@@ -19,8 +20,6 @@ import (
        "sync"
        "testing"
        "text/template"
-
-       "cmd/internal/sys"
 )
 
 func getCCAndCCFLAGS(t *testing.T, env []string) (string, []string) {
@@ -280,7 +279,7 @@ func TestPIESize(t *testing.T) {
        // always skip the test if cgo is not supported.
        testenv.MustHaveCGO(t)
 
-       if !sys.BuildModeSupported(runtime.Compiler, "pie", runtime.GOOS, runtime.GOARCH) {
+       if !platform.BuildModeSupported(runtime.Compiler, "pie", runtime.GOOS, runtime.GOARCH) {
                t.Skip("-buildmode=pie not supported")
        }
 
index 4dd43a16aba79f173a759110f49ffcfd1d71f449..336cb33e3ba399f5871e3cc87fcbfe27c01f1138 100644 (file)
@@ -8,6 +8,7 @@ import (
        "cmd/internal/sys"
        "fmt"
        "internal/buildcfg"
+       "internal/platform"
 )
 
 // A BuildMode indicates the sort of object we are building.
@@ -185,7 +186,7 @@ func mustLinkExternal(ctxt *Link) (res bool, reason string) {
                }()
        }
 
-       if sys.MustLinkExternal(buildcfg.GOOS, buildcfg.GOARCH) {
+       if platform.MustLinkExternal(buildcfg.GOOS, buildcfg.GOARCH) {
                return true, fmt.Sprintf("%s/%s requires external linking", buildcfg.GOOS, buildcfg.GOARCH)
        }
 
index c1a30363cb1eea1c3011aa1e2991ed8b114fa64d..35babe61fc0ec93084c9a8c7260517c0244ef426 100644 (file)
@@ -9,6 +9,7 @@ import (
        "bytes"
        "debug/macho"
        "internal/buildcfg"
+       "internal/platform"
        "internal/testenv"
        "os"
        "os/exec"
@@ -17,8 +18,6 @@ import (
        "runtime"
        "strings"
        "testing"
-
-       "cmd/internal/sys"
 )
 
 var AuthorPaidByTheColumnInch struct {
@@ -976,7 +975,7 @@ func main() {
 func TestIssue42396(t *testing.T) {
        testenv.MustHaveGoBuild(t)
 
-       if !sys.RaceDetectorSupported(runtime.GOOS, runtime.GOARCH) {
+       if !platform.RaceDetectorSupported(runtime.GOOS, runtime.GOARCH) {
                t.Skip("no race detector support")
        }
 
index 86e904dcd5b611c8cd58b0be22488957efda3298..bbf942503a24131ba8cf91fea8399b293ad6ce37 100644 (file)
@@ -6,10 +6,10 @@ package main
 
 import (
        "cmd/internal/notsha256"
-       "cmd/internal/sys"
        "flag"
        "fmt"
        "go/build"
+       "internal/platform"
        "internal/testenv"
        "os"
        "os/exec"
@@ -287,7 +287,7 @@ func TestDisasmExtld(t *testing.T) {
 }
 
 func TestDisasmPIE(t *testing.T) {
-       if !sys.BuildModeSupported("gc", "pie", runtime.GOOS, runtime.GOARCH) {
+       if !platform.BuildModeSupported("gc", "pie", runtime.GOOS, runtime.GOARCH) {
                t.Skipf("skipping on %s/%s, PIE buildmode not supported", runtime.GOOS, runtime.GOARCH)
        }
        t.Parallel()
index d1aeb00947e375d6b60ff24d6d96ce756afeeb81..69cff07cbd0bbb25f00daea06d795e216eb25f95 100644 (file)
@@ -44,7 +44,7 @@ var depsRules = `
          internal/coverage/uleb128, internal/coverage/calloc,
       internal/cpu, internal/goarch,
          internal/goexperiment, internal/goos,
-         internal/goversion, internal/nettrace,
+         internal/goversion, internal/nettrace, internal/platform,
          unicode/utf8, unicode/utf16, unicode,
          unsafe;
 
@@ -529,7 +529,7 @@ var depsRules = `
        internal/fuzz, internal/testlog, runtime/pprof, regexp
        < testing/internal/testdeps;
 
-       OS, flag, testing, internal/cfg
+       OS, flag, testing, internal/cfg, internal/platform
        < internal/testenv;
 
        OS, encoding/base64
index bf281570681fb57542fc5d7dba7b644d964c75e5..028065ce30f6ac45a4094e6c87eb8bdf26d9d857 100644 (file)
@@ -6,7 +6,7 @@
 // the instrumentation is OS specific, but only amd64 and arm64 are
 // supported in the runtime. See src/runtime/libfuzzer*.
 //
-// If you update this constraint, also update cmd/internal/sys.FuzzInstrumeted.
+// If you update this constraint, also update internal/platform.FuzzInstrumeted.
 //
 //go:build !((darwin || linux || windows || freebsd) && (amd64 || arm64))
 
index f84dae6a61fddb649e68ca18c93af9b71c63f2db..8687c1f963e1ba7136337f55bf0e6704757876d1 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// If you update this constraint, also update cmd/internal/sys.FuzzSupported.
+// If you update this constraint, also update internal/platform.FuzzSupported.
 //
 //go:build !darwin && !freebsd && !linux && !windows
 
similarity index 97%
rename from src/cmd/internal/sys/supported.go
rename to src/internal/platform/supported.go
index ee98d0548e659c859a4d76d2e61fa529dcf7ef35..c9264c03ee2da628e5b2b59d10cbd9c93c97ae9d 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package sys
+package platform
 
 // RaceDetectorSupported reports whether goos/goarch supports the race
 // detector. There is a copy of this function in cmd/dist/test.go.
@@ -70,7 +70,6 @@ func FuzzInstrumented(goos, goarch string) bool {
 }
 
 // MustLinkExternal reports whether goos/goarch requires external linking.
-// (This is the opposite of internal/testenv.CanInternalLink. Keep them in sync.)
 func MustLinkExternal(goos, goarch string) bool {
        switch goos {
        case "android":
index 7b435fd002ab44818e56c0e8a2dc550dbdcb0207..fe34a92d9c9e6c44b7f58015cedef5ec0785875e 100644 (file)
@@ -16,6 +16,7 @@ import (
        "flag"
        "fmt"
        "internal/cfg"
+       "internal/platform"
        "os"
        "os/exec"
        "path/filepath"
@@ -295,19 +296,8 @@ func MustHaveCGO(t testing.TB) {
 
 // CanInternalLink reports whether the current system can link programs with
 // internal linking.
-// (This is the opposite of cmd/internal/sys.MustLinkExternal. Keep them in sync.)
 func CanInternalLink() bool {
-       switch runtime.GOOS {
-       case "android":
-               if runtime.GOARCH != "arm64" {
-                       return false
-               }
-       case "ios":
-               if runtime.GOARCH == "arm64" {
-                       return false
-               }
-       }
-       return true
+       return !platform.MustLinkExternal(runtime.GOOS, runtime.GOARCH)
 }
 
 // MustInternalLink checks that the current system can link programs with internal