29#define DEBUG_TYPE "cross-dso-cfi"
31STATISTIC(NumTypeIds,
"Number of unique type identifiers");
39 void buildCFICheck(
Module &M);
40 bool runOnModule(
Module &M);
51 auto C = dyn_cast_or_null<ConstantInt>(
TM->getValue());
52 if (!
C)
return nullptr;
54 if (
C->getBitWidth() != 64)
return nullptr;
60void CrossDSOCFI::buildCFICheck(
Module &M) {
67 GO.getMetadata(LLVMContext::MD_type, Types);
70 TypeIds.
insert(TypeId->getZExtValue());
73 NamedMDNode *CfiFunctionsMD =
M.getNamedMetadata(
"cfi.functions");
75 for (
auto *Func : CfiFunctionsMD->
operands()) {
77 for (
unsigned I = 2;
I <
Func->getNumOperands(); ++
I)
79 extractNumericTypeId(cast<MDNode>(
Func->getOperand(
I).get())))
80 TypeIds.
insert(TypeId->getZExtValue());
87 PointerType::getUnqual(Ctx), PointerType::getUnqual(Ctx));
92 F->setAlignment(
Align(4096));
95 if (
T.isARM() ||
T.isThumb())
96 F->addFnAttr(
"target-features",
"+thumb-mode");
98 auto args =
F->arg_begin();
100 CallSiteTypeId.
setName(
"CallSiteTypeId");
102 Addr.setName(
"Addr");
104 CFICheckFailData.
setName(
"CFICheckFailData");
114 PointerType::getUnqual(Ctx));
115 IRBFail.CreateCall(CFICheckFailFn, {&CFICheckFailData, &
Addr});
116 IRBFail.CreateBr(ExitBB);
119 IRBExit.CreateRetVoid();
129 Intrinsic::type_test, {},
133 BI->
setMetadata(LLVMContext::MD_prof, VeryLikelyWeights);
135 SI->addCase(CaseTypeId, TestBB);
140bool CrossDSOCFI::runOnModule(
Module &M) {
142 if (
M.getModuleFlag(
"Cross-DSO CFI") ==
nullptr)
150 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.
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.