Skip to content

Commit 1eb0465

Browse files
committed
cmd/compile: turn off jump tables when spectre retpolines are on
Fixes #57097 Change-Id: I6ab659abbca1ae0ac8710674d39aec116fab0baa Reviewed-on: https://go-review.googlesource.com/c/go/+/455336 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Cherry Mui <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Keith Randall <[email protected]>
1 parent 9dde2de commit 1eb0465

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/cmd/compile/internal/walk/switch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func (s *exprSwitch) tryJumpTable(cc []exprClause, out *ir.Nodes) bool {
290290
const minCases = 8 // have at least minCases cases in the switch
291291
const minDensity = 4 // use at least 1 out of every minDensity entries
292292

293-
if !go119UseJumpTables || base.Flag.N != 0 || !ssagen.Arch.LinkArch.CanJumpTable {
293+
if !go119UseJumpTables || base.Flag.N != 0 || !ssagen.Arch.LinkArch.CanJumpTable || base.Ctxt.Retpoline {
294294
return false
295295
}
296296
if len(cc) < minCases {

test/codegen/retpoline.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,31 @@ func CallInterface(x interface{ M() }) {
1212
// amd64:`CALL\truntime.retpoline`
1313
x.M()
1414
}
15+
16+
// Check to make sure that jump tables are disabled
17+
// when retpoline is on. See issue 57097.
18+
func noJumpTables(x int) int {
19+
switch x {
20+
case 0:
21+
return 0
22+
case 1:
23+
return 1
24+
case 2:
25+
return 2
26+
case 3:
27+
return 3
28+
case 4:
29+
return 4
30+
case 5:
31+
return 5
32+
case 6:
33+
return 6
34+
case 7:
35+
return 7
36+
case 8:
37+
return 8
38+
case 9:
39+
return 9
40+
}
41+
return 10
42+
}

0 commit comments

Comments
 (0)