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 ELFSYMBOLTABLEENTRY_H 19 #define ELFSYMBOLTABLEENTRY_H 20 21 #include <cstdint> 22 #include <elf.h> 23 24 class ElfSectionHeader; 25 class ElfSection; 26 class ElfSymbolTableSection; 27 28 /** Symbol table entry. */ 29 class ElfSymbolTableEntry 30 { 31 public: 32 ElfSymbolTableEntry(); 33 explicit ElfSymbolTableEntry(const ElfSymbolTableSection* section, uint32_t index); 34 35 const ElfSymbolTableSection* symbolTable() const; 36 37 uint16_t sectionIndex() const; 38 uint64_t value() const; 39 uint64_t size() const; 40 41 /** Bind type. */ 42 uint8_t bindType() const; 43 /** Symbol type. */ 44 uint8_t type() const; 45 /** Symbol visibility. */ 46 uint8_t visibility() const; 47 48 /** Pointer to the associated code/data. */ 49 const unsigned char* data() const; 50 51 /** Mangled name from string table. */ 52 const char* name() const; 53 54 /** Returns true if this symbol is in a valid section. */ 55 bool hasValidSection() const; 56 /** Header of the section this symbol is in. */ 57 ElfSectionHeader* sectionHeader() const; 58 /** Section this symbol is in. */ 59 ElfSection* section() const; 60 61 /** Index in the symbol table. */ 62 uint32_t index() const; 63 64 private: 65 uint32_t nameIndex() const; 66 uint8_t info() const; 67 uint8_t other() const; 68 69 const ElfSymbolTableSection *m_section; 70 union { 71 Elf32_Sym* sym32; 72 Elf64_Sym* sym64; 73 } m_symbol; 74 }; 75 76 #endif // ELFSYMBOLTABLEENTRY_H 77