ELFSectionSymTab.hxx revision e586f183e46f921301281352a87f67dbdc1a43b6
1#ifndef ELF_SECTION_SYM_TAB_HXX 2#define ELF_SECTION_SYM_TAB_HXX 3 4#include "ELFSectionHeader.h" 5#include "ELFSymbol.h" 6 7template <unsigned Bitwidth> 8ELFSectionSymTab<Bitwidth>::~ELFSectionSymTab() { 9 for (size_t i = 0; i < table.size(); ++i) { 10 delete table[i]; 11 } 12} 13 14template <unsigned Bitwidth> 15size_t ELFSectionSymTab<Bitwidth>::getExternFuncCount() const { 16 size_t result = 0; 17 for (size_t i = 0; i < table.size(); ++i) { 18 if (table[i] && table[i]->isExternFunc()) { 19 result++; 20 } 21 } 22 return result; 23} 24 25template <unsigned Bitwidth> 26template <typename Archiver> 27ELFSectionSymTab<Bitwidth> * 28ELFSectionSymTab<Bitwidth>::read(Archiver &AR, 29 ELFObjectTy *owner, 30 ELFSectionHeaderTy const *sh) { 31 32 llvm::OwningPtr<ELFSectionSymTabTy> st(new ELFSectionSymTabTy()); 33 34 // Assert that entry size will be the same as standard. 35 assert(sh->getEntrySize() == TypeTraits<ELFSymbolTy>::size); 36 37 // Seek to the start of symbol table 38 AR.seek(sh->getOffset(), true); 39 40 // Read all symbol table entry 41 size_t size = sh->getSize() / sh->getEntrySize(); 42 for (size_t i = 0; i < size; ++i) { 43 st->table.push_back(ELFSymbolTy::read(AR, owner, i)); 44 } 45 46 if (!AR) { 47 // Unable to read the table. 48 return 0; 49 } 50 51 return st.take(); 52} 53 54template <unsigned Bitwidth> 55void ELFSectionSymTab<Bitwidth>::print() const { 56 using namespace llvm; 57 58 out() << '\n' << fillformat('=', 79) << '\n'; 59 out().changeColor(raw_ostream::WHITE, true); 60 out() << "Symbol Table" << '\n'; 61 out().resetColor(); 62 63 for (size_t i = 0; i < table.size(); ++i) { 64 table[i]->print(); 65 } 66 67 out() << fillformat('=', 79) << '\n'; 68} 69 70#endif // ELF_SECTION_SYM_TAB_HXX 71