Skip to content

Commit 3f2baa3

Browse files
committed
cmd/dist: re-enable GOARM auto-detection
cmd/dist will re-exec itself to detect VFP support at run-time. Fixes #9732, #12548. Change-Id: I9ad0c5c7fa3e97bd79a32da372e1a962565bb3af Reviewed-on: https://go-review.googlesource.com/3973 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent a370fba commit 3f2baa3

File tree

5 files changed

+62
-31
lines changed

5 files changed

+62
-31
lines changed

src/cmd/dist/util.go

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,14 @@ func main() {
480480
}
481481
}
482482

483+
if len(os.Args) > 1 && os.Args[1] == "-check-goarm" {
484+
useVFPv1() // might fail with SIGILL
485+
println("VFPv1 OK.")
486+
useVFPv3() // might fail with SIGILL
487+
println("VFPv3 OK.")
488+
os.Exit(0)
489+
}
490+
483491
xinit()
484492
xmain()
485493
xexit(0)
@@ -515,40 +523,21 @@ func xgetgoarm() string {
515523
// OpenBSD currently only supports softfloat.
516524
return "5"
517525
}
518-
if goos != "linux" {
519-
// All other arm platforms that we support
520-
// require ARMv7.
526+
527+
// Try to exec ourselves in a mode to detect VFP support.
528+
// Seeing how far it gets determines which instructions failed.
529+
// The test is OS-agnostic.
530+
out := run("", 0, os.Args[0], "-check-goarm")
531+
v1ok := strings.Contains(out, "VFPv1 OK.")
532+
v3ok := strings.Contains(out, "VFPv3 OK.")
533+
534+
if v1ok && v3ok {
521535
return "7"
522536
}
523-
cpuinfo := readfile("/proc/cpuinfo")
524-
goarm := "5"
525-
for _, line := range splitlines(cpuinfo) {
526-
line := strings.SplitN(line, ":", 2)
527-
if len(line) < 2 {
528-
continue
529-
}
530-
if strings.TrimSpace(line[0]) != "Features" {
531-
continue
532-
}
533-
features := splitfields(line[1])
534-
sort.Strings(features) // so vfpv3 sorts after vfp
535-
536-
// Infer GOARM value from the vfp features available
537-
// on this host. Values of GOARM detected are:
538-
// 5: no vfp support was found
539-
// 6: vfp (v1) support was detected, but no higher
540-
// 7: vfpv3 support was detected.
541-
// This matches the assertions in runtime.checkarm.
542-
for _, f := range features {
543-
switch f {
544-
case "vfp":
545-
goarm = "6"
546-
case "vfpv3":
547-
goarm = "7"
548-
}
549-
}
537+
if v1ok {
538+
return "6"
550539
}
551-
return goarm
540+
return "5"
552541
}
553542

554543
func min(a, b int) int {

src/cmd/dist/util_gc.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,11 @@ func cansse2() bool {
1717
cpuid(&info, 1)
1818
return info[3]&(1<<26) != 0 // SSE2
1919
}
20+
21+
// useVFPv1 tries to execute one VFPv1 instruction on ARM.
22+
// It will crash the current process if VFPv1 is missing.
23+
func useVFPv1()
24+
25+
// useVFPv3 tries to execute one VFPv3 instruction on ARM.
26+
// It will crash the current process if VFPv3 is missing.
27+
func useVFPv3()

src/cmd/dist/util_gccgo.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ int supports_sse2() {
1818
import "C"
1919

2020
func cansse2() bool { return C.supports_sse2() != 0 }
21+
22+
func useVFPv1() {}
23+
24+
func useVFPv3() {}

src/cmd/dist/vfp_arm.s

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2015 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build gc,arm
6+
7+
#include "textflag.h"
8+
9+
// try to run "vmov.f64 d0, d0" instruction
10+
TEXT ·useVFPv1(SB),NOSPLIT,$0
11+
WORD $0xeeb00b40 // vmov.f64 d0, d0
12+
RET
13+
14+
// try to run VFPv3-only "vmov.f64 d0, #112" instruction
15+
TEXT ·useVFPv3(SB),NOSPLIT,$0
16+
WORD $0xeeb70b00 // vmov.f64 d0, #112
17+
RET

src/cmd/dist/vfp_default.s

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2015 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build !arm,gc
6+
7+
#include "textflag.h"
8+
9+
TEXT ·useVFPv1(SB),NOSPLIT,$0
10+
RET
11+
12+
TEXT ·useVFPv3(SB),NOSPLIT,$0
13+
RET

0 commit comments

Comments
 (0)