31#define DEBUG_TYPE "cross-dso-cfi"
33STATISTIC(NumTypeIds,
"Number of unique type identifiers");
40 void buildCFICheck(
Module &M);
41 bool runOnModule(
Module &M);
47void CrossDSOCFI::buildCFICheck(
Module &M) {
52 LLVMContext &Ctx =
M.getContext();
53 FunctionCallee
C =
M.getOrInsertFunction(
54 "__cfi_check", Type::getVoidTy(Ctx), Type::getInt64Ty(Ctx),
55 PointerType::getUnqual(Ctx), PointerType::getUnqual(Ctx));
60 F->setAlignment(
Align(4096));
65 Triple
T(
M.getTargetTriple());
66 if (
T.isARM() ||
T.isThumb())
67 F->addFnAttr(
"target-features",
"+thumb-mode");
69 auto args =
F->arg_begin();
71 CallSiteTypeId.
setName(
"CallSiteTypeId");
75 CFICheckFailData.
setName(
"CFICheckFailData");
83 FunctionCallee CFICheckFailFn =
M.getOrInsertFunction(
84 "__cfi_check_fail", Type::getVoidTy(Ctx), PointerType::getUnqual(Ctx),
85 PointerType::getUnqual(Ctx));
86 IRBFail.CreateCall(CFICheckFailFn, {&CFICheckFailData, &Addr});
87 IRBFail.CreateBr(ExitBB);
90 IRBExit.CreateRetVoid();
93 SwitchInst *
SI = IRB.CreateSwitch(&CallSiteTypeId, TrapBB, TypeIds.
size());
97 ConstantInt *CaseTypeId = ConstantInt::get(Type::getInt64Ty(Ctx), TypeId);
102 Intrinsic::type_test,
105 CondBrInst *BI = IRBTest.CreateCondBr(
Test, ExitBB, TrapBB);
106 BI->
setMetadata(LLVMContext::MD_prof, VeryLikelyWeights);
108 SI->addCase(CaseTypeId, TestBB);
113bool CrossDSOCFI::runOnModule(
Module &M) {
114 VeryLikelyWeights = MDBuilder(
M.getContext()).createLikelyBranchWeights();
115 if (
M.getModuleFlag(
"Cross-DSO CFI") ==
nullptr)
123 bool Changed = Impl.runOnModule(M);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
Machine Check Debug Module
This file contains the declarations for profiling metadata utility functions.
This file implements a set that has insertion order iteration characteristics.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
size_type size() const
Determine the number of elements in the SetVector.
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ BasicBlock
Various leaf nodes.
LLVM_ABI SetVector< uint64_t > findCfiTypeIds(const Module &M)
Finds all 64-bit numeric type identifiers in M used for cross-DSO CFI.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void setExplicitlyUnknownBranchWeights(Instruction &I, StringRef PassName)
Specify that the branch weights for this terminator cannot be known at compile time.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
IRBuilder(LLVMContext &, FolderTy, InserterTy) -> IRBuilder< FolderTy, InserterTy >
LLVM_ABI void setExplicitlyUnknownFunctionEntryCount(Function &F, StringRef PassName)
Analogous to setExplicitlyUnknownBranchWeights, but for functions and their entry counts.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.