27#define DEBUG_TYPE "instrorderfile"
30 "orderfile-write-mapping",
cl::init(
""),
32 "Dump functions and their MD5 hash to deobfuscate profile data"),
42std::mutex MappingMutex;
44struct InstrOrderFile {
53 InstrOrderFile() =
default;
55 void createOrderFileData(
Module &M) {
59 if (!
F.isDeclaration())
69 std::string
SymbolName = INSTR_PROF_ORDERFILE_BUFFER_NAME_STR;
76 std::string IndexName = INSTR_PROF_ORDERFILE_BUFFER_IDX_NAME_STR;
80 std::string BitMapName =
"bitmap_0";
89 std::lock_guard<std::mutex> LogLock(MappingMutex);
95 " to save mapping file for order file instrumentation\n");
97 std::stringstream stream;
98 stream << std::hex <<
MD5Hash(
F.getName());
99 std::string singleLine =
"MD5 " + stream.str() +
" " +
100 std::string(
F.getName()) +
'\n';
123 Value *IdxFlags[] = {ConstantInt::get(Int32Ty, 0),
124 ConstantInt::get(Int32Ty,
FuncId)};
125 Value *MapAddr = entryB.CreateGEP(MapTy, BitMap, IdxFlags,
"");
126 LoadInst *loadBitMap = entryB.CreateLoad(Int8Ty, MapAddr,
"");
127 entryB.CreateStore(ConstantInt::get(Int8Ty, 1), MapAddr);
128 Value *IsNotExecuted =
129 entryB.CreateICmpEQ(loadBitMap, ConstantInt::get(Int8Ty, 0));
130 entryB.CreateCondBr(IsNotExecuted, UpdateOrderFileBB, OrigEntry);
133 Value *IdxVal = updateB.CreateAtomicRMW(
135 MaybeAlign(), AtomicOrdering::SequentiallyConsistent);
137 Value *WrappedIdx = updateB.CreateAnd(
138 IdxVal, ConstantInt::get(Int32Ty, INSTR_ORDER_FILE_BUFFER_MASK));
139 Value *BufferGEPIdx[] = {ConstantInt::get(Int32Ty, 0), WrappedIdx};
141 updateB.CreateGEP(BufferTy, OrderFileBuffer, BufferGEPIdx,
"");
144 updateB.CreateBr(OrigEntry);
148 createOrderFileData(M);
152 if (
F.isDeclaration())
154 generateCodeSequence(M,
F,
FuncId);
166 if (InstrOrderFile().
run(M))
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
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)
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.