Skip to content

Commit 81c66e7

Browse files
andreybokhankogopherbot
authored andcommitted
runtime: check LSE support on ARM64 at runtime init
Check presence of LSE support on ARM64 chip if we targeted it at compile time. Related to #69124 Updates #60905 Fixes #71411 Change-Id: I65e899a28ff64a390182572c0c353aa5931fc85d Reviewed-on: https://go-review.googlesource.com/c/go/+/645795 Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]>
1 parent d524e1e commit 81c66e7

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/runtime/asm_arm64.s

+50
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,28 @@
88
#include "funcdata.h"
99
#include "textflag.h"
1010

11+
#ifdef GOARM64_LSE
12+
DATA no_lse_msg<>+0x00(SB)/64, $"This program can only run on ARM64 processors with LSE support.\n"
13+
GLOBL no_lse_msg<>(SB), RODATA, $64
14+
#endif
15+
16+
// We know for sure that Linux and FreeBSD allow to read instruction set
17+
// attribute registers (while some others OSes, like OpenBSD and Darwin,
18+
// are not). Let's be conservative and allow code reading such registers
19+
// only when we sure this won't lead to sigill.
20+
#ifdef GOOS_linux
21+
#define ISA_REGS_READABLE
22+
#endif
23+
#ifdef GOOS_freebsd
24+
#define ISA_REGS_READABLE
25+
#endif
26+
27+
#ifdef GOARM64_LSE
28+
#ifdef ISA_REGS_READABLE
29+
#define CHECK_GOARM64_LSE
30+
#endif
31+
#endif
32+
1133
TEXT runtime·rt0_go(SB),NOSPLIT|TOPFRAME,$0
1234
// SP = stack; R0 = argc; R1 = argv
1335

@@ -77,6 +99,19 @@ nocgo:
7799
BL runtime·wintls(SB)
78100
#endif
79101

102+
// Check that CPU we use for execution supports instructions targeted during compile-time.
103+
#ifdef CHECK_GOARM64_LSE
104+
// Read the ID_AA64ISAR0_EL1 register
105+
MRS ID_AA64ISAR0_EL1, R0
106+
107+
// Extract the LSE field (bits [23:20])
108+
LSR $20, R0, R0
109+
AND $0xf, R0, R0
110+
111+
// LSE support is indicated by a non-zero value
112+
CBZ R0, no_lse
113+
#endif
114+
80115
MOVW 8(RSP), R0 // copy argc
81116
MOVW R0, -8(RSP)
82117
MOVD 16(RSP), R0 // copy argv
@@ -95,6 +130,21 @@ nocgo:
95130

96131
// start this M
97132
BL runtime·mstart(SB)
133+
UNDEF
134+
135+
#ifdef CHECK_GOARM64_LSE
136+
no_lse:
137+
MOVD $1, R0 // stderr
138+
MOVD R0, 8(RSP)
139+
MOVD $no_lse_msg<>(SB), R1 // message address
140+
MOVD R1, 16(RSP)
141+
MOVD $64, R2 // message length
142+
MOVD R2, 24(RSP)
143+
CALL runtime·write(SB)
144+
CALL runtime·exit(SB)
145+
CALL runtime·abort(SB)
146+
RET
147+
#endif
98148

99149
// Prevent dead-code elimination of debugCallV2 and debugPinnerV1, which are
100150
// intended to be called by debuggers.

0 commit comments

Comments
 (0)