-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cpu: get hwcap/auxv from the Go 1.21+ runtime
Depends on https://go.dev/cl/458256 This change only does Linux for now. Updates golang/go#57336 Change-Id: I0659697c1bdc6e2577c6251b964a0df32047ee12 Reviewed-on: https://go-review.googlesource.com/c/sys/+/465295 Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2023 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package cpu | ||
|
||
// getAuxvFn is non-nil on Go 1.21+ (via runtime_auxv_go121.go init) | ||
// on platforms that use auxv. | ||
var getAuxvFn func() []uintptr | ||
|
||
func getAuxv() []uintptr { | ||
if getAuxvFn == nil { | ||
return nil | ||
} | ||
return getAuxvFn() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2023 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build go1.21 | ||
// +build go1.21 | ||
|
||
package cpu | ||
|
||
import ( | ||
_ "unsafe" // for linkname | ||
) | ||
|
||
//go:linkname runtime_getAuxv runtime.getAuxv | ||
func runtime_getAuxv() []uintptr | ||
|
||
func init() { | ||
getAuxvFn = runtime_getAuxv | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2023 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build go1.21 | ||
// +build go1.21 | ||
|
||
package cpu | ||
|
||
import ( | ||
"runtime" | ||
"testing" | ||
) | ||
|
||
func TestAuxvFromRuntime(t *testing.T) { | ||
got := getAuxv() | ||
t.Logf("got: %v", got) // notably: we didn't panic | ||
if runtime.GOOS == "linux" && len(got) == 0 { | ||
t.Errorf("expected auxv on linux; got zero entries") | ||
} | ||
} |