From f9ae4391568cfcbf4e6de0475bddcdd68e9b31d2 Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Tue, 10 Mar 2015 12:34:36 +0100 Subject: [PATCH] Finish current function before starting next one When BasicBlocks appear in multiple functions, we ran into the situation where a unfinished basicblock is included in a different function and causing bad loops as it's end address wasn't set yet --- src/disassembler/llvm/LLVMDisassembler.cxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/disassembler/llvm/LLVMDisassembler.cxx b/src/disassembler/llvm/LLVMDisassembler.cxx index 875a474..1f1cdff 100644 --- a/src/disassembler/llvm/LLVMDisassembler.cxx +++ b/src/disassembler/llvm/LLVMDisassembler.cxx @@ -206,6 +206,7 @@ Function* LLVMDisassembler::disassembleFunctionAt(uint64_t address, const template void LLVMDisassembler::disassembleFunction(Function* function) { + std::vector called_functions; std::stack remaining_blocks; /* TODO: * Do all blocks get added properly? We should take care to remove @@ -249,7 +250,7 @@ void LLVMDisassembler::disassembleFunction(Function* function) { if (!MIA->isIndirectBranch(inst)) { if (MIA->isCall(inst)) { if (NULL == manager->getFunction(jmptarget)) - disassembleFunctionAt(jmptarget); + called_functions.push_back(jmptarget); } else { current_block->setNextBlock(0, jmptarget); if (new_blocks.find(jmptarget) == new_blocks.end()) { @@ -298,6 +299,8 @@ void LLVMDisassembler::disassembleFunction(Function* function) { splitBlocks(function); LOG4CXX_DEBUG(logger, "Finished function " << function->getName()); manager->finishFunction(function); + for (uint64_t address : called_functions) + disassembleFunctionAt(address); } template -- 2.39.5