diff --git a/src/cmd/go/internal/work/gc.go b/src/cmd/go/internal/work/gc.go index 85da4f89f9..2ae908bc8f 100644 --- a/src/cmd/go/internal/work/gc.go +++ b/src/cmd/go/internal/work/gc.go @@ -29,6 +29,18 @@ import ( // The 'path' used for GOROOT_FINAL when -trimpath is specified const trimPathGoRootFinal = "go" +var runtimePackages = map[string]struct{}{ + "internal/abi": struct{}{}, + "internal/bytealg": struct{}{}, + "internal/cpu": struct{}{}, + "internal/goarch": struct{}{}, + "internal/goos": struct{}{}, + "runtime": struct{}{}, + "runtime/internal/atomic": struct{}{}, + "runtime/internal/math": struct{}{}, + "runtime/internal/sys": struct{}{}, +} + // The Go toolchain. type gcToolchain struct{} @@ -88,11 +100,8 @@ func (gcToolchain) gc(b *Builder, a *Action, archive string, importcfg, embedcfg if p.Standard { gcargs = append(gcargs, "-std") } - compilingRuntime := p.Standard && (p.ImportPath == "runtime" || strings.HasPrefix(p.ImportPath, "runtime/internal")) - // The runtime package imports a couple of general internal packages. - if p.Standard && (p.ImportPath == "internal/cpu" || p.ImportPath == "internal/bytealg" || p.ImportPath == "internal/abi") { - compilingRuntime = true - } + _, compilingRuntime := runtimePackages[p.ImportPath] + compilingRuntime = compilingRuntime && p.Standard if compilingRuntime { // runtime compiles with a special gc flag to check for // memory allocations that are invalid in the runtime package, diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go index 45e2f25df7..b440f7d235 100644 --- a/src/go/build/deps_test.go +++ b/src/go/build/deps_test.go @@ -71,7 +71,8 @@ var depsRules = ` # No dependencies allowed for any of these packages. NONE < container/list, container/ring, - internal/cfg, internal/cpu, internal/goexperiment, + internal/cfg, internal/cpu, internal/goarch, + internal/goexperiment, internal/goos, internal/goversion, internal/nettrace, unicode/utf8, unicode/utf16, unicode, unsafe; @@ -81,7 +82,8 @@ var depsRules = ` < internal/abi; # RUNTIME is the core runtime group of packages, all of them very light-weight. - internal/abi, internal/cpu, internal/goexperiment, unsafe + internal/abi, internal/cpu, internal/goarch, + internal/goexperiment, internal/goos, unsafe < internal/bytealg < internal/itoa < internal/unsafeheader diff --git a/src/internal/goarch/gengoarch.go b/src/internal/goarch/gengoarch.go new file mode 100644 index 0000000000..58c3b1104c --- /dev/null +++ b/src/internal/goarch/gengoarch.go @@ -0,0 +1,59 @@ +// Copyright 2014 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. + +//go:build ignore +// +build ignore + +package main + +import ( + "bytes" + "fmt" + "log" + "os" + "strconv" + "strings" +) + +var goarches []string + +func main() { + data, err := os.ReadFile("../../go/build/syslist.go") + if err != nil { + log.Fatal(err) + } + const goarchPrefix = `const goarchList = ` + for _, line := range strings.Split(string(data), "\n") { + if strings.HasPrefix(line, goarchPrefix) { + text, err := strconv.Unquote(strings.TrimPrefix(line, goarchPrefix)) + if err != nil { + log.Fatalf("parsing goarchList: %v", err) + } + goarches = strings.Fields(text) + } + } + + for _, target := range goarches { + if target == "amd64p32" { + continue + } + var buf bytes.Buffer + fmt.Fprintf(&buf, "// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.\n\n") + fmt.Fprintf(&buf, "//go:build %s\n", target) + fmt.Fprintf(&buf, "// +build %s\n\n", target) // must explicitly include target for bootstrapping purposes + fmt.Fprintf(&buf, "package goarch\n\n") + fmt.Fprintf(&buf, "const GOARCH = `%s`\n\n", target) + for _, goarch := range goarches { + value := 0 + if goarch == target { + value = 1 + } + fmt.Fprintf(&buf, "const Goarch%s = %d\n", strings.Title(goarch), value) + } + err := os.WriteFile("zgoarch_"+target+".go", buf.Bytes(), 0666) + if err != nil { + log.Fatal(err) + } + } +} diff --git a/src/runtime/internal/sys/arch.go b/src/internal/goarch/goarch.go similarity index 79% rename from src/runtime/internal/sys/arch.go rename to src/internal/goarch/goarch.go index 3c99a2f7da..8e240295b3 100644 --- a/src/runtime/internal/sys/arch.go +++ b/src/internal/goarch/goarch.go @@ -1,8 +1,15 @@ -// Copyright 2014 The Go Authors. All rights reserved. +// Copyright 2021 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 +// package goarch contains GOARCH-specific constants. +package goarch + +// The next line makes 'go generate' write the zgoarch*.go files with +// per-arch information, including constants named Goarch$GOARCH for every +// GOARCH. The constant is 1 on the current system, 0 otherwise; multiplying +// by them is useful for defining GOARCH-specific constants. +//go:generate go run gengoarch.go type ArchFamilyType int @@ -23,9 +30,6 @@ const ( // It is also the size of the machine's native word size (that is, 4 on 32-bit systems, 8 on 64-bit). const PtrSize = 4 << (^uintptr(0) >> 63) -// AIX requires a larger stack for syscalls. -const StackGuardMultiplier = StackGuardMultiplierDefault*(1-GoosAix) + 2*GoosAix - // ArchFamily is the architecture family (AMD64, ARM, ...) const ArchFamily ArchFamilyType = _ArchFamily diff --git a/src/runtime/internal/sys/arch_386.go b/src/internal/goarch/goarch_386.go similarity index 95% rename from src/runtime/internal/sys/arch_386.go rename to src/internal/goarch/goarch_386.go index 1ebce3435e..c6214217fc 100644 --- a/src/runtime/internal/sys/arch_386.go +++ b/src/internal/goarch/goarch_386.go @@ -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 goarch const ( _ArchFamily = I386 diff --git a/src/runtime/internal/sys/arch_amd64.go b/src/internal/goarch/goarch_amd64.go similarity index 95% rename from src/runtime/internal/sys/arch_amd64.go rename to src/internal/goarch/goarch_amd64.go index 7f003d0f1d..911e3e7242 100644 --- a/src/runtime/internal/sys/arch_amd64.go +++ b/src/internal/goarch/goarch_amd64.go @@ -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 goarch const ( _ArchFamily = AMD64 diff --git a/src/runtime/internal/sys/arch_arm.go b/src/internal/goarch/goarch_arm.go similarity index 95% rename from src/runtime/internal/sys/arch_arm.go rename to src/internal/goarch/goarch_arm.go index ef2048bb71..a6591713c8 100644 --- a/src/runtime/internal/sys/arch_arm.go +++ b/src/internal/goarch/goarch_arm.go @@ -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 goarch const ( _ArchFamily = ARM diff --git a/src/runtime/internal/sys/arch_arm64.go b/src/internal/goarch/goarch_arm64.go similarity index 95% rename from src/runtime/internal/sys/arch_arm64.go rename to src/internal/goarch/goarch_arm64.go index b9f2f7b1fe..85d0b47639 100644 --- a/src/runtime/internal/sys/arch_arm64.go +++ b/src/internal/goarch/goarch_arm64.go @@ -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 goarch const ( _ArchFamily = ARM64 diff --git a/src/runtime/internal/sys/arch_mips.go b/src/internal/goarch/goarch_mips.go similarity index 95% rename from src/runtime/internal/sys/arch_mips.go rename to src/internal/goarch/goarch_mips.go index 4cb0eebea7..59f3995e2a 100644 --- a/src/runtime/internal/sys/arch_mips.go +++ b/src/internal/goarch/goarch_mips.go @@ -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 goarch const ( _ArchFamily = MIPS diff --git a/src/runtime/internal/sys/arch_mips64le.go b/src/internal/goarch/goarch_mips64.go similarity index 95% rename from src/runtime/internal/sys/arch_mips64le.go rename to src/internal/goarch/goarch_mips64.go index 57636ac4a4..9e4f82797d 100644 --- a/src/runtime/internal/sys/arch_mips64le.go +++ b/src/internal/goarch/goarch_mips64.go @@ -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 goarch const ( _ArchFamily = MIPS64 diff --git a/src/runtime/internal/sys/arch_mips64.go b/src/internal/goarch/goarch_mips64le.go similarity index 95% rename from src/runtime/internal/sys/arch_mips64.go rename to src/internal/goarch/goarch_mips64le.go index 57636ac4a4..9e4f82797d 100644 --- a/src/runtime/internal/sys/arch_mips64.go +++ b/src/internal/goarch/goarch_mips64le.go @@ -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 goarch const ( _ArchFamily = MIPS64 diff --git a/src/runtime/internal/sys/arch_mipsle.go b/src/internal/goarch/goarch_mipsle.go similarity index 95% rename from src/runtime/internal/sys/arch_mipsle.go rename to src/internal/goarch/goarch_mipsle.go index 4240f5ce47..3e6642bb86 100644 --- a/src/runtime/internal/sys/arch_mipsle.go +++ b/src/internal/goarch/goarch_mipsle.go @@ -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 goarch const ( _ArchFamily = MIPS diff --git a/src/runtime/internal/sys/arch_ppc64.go b/src/internal/goarch/goarch_ppc64.go similarity index 95% rename from src/runtime/internal/sys/arch_ppc64.go rename to src/internal/goarch/goarch_ppc64.go index 1869213ce2..60cc846e6a 100644 --- a/src/runtime/internal/sys/arch_ppc64.go +++ b/src/internal/goarch/goarch_ppc64.go @@ -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 goarch const ( _ArchFamily = PPC64 diff --git a/src/runtime/internal/sys/arch_ppc64le.go b/src/internal/goarch/goarch_ppc64le.go similarity index 95% rename from src/runtime/internal/sys/arch_ppc64le.go rename to src/internal/goarch/goarch_ppc64le.go index 1869213ce2..60cc846e6a 100644 --- a/src/runtime/internal/sys/arch_ppc64le.go +++ b/src/internal/goarch/goarch_ppc64le.go @@ -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 goarch const ( _ArchFamily = PPC64 diff --git a/src/runtime/internal/sys/arch_riscv64.go b/src/internal/goarch/goarch_riscv64.go similarity index 95% rename from src/runtime/internal/sys/arch_riscv64.go rename to src/internal/goarch/goarch_riscv64.go index 360d236e32..3b6da1e02f 100644 --- a/src/runtime/internal/sys/arch_riscv64.go +++ b/src/internal/goarch/goarch_riscv64.go @@ -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 goarch const ( _ArchFamily = RISCV64 diff --git a/src/runtime/internal/sys/arch_s390x.go b/src/internal/goarch/goarch_s390x.go similarity index 95% rename from src/runtime/internal/sys/arch_s390x.go rename to src/internal/goarch/goarch_s390x.go index e33e0b7f2b..20c5705581 100644 --- a/src/runtime/internal/sys/arch_s390x.go +++ b/src/internal/goarch/goarch_s390x.go @@ -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 goarch const ( _ArchFamily = S390X diff --git a/src/runtime/internal/sys/arch_wasm.go b/src/internal/goarch/goarch_wasm.go similarity index 95% rename from src/runtime/internal/sys/arch_wasm.go rename to src/internal/goarch/goarch_wasm.go index ee919ff9e6..98618d6980 100644 --- a/src/runtime/internal/sys/arch_wasm.go +++ b/src/internal/goarch/goarch_wasm.go @@ -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 goarch const ( _ArchFamily = WASM diff --git a/src/runtime/internal/sys/zgoarch_386.go b/src/internal/goarch/zgoarch_386.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_386.go rename to src/internal/goarch/zgoarch_386.go index 98a2401bfe..f424b5a6b9 100644 --- a/src/runtime/internal/sys/zgoarch_386.go +++ b/src/internal/goarch/zgoarch_386.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build 386 // +build 386 -package sys +package goarch const GOARCH = `386` diff --git a/src/runtime/internal/sys/zgoarch_amd64.go b/src/internal/goarch/zgoarch_amd64.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_amd64.go rename to src/internal/goarch/zgoarch_amd64.go index d8faa5c786..728896c367 100644 --- a/src/runtime/internal/sys/zgoarch_amd64.go +++ b/src/internal/goarch/zgoarch_amd64.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build amd64 // +build amd64 -package sys +package goarch const GOARCH = `amd64` diff --git a/src/runtime/internal/sys/zgoarch_arm.go b/src/internal/goarch/zgoarch_arm.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_arm.go rename to src/internal/goarch/zgoarch_arm.go index b64a69c9b4..9d388b0554 100644 --- a/src/runtime/internal/sys/zgoarch_arm.go +++ b/src/internal/goarch/zgoarch_arm.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build arm // +build arm -package sys +package goarch const GOARCH = `arm` diff --git a/src/runtime/internal/sys/zgoarch_arm64.go b/src/internal/goarch/zgoarch_arm64.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_arm64.go rename to src/internal/goarch/zgoarch_arm64.go index de6f85347b..a375ac8076 100644 --- a/src/runtime/internal/sys/zgoarch_arm64.go +++ b/src/internal/goarch/zgoarch_arm64.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build arm64 // +build arm64 -package sys +package goarch const GOARCH = `arm64` diff --git a/src/runtime/internal/sys/zgoarch_arm64be.go b/src/internal/goarch/zgoarch_arm64be.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_arm64be.go rename to src/internal/goarch/zgoarch_arm64be.go index b762bb069f..6fcc4f6bfa 100644 --- a/src/runtime/internal/sys/zgoarch_arm64be.go +++ b/src/internal/goarch/zgoarch_arm64be.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build arm64be // +build arm64be -package sys +package goarch const GOARCH = `arm64be` diff --git a/src/runtime/internal/sys/zgoarch_armbe.go b/src/internal/goarch/zgoarch_armbe.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_armbe.go rename to src/internal/goarch/zgoarch_armbe.go index e5297e4b16..a3ac487d80 100644 --- a/src/runtime/internal/sys/zgoarch_armbe.go +++ b/src/internal/goarch/zgoarch_armbe.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build armbe // +build armbe -package sys +package goarch const GOARCH = `armbe` diff --git a/src/runtime/internal/sys/zgoarch_mips.go b/src/internal/goarch/zgoarch_mips.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_mips.go rename to src/internal/goarch/zgoarch_mips.go index b5f4ed390c..00cfd90c3b 100644 --- a/src/runtime/internal/sys/zgoarch_mips.go +++ b/src/internal/goarch/zgoarch_mips.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build mips // +build mips -package sys +package goarch const GOARCH = `mips` diff --git a/src/runtime/internal/sys/zgoarch_mips64.go b/src/internal/goarch/zgoarch_mips64.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_mips64.go rename to src/internal/goarch/zgoarch_mips64.go index 73777cceb2..947db612eb 100644 --- a/src/runtime/internal/sys/zgoarch_mips64.go +++ b/src/internal/goarch/zgoarch_mips64.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build mips64 // +build mips64 -package sys +package goarch const GOARCH = `mips64` diff --git a/src/runtime/internal/sys/zgoarch_mips64le.go b/src/internal/goarch/zgoarch_mips64le.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_mips64le.go rename to src/internal/goarch/zgoarch_mips64le.go index 0c81c36c09..35ffbe2d3f 100644 --- a/src/runtime/internal/sys/zgoarch_mips64le.go +++ b/src/internal/goarch/zgoarch_mips64le.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build mips64le // +build mips64le -package sys +package goarch const GOARCH = `mips64le` diff --git a/src/runtime/internal/sys/zgoarch_mips64p32.go b/src/internal/goarch/zgoarch_mips64p32.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_mips64p32.go rename to src/internal/goarch/zgoarch_mips64p32.go index d63ce27d24..c7c712032b 100644 --- a/src/runtime/internal/sys/zgoarch_mips64p32.go +++ b/src/internal/goarch/zgoarch_mips64p32.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build mips64p32 // +build mips64p32 -package sys +package goarch const GOARCH = `mips64p32` diff --git a/src/runtime/internal/sys/zgoarch_mips64p32le.go b/src/internal/goarch/zgoarch_mips64p32le.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_mips64p32le.go rename to src/internal/goarch/zgoarch_mips64p32le.go index 2d577890b2..f605a6ff78 100644 --- a/src/runtime/internal/sys/zgoarch_mips64p32le.go +++ b/src/internal/goarch/zgoarch_mips64p32le.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build mips64p32le // +build mips64p32le -package sys +package goarch const GOARCH = `mips64p32le` diff --git a/src/runtime/internal/sys/zgoarch_mipsle.go b/src/internal/goarch/zgoarch_mipsle.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_mipsle.go rename to src/internal/goarch/zgoarch_mipsle.go index 8af919d03a..56e24dc7b3 100644 --- a/src/runtime/internal/sys/zgoarch_mipsle.go +++ b/src/internal/goarch/zgoarch_mipsle.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build mipsle // +build mipsle -package sys +package goarch const GOARCH = `mipsle` diff --git a/src/runtime/internal/sys/zgoarch_ppc.go b/src/internal/goarch/zgoarch_ppc.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_ppc.go rename to src/internal/goarch/zgoarch_ppc.go index f6f12a5ddc..4617d12792 100644 --- a/src/runtime/internal/sys/zgoarch_ppc.go +++ b/src/internal/goarch/zgoarch_ppc.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build ppc // +build ppc -package sys +package goarch const GOARCH = `ppc` diff --git a/src/runtime/internal/sys/zgoarch_ppc64.go b/src/internal/goarch/zgoarch_ppc64.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_ppc64.go rename to src/internal/goarch/zgoarch_ppc64.go index a8379601f4..f3cb16e9b6 100644 --- a/src/runtime/internal/sys/zgoarch_ppc64.go +++ b/src/internal/goarch/zgoarch_ppc64.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build ppc64 // +build ppc64 -package sys +package goarch const GOARCH = `ppc64` diff --git a/src/runtime/internal/sys/zgoarch_ppc64le.go b/src/internal/goarch/zgoarch_ppc64le.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_ppc64le.go rename to src/internal/goarch/zgoarch_ppc64le.go index f2ec5dcba7..b70abfb953 100644 --- a/src/runtime/internal/sys/zgoarch_ppc64le.go +++ b/src/internal/goarch/zgoarch_ppc64le.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build ppc64le // +build ppc64le -package sys +package goarch const GOARCH = `ppc64le` diff --git a/src/runtime/internal/sys/zgoarch_riscv.go b/src/internal/goarch/zgoarch_riscv.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_riscv.go rename to src/internal/goarch/zgoarch_riscv.go index 83a3312f5f..f72973fbc5 100644 --- a/src/runtime/internal/sys/zgoarch_riscv.go +++ b/src/internal/goarch/zgoarch_riscv.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build riscv // +build riscv -package sys +package goarch const GOARCH = `riscv` diff --git a/src/runtime/internal/sys/zgoarch_riscv64.go b/src/internal/goarch/zgoarch_riscv64.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_riscv64.go rename to src/internal/goarch/zgoarch_riscv64.go index 1dfcc84997..5d09b63a03 100644 --- a/src/runtime/internal/sys/zgoarch_riscv64.go +++ b/src/internal/goarch/zgoarch_riscv64.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build riscv64 // +build riscv64 -package sys +package goarch const GOARCH = `riscv64` diff --git a/src/runtime/internal/sys/zgoarch_s390.go b/src/internal/goarch/zgoarch_s390.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_s390.go rename to src/internal/goarch/zgoarch_s390.go index 91aba5a0f6..0ceffe6c2e 100644 --- a/src/runtime/internal/sys/zgoarch_s390.go +++ b/src/internal/goarch/zgoarch_s390.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build s390 // +build s390 -package sys +package goarch const GOARCH = `s390` diff --git a/src/runtime/internal/sys/zgoarch_s390x.go b/src/internal/goarch/zgoarch_s390x.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_s390x.go rename to src/internal/goarch/zgoarch_s390x.go index edce50234e..142bc0f1e3 100644 --- a/src/runtime/internal/sys/zgoarch_s390x.go +++ b/src/internal/goarch/zgoarch_s390x.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build s390x // +build s390x -package sys +package goarch const GOARCH = `s390x` diff --git a/src/runtime/internal/sys/zgoarch_sparc.go b/src/internal/goarch/zgoarch_sparc.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_sparc.go rename to src/internal/goarch/zgoarch_sparc.go index 5ae9560ab0..62452b9d38 100644 --- a/src/runtime/internal/sys/zgoarch_sparc.go +++ b/src/internal/goarch/zgoarch_sparc.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build sparc // +build sparc -package sys +package goarch const GOARCH = `sparc` diff --git a/src/runtime/internal/sys/zgoarch_sparc64.go b/src/internal/goarch/zgoarch_sparc64.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_sparc64.go rename to src/internal/goarch/zgoarch_sparc64.go index e2a0134aff..5149507917 100644 --- a/src/runtime/internal/sys/zgoarch_sparc64.go +++ b/src/internal/goarch/zgoarch_sparc64.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build sparc64 // +build sparc64 -package sys +package goarch const GOARCH = `sparc64` diff --git a/src/runtime/internal/sys/zgoarch_wasm.go b/src/internal/goarch/zgoarch_wasm.go similarity index 87% rename from src/runtime/internal/sys/zgoarch_wasm.go rename to src/internal/goarch/zgoarch_wasm.go index 52e85dea37..fd25e93e74 100644 --- a/src/runtime/internal/sys/zgoarch_wasm.go +++ b/src/internal/goarch/zgoarch_wasm.go @@ -1,9 +1,9 @@ -// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. +// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT. //go:build wasm // +build wasm -package sys +package goarch const GOARCH = `wasm` diff --git a/src/runtime/internal/sys/gengoos.go b/src/internal/goos/gengoos.go similarity index 59% rename from src/runtime/internal/sys/gengoos.go rename to src/internal/goos/gengoos.go index ffe962f71d..ebcdfec3ba 100644 --- a/src/runtime/internal/sys/gengoos.go +++ b/src/internal/goos/gengoos.go @@ -16,17 +16,14 @@ import ( "strings" ) -var gooses, goarches []string +var gooses []string func main() { - data, err := os.ReadFile("../../../go/build/syslist.go") + data, err := os.ReadFile("../../go/build/syslist.go") if err != nil { log.Fatal(err) } - const ( - goosPrefix = `const goosList = ` - goarchPrefix = `const goarchList = ` - ) + const goosPrefix = `const goosList = ` for _, line := range strings.Split(string(data), "\n") { if strings.HasPrefix(line, goosPrefix) { text, err := strconv.Unquote(strings.TrimPrefix(line, goosPrefix)) @@ -35,13 +32,6 @@ func main() { } gooses = strings.Fields(text) } - if strings.HasPrefix(line, goarchPrefix) { - text, err := strconv.Unquote(strings.TrimPrefix(line, goarchPrefix)) - if err != nil { - log.Fatalf("parsing goarchList: %v", err) - } - goarches = strings.Fields(text) - } } for _, target := range gooses { @@ -63,7 +53,7 @@ func main() { fmt.Fprintf(&buf, "// Code generated by gengoos.go using 'go generate'. DO NOT EDIT.\n\n") fmt.Fprintf(&buf, "//go:build %s\n", strings.Join(tags, " && ")) fmt.Fprintf(&buf, "// +build %s\n\n", strings.Join(tags, ",")) - fmt.Fprintf(&buf, "package sys\n\n") + fmt.Fprintf(&buf, "package goos\n\n") fmt.Fprintf(&buf, "const GOOS = `%s`\n\n", target) for _, goos := range gooses { value := 0 @@ -77,27 +67,4 @@ func main() { log.Fatal(err) } } - - for _, target := range goarches { - if target == "amd64p32" { - continue - } - var buf bytes.Buffer - fmt.Fprintf(&buf, "// Code generated by gengoos.go using 'go generate'. DO NOT EDIT.\n\n") - fmt.Fprintf(&buf, "//go:build %s\n", target) - fmt.Fprintf(&buf, "// +build %s\n\n", target) // must explicitly include target for bootstrapping purposes - fmt.Fprintf(&buf, "package sys\n\n") - fmt.Fprintf(&buf, "const GOARCH = `%s`\n\n", target) - for _, goarch := range goarches { - value := 0 - if goarch == target { - value = 1 - } - fmt.Fprintf(&buf, "const Goarch%s = %d\n", strings.Title(goarch), value) - } - err := os.WriteFile("zgoarch_"+target+".go", buf.Bytes(), 0666) - if err != nil { - log.Fatal(err) - } - } } diff --git a/src/internal/goos/goos.go b/src/internal/goos/goos.go new file mode 100644 index 0000000000..332cf51e5d --- /dev/null +++ b/src/internal/goos/goos.go @@ -0,0 +1,12 @@ +// Copyright 2015 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 goos contains GOOS-specific constants. +package goos + +// The next line makes 'go generate' write the zgoos*.go files with +// per-OS information, including constants named Goos$GOOS for every +// known GOOS. The constant is 1 on the current system, 0 otherwise; +// multiplying by them is useful for defining GOOS-specific constants. +//go:generate go run gengoos.go diff --git a/src/runtime/internal/sys/zgoos_aix.go b/src/internal/goos/zgoos_aix.go similarity index 97% rename from src/runtime/internal/sys/zgoos_aix.go rename to src/internal/goos/zgoos_aix.go index f3b907471f..f453a8a0a8 100644 --- a/src/runtime/internal/sys/zgoos_aix.go +++ b/src/internal/goos/zgoos_aix.go @@ -3,7 +3,7 @@ //go:build aix // +build aix -package sys +package goos const GOOS = `aix` diff --git a/src/runtime/internal/sys/zgoos_android.go b/src/internal/goos/zgoos_android.go similarity index 97% rename from src/runtime/internal/sys/zgoos_android.go rename to src/internal/goos/zgoos_android.go index e28baf7c48..d90c04f758 100644 --- a/src/runtime/internal/sys/zgoos_android.go +++ b/src/internal/goos/zgoos_android.go @@ -3,7 +3,7 @@ //go:build android // +build android -package sys +package goos const GOOS = `android` diff --git a/src/runtime/internal/sys/zgoos_darwin.go b/src/internal/goos/zgoos_darwin.go similarity index 97% rename from src/runtime/internal/sys/zgoos_darwin.go rename to src/internal/goos/zgoos_darwin.go index 3c7f7b543e..18f6c28b12 100644 --- a/src/runtime/internal/sys/zgoos_darwin.go +++ b/src/internal/goos/zgoos_darwin.go @@ -3,7 +3,7 @@ //go:build !ios && darwin // +build !ios,darwin -package sys +package goos const GOOS = `darwin` diff --git a/src/runtime/internal/sys/zgoos_dragonfly.go b/src/internal/goos/zgoos_dragonfly.go similarity index 97% rename from src/runtime/internal/sys/zgoos_dragonfly.go rename to src/internal/goos/zgoos_dragonfly.go index f844d29e2a..a658d1d07f 100644 --- a/src/runtime/internal/sys/zgoos_dragonfly.go +++ b/src/internal/goos/zgoos_dragonfly.go @@ -3,7 +3,7 @@ //go:build dragonfly // +build dragonfly -package sys +package goos const GOOS = `dragonfly` diff --git a/src/runtime/internal/sys/zgoos_freebsd.go b/src/internal/goos/zgoos_freebsd.go similarity index 97% rename from src/runtime/internal/sys/zgoos_freebsd.go rename to src/internal/goos/zgoos_freebsd.go index 8999a2797a..2534eb8c6f 100644 --- a/src/runtime/internal/sys/zgoos_freebsd.go +++ b/src/internal/goos/zgoos_freebsd.go @@ -3,7 +3,7 @@ //go:build freebsd // +build freebsd -package sys +package goos const GOOS = `freebsd` diff --git a/src/runtime/internal/sys/zgoos_hurd.go b/src/internal/goos/zgoos_hurd.go similarity index 97% rename from src/runtime/internal/sys/zgoos_hurd.go rename to src/internal/goos/zgoos_hurd.go index a546488bf8..3fefb1fbb1 100644 --- a/src/runtime/internal/sys/zgoos_hurd.go +++ b/src/internal/goos/zgoos_hurd.go @@ -3,7 +3,7 @@ //go:build hurd // +build hurd -package sys +package goos const GOOS = `hurd` diff --git a/src/runtime/internal/sys/zgoos_illumos.go b/src/internal/goos/zgoos_illumos.go similarity index 97% rename from src/runtime/internal/sys/zgoos_illumos.go rename to src/internal/goos/zgoos_illumos.go index 02a4ca06e8..77495a3369 100644 --- a/src/runtime/internal/sys/zgoos_illumos.go +++ b/src/internal/goos/zgoos_illumos.go @@ -3,7 +3,7 @@ //go:build illumos // +build illumos -package sys +package goos const GOOS = `illumos` diff --git a/src/runtime/internal/sys/zgoos_ios.go b/src/internal/goos/zgoos_ios.go similarity index 97% rename from src/runtime/internal/sys/zgoos_ios.go rename to src/internal/goos/zgoos_ios.go index 033eec623d..92820fe77e 100644 --- a/src/runtime/internal/sys/zgoos_ios.go +++ b/src/internal/goos/zgoos_ios.go @@ -3,7 +3,7 @@ //go:build ios // +build ios -package sys +package goos const GOOS = `ios` diff --git a/src/runtime/internal/sys/zgoos_js.go b/src/internal/goos/zgoos_js.go similarity index 97% rename from src/runtime/internal/sys/zgoos_js.go rename to src/internal/goos/zgoos_js.go index 28226ad60a..6331a5c3f1 100644 --- a/src/runtime/internal/sys/zgoos_js.go +++ b/src/internal/goos/zgoos_js.go @@ -3,7 +3,7 @@ //go:build js // +build js -package sys +package goos const GOOS = `js` diff --git a/src/runtime/internal/sys/zgoos_linux.go b/src/internal/goos/zgoos_linux.go similarity index 97% rename from src/runtime/internal/sys/zgoos_linux.go rename to src/internal/goos/zgoos_linux.go index 01546e4b9f..aa4e2d3145 100644 --- a/src/runtime/internal/sys/zgoos_linux.go +++ b/src/internal/goos/zgoos_linux.go @@ -3,7 +3,7 @@ //go:build !android && linux // +build !android,linux -package sys +package goos const GOOS = `linux` diff --git a/src/runtime/internal/sys/zgoos_netbsd.go b/src/internal/goos/zgoos_netbsd.go similarity index 97% rename from src/runtime/internal/sys/zgoos_netbsd.go rename to src/internal/goos/zgoos_netbsd.go index 9d658b20ee..39635104c0 100644 --- a/src/runtime/internal/sys/zgoos_netbsd.go +++ b/src/internal/goos/zgoos_netbsd.go @@ -3,7 +3,7 @@ //go:build netbsd // +build netbsd -package sys +package goos const GOOS = `netbsd` diff --git a/src/runtime/internal/sys/zgoos_openbsd.go b/src/internal/goos/zgoos_openbsd.go similarity index 97% rename from src/runtime/internal/sys/zgoos_openbsd.go rename to src/internal/goos/zgoos_openbsd.go index 0f55454a95..61d4ac8bb0 100644 --- a/src/runtime/internal/sys/zgoos_openbsd.go +++ b/src/internal/goos/zgoos_openbsd.go @@ -3,7 +3,7 @@ //go:build openbsd // +build openbsd -package sys +package goos const GOOS = `openbsd` diff --git a/src/runtime/internal/sys/zgoos_plan9.go b/src/internal/goos/zgoos_plan9.go similarity index 97% rename from src/runtime/internal/sys/zgoos_plan9.go rename to src/internal/goos/zgoos_plan9.go index d0347464d6..7f0dc2fa04 100644 --- a/src/runtime/internal/sys/zgoos_plan9.go +++ b/src/internal/goos/zgoos_plan9.go @@ -3,7 +3,7 @@ //go:build plan9 // +build plan9 -package sys +package goos const GOOS = `plan9` diff --git a/src/runtime/internal/sys/zgoos_solaris.go b/src/internal/goos/zgoos_solaris.go similarity index 97% rename from src/runtime/internal/sys/zgoos_solaris.go rename to src/internal/goos/zgoos_solaris.go index 05c3007e2c..7497324a4f 100644 --- a/src/runtime/internal/sys/zgoos_solaris.go +++ b/src/internal/goos/zgoos_solaris.go @@ -3,7 +3,7 @@ //go:build !illumos && solaris // +build !illumos,solaris -package sys +package goos const GOOS = `solaris` diff --git a/src/runtime/internal/sys/zgoos_windows.go b/src/internal/goos/zgoos_windows.go similarity index 97% rename from src/runtime/internal/sys/zgoos_windows.go rename to src/internal/goos/zgoos_windows.go index 7d07fa3a45..e316b80c82 100644 --- a/src/runtime/internal/sys/zgoos_windows.go +++ b/src/internal/goos/zgoos_windows.go @@ -3,7 +3,7 @@ //go:build windows // +build windows -package sys +package goos const GOOS = `windows` diff --git a/src/runtime/internal/sys/zgoos_zos.go b/src/internal/goos/zgoos_zos.go similarity index 97% rename from src/runtime/internal/sys/zgoos_zos.go rename to src/internal/goos/zgoos_zos.go index d6e5b9b0cb..26471f4f36 100644 --- a/src/runtime/internal/sys/zgoos_zos.go +++ b/src/internal/goos/zgoos_zos.go @@ -3,7 +3,7 @@ //go:build zos // +build zos -package sys +package goos const GOOS = `zos` diff --git a/src/runtime/internal/sys/consts.go b/src/runtime/internal/sys/consts.go new file mode 100644 index 0000000000..815f789380 --- /dev/null +++ b/src/runtime/internal/sys/consts.go @@ -0,0 +1,109 @@ +// Copyright 2014 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/goarch" + "internal/goos" +) + +type ArchFamilyType = goarch.ArchFamilyType + +const ( + AMD64 = goarch.AMD64 + ARM = goarch.ARM + ARM64 = goarch.ARM64 + I386 = goarch.I386 + MIPS = goarch.MIPS + MIPS64 = goarch.MIPS64 + PPC64 = goarch.PPC64 + RISCV64 = goarch.RISCV64 + S390X = goarch.S390X + WASM = goarch.WASM +) + +// PtrSize is the size of a pointer in bytes - unsafe.Sizeof(uintptr(0)) but as an ideal constant. +// It is also the size of the machine's native word size (that is, 4 on 32-bit systems, 8 on 64-bit). +const PtrSize = goarch.PtrSize + +// ArchFamily is the architecture family (AMD64, ARM, ...) +const ArchFamily ArchFamilyType = goarch.ArchFamily + +// AIX requires a larger stack for syscalls. +const StackGuardMultiplier = StackGuardMultiplierDefault*(1-goos.GoosAix) + 2*goos.GoosAix + +// BigEndian reports whether the architecture is big-endian. +const BigEndian = goarch.BigEndian + +// DefaultPhysPageSize is the default physical page size. +const DefaultPhysPageSize = goarch.DefaultPhysPageSize + +// PCQuantum is the minimal unit for a program counter (1 on x86, 4 on most other systems). +// The various PC tables record PC deltas pre-divided by PCQuantum. +const PCQuantum = goarch.PCQuantum + +// Int64Align is the required alignment for a 64-bit integer (4 on 32-bit systems, 8 on 64-bit). +const Int64Align = goarch.PtrSize + +// MinFrameSize is the size of the system-reserved words at the bottom +// of a frame (just above the architectural stack pointer). +// It is zero on x86 and PtrSize on most non-x86 (LR-based) systems. +// On PowerPC it is larger, to cover three more reserved words: +// the compiler word, the link editor word, and the TOC save word. +const MinFrameSize = goarch.MinFrameSize + +// StackAlign is the required alignment of the SP register. +// The stack must be at least word aligned, but some architectures require more. +const StackAlign = goarch.StackAlign + +const GOARCH = goarch.GOARCH + +const ( + Goarch386 = goarch.Goarch386 + GoarchAmd64 = goarch.GoarchAmd64 + GoarchAmd64p32 = goarch.GoarchAmd64p32 + GoarchArm = goarch.GoarchArm + GoarchArmbe = goarch.GoarchArmbe + GoarchArm64 = goarch.GoarchArm64 + GoarchArm64be = goarch.GoarchArm64be + GoarchPpc64 = goarch.GoarchPpc64 + GoarchPpc64le = goarch.GoarchPpc64le + GoarchMips = goarch.GoarchMips + GoarchMipsle = goarch.GoarchMipsle + GoarchMips64 = goarch.GoarchMips64 + GoarchMips64le = goarch.GoarchMips64le + GoarchMips64p32 = goarch.GoarchMips64p32 + GoarchMips64p32le = goarch.GoarchMips64p32le + GoarchPpc = goarch.GoarchPpc + GoarchRiscv = goarch.GoarchRiscv + GoarchRiscv64 = goarch.GoarchRiscv64 + GoarchS390 = goarch.GoarchS390 + GoarchS390x = goarch.GoarchS390x + GoarchSparc = goarch.GoarchSparc + GoarchSparc64 = goarch.GoarchSparc64 + GoarchWasm = goarch.GoarchWasm +) + +const GOOS = goos.GOOS + +const ( + GoosAix = goos.GoosAix + GoosAndroid = goos.GoosAndroid + GoosDarwin = goos.GoosDarwin + GoosDragonfly = goos.GoosDragonfly + GoosFreebsd = goos.GoosFreebsd + GoosHurd = goos.GoosHurd + GoosIllumos = goos.GoosIllumos + GoosIos = goos.GoosIos + GoosJs = goos.GoosJs + GoosLinux = goos.GoosLinux + GoosNacl = goos.GoosNacl + GoosNetbsd = goos.GoosNetbsd + GoosOpenbsd = goos.GoosOpenbsd + GoosPlan9 = goos.GoosPlan9 + GoosSolaris = goos.GoosSolaris + GoosWindows = goos.GoosWindows + GoosZos = goos.GoosZos +) diff --git a/src/runtime/internal/sys/sys.go b/src/runtime/internal/sys/sys.go index 9d9ac4507f..694101d36f 100644 --- a/src/runtime/internal/sys/sys.go +++ b/src/runtime/internal/sys/sys.go @@ -5,11 +5,3 @@ // package sys contains system- and configuration- and architecture-specific // constants used by the runtime. package sys - -// The next line makes 'go generate' write the zgo*.go files with -// per-OS and per-arch information, including constants -// named Goos$GOOS and Goarch$GOARCH for every -// known GOOS and GOARCH. The constant is 1 on the -// current system, 0 otherwise; multiplying by them is -// useful for defining GOOS- or GOARCH-specific constants. -//go:generate go run gengoos.go