37 #define DEBUG_TYPE "cross-dso-cfi" 39 STATISTIC(NumTypeIds,
"Number of unique type identifiers");
52 void buildCFICheck(
Module &M);
53 bool runOnModule(
Module &M)
override;
61 char CrossDSOCFI::
ID = 0;
71 auto C = dyn_cast_or_null<ConstantInt>(
TM->getValue());
72 if (!
C)
return nullptr;
74 if (
C->getBitWidth() != 64)
return nullptr;
80 void CrossDSOCFI::buildCFICheck(
Module &M) {
90 assert(!isa<Function>(&GO) || !cast<Function>(&GO)->isDeclaration());
93 TypeIds.
insert(TypeId->getZExtValue());
99 for (
auto Func : CfiFunctionsMD->
operands()) {
100 assert(Func->getNumOperands() >= 2);
101 for (
unsigned I = 2;
I < Func->getNumOperands(); ++
I)
103 extractNumericTypeId(cast<MDNode>(Func->getOperand(
I).get())))
104 TypeIds.
insert(TypeId->getZExtValue());
119 if (
T.isARM() ||
T.isThumb())
120 F->
addFnAttr(
"target-features",
"+thumb-mode");
123 Value &CallSiteTypeId = *(args++);
124 CallSiteTypeId.
setName(
"CallSiteTypeId");
125 Value &Addr = *(args++);
127 Value &CFICheckFailData = *(args++);
128 CFICheckFailData.
setName(
"CFICheckFailData");
139 IRBFail.CreateCall(CFICheckFailFn, {&CFICheckFailData, &Addr});
140 IRBFail.CreateBr(ExitBB);
143 IRBExit.CreateRetVoid();
147 for (uint64_t TypeId : TypeIds) {
153 Value *Test = IRBTest.CreateCall(
156 BranchInst *BI = IRBTest.CreateCondBr(Test, ExitBB, TrapBB);
159 SI->
addCase(CaseTypeId, TestBB);
164 bool CrossDSOCFI::runOnModule(
Module &M) {
175 bool Changed = Impl.runOnModule(M);
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
size_type size() const
Determine the number of elements in the SetVector.
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
A Module instance is used to store all the information related to an LLVM module. ...
void addCase(ConstantInt *OnVal, BasicBlock *Dest)
Add an entry to the switch instruction.
STATISTIC(NumFunctions, "Total number of functions")
const MDOperand & getOperand(unsigned I) const
static IntegerType * getInt64Ty(LLVMContext &C)
void setAlignment(unsigned Align)
iterator_range< global_object_iterator > global_objects()
LLVMContext & getContext() const
Get the global data context.
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.
bool insert(const value_type &X)
Insert a new element into the SetVector.
void initializeCrossDSOCFIPass(PassRegistry &)
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
iterator_range< op_iterator > operands()
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.
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.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
void deleteBody()
deleteBody - This method deletes the body of the function, and converts the linkage to external...
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static Type * getVoidTy(LLVMContext &C)
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)
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Triple - Helper class for working with autoconf configuration names.
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.
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 vector that has set insertion semantics.
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
A container for analyses that lazily runs them and caches their results.