Skip to content

Commit

Permalink
[release-branch.go1.19] cmd/compile: turn off jump tables when spectr…
Browse files Browse the repository at this point in the history
…e retpolines are on

Fixes #57100

Change-Id: I6ab659abbca1ae0ac8710674d39aec116fab0baa
Reviewed-on: https://go-review.googlesource.com/c/go/+/455336
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
(cherry picked from commit 1eb0465)
Reviewed-on: https://go-review.googlesource.com/c/go/+/455416
Reviewed-by: Michael Pratt <mpratt@google.com>
  • Loading branch information
randall77 authored and prattmic committed Dec 9, 2022
1 parent dc04f3b commit 1565780
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/walk/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (s *exprSwitch) tryJumpTable(cc []exprClause, out *ir.Nodes) bool {
const minCases = 8 // have at least minCases cases in the switch
const minDensity = 4 // use at least 1 out of every minDensity entries

if !go119UseJumpTables || base.Flag.N != 0 || !ssagen.Arch.LinkArch.CanJumpTable {
if !go119UseJumpTables || base.Flag.N != 0 || !ssagen.Arch.LinkArch.CanJumpTable || base.Ctxt.Retpoline {
return false
}
if len(cc) < minCases {
Expand Down
28 changes: 28 additions & 0 deletions test/codegen/retpoline.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,31 @@ func CallInterface(x interface{ M() }) {
// amd64:`CALL\truntime.retpoline`
x.M()
}

// Check to make sure that jump tables are disabled
// when retpoline is on. See issue 57097.
func noJumpTables(x int) int {
switch x {
case 0:
return 0
case 1:
return 1
case 2:
return 2
case 3:
return 3
case 4:
return 4
case 5:
return 5
case 6:
return 6
case 7:
return 7
case 8:
return 8
case 9:
return 9
}
return 10
}

0 comments on commit 1565780

Please sign in to comment.