40 #define DEBUG_TYPE "instrorderfile" 43 "orderfile-write-mapping",
cl::init(
""),
45 "Dump functions and their MD5 hash to deobfuscate profile data"),
55 std::mutex MappingMutex;
57 struct InstrOrderFile {
68 void createOrderFileData(
Module &M) {
72 if (!
F.isDeclaration())
82 std::string
SymbolName = INSTR_PROF_ORDERFILE_BUFFER_NAME_STR;
89 std::string IndexName = INSTR_PROF_ORDERFILE_BUFFER_IDX_NAME_STR;
93 std::string BitMapName =
"bitmap_0";
102 std::lock_guard<std::mutex> LogLock(MappingMutex);
108 " to save mapping file for order file instrumentation\n");
110 std::stringstream stream;
112 std::string singleLine =
"MD5 " + stream.str() +
" " +
113 std::string(F.
getName()) +
'\n';
138 Value *MapAddr = entryB.CreateGEP(MapTy, BitMap, IdxFlags,
"");
139 LoadInst *loadBitMap = entryB.CreateLoad(Int8Ty, MapAddr,
"");
141 Value *IsNotExecuted =
143 entryB.CreateCondBr(IsNotExecuted, UpdateOrderFileBB, OrigEntry);
146 Value *IdxVal = updateB.CreateAtomicRMW(
150 Value *WrappedIdx = updateB.CreateAnd(
154 updateB.CreateGEP(BufferTy, OrderFileBuffer, BufferGEPIdx,
"");
157 updateB.CreateBr(OrigEntry);
161 createOrderFileData(M);
167 generateCodeSequence(M, F, FuncId);
176 class InstrOrderFileLegacyPass :
public ModulePass {
185 bool runOnModule(
Module &M)
override;
190 bool InstrOrderFileLegacyPass::runOnModule(
Module &M) {
194 return InstrOrderFile().run(M);
199 if (InstrOrderFile().run(M))
205 "Instrumentation for Order File",
false,
false)
209 char InstrOrderFileLegacyPass::
ID = 0;
212 return new InstrOrderFileLegacyPass();
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
INITIALIZE_PASS_BEGIN(InstrOrderFileLegacyPass, "instrorderfile", "Instrumentation for Order File", false, false) INITIALIZE_PASS_END(InstrOrderFileLegacyPass
uint64_t MD5Hash(StringRef Str)
Helper to compute and return lower 64 bits of the given string's MD5 hash.
Like Internal, but omit from symbol table.
std::string getInstrProfSectionName(InstrProfSectKind IPSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)
Return the name of the profile section corresponding to IPSK.
An instruction for reading from memory.
static IntegerType * getInt64Ty(LLVMContext &C)
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVMContext & getContext() const
Get the global data context.
ModulePass * createInstrOrderFilePass()
void initializeInstrOrderFileLegacyPassPass(PassRegistry &)
Class to represent array types.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
const BasicBlock & getEntryBlock() const
Same, but only replaced by something equivalent.
initializer< Ty > init(const Ty &Val)
A set of analyses that are preserved following a run of a transformation pass.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
Instrumentation for Order File
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)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Class to represent integer types.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
Triple - Helper class for working with autoconf configuration names.
Module.h This file contains the declarations for the Module class.
The file should be opened in append mode.
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.
A raw_ostream that writes to a file descriptor.
static IntegerType * getInt32Ty(LLVMContext &C)
ObjectFormatType getObjectFormat() const
getFormat - Get the object format for this triple.
StringRef getName() const
Return a constant reference to the value's name.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
LLVM Value Representation.
A container for analyses that lazily runs them and caches their results.
for(unsigned i=Desc.getNumOperands(), e=OldMI.getNumOperands();i !=e;++i)
static IntegerType * getInt8Ty(LLVMContext &C)
void setSection(StringRef S)
Change the section for this global.