38 #define DEBUG_TYPE "cross-dso-cfi"
40 STATISTIC(NumTypeIds,
"Number of unique type identifiers");
53 void buildCFICheck(
Module &M);
54 bool runOnModule(
Module &M)
override;
62 char CrossDSOCFI::
ID = 0;
72 auto C = dyn_cast_or_null<ConstantInt>(
TM->getValue());
73 if (!
C)
return nullptr;
75 if (
C->getBitWidth() != 64)
return nullptr;
81 void CrossDSOCFI::buildCFICheck(
Module &M) {
91 assert(!isa<Function>(&GO) || !cast<Function>(&GO)->isDeclaration());
94 TypeIds.
insert(TypeId->getZExtValue());
105 Value &CallSiteTypeId = *(args++);
106 CallSiteTypeId.
setName(
"CallSiteTypeId");
107 Value &Addr = *(args++);
109 Value &CFICheckFailData = *(args++);
110 CFICheckFailData.
setName(
"CFICheckFailData");
121 IRBFail.CreateCall(CFICheckFailFn, {&CFICheckFailData, &Addr});
122 IRBFail.CreateBr(ExitBB);
125 IRBExit.CreateRetVoid();
129 for (uint64_t TypeId : TypeIds) {
135 Value *Test = IRBTest.CreateCall(
138 BranchInst *BI = IRBTest.CreateCondBr(Test, ExitBB, TrapBB);
141 SI->
addCase(CaseTypeId, TestBB);
146 bool CrossDSOCFI::runOnModule(
Module &M) {
160 bool Changed = Impl.runOnModule(M);
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
STATISTIC(NumFunctions,"Total number of functions")
A Module instance is used to store all the information related to an LLVM module. ...
Implements a dense probed hash-table based set.
void addCase(ConstantInt *OnVal, BasicBlock *Dest)
Add an entry to the switch instruction.
static IntegerType * getInt64Ty(LLVMContext &C)
void setAlignment(unsigned Align)
iterator_range< global_object_iterator > global_objects()
ModulePass * createCrossDSOCFIPass()
This pass export CFI checks for use by external modules.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
void setName(const Twine &Name)
Change the name of the value.
void initializeCrossDSOCFIPass(PassRegistry &)
Function Alias Analysis false
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
A set of analyses that are preserved following a run of a transformation pass.
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeSet AttributeList)
Look up the specified function in the module symbol table.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
Conditional or Unconditional Branch instruction.
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::pair< iterator, bool > insert(const ValueT &V)
static Type * getVoidTy(LLVMContext &C)
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
const MDOperand & getOperand(unsigned I) const
This is the shared class of boolean and integer constants.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
A container for analyses that lazily runs them and caches their results.
LLVMContext & getContext() const
Get the global data context.