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);
177 std::pair<Function *, Function *>
183 assert(!CtorName.
empty() &&
"Expected ctor function name");
188 if (Ctor->arg_size() == 0 ||
194 M, CtorName, InitName, InitArgTypes, InitArgs, VersionCheckName);
195 FunctionsCreatedCallback(Ctor, InitFunction);
196 return std::make_pair(Ctor, InitFunction);
200 assert(!Name.
empty() &&
"Expected init function name");
202 if (
F->arg_size() != 0 ||
206 Stream <<
"Sanitizer interface function defined with wrong type: " << *
F;
227 for (
Function *
F : DeadComdatFunctions) {
229 assert(C &&
"Expected all input GVs to be in a comdat!");
230 ComdatEntriesCovered[
C] += 1;
233 auto CheckComdat = [&](
Comdat &
C) {
234 auto CI = ComdatEntriesCovered.
find(&
C);
235 if (CI == ComdatEntriesCovered.
end())
240 if (CI->second > 0) {
247 ComdatEntriesCovered.
erase(CI);
250 auto CheckAllComdats = [&] {
254 if (ComdatEntriesCovered.
empty())
258 if (
Comdat *
C = GV.getComdat()) {
260 if (ComdatEntriesCovered.
empty())
264 if (
Comdat *
C = GA.getComdat()) {
266 if (ComdatEntriesCovered.
empty())
272 if (ComdatEntriesCovered.
empty()) {
273 DeadComdatFunctions.clear();
280 ComdatEntriesCovered.
end();
286 bool ExportsSymbols =
false;
288 if (GV.isDeclaration() || GV.getName().startswith(
"llvm.") ||
289 !GV.hasExternalLinkage() || GV.hasComdat())
291 ExportsSymbols =
true;
298 for (
auto &GV : M->globals())
300 for (
auto &GA : M->aliases())
302 for (
auto &
IF : M->ifuncs())
313 return (
"$" + Str).str();
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue *> Values)
Adds global values to the llvm.compiler.used list.
Function * declareSanitizerInitFunction(Module &M, StringRef InitName, ArrayRef< Type *> InitArgTypes)
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)
Function * getOrCreateInitFunction(Module &M, StringRef Name)
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
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.
unsigned getNumElements() const
Random access to the elements.
void push_back(const T &Elt)
An efficient, type-erasing, non-owning reference to a callable.
const GlobalVariable * getNamedGlobal(StringRef Name) const
Return the global variable in the module with the specified name, of arbitrary type.
Externally visible function.
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
static Constant * get(ArrayType *T, ArrayRef< Constant *> V)
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)
amdgpu Simplify well known AMD library false Value Value const Twine & Name
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
Class to represent struct types.
LLVMContext & getContext() const
Get the global data context.
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...
static StructType * get(LLVMContext &Context, ArrayRef< Type *> Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Class to represent function types.
void appendToUsed(Module &M, ArrayRef< GlobalValue *> Values)
Adds global values to the llvm.used list.
Class to represent array types.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
iterator find(const_arg_type_t< KeyT > Val)
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool erase(const KeyT &Val)
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
iterator_range< iterator > functions()
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
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.
size_t size() const
size - Get the array size.
This is an important base class in LLVM.
static void appendToGlobalArray(const char *Array, Module &M, Function *F, int Priority, Constant *Data)
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)
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Constant * get(StructType *T, ArrayRef< Constant *> V)
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
static void appendToUsedList(Module &M, StringRef Name, ArrayRef< GlobalValue *> Values)
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.
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...
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 setLinkage(LinkageTypes LT)
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
const Comdat * getComdat() const
ConstantArray - Constant Array Declarations.
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
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.
Type * getElementType() const
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.
std::pair< Function *, Function * > getOrCreateSanitizerCtorAndInitFunctions(Module &M, StringRef CtorName, StringRef InitName, ArrayRef< Type *> InitArgTypes, ArrayRef< Value *> InitArgs, function_ref< void(Function *, Function *)> FunctionsCreatedCallback, StringRef VersionCheckName=StringRef())
Creates sanitizer constructor function lazily.
iterator_range< alias_iterator > aliases()