void annotateStubs(Executable& executable, Module& module) { Function* jumpIntrin = module.getFunction("x86_jump_intrin"); // This may eventually need to be moved to a pass of its own or something. vector<Function*> functions; for (Function& fn : module.getFunctionList()) { if (md::isPrototype(fn)) { continue; } BasicBlock& entry = fn.getEntryBlock(); auto terminator = entry.getTerminator(); if (isa<UnreachableInst>(terminator)) { if (auto prev = dyn_cast<CallInst>(terminator->getPrevNode())) if (prev->getCalledFunction() == jumpIntrin) if (auto load = dyn_cast<LoadInst>(prev->getOperand(2))) if (auto constantExpr = dyn_cast<ConstantExpr>(load->getPointerOperand())) { unique_ptr<Instruction> inst(constantExpr->getAsInstruction()); if (auto int2ptr = dyn_cast<IntToPtrInst>(inst.get())) { auto value = cast<ConstantInt>(int2ptr->getOperand(0)); auto intValue = value->getLimitedValue(); if (const string* stubTarget = executable.getStubTarget(intValue)) { md::setImportName(fn, *stubTarget); fn.setName(*stubTarget); } } } } } }