]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link/internal/ld: make runtime.buildVersion with experiments valid
authormatloob@golang.org <matloob@golang.org>
Tue, 11 Nov 2025 18:54:52 +0000 (13:54 -0500)
committerMichael Matloob <matloob@google.com>
Fri, 14 Nov 2025 17:15:38 +0000 (09:15 -0800)
Specifically if there are experiments but no nonstandard toolchain
suffix such as "-devel", the go version will not be valid according to
go/version.IsValid. To fix that, always put the X: part into the suffix,
resulting in, for example, go1.25.0-X:foo.

Fixes #75953

Change-Id: I6a6a696468f3ba9b82b6a410fb88831428e93b58
Reviewed-on: https://go-review.googlesource.com/c/go/+/719701
Reviewed-by: Michael Matloob <matloob@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/cmd/go/internal/cache/hash.go
src/cmd/link/internal/ld/main.go

index 4f79c3150024492db1572271c08ffb1a3eeca082..27d275644a4bd0cdafe3ef30104f35a3f4a15926 100644 (file)
@@ -51,6 +51,9 @@ func stripExperiment(version string) string {
        if i := strings.Index(version, " X:"); i >= 0 {
                return version[:i]
        }
+       if i := strings.Index(version, "-X:"); i >= 0 {
+               return version[:i]
+       }
        return version
 }
 
index d913953944bc431c6ea0b3873f9176811c90fde6..a4b3a0422f2f417a4f7eb03fcd77c1d69b2134fd 100644 (file)
@@ -188,7 +188,11 @@ func Main(arch *sys.Arch, theArch Arch) {
 
        buildVersion := buildcfg.Version
        if goexperiment := buildcfg.Experiment.String(); goexperiment != "" {
-               buildVersion += " X:" + goexperiment
+               sep := " "
+               if !strings.Contains(buildVersion, "-") { // See go.dev/issue/75953.
+                       sep = "-"
+               }
+               buildVersion += sep + "X:" + goexperiment
        }
        addstrdata1(ctxt, "runtime.buildVersion="+buildVersion)