Skip to content

Commit 9daaab3

Browse files
committed
cmd/link/internal/ld: make runtime.buildVersion with experiments valid
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent d50a571 commit 9daaab3

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/cmd/go/internal/cache/hash.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ func stripExperiment(version string) string {
5151
if i := strings.Index(version, " X:"); i >= 0 {
5252
return version[:i]
5353
}
54+
if i := strings.Index(version, "-X:"); i >= 0 {
55+
return version[:i]
56+
}
5457
return version
5558
}
5659

src/cmd/link/internal/ld/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,11 @@ func Main(arch *sys.Arch, theArch Arch) {
188188

189189
buildVersion := buildcfg.Version
190190
if goexperiment := buildcfg.Experiment.String(); goexperiment != "" {
191-
buildVersion += " X:" + goexperiment
191+
sep := " "
192+
if !strings.Contains(buildVersion, "-") { // See go.dev/issue/75953.
193+
sep = "-"
194+
}
195+
buildVersion += sep + "X:" + goexperiment
192196
}
193197
addstrdata1(ctxt, "runtime.buildVersion="+buildVersion)
194198

0 commit comments

Comments
 (0)