[X86] Fix fentry handling in X86IndirectBranchTracking.cpp
authorJoao Moreira <joao.moreira@intel.com>
Tue, 7 Dec 2021 02:34:37 +0000 (10:34 +0800)
committerPhoebe Wang <phoebe.wang@intel.com>
Tue, 7 Dec 2021 04:10:03 +0000 (12:10 +0800)
commitdfcf69770bc522b9e411c66454934a37c1f35332
tree8f6801528049a2c886c04881b9896d35101f2826
parent2bd7384d3a99edd345fcc5e8ee8d550bd65dddb2
[X86] Fix fentry handling in X86IndirectBranchTracking.cpp

When compiling with indirect branch tracking and fentry (-fcf-protection=branch -mfentry -pg) the X86IndirectBranchTrackingPass will attempt to place endbr in basic blocks, checking for Calls/IsCallReturnTwice. For calling the function IsCallReturnTwice(), the pass attempts to retrieve the first operand of the respective machine instruction. Since FENTRY_CALL is considered a call, and it does not have any argument, the condition inside the pass will attempt to call IsCallReturnTwice on the machine instruction, but since it does not have operands, it will lead into a crash.

Kudos to Alyssa Milburn for helping in the issue triage. The diff brings a test, but to reproduce the problem, follow the steps below.

```
echo "int main() {};" > repro.c
clang repro.c -fcf-protection=branch -mfentry -pg
```

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D111108
llvm/lib/Target/X86/X86IndirectBranchTracking.cpp
llvm/test/CodeGen/X86/fentry-ibt.ll [new file with mode: 0644]