Go to the documentation of this file.
31 #define DEBUG_TYPE "instrorderfile"
34 "orderfile-write-mapping",
cl::init(
""),
36 "Dump functions and their MD5 hash to deobfuscate profile data"),
46 std::mutex MappingMutex;
48 struct InstrOrderFile {
57 InstrOrderFile() =
default;
59 void createOrderFileData(
Module &M) {
63 if (!
F.isDeclaration())
73 std::string
SymbolName = INSTR_PROF_ORDERFILE_BUFFER_NAME_STR;
80 std::string IndexName = INSTR_PROF_ORDERFILE_BUFFER_IDX_NAME_STR;
84 std::string BitMapName =
"bitmap_0";
93 std::lock_guard<std::mutex> LogLock(MappingMutex);
99 " to save mapping file for order file instrumentation\n");
101 std::stringstream stream;
102 stream << std::hex <<
MD5Hash(
F.getName());
103 std::string singleLine =
"MD5 " + stream.str() +
" " +
104 std::string(
F.getName()) +
'\n';
129 Value *MapAddr = entryB.CreateGEP(MapTy, BitMap, IdxFlags,
"");
130 LoadInst *loadBitMap = entryB.CreateLoad(Int8Ty, MapAddr,
"");
132 Value *IsNotExecuted =
134 entryB.CreateCondBr(IsNotExecuted, UpdateOrderFileBB, OrigEntry);
137 Value *IdxVal = updateB.CreateAtomicRMW(
141 Value *WrappedIdx = updateB.CreateAnd(
145 updateB.CreateGEP(BufferTy, OrderFileBuffer, BufferGEPIdx,
"");
148 updateB.CreateBr(OrigEntry);
152 createOrderFileData(M);
156 if (
F.isDeclaration())
158 generateCodeSequence(M,
F,
FuncId);
167 class InstrOrderFileLegacyPass :
public ModulePass {
176 bool runOnModule(
Module &M)
override;
181 bool InstrOrderFileLegacyPass::runOnModule(
Module &M) {
185 return InstrOrderFile().run(M);
190 if (InstrOrderFile().
run(
M))
196 "Instrumentation for Order File",
false,
false)
200 char InstrOrderFileLegacyPass::
ID = 0;
203 return new InstrOrderFileLegacyPass();
A set of analyses that are preserved following a run of a transformation pass.
This is an optimization pass for GlobalISel generic memory operations.
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Triple - Helper class for working with autoconf configuration names.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
The instances of the Type class are immutable: once they are created, they are never changed.
Class to represent array types.
static IntegerType * getInt8Ty(LLVMContext &C)
static IntegerType * getInt32Ty(LLVMContext &C)
LLVM Basic Block Representation.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
static cl::opt< std::string > ClOrderFileWriteMapping("orderfile-write-mapping", cl::init(""), cl::desc("Dump functions and their MD5 hash to deobfuscate profile data"), cl::Hidden)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
void setSection(StringRef S)
Change the section for this global.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Class to represent integer types.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
This is an important class for using LLVM in a threaded context.
initializer< Ty > init(const Ty &Val)
INITIALIZE_PASS_BEGIN(InstrOrderFileLegacyPass, "instrorderfile", "Instrumentation for Order File", false, false) INITIALIZE_PASS_END(InstrOrderFileLegacyPass
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
A Module instance is used to store all the information related to an LLVM module.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
this could be done in SelectionDAGISel along with other special for
An instruction for reading from memory.
A raw_ostream that writes to a file descriptor.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static IntegerType * getInt64Ty(LLVMContext &C)
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void initializeInstrOrderFileLegacyPassPass(PassRegistry &)
std::string getInstrProfSectionName(InstrProfSectKind IPSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)
Return the name of the profile section corresponding to IPSK.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ OF_Append
The file should be opened in append mode.
ModulePass * createInstrOrderFilePass()
A container for analyses that lazily runs them and caches their results.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
LLVM Value Representation.
uint64_t MD5Hash(StringRef Str)
Helper to compute and return lower 64 bits of the given string's MD5 hash.