30#define DEBUG_TYPE "cross-dso-cfi"
32STATISTIC(NumTypeIds,
"Number of unique type identifiers");
40 void buildCFICheck(
Module &M);
41 bool runOnModule(
Module &M);
52 auto C = dyn_cast_or_null<ConstantInt>(
TM->getValue());
53 if (!
C)
return nullptr;
55 if (
C->getBitWidth() != 64)
return nullptr;
61void CrossDSOCFI::buildCFICheck(
Module &M) {
68 GO.getMetadata(LLVMContext::MD_type, Types);
71 TypeIds.
insert(TypeId->getZExtValue());
74 NamedMDNode *CfiFunctionsMD =
M.getNamedMetadata(
"cfi.functions");
76 for (
auto *Func : CfiFunctionsMD->
operands()) {
78 for (
unsigned I = 2;
I <
Func->getNumOperands(); ++
I)
80 extractNumericTypeId(cast<MDNode>(
Func->getOperand(
I).get())))
81 TypeIds.
insert(TypeId->getZExtValue());
88 PointerType::getUnqual(Ctx), PointerType::getUnqual(Ctx));
93 F->setAlignment(
Align(4096));
96 if (
T.isARM() ||
T.isThumb())
97 F->addFnAttr(
"target-features",
"+thumb-mode");
99 auto args =
F->arg_begin();
101 CallSiteTypeId.
setName(
"CallSiteTypeId");
103 Addr.setName(
"Addr");
105 CFICheckFailData.
setName(
"CFICheckFailData");
115 PointerType::getUnqual(Ctx));
116 IRBFail.CreateCall(CFICheckFailFn, {&CFICheckFailData, &
Addr});
117 IRBFail.CreateBr(ExitBB);
120 IRBExit.CreateRetVoid();
134 BI->
setMetadata(LLVMContext::MD_prof, VeryLikelyWeights);
136 SI->addCase(CaseTypeId, TestBB);
141bool CrossDSOCFI::runOnModule(
Module &M) {
143 if (
M.getModuleFlag(
"Cross-DSO CFI") ==
nullptr)
151 bool Changed = Impl.runOnModule(M);
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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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)
A container for analyses that lazily runs them and caches their results.
LLVM Basic Block Representation.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Conditional or Unconditional Branch instruction.
This is the shared class of boolean and integer constants.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
This is an important class for using LLVM in a threaded context.
MDNode * createLikelyBranchWeights()
Return metadata containing two branch weights, with significant bias towards true destination.
const MDOperand & getOperand(unsigned I) const
A Module instance is used to store all the information related to an LLVM module.
iterator_range< op_iterator > operands()
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.
A vector that has set insertion semantics.
size_type size() const
Determine the number of elements in the SetVector.
bool insert(const value_type &X)
Insert a new element into the SetVector.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Triple - Helper class for working with autoconf configuration names.
The instances of the Type class are immutable: once they are created, they are never changed.
static Type * getVoidTy(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
LLVM Value Representation.
void setName(const Twine &Name)
Change the name of the value.
@ C
The default llvm calling convention, compatible with C.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=std::nullopt)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
NodeAddr< FuncNode * > Func
This is an optimization pass for GlobalISel generic memory operations.
This struct is a compact representation of a valid (non-zero power of two) alignment.