This is an archive of the discontinued LLVM Phabricator instance.

[Spectre] Fix MIR verifier errors in retpoline thunks
ClosedPublic

Authored by rnk on Oct 24 2018, 9:26 AM.

Details

Summary

The main challenge here is that X86InstrInfo::AnalyzeBranch doesn't
understand the way we're using a CALL instruction as a branch, so we
can't list the CallTarget MBB as a successor of the entry block. If we
don't list it as a successor, then the AsmPrinter doesn't print a label
for the MBB.

Fix the issue by inserting our own label at the beginning of the call
target block. We can rely on the AsmPrinter to always emit it, even
though the block appears to be unreachable, but address-taken.

Fixes PR38391.

Diff Detail

Repository
rL LLVM

Event Timeline

rnk created this revision.Oct 24 2018, 9:26 AM

The main challenge here is that X86InstrInfo::AnalyzeBranch doesn't understand the way we're using a CALL instruction as a branch

This seems like something which could be fixed directly by adding a pseudo-instruction to represent the "call". For example, on Thumb1, we have tBfar. But maybe it's not worth fixing if the only place it would be used is inside retpoline thunks.

rnk added a comment.Oct 24 2018, 11:00 AM

The main challenge here is that X86InstrInfo::AnalyzeBranch doesn't understand the way we're using a CALL instruction as a branch

This seems like something which could be fixed directly by adding a pseudo-instruction to represent the "call". For example, on Thumb1, we have tBfar. But maybe it's not worth fixing if the only place it would be used is inside retpoline thunks.

I agree, it's not worth a pseudo. We're generating this MIR as late as possible, and honestly if we could generate MC instead, I would. The semantics of this are only explicable in raw assembly.

rnk added a comment.Oct 26 2018, 1:27 PM

I'm going to land this so we can close out the bug and enable the MIR verifier for x86. Feel free to add comments post commit.

This revision was not accepted when it landed; it landed in state Needs Review.Oct 26 2018, 1:28 PM
This revision was automatically updated to reflect the committed changes.