[x86/SLH] Teach SLH to harden indirect branches and switches without
authorChandler Carruth <chandlerc@gmail.com>
Tue, 4 Sep 2018 10:44:21 +0000 (10:44 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Tue, 4 Sep 2018 10:44:21 +0000 (10:44 +0000)
commit8d8489f513a7b777eeb55850d9a1487bf9a1bf1c
tree2f6b48460ea3add087c484a0b72d94d39d9fc0a4
parent9588ad9611368d65a6f619ae5e79fff70854a1fc
[x86/SLH] Teach SLH to harden indirect branches and switches without
retpolines.

This implements the core design of tracing the intended target into the
target, checking it, and using that to update the predicate state. It
takes advantage of a few interesting aspects of SLH to make it a bit
easier to implement:
- We already split critical edges with conditional branches, so we can
assume those are gone.
- We already unfolded any memory access in the indirect branch
instruction itself.

I've left hard errors in place to catch if any of these somewhat subtle
invariants get violated.

There is some code that I can factor out and share with D50837 when it
lands, but I didn't want to couple landing the two patches, so I'll do
that in a follow-up cleanup commit if alright.

Factoring out the code to handle different scenarios of materializing an
address remains frustratingly hard. In a bunch of cases you want to fold
one of the cases into an immediate operand of some other instruction,
and you also have both symbols and basic blocks being used which require
different methods on the MI builder (and different operand kinds).
Still, I'll take a stab at sharing at least some of this code in
a follow-up if I can figure out how.

Differential Revision: https://reviews.llvm.org/D51083

llvm-svn: 341356
llvm/lib/Target/X86/X86SpeculativeLoadHardening.cpp
llvm/test/CodeGen/X86/speculative-load-hardening-indirect.ll