]> Cypherpunks.ru repositories - gostls13.git/commitdiff
runtime,cmd/link: include GOEXPERIMENTs in runtime.Version(), "go version X"
authorAustin Clements <austin@google.com>
Tue, 6 Apr 2021 21:04:52 +0000 (17:04 -0400)
committerAustin Clements <austin@google.com>
Thu, 8 Apr 2021 02:17:22 +0000 (02:17 +0000)
This adds the set of GOEXPERIMENTs to the build version if it differs
from the default set of experiments. This exposes the experiment
settings via runtime.Version() and "go version <binary>".

Change-Id: I143dbbc50f66a4cf175469199974e18848075af6
Reviewed-on: https://go-review.googlesource.com/c/go/+/307820
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/dist/buildruntime.go
src/cmd/go/testdata/script/version_goexperiment.txt [new file with mode: 0644]
src/cmd/link/internal/ld/main.go
src/internal/goexperiment/flags.go
src/runtime/extern.go
src/runtime/proc.go

index e0a101a3532428a2d94fa2ae89edf005784b47c8..3ef551e187e9b11131f060c01b6b29ceeecdb313 100644 (file)
@@ -19,7 +19,6 @@ import (
 //
 //     package sys
 //
-//     const TheVersion = <version>
 //     const StackGuardMultiplier = <multiplier value>
 //
 func mkzversion(dir, file string) {
@@ -28,7 +27,6 @@ func mkzversion(dir, file string) {
        fmt.Fprintln(&buf)
        fmt.Fprintf(&buf, "package sys\n")
        fmt.Fprintln(&buf)
-       fmt.Fprintf(&buf, "const TheVersion = `%s`\n", findgoversion())
        fmt.Fprintf(&buf, "const StackGuardMultiplierDefault = %d\n", stackGuardMultiplierDefault())
 
        writefile(buf.String(), file, writeSkipSame)
diff --git a/src/cmd/go/testdata/script/version_goexperiment.txt b/src/cmd/go/testdata/script/version_goexperiment.txt
new file mode 100644 (file)
index 0000000..4b165eb
--- /dev/null
@@ -0,0 +1,16 @@
+# Test that experiments appear in "go version <binary>"
+
+# This test requires rebuilding the runtime, which takes a while.
+[short] skip
+
+env GOEXPERIMENT=fieldtrack
+go build -o main$GOEXE version.go
+go version main$GOEXE
+stdout 'X:fieldtrack$'
+exec ./main$GOEXE
+stderr 'X:fieldtrack$'
+
+-- version.go --
+package main
+import "runtime"
+func main() { println(runtime.Version()) }
index 95c89f813be8f0fc7c0d6a56de19977065b152a9..8631cf2939601537892d1cd249ed81da698560e8 100644 (file)
@@ -118,6 +118,12 @@ func Main(arch *sys.Arch, theArch Arch) {
        addstrdata1(ctxt, "runtime.defaultGOROOT="+final)
        addstrdata1(ctxt, "cmd/internal/objabi.defaultGOROOT="+final)
 
+       buildVersion := objabi.Version
+       if goexperiment := objabi.GOEXPERIMENT(); goexperiment != "" {
+               buildVersion += " X:" + goexperiment
+       }
+       addstrdata1(ctxt, "runtime.buildVersion="+buildVersion)
+
        // TODO(matloob): define these above and then check flag values here
        if ctxt.Arch.Family == sys.AMD64 && objabi.GOOS == "plan9" {
                flag.BoolVar(&flag8, "8", false, "use 64-bit addresses in symbol table")
index 1c513d5a709a8346d8b6be944d9af4207e85806d..4803fabe28e87d024b5c97dc8d4c4fe668b43af1 100644 (file)
@@ -26,6 +26,9 @@
 // In the toolchain, the set of experiments enabled for the current
 // build should be accessed via objabi.Experiment.
 //
+// The set of experiments is included in the output of runtime.Version()
+// and "go version <binary>" if it differs from the default experiments.
+//
 // For the set of experiments supported by the current toolchain, see
 // go doc internal/experiment.Flags.
 package goexperiment
index b73d68428fe988304ad7730c3a0c32a9ae2c7d07..48e1e6603b7aeb179bdf627c801f91665e3106b0 100644 (file)
@@ -240,11 +240,21 @@ func GOROOT() string {
        return defaultGOROOT
 }
 
+// buildVersion is the Go tree's version string at build time.
+//
+// If any GOEXPERIMENTs are set to non-default values, it will include
+// "X:<GOEXPERIMENT>".
+//
+// This is set by the linker.
+//
+// This is accessed by "go version <binary>".
+var buildVersion string
+
 // Version returns the Go tree's version string.
 // It is either the commit hash and date at the time of the build or,
 // when possible, a release tag like "go1.3".
 func Version() string {
-       return sys.TheVersion
+       return buildVersion
 }
 
 // GOOS is the running program's operating system target:
index 35a3f9ca199a6b07e3d23c728c44d4d8149ff441..d545a143a036fc5daa7b691067775fe12a22848d 100644 (file)
@@ -12,8 +12,6 @@ import (
        "unsafe"
 )
 
-var buildVersion = sys.TheVersion
-
 // set using cmd/go/internal/modload.ModInfoProg
 var modinfo string