internal/cpu: inline DebugOptions

internal/cpu.DebugOptions is only ever set in runtime.cpuinit on
unix-like platforms. DebugOptions itself is only used in
MustHaveDebugOptionsSupport, so inline the GOOS check there.

Change-Id: I6a35d6b8afcdadfc59585258002f53c20026116c
Reviewed-on: https://go-review.googlesource.com/c/go/+/699775
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Florian Lehner <lehner.florian86@gmail.com>
This commit is contained in:
Tobias Klauser 2025-08-28 16:50:12 +02:00 committed by Gopher Robot
parent 94b7d519bd
commit fe42628dae
3 changed files with 4 additions and 10 deletions

View file

@ -8,11 +8,6 @@ package cpu
import _ "unsafe" // for linkname import _ "unsafe" // for linkname
// DebugOptions is set to true by the runtime if the OS supports reading
// GODEBUG early in runtime startup.
// This should not be changed after it is initialized.
var DebugOptions bool
// CacheLinePad is used to pad structs to avoid false sharing. // CacheLinePad is used to pad structs to avoid false sharing.
type CacheLinePad struct{ _ [CacheLinePadSize]byte } type CacheLinePad struct{ _ [CacheLinePadSize]byte }

View file

@ -9,11 +9,14 @@ import (
"internal/godebug" "internal/godebug"
"internal/testenv" "internal/testenv"
"os/exec" "os/exec"
"runtime"
"testing" "testing"
) )
func MustHaveDebugOptionsSupport(t *testing.T) { func MustHaveDebugOptionsSupport(t *testing.T) {
if !DebugOptions { switch runtime.GOOS {
case "aix", "darwin", "ios", "dragonfly", "freebsd", "netbsd", "openbsd", "illumos", "solaris", "linux":
default:
t.Skipf("skipping test: cpu feature options not supported by OS") t.Skipf("skipping test: cpu feature options not supported by OS")
} }
} }

View file

@ -760,10 +760,6 @@ const (
// cpuinit sets up CPU feature flags and calls internal/cpu.Initialize. env should be the complete // cpuinit sets up CPU feature flags and calls internal/cpu.Initialize. env should be the complete
// value of the GODEBUG environment variable. // value of the GODEBUG environment variable.
func cpuinit(env string) { func cpuinit(env string) {
switch GOOS {
case "aix", "darwin", "ios", "dragonfly", "freebsd", "netbsd", "openbsd", "illumos", "solaris", "linux":
cpu.DebugOptions = true
}
cpu.Initialize(env) cpu.Initialize(env)
// Support cpu feature variables are used in code generated by the compiler // Support cpu feature variables are used in code generated by the compiler