From 879c174dd56331b6c7b3254edd115e46a0b5e78c Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Wed, 21 Jan 2015 13:17:12 +0100 Subject: [PATCH] Create ObjectFile only once and store it with full type ObjectFiles was created twice, once to check the type it has and then again to store and use it in the disassembler. We now create it only once and store it with full type information for additional use --- src/disassembler/llvm/LLVMDisassembler.cxx | 49 ++++++++++++---------- src/disassembler/llvm/LLVMDisassembler.hxx | 5 ++- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/disassembler/llvm/LLVMDisassembler.cxx b/src/disassembler/llvm/LLVMDisassembler.cxx index cf40aaa..8dd5483 100644 --- a/src/disassembler/llvm/LLVMDisassembler.cxx +++ b/src/disassembler/llvm/LLVMDisassembler.cxx @@ -18,24 +18,20 @@ Disassembler * createLLVMDisassembler(const std::string& filename, InformationMa std::unique_ptr o; o.reset(createBinary(filename).get()); - const Binary * op = o.get(); + Binary * op = o.release(); // ELFType - if (const ELF32LEObjectFile * _ = dyn_cast(op)) { -#pragma unused(_) - return new LLVMDisassembler>(filename, manager); + if (ELF32LEObjectFile * object = dyn_cast(op)) { + return new LLVMDisassembler>(filename, manager, object); } - if (const ELF64LEObjectFile * _ = dyn_cast(op)) { -#pragma unused(_) - return new LLVMDisassembler>(filename, manager); + if (ELF64LEObjectFile * object = dyn_cast(op)) { + return new LLVMDisassembler>(filename, manager, object); } - if (const ELF32BEObjectFile * _ = dyn_cast(op)) { -#pragma unused(_) - return new LLVMDisassembler>(filename, manager); + if (ELF32BEObjectFile * object = dyn_cast(op)) { + return new LLVMDisassembler>(filename, manager, object); } - if (const ELF64BEObjectFile * _ = dyn_cast(op)) { -#pragma unused(_) - return new LLVMDisassembler>(filename, manager); + if (ELF64BEObjectFile * object = dyn_cast(op)) { + return new LLVMDisassembler>(filename, manager, object); } return NULL; @@ -48,25 +44,32 @@ Disassembler * createLLVMDisassembler(const std::string& filename, InformationMa */ template LLVMDisassembler::LLVMDisassembler(const std::string& filename, - InformationManager* manager) + InformationManager* manager, + ELFObjectFile* file) : Disassembler(filename, manager) , logger(log4cxx::Logger::getLogger("LLVMDisassembler")) , triple("unknown-unknown-unknown") , manager(manager) { LOG4CXX_DEBUG(logger, "Handling file" << filename); - auto result = createBinary(filename); - error_code ec; - if ((ec = result.getError())) { - LOG4CXX_ERROR(logger, "Failed to load Binary" << ec.message()); - binary = NULL; - return; - } + if (!file) { + auto result = createBinary(filename); - binary.reset(result.get()); + error_code ec; + if ((ec = result.getError())) { + LOG4CXX_ERROR(logger, "Failed to load Binary" << ec.message()); + binary = NULL; + return; + } - o = dyn_cast(binary.get()); + binary.reset(result.get()); + + o = dyn_cast>(binary.get()); + } else { + o = file; + binary.reset(file); + } triple.setArch(Triple::ArchType(o->getArch())); std::string tripleName(triple.getTriple()); diff --git a/src/disassembler/llvm/LLVMDisassembler.hxx b/src/disassembler/llvm/LLVMDisassembler.hxx index 59f7349..6c8767a 100644 --- a/src/disassembler/llvm/LLVMDisassembler.hxx +++ b/src/disassembler/llvm/LLVMDisassembler.hxx @@ -20,7 +20,8 @@ template class LLVMDisassembler : public Disassembler { public: - LLVMDisassembler(const std::string& filename, InformationManager* manager); + LLVMDisassembler(const std::string& filename, InformationManager* manager, + llvm::object::ELFObjectFile* file = NULL); virtual ~LLVMDisassembler(); void start(); @@ -59,7 +60,7 @@ private: std::shared_ptr binary; const llvm::Target * target; - llvm::object::ObjectFile * o; + llvm::object::ELFObjectFile * o; std::unique_ptr MRI; std::unique_ptr AsmInfo; -- 2.39.5