43#define DEBUG_TYPE "jmc-instrumenter"
52char JMCInstrumenter::ID = 0;
62 "Instrument function entry with call to __CheckForDebuggerJustMyCode",
68const char CheckFunctionName[] =
"__CheckForDebuggerJustMyCode";
70std::string getFlagName(
DISubprogram &SP,
bool UseX86FastCall) {
78 SP.getDirectory().contains(
"\\") ||
79 SP.getFilename().contains(
"\\")
100 Suffix.push_back(
C ==
'.' ?
'@' :
C);
103 return (UseX86FastCall ?
"_" :
"__") +
116 DB.createBasicType(
"unsigned char", 8, dwarf::DW_ATE_unsigned_char,
117 llvm::DINode::FlagArtificial);
119 auto *DGVE =
DB.createGlobalVariableExpression(
121 0, DType,
true,
true);
132Function *createDefaultCheckFunction(
Module &M,
bool UseX86FastCall) {
134 const char *DefaultCheckFunctionName =
135 UseX86FastCall ?
"_JustMyCode_Default" :
"__JustMyCode_Default";
139 DefaultCheckFunctionName, &M);
147 return DefaultCheckFunc;
154 Triple ModuleTriple(M.getTargetTriple());
157 assert((IsELF || IsMSVC) &&
"Unsupported triple for JMC");
159 const char *
const FlagSymbolSection = IsELF ?
".data.just.my.code" :
".msvcjmc";
164 if (
F.isDeclaration())
166 auto *SP =
F.getSubprogram();
172 std::string FlagName = getFlagName(*SP, UseX86FastCall);
174 Flag = M.getOrInsertGlobal(FlagName, FlagTy, [&] {
179 ConstantInt::get(FlagTy, 1), FlagName);
183 attachDebugInfo(*GV, *SP);
188 if (!CheckFunction) {
190 createDefaultCheckFunction(M, UseX86FastCall);
192 DefaultCheckFunc->
setName(CheckFunctionName);
194 CheckFunction = DefaultCheckFunc;
196 assert(!M.getFunction(CheckFunctionName) &&
197 "JMC instrument more than once?");
199 M.getOrInsertFunction(CheckFunctionName, getCheckFunctionType(Ctx))
202 CheckFunc->addParamAttr(0, Attribute::NoUndef);
203 if (UseX86FastCall) {
205 CheckFunc->addParamAttr(0, Attribute::InReg);
207 CheckFunction = CheckFunc;
211 Comdat *
C = M.getOrInsertComdat(DefaultCheckFunctionName);
217 std::string AltOption = std::string(
"/alternatename:") +
218 CheckFunctionName +
"=" +
219 DefaultCheckFunctionName.
str();
222 M.getOrInsertNamedMetadata(
"llvm.linker.options")->addOperand(
N);
228 {Flag},
"",
F.begin()->getFirstInsertionPt());
229 CI->addParamAttr(0, Attribute::NoUndef);
230 if (UseX86FastCall) {
232 CI->addParamAttr(0, Attribute::InReg);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool runImpl(Function &F, const TargetLowering &TLI, const LibcallLoweringInfo &Libcalls, 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.
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.
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.