28#define DEBUG_TYPE "instrorderfile"
31 "orderfile-write-mapping",
cl::init(
""),
33 "Dump functions and their MD5 hash to deobfuscate profile data"),
43std::mutex MappingMutex;
45struct InstrOrderFile {
54 InstrOrderFile() =
default;
56 void createOrderFileData(
Module &M) {
60 if (!
F.isDeclaration())
70 std::string
SymbolName = INSTR_PROF_ORDERFILE_BUFFER_NAME_STR;
77 std::string IndexName = INSTR_PROF_ORDERFILE_BUFFER_IDX_NAME_STR;
81 std::string BitMapName =
"bitmap_0";
90 std::lock_guard<std::mutex> LogLock(MappingMutex);
96 " to save mapping file for order file instrumentation\n");
98 std::stringstream stream;
99 stream << std::hex <<
MD5Hash(
F.getName());
100 std::string singleLine =
"MD5 " + stream.str() +
" " +
101 std::string(
F.getName()) +
'\n';
124 Value *IdxFlags[] = {ConstantInt::get(Int32Ty, 0),
125 ConstantInt::get(Int32Ty,
FuncId)};
126 Value *MapAddr = entryB.CreateGEP(MapTy, BitMap, IdxFlags,
"");
127 LoadInst *loadBitMap = entryB.CreateLoad(Int8Ty, MapAddr,
"");
128 entryB.CreateStore(ConstantInt::get(Int8Ty, 1), MapAddr);
129 Value *IsNotExecuted =
130 entryB.CreateICmpEQ(loadBitMap, ConstantInt::get(Int8Ty, 0));
131 entryB.CreateCondBr(IsNotExecuted, UpdateOrderFileBB, OrigEntry);
134 Value *IdxVal = updateB.CreateAtomicRMW(
136 MaybeAlign(), AtomicOrdering::SequentiallyConsistent);
138 Value *WrappedIdx = updateB.CreateAnd(
139 IdxVal, ConstantInt::get(Int32Ty, INSTR_ORDER_FILE_BUFFER_MASK));
140 Value *BufferGEPIdx[] = {ConstantInt::get(Int32Ty, 0), WrappedIdx};
142 updateB.CreateGEP(BufferTy, OrderFileBuffer, BufferGEPIdx,
"");
145 updateB.CreateBr(OrigEntry);
149 createOrderFileData(M);
153 if (
F.isDeclaration())
155 generateCodeSequence(M,
F,
FuncId);
167 if (InstrOrderFile().
run(M))
This file contains the declarations for the subclasses of Constant, which represent the different fla...
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)
Module.h This file contains the declarations for the Module class.
A container for analyses that lazily runs them and caches their results.
LLVM Basic Block Representation.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
void setSection(StringRef S)
Change the section for this global.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Class to represent integer types.
This is an important class for using LLVM in a threaded context.
An instruction for reading from memory.
A Module instance is used to store all the information related to an LLVM module.
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.
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
static IntegerType * getInt8Ty(LLVMContext &C)
static IntegerType * getInt32Ty(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
LLVM Value Representation.
A raw_ostream that writes to a file descriptor.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
initializer< Ty > init(const Ty &Val)
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
uint64_t MD5Hash(const FunctionId &Obj)
@ OF_Append
The file should be opened in append mode.
This is an optimization pass for GlobalISel generic memory operations.
std::string getInstrProfSectionName(InstrProfSectKind IPSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)
Return the name of the profile section corresponding to IPSK.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.