33 ArrayType *ATy = cast<ArrayType>(GVCtor->getValueType());
36 if (Data && OldEltTy->getNumElements() < 3)
42 unsigned n =
Init->getNumOperands();
43 CurrentCtors.reserve(n + 1);
44 for (
unsigned i = 0; i != n; ++i) {
45 auto Ctor = cast<Constant>(
Init->getOperand(i));
46 if (EltTy != OldEltTy)
49 Ctor->getAggregateElement(1),
51 CurrentCtors.push_back(Ctor);
54 GVCtor->eraseFromParent();
63 CSVals[0] = IRB.getInt32(Priority);
72 CurrentCtors.push_back(RuntimeCtorInit);
100 if (InitAsSet.
insert(C).second)
107 for (
auto *V : Values) {
109 if (InitAsSet.
insert(C).second)
119 GV->setSection(
"llvm.metadata");
131 if (isa<Function>(FuncOrBitcast))
132 return cast<Function>(FuncOrBitcast);
137 Stream <<
"Sanitizer interface function redefined: " << *FuncOrBitcast;
143 assert(!InitName.
empty() &&
"Expected init function name");
156 assert(!InitName.
empty() &&
"Expected init function name");
158 "Sanitizer's init function expects different number of arguments");
166 IRB.CreateCall(InitFunction, InitArgs);
167 if (!VersionCheckName.
empty()) {
172 IRB.CreateCall(VersionCheckFunction, {});
174 return std::make_pair(Ctor, InitFunction);
184 for (
Function *
F : DeadComdatFunctions) {
186 assert(C &&
"Expected all input GVs to be in a comdat!");
187 ComdatEntriesCovered[
C] += 1;
190 auto CheckComdat = [&](
Comdat &
C) {
191 auto CI = ComdatEntriesCovered.
find(&
C);
192 if (CI == ComdatEntriesCovered.
end())
197 if (CI->second > 0) {
204 ComdatEntriesCovered.
erase(CI);
207 auto CheckAllComdats = [&] {
211 if (ComdatEntriesCovered.
empty())
215 if (
Comdat *
C = GV.getComdat()) {
217 if (ComdatEntriesCovered.
empty())
221 if (
Comdat *
C = GA.getComdat()) {
223 if (ComdatEntriesCovered.
empty())
229 if (ComdatEntriesCovered.
empty()) {
230 DeadComdatFunctions.clear();
237 ComdatEntriesCovered.
end();
243 bool ExportsSymbols =
false;
245 if (GV.isDeclaration() || GV.getName().startswith(
"llvm.") ||
246 !GV.hasExternalLinkage())
248 ExportsSymbols =
true;
255 for (
auto &GV : M->globals())
257 for (
auto &GA : M->aliases())
259 for (
auto &
IF : M->ifuncs())
270 return (
"$" + Str).str();
void push_back(const T &Elt)
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void appendToGlobalDtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Same as appendToGlobalCtors(), but for global dtors.
Special purpose, only applies to global arrays.
Function * checkSanitizerInterfaceFunction(Constant *FuncOrBitcast)
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
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. ...
static void stringifyResult(MD5Result &Result, SmallString< 32 > &Str)
Translates the bytes in Res to a hex string that is deposited into Str.
Externally visible function.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
const Comdat * getComdat() const
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
const GlobalVariable * getNamedGlobal(StringRef Name) const
Return the global variable in the module with the specified name, of arbitrary type.
void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
Class to represent struct types.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
void filterDeadComdatFunctions(Module &M, SmallVectorImpl< Function * > &DeadComdatFunctions)
Filter out potentially dead comdat functions where other entries keep the entire comdat group alive...
LLVM_NODISCARD bool empty() const
Class to represent function types.
Class to represent array types.
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Type * getElementType() const
size_t size() const
size - Get the array size.
iterator find(const_arg_type_t< KeyT > Val)
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Function * declareSanitizerInitFunction(Module &M, StringRef InitName, ArrayRef< Type * > InitArgTypes)
bool erase(const KeyT &Val)
iterator_range< iterator > functions()
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important base class in LLVM.
static void appendToGlobalArray(const char *Array, Module &M, Function *F, int Priority, Constant *Data)
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
static Type * getVoidTy(LLVMContext &C)
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
std::string getUniqueModuleId(Module *M)
Produce a unique identifier for this module by taking the MD5 sum of the names of the module's strong...
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
std::pair< Function *, Function * > createSanitizerCtorAndInitFunctions(Module &M, StringRef CtorName, StringRef InitName, ArrayRef< Type * > InitArgTypes, ArrayRef< Value * > InitArgs, StringRef VersionCheckName=StringRef())
Creates sanitizer constructor function, and calls sanitizer's init function from it.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the generic address space (address sp...
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
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.
void appendToGlobalCtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Append F to the list of global ctors of module M with the given Priority.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
ConstantArray - Constant Array Declarations.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
static void appendToUsedList(Module &M, StringRef Name, ArrayRef< GlobalValue * > Values)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Rename collisions when linking (static functions).
LLVM_NODISCARD bool empty() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
void appendToUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.used list.
void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
iterator_range< global_iterator > globals()
StringRef - Represent a constant reference to a string, i.e.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
unsigned getNumElements() const
Random access to the elements.
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
LLVMContext & getContext() const
Get the global data context.
iterator_range< alias_iterator > aliases()