#include "bolt/Passes/RetpolineInsertion.h"
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/Support/raw_ostream.h"
#define DEBUG_TYPE …
usingnamespacellvm;
usingnamespacebolt;
namespace opts {
extern cl::OptionCategory BoltCategory;
llvm::cl::opt<bool> InsertRetpolines("insert-retpolines",
cl::desc("run retpoline insertion pass"),
cl::cat(BoltCategory));
llvm::cl::opt<bool>
RetpolineLfence("retpoline-lfence",
cl::desc("determine if lfence instruction should exist in the retpoline"),
cl::init(true),
cl::ZeroOrMore,
cl::Hidden,
cl::cat(BoltCategory));
cl::opt<RetpolineInsertion::AvailabilityOptions> R11Availability(
"r11-availability",
cl::desc("determine the availability of r11 before indirect branches"),
cl::init(RetpolineInsertion::AvailabilityOptions::NEVER),
cl::values(clEnumValN(RetpolineInsertion::AvailabilityOptions::NEVER,
"never", "r11 not available"),
clEnumValN(RetpolineInsertion::AvailabilityOptions::ALWAYS,
"always", "r11 available before calls and jumps"),
clEnumValN(RetpolineInsertion::AvailabilityOptions::ABI, "abi",
"r11 available before calls but not before jumps")),
cl::ZeroOrMore, cl::cat(BoltCategory));
}
namespace llvm {
namespace bolt {
BinaryFunction *createNewRetpoline(BinaryContext &BC,
const std::string &RetpolineTag,
const IndirectBranchInfo &BrInfo,
bool R11Available) { … }
std::string createRetpolineFunctionTag(BinaryContext &BC,
const IndirectBranchInfo &BrInfo,
bool R11Available) { … }
BinaryFunction *RetpolineInsertion::getOrCreateRetpoline(
BinaryContext &BC, const IndirectBranchInfo &BrInfo, bool R11Available) { … }
void createBranchReplacement(BinaryContext &BC,
const IndirectBranchInfo &BrInfo,
bool R11Available,
InstructionListType &Replacement,
const MCSymbol *RetpolineSymbol) { … }
IndirectBranchInfo::IndirectBranchInfo(MCInst &Inst, MCPlusBuilder &MIB) { … }
Error RetpolineInsertion::runOnFunctions(BinaryContext &BC) { … }
}
}