cpu: don't panic on error reading /proc/self/auxv
On Android /proc/self/auxv is not readable, leading to a panic in init.
Instead of panic'ing in this case, introduce the Initialized global bool
to report whether the CPU features were initialized i.e. /proc/self/auxv
was successfullly read.
Fixes golang/go#30413
Change-Id: Ib520f202990614a76bceb0bf9d19a88eadd13e10
Reviewed-on: https://go-review.googlesource.com/c/164057
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/cpu/cpu_linux.go b/cpu/cpu_linux.go
index 33b61e5..76b5f50 100644
--- a/cpu/cpu_linux.go
+++ b/cpu/cpu_linux.go
@@ -28,7 +28,9 @@
func init() {
buf, err := ioutil.ReadFile(procAuxv)
if err != nil {
- panic("read proc auxv failed: " + err.Error())
+ // e.g. on android /proc/self/auxv is not accessible, so silently
+ // ignore the error and leave Initialized = false
+ return
}
bo := hostByteOrder()
@@ -52,4 +54,6 @@
}
}
doinit()
+
+ Initialized = true
}