Skip to content

Commit 1565780

Browse files
randall77prattmic
authored andcommitted
[release-branch.go1.19] cmd/compile: turn off jump tables when spectre retpolines are on
Fixes #57100 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]> (cherry picked from commit 1eb0465) Reviewed-on: https://go-review.googlesource.com/c/go/+/455416 Reviewed-by: Michael Pratt <[email protected]>
1 parent dc04f3b commit 1565780

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

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

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

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

test/codegen/retpoline.go

+28
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)