Skip to content

Commit

Permalink
internal/buildcfg: move build configuration out of cmd/internal/objabi
Browse files Browse the repository at this point in the history
The go/build package needs access to this configuration,
so move it into a new package available to the standard library.

Change-Id: I868a94148b52350c76116451f4ad9191246adcff
Reviewed-on: https://go-review.googlesource.com/c/go/+/310731
Trust: Russ Cox <[email protected]>
Run-TryBot: Russ Cox <[email protected]>
Reviewed-by: Austin Clements <[email protected]>
Reviewed-by: Jay Conrod <[email protected]>
  • Loading branch information
rsc committed Apr 16, 2021
1 parent 2fc0ebb commit 95ed5c3
Show file tree
Hide file tree
Showing 94 changed files with 674 additions and 549 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ _testmain.go
/src/cmd/internal/objabi/zbootstrap.go
/src/go/build/zcgo.go
/src/go/doc/headscan
/src/internal/buildcfg/zbootstrap.go
/src/runtime/internal/sys/zversion.go
/src/unicode/maketables
/test.out
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/asm/internal/asm/endtoend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bufio"
"bytes"
"fmt"
"internal/buildcfg"
"io/ioutil"
"os"
"path/filepath"
Expand All @@ -19,7 +20,6 @@ import (

"cmd/asm/internal/lex"
"cmd/internal/obj"
"cmd/internal/objabi"
)

// An end-to-end test for the assembler: Do we print what we parse?
Expand Down Expand Up @@ -368,10 +368,10 @@ func Test386EndToEnd(t *testing.T) {
}

func TestARMEndToEnd(t *testing.T) {
defer func(old int) { objabi.GOARM = old }(objabi.GOARM)
defer func(old int) { buildcfg.GOARM = old }(buildcfg.GOARM)
for _, goarm := range []int{5, 6, 7} {
t.Logf("GOARM=%d", goarm)
objabi.GOARM = goarm
buildcfg.GOARM = goarm
testEndToEnd(t, "arm", "arm")
if goarm == 6 {
testEndToEnd(t, "arm", "armv6")
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/asm/internal/asm/operand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
package asm

import (
"internal/buildcfg"
"strings"
"testing"

"cmd/asm/internal/arch"
"cmd/asm/internal/lex"
"cmd/internal/obj"
"cmd/internal/objabi"
)

// A simple in-out test: Do we print what we parse?

func setArch(goarch string) (*arch.Arch, *obj.Link) {
objabi.GOOS = "linux" // obj can handle this OS for all architectures.
objabi.GOARCH = goarch
buildcfg.GOOS = "linux" // obj can handle this OS for all architectures.
buildcfg.GOARCH = goarch
architecture := arch.Set(goarch)
if architecture == nil {
panic("asm: unrecognized architecture " + goarch)
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/asm/internal/lex/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package lex

import (
"fmt"
"internal/buildcfg"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -49,7 +50,7 @@ func predefine(defines flags.MultiFlag) map[string]*Macro {
// Set macros for GOEXPERIMENTs so we can easily switch
// runtime assembly code based on them.
if *flags.CompilingRuntime {
for _, exp := range objabi.EnabledExperiments() {
for _, exp := range buildcfg.EnabledExperiments() {
// Define macro.
name := "GOEXPERIMENT_" + exp
macros[name] = &Macro{
Expand Down
7 changes: 4 additions & 3 deletions src/cmd/asm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bufio"
"flag"
"fmt"
"internal/buildcfg"
"log"
"os"

Expand All @@ -18,14 +19,14 @@ import (

"cmd/internal/bio"
"cmd/internal/obj"
"cmd/internal/objabi"
)

func main() {
log.SetFlags(0)
log.SetPrefix("asm: ")

GOARCH := objabi.GOARCH
buildcfg.Check()
GOARCH := buildcfg.GOARCH

architecture := arch.Set(GOARCH)
if architecture == nil {
Expand Down Expand Up @@ -68,7 +69,7 @@ func main() {
defer buf.Close()

if !*flags.SymABIs {
fmt.Fprintf(buf, "go object %s %s %s\n", objabi.GOOS, objabi.GOARCH, objabi.Version)
fmt.Fprintf(buf, "go object %s %s %s\n", buildcfg.GOOS, buildcfg.GOARCH, buildcfg.Version)
fmt.Fprintf(buf, "!\n")
}

Expand Down
6 changes: 4 additions & 2 deletions src/cmd/cgo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"go/ast"
"go/printer"
"go/token"
"internal/buildcfg"
"io"
"io/ioutil"
"os"
Expand Down Expand Up @@ -414,8 +415,9 @@ func newPackage(args []string) *Package {
if s := os.Getenv("GOOS"); s != "" {
goos = s
}
gomips = objabi.GOMIPS
gomips64 = objabi.GOMIPS64
buildcfg.Check()
gomips = buildcfg.GOMIPS
gomips64 = buildcfg.GOMIPS64
ptrSize := ptrSizeMap[goarch]
if ptrSize == 0 {
fatalf("unknown ptrSize for $GOARCH %q", goarch)
Expand Down
8 changes: 4 additions & 4 deletions src/cmd/compile/internal/amd64/ggen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
"cmd/compile/internal/types"
"cmd/internal/obj"
"cmd/internal/obj/x86"
"cmd/internal/objabi"
"internal/buildcfg"
)

// no floating point in note handlers on Plan 9
var isPlan9 = objabi.GOOS == "plan9"
var isPlan9 = buildcfg.GOOS == "plan9"

// DUFFZERO consists of repeated blocks of 4 MOVUPSs + LEAQ,
// See runtime/mkduff.go.
Expand Down Expand Up @@ -85,7 +85,7 @@ func zerorange(pp *objw.Progs, p *obj.Prog, off, cnt int64, state *uint32) *obj.
}
p = pp.Append(p, x86.AMOVQ, obj.TYPE_REG, x86.REG_R13, 0, obj.TYPE_MEM, x86.REG_SP, off)
} else if !isPlan9 && cnt <= int64(8*types.RegSize) {
if !objabi.Experiment.RegabiG && *state&x15 == 0 {
if !buildcfg.Experiment.RegabiG && *state&x15 == 0 {
p = pp.Append(p, x86.AXORPS, obj.TYPE_REG, x86.REG_X15, 0, obj.TYPE_REG, x86.REG_X15, 0)
*state |= x15
}
Expand All @@ -98,7 +98,7 @@ func zerorange(pp *objw.Progs, p *obj.Prog, off, cnt int64, state *uint32) *obj.
p = pp.Append(p, x86.AMOVUPS, obj.TYPE_REG, x86.REG_X15, 0, obj.TYPE_MEM, x86.REG_SP, off+cnt-int64(16))
}
} else if !isPlan9 && (cnt <= int64(128*types.RegSize)) {
if !objabi.Experiment.RegabiG && *state&x15 == 0 {
if !buildcfg.Experiment.RegabiG && *state&x15 == 0 {
p = pp.Append(p, x86.AXORPS, obj.TYPE_REG, x86.REG_X15, 0, obj.TYPE_REG, x86.REG_X15, 0)
*state |= x15
}
Expand Down
14 changes: 7 additions & 7 deletions src/cmd/compile/internal/amd64/ssa.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package amd64

import (
"fmt"
"internal/buildcfg"
"math"

"cmd/compile/internal/base"
Expand All @@ -17,7 +18,6 @@ import (
"cmd/compile/internal/types"
"cmd/internal/obj"
"cmd/internal/obj/x86"
"cmd/internal/objabi"
)

// markMoves marks any MOVXconst ops that need to avoid clobbering flags.
Expand Down Expand Up @@ -825,7 +825,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
p.To.Reg = v.Args[0].Reg()
ssagen.AddAux2(&p.To, v, sc.Off64())
case ssa.OpAMD64MOVOstorezero:
if !objabi.Experiment.RegabiG || s.ABI != obj.ABIInternal {
if !buildcfg.Experiment.RegabiG || s.ABI != obj.ABIInternal {
// zero X15 manually
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
}
Expand Down Expand Up @@ -916,7 +916,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
p.To.Type = obj.TYPE_REG
p.To.Reg = v.Reg()
case ssa.OpAMD64DUFFZERO:
if !objabi.Experiment.RegabiG || s.ABI != obj.ABIInternal {
if !buildcfg.Experiment.RegabiG || s.ABI != obj.ABIInternal {
// zero X15 manually
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
}
Expand Down Expand Up @@ -999,20 +999,20 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
// Closure pointer is DX.
ssagen.CheckLoweredGetClosurePtr(v)
case ssa.OpAMD64LoweredGetG:
if objabi.Experiment.RegabiG && s.ABI == obj.ABIInternal {
if buildcfg.Experiment.RegabiG && s.ABI == obj.ABIInternal {
v.Fatalf("LoweredGetG should not appear in ABIInternal")
}
r := v.Reg()
getgFromTLS(s, r)
case ssa.OpAMD64CALLstatic:
if objabi.Experiment.RegabiG && s.ABI == obj.ABI0 && v.Aux.(*ssa.AuxCall).Fn.ABI() == obj.ABIInternal {
if buildcfg.Experiment.RegabiG && s.ABI == obj.ABI0 && v.Aux.(*ssa.AuxCall).Fn.ABI() == obj.ABIInternal {
// zeroing X15 when entering ABIInternal from ABI0
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
// set G register from TLS
getgFromTLS(s, x86.REG_R14)
}
s.Call(v)
if objabi.Experiment.RegabiG && s.ABI == obj.ABIInternal && v.Aux.(*ssa.AuxCall).Fn.ABI() == obj.ABI0 {
if buildcfg.Experiment.RegabiG && s.ABI == obj.ABIInternal && v.Aux.(*ssa.AuxCall).Fn.ABI() == obj.ABI0 {
// zeroing X15 when entering ABIInternal from ABI0
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
// set G register from TLS
Expand Down Expand Up @@ -1306,7 +1306,7 @@ func ssaGenBlock(s *ssagen.State, b, next *ssa.Block) {
case ssa.BlockRet:
s.Prog(obj.ARET)
case ssa.BlockRetJmp:
if objabi.Experiment.RegabiG && s.ABI == obj.ABI0 && b.Aux.(*obj.LSym).ABI() == obj.ABIInternal {
if buildcfg.Experiment.RegabiG && s.ABI == obj.ABI0 && b.Aux.(*obj.LSym).ABI() == obj.ABIInternal {
// zeroing X15 when entering ABIInternal from ABI0
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
// set G register from TLS
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/arm/galign.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"cmd/compile/internal/ssa"
"cmd/compile/internal/ssagen"
"cmd/internal/obj/arm"
"cmd/internal/objabi"
"internal/buildcfg"
)

func Init(arch *ssagen.ArchInfo) {
arch.LinkArch = &arm.Linkarm
arch.REGSP = arm.REGSP
arch.MAXWIDTH = (1 << 32) - 1
arch.SoftFloat = objabi.GOARM == 5
arch.SoftFloat = buildcfg.GOARM == 5
arch.ZeroRange = zerorange
arch.Ginsnop = ginsnop
arch.Ginsnopdefer = ginsnop
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/compile/internal/arm/ssa.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package arm

import (
"fmt"
"internal/buildcfg"
"math"
"math/bits"

Expand All @@ -17,7 +18,6 @@ import (
"cmd/compile/internal/types"
"cmd/internal/obj"
"cmd/internal/obj/arm"
"cmd/internal/objabi"
)

// loadByType returns the load instruction of the given type.
Expand Down Expand Up @@ -286,7 +286,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
case ssa.OpARMANDconst, ssa.OpARMBICconst:
// try to optimize ANDconst and BICconst to BFC, which saves bytes and ticks
// BFC is only available on ARMv7, and its result and source are in the same register
if objabi.GOARM == 7 && v.Reg() == v.Args[0].Reg() {
if buildcfg.GOARM == 7 && v.Reg() == v.Args[0].Reg() {
var val uint32
if v.Op == ssa.OpARMANDconst {
val = ^uint32(v.AuxInt)
Expand Down Expand Up @@ -643,7 +643,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
default:
}
}
if objabi.GOARM >= 6 {
if buildcfg.GOARM >= 6 {
// generate more efficient "MOVB/MOVBU/MOVH/MOVHU Reg@>0, Reg" on ARMv6 & ARMv7
genshift(s, v.Op.Asm(), 0, v.Args[0].Reg(), v.Reg(), arm.SHIFT_RR, 0)
return
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/arm64/ggen.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"cmd/compile/internal/types"
"cmd/internal/obj"
"cmd/internal/obj/arm64"
"cmd/internal/objabi"
"internal/buildcfg"
)

var darwin = objabi.GOOS == "darwin" || objabi.GOOS == "ios"
var darwin = buildcfg.GOOS == "darwin" || buildcfg.GOOS == "ios"

func padframe(frame int64) int64 {
// arm64 requires that the frame size (not counting saved FP&LR)
Expand Down
19 changes: 10 additions & 9 deletions src/cmd/compile/internal/base/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"flag"
"fmt"
"internal/buildcfg"
"io/ioutil"
"log"
"os"
Expand Down Expand Up @@ -146,7 +147,7 @@ func ParseFlags() {
Flag.LowerP = &Ctxt.Pkgpath
Flag.LowerV = &Ctxt.Debugvlog

Flag.Dwarf = objabi.GOARCH != "wasm"
Flag.Dwarf = buildcfg.GOARCH != "wasm"
Flag.DwarfBASEntries = &Ctxt.UseBASEntries
Flag.DwarfLocationLists = &Ctxt.Flag_locationlists
*Flag.DwarfLocationLists = true
Expand All @@ -168,14 +169,14 @@ func ParseFlags() {
registerFlags()
objabi.Flagparse(usage)

if Flag.MSan && !sys.MSanSupported(objabi.GOOS, objabi.GOARCH) {
log.Fatalf("%s/%s does not support -msan", objabi.GOOS, objabi.GOARCH)
if Flag.MSan && !sys.MSanSupported(buildcfg.GOOS, buildcfg.GOARCH) {
log.Fatalf("%s/%s does not support -msan", buildcfg.GOOS, buildcfg.GOARCH)
}
if Flag.Race && !sys.RaceDetectorSupported(objabi.GOOS, objabi.GOARCH) {
log.Fatalf("%s/%s does not support -race", objabi.GOOS, objabi.GOARCH)
if Flag.Race && !sys.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) {
log.Fatalf("%s/%s does not support -shared", objabi.GOOS, objabi.GOARCH)
log.Fatalf("%s/%s does not support -shared", buildcfg.GOOS, buildcfg.GOARCH)
}
parseSpectre(Flag.Spectre) // left as string for RecordFlags

Expand Down Expand Up @@ -347,7 +348,7 @@ func concurrentBackendAllowed() bool {
return false
}
// TODO: Test and delete this condition.
if objabi.Experiment.FieldTrack {
if buildcfg.Experiment.FieldTrack {
return false
}
// TODO: fix races and enable the following flags
Expand Down Expand Up @@ -458,11 +459,11 @@ func parseSpectre(s string) {
}

if Flag.Cfg.SpectreIndex {
switch objabi.GOARCH {
switch buildcfg.GOARCH {
case "amd64":
// ok
default:
log.Fatalf("GOARCH=%s does not support -spectre=index", objabi.GOARCH)
log.Fatalf("GOARCH=%s does not support -spectre=index", buildcfg.GOARCH)
}
}
}
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/base/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ package base

import (
"fmt"
"internal/buildcfg"
"os"
"runtime/debug"
"sort"
"strings"

"cmd/internal/objabi"
"cmd/internal/src"
)

Expand Down Expand Up @@ -217,7 +217,7 @@ func FatalfAt(pos src.XPos, format string, args ...interface{}) {
fmt.Printf("\n")

// If this is a released compiler version, ask for a bug report.
if strings.HasPrefix(objabi.Version, "go") {
if strings.HasPrefix(buildcfg.Version, "go") {
fmt.Printf("\n")
fmt.Printf("Please file a bug report including a short program that triggers the error.\n")
fmt.Printf("https://golang.org/issue/new\n")
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/compile/internal/dwarfgen/dwarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bytes"
"flag"
"fmt"
"internal/buildcfg"
"sort"

"cmd/compile/internal/base"
Expand Down Expand Up @@ -278,7 +279,7 @@ func createSimpleVar(fnsym *obj.LSym, n *ir.Name) *dwarf.Var {
if base.Ctxt.FixedFrameSize() == 0 {
offs -= int64(types.PtrSize)
}
if objabi.FramePointerEnabled {
if buildcfg.FramePointerEnabled {
offs -= int64(types.PtrSize)
}

Expand Down
Loading

0 comments on commit 95ed5c3

Please sign in to comment.