1 /*
2     Copyright (C) 2013-2014 Volker Krause <vkrause@kde.org>
3 
4     This program is free software; you can redistribute it and/or modify it
5     under the terms of the GNU Library General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or (at your
7     option) any later version.
8 
9     This program is distributed in the hope that it will be useful, but WITHOUT
10     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
12     License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with this program.  If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef ELFSYMBOLTABLESECTION_H
19 #define ELFSYMBOLTABLESECTION_H
20 
21 #include "elfarraysection.h"
22 #include "elfsymboltableentry.h"
23 
24 #include <vector>
25 
26 /** Represents a symbol table sections (.symtab or .dynsym). */
27 class ElfSymbolTableSection : public ElfSection
28 {
29 public:
30     explicit ElfSymbolTableSection(ElfFile* file, ElfSectionHeader *shdr);
31     ~ElfSymbolTableSection();
32 
33     /** Number of exported entries. */
34     int exportCount() const;
35 
36     /** Number of undefined symbols, i.e. symbols needed to be provided from other libraries. */
37     int importCount() const;
38 
39     /** Returns the symbol table at @p index. */
40     ElfSymbolTableEntry* entry(uint32_t index) const;
41 
42     /** Finds the first symbol table entry with the given value.
43      *  @return @c 0 if there is no matching entry.
44      */
45     ElfSymbolTableEntry* entryWithValue(uint64_t value) const;
46 
47     /** Similar as the above, but looks for entries containing @p value rather than matching it exactly .*/
48     ElfSymbolTableEntry* entryContainingValue(uint64_t value) const;
49 
50 private:
51     // entries in order of occurrence
52     std::vector<ElfSymbolTableEntry> m_entries;
53     // entry pointers in order of their virtual address, for fast reverse lookup
54     std::vector<ElfSymbolTableEntry*> m_entriesByValue;
55 };
56 
57 #endif // ELFSYMBOLTABLESECTION_H
58