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