+template <typename ELFT>
+uint64_t LLVMDisassembler<ELFT>::entryAddress() {
+ const auto elffile = dyn_cast<ELFObjectFile<ELFT>>(o)->getELFFile();
+ const auto * header = elffile->getHeader();
+
+ return header->e_entry;
+}
+
+template <typename ELFT>
+void LLVMDisassembler<ELFT>::splitBlocks(Function* function) {
+ SectionRef text_section = sections[".text"];
+ StringRef bytes;
+ text_section.getContents(bytes);
+ StringRefMemoryObject ref(bytes);
+
+ // Split blocks where jumps are going inside the block
+ for (auto it = function->blocks().begin();
+ it != function->blocks().end();
+ ++it) {
+ BasicBlock * current_block = it->second;
+ uint64_t inst_size;
+ uint64_t base_address;
+ text_section.getAddress(base_address);
+ uint64_t current_address = current_block->getStartAddress() - base_address;
+ while(current_block->getEndAddress() - base_address > current_address) {
+ MCInst inst;
+ std::string buf;
+ llvm::raw_string_ostream s(buf);
+
+ if(llvm::MCDisassembler::Success ==
+ DisAsm->getInstruction(inst, inst_size, ref, current_address, nulls(), nulls())) {
+ // See if some other block starts here
+ BasicBlock* other = manager->getBasicBlock(current_address
+ + inst_size
+ + base_address);
+
+ // Special case, other block starts here but we are at the end anyway
+ if (other != NULL) {
+ uint64_t endaddress = current_address + inst_size + base_address;
+ if (endaddress != current_block->getEndAddress()) {
+ LOG4CXX_DEBUG(logger, "Shortening block starting at "
+ << std::hex
+ << current_block->getStartAddress()
+ << " now ending at "
+ << other->getStartAddress());
+ function->addBasicBlock(other);
+ current_block->setEndAddress(endaddress);
+ current_block->setNextBlock(0, other->getStartAddress());
+ current_block->setNextBlock(1, 0);
+ }
+ }
+ } else {
+ inst_size = 1;
+ }
+ current_address += inst_size;
+ }
+ }
+}
+
+template<>
+void LLVMDisassembler<COFFT>::readDynamicSymbols() {
+ //TODO
+}
+
+template <typename ELFT>
+void LLVMDisassembler<ELFT>::readDynamicSymbols() {
+ const auto elffile = dyn_cast<ELFObjectFile<ELFT>>(o)->getELFFile();
+ for (auto it = elffile->begin_dynamic_symbols(),
+ end = elffile->end_dynamic_symbols();
+ it != end;
+ ++it) {
+ if (it->getType() == 2) { // Function
+ bool is_default;
+ // TODO: Error handling
+ std::string symbolname = *(elffile->getSymbolName(it));
+ std::string symbolversion = *(elffile->getSymbolVersion(nullptr, &*it, is_default));
+ manager->signal_new_dyn_symbol(symbolname + (is_default? "@@" : "@") + symbolversion);
+ LOG4CXX_DEBUG(logger, "Adding dynamic Symbol " << symbolname << (is_default? "@@" : "@") << symbolversion);
+ }
+ }
+}
+
+template <typename ELFT>
+void LLVMDisassembler<ELFT>::readSymbols() {
+ error_code ec;
+ symbol_iterator si(o->symbol_begin()), se(o->symbol_end());
+ for (; si != se; ++si) {
+ StringRef name;
+ if ((ec = si->getName(name))) {
+ LOG4CXX_ERROR(logger, ec.message());
+ break;
+ }
+ LOG4CXX_DEBUG(logger, "Added symbol " << name.str());
+ symbols.insert(make_pair(name.str(), *si));
+ }
+}
+
+template <typename ELFT>
+void LLVMDisassembler<ELFT>::readSections() {
+ error_code ec;
+ section_iterator i(o->section_begin()), e(o->section_end());
+ for (; i != e; ++i) {
+ StringRef name;
+ if ((ec = i->getName(name))) {
+ LOG4CXX_ERROR(logger, ec.message());
+ break;
+ }
+ LOG4CXX_DEBUG(logger, "Added section " << name.str());
+ sections.insert(make_pair(name.str(), *i));
+ }
+
+}