43#define DEBUG_TYPE "jmc-instrumenter"
54char JMCInstrumenter::ID = 0;
64 "Instrument function entry with call to __CheckForDebuggerJustMyCode",
70const char CheckFunctionName[] =
"__CheckForDebuggerJustMyCode";
72std::string getFlagName(
DISubprogram &SP,
bool UseX86FastCall) {
80 SP.getDirectory().contains(
"\\") ||
81 SP.getFilename().contains(
"\\")
102 Suffix.push_back(
C ==
'.' ?
'@' :
C);
105 return (UseX86FastCall ?
"_" :
"__") +
118 DB.createBasicType(
"unsigned char", 8, dwarf::DW_ATE_unsigned_char,
119 llvm::DINode::FlagArtificial);
121 auto *DGVE =
DB.createGlobalVariableExpression(
123 0, DType,
true,
true);
134Function *createDefaultCheckFunction(
Module &M,
bool UseX86FastCall) {
136 const char *DefaultCheckFunctionName =
137 UseX86FastCall ?
"_JustMyCode_Default" :
"__JustMyCode_Default";
141 DefaultCheckFunctionName, &M);
149 return DefaultCheckFunc;
156 Triple ModuleTriple(M.getTargetTriple());
159 assert((IsELF || IsMSVC) &&
"Unsupported triple for JMC");
161 const char *
const FlagSymbolSection = IsELF ?
".data.just.my.code" :
".msvcjmc";
166 if (
F.isDeclaration())
168 auto *SP =
F.getSubprogram();
174 std::string FlagName = getFlagName(*SP, UseX86FastCall);
176 Flag = M.getOrInsertGlobal(FlagName, FlagTy, [&] {
181 ConstantInt::get(FlagTy, 1), FlagName);
185 attachDebugInfo(*GV, *SP);
190 if (!CheckFunction) {
192 createDefaultCheckFunction(M, UseX86FastCall);
194 DefaultCheckFunc->
setName(CheckFunctionName);
196 CheckFunction = DefaultCheckFunc;
198 assert(!M.getFunction(CheckFunctionName) &&
199 "JMC instrument more than once?");
201 M.getOrInsertFunction(CheckFunctionName, getCheckFunctionType(Ctx))
204 CheckFunc->addParamAttr(0, Attribute::NoUndef);
205 if (UseX86FastCall) {
207 CheckFunc->addParamAttr(0, Attribute::InReg);
209 CheckFunction = CheckFunc;
213 Comdat *
C = M.getOrInsertComdat(DefaultCheckFunctionName);
219 std::string AltOption = std::string(
"/alternatename:") +
220 CheckFunctionName +
"=" +
221 DefaultCheckFunctionName.
str();
224 M.getOrInsertNamedMetadata(
"llvm.linker.options")->addOperand(
N);
230 {Flag},
"",
F.begin()->getFirstInsertionPt());
231 CI->addParamAttr(0, Attribute::NoUndef);
232 if (UseX86FastCall) {
234 CI->addParamAttr(0, Attribute::InReg);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool runImpl(Function &F, const TargetLowering &TLI, AssumptionCache *AC)
Module.h This file contains the declarations for the Module class.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
static bool runImpl(Module &M)
Machine Check Debug Module
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the SmallString class.
LLVM Basic Block Representation.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
@ Any
The linker may choose any COMDAT.
This is an important base class in LLVM.
Subprogram description. Uses SubclassData1.
Class to represent function types.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
adds the attribute to the list of attributes for the given arg.
LLVM_ABI void setComdat(Comdat *C)
LLVM_ABI void setSection(StringRef S)
Change the section for this global.
LLVM_ABI void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
void setUnnamedAddr(UnnamedAddr Val)
void setLinkage(LinkageTypes LT)
Module * getParent()
Get the module that this global value is contained inside of...
@ InternalLinkage
Rename collisions when linking (static functions).
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalVariable.
Class to represent integer types.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
This is an important class for using LLVM in a threaded context.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
A Module instance is used to store all the information related to an LLVM module.
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Class to represent pointers.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
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.
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, InsertPosition InsertBefore=nullptr)
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
Triple - Helper class for working with autoconf configuration names.
ArchType getArch() const
Get the parsed architecture type of this triple.
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
bool isKnownWindowsMSVCEnvironment() const
Checks if the environment is MSVC.
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
@ X86_FastCall
'fast' analog of X86_StdCall.
LLVM_ABI void remove_filename(SmallVectorImpl< char > &path, Style style=Style::native)
Remove the last component from path unless it is the root dir.
LLVM_ABI bool has_root_name(const Twine &path, Style style=Style::native)
Has root name?
LLVM_ABI bool remove_dots(SmallVectorImpl< char > &path, bool remove_dot_dot=false, Style style=Style::native)
In-place remove any '.
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI ModulePass * createJMCInstrumenterPass()
JMC instrument pass.
LLVM_ABI void initializeJMCInstrumenterPass(PassRegistry &)
std::string utohexstr(uint64_t X, bool LowerCase=false, unsigned Width=0)
uint32_t djbHash(StringRef Buffer, uint32_t H=5381)
The Bernstein hash function used by the DWARF accelerator tables.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI void appendToUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.used list.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
This struct is a compact representation of a valid (non-zero power of two) alignment.