File indexing completed on 2024-05-12 05:43:30

0001 /*
0002     Copyright (C) 2013-2014 Volker Krause <vkrause@kde.org>
0003 
0004     This program is free software; you can redistribute it and/or modify it
0005     under the terms of the GNU Library General Public License as published by
0006     the Free Software Foundation; either version 2 of the License, or (at your
0007     option) any later version.
0008 
0009     This program is distributed in the hope that it will be useful, but WITHOUT
0010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
0012     License for more details.
0013 
0014     You should have received a copy of the GNU General Public License
0015     along with this program.  If not, see <https://www.gnu.org/licenses/>.
0016 */
0017 
0018 #ifndef ELFSYMBOLTABLEENTRY_H
0019 #define ELFSYMBOLTABLEENTRY_H
0020 
0021 #include <cstdint>
0022 #include <elf.h>
0023 
0024 class ElfSectionHeader;
0025 class ElfSection;
0026 class ElfSymbolTableSection;
0027 
0028 /** Symbol table entry. */
0029 class ElfSymbolTableEntry
0030 {
0031 public:
0032     ElfSymbolTableEntry();
0033     explicit ElfSymbolTableEntry(const ElfSymbolTableSection* section, uint32_t index);
0034 
0035     const ElfSymbolTableSection* symbolTable() const;
0036 
0037     uint16_t sectionIndex() const;
0038     uint64_t value() const;
0039     uint64_t size() const;
0040 
0041     /** Bind type. */
0042     uint8_t bindType() const;
0043     /** Symbol type. */
0044     uint8_t type() const;
0045     /** Symbol visibility. */
0046     uint8_t visibility() const;
0047 
0048     /** Pointer to the associated code/data. */
0049     const unsigned char* data() const;
0050 
0051     /** Mangled name from string table. */
0052     const char* name() const;
0053 
0054     /** Returns true if this symbol is in a valid section. */
0055     bool hasValidSection() const;
0056     /** Header of the section this symbol is in. */
0057     ElfSectionHeader* sectionHeader() const;
0058     /** Section this symbol is in. */
0059     ElfSection* section() const;
0060 
0061     /** Index in the symbol table. */
0062     uint32_t index() const;
0063 
0064 private:
0065     uint32_t nameIndex() const;
0066     uint8_t info() const;
0067     uint8_t other() const;
0068 
0069     const ElfSymbolTableSection *m_section;
0070     union {
0071         Elf32_Sym* sym32;
0072         Elf64_Sym* sym64;
0073     } m_symbol;
0074 };
0075 
0076 #endif // ELFSYMBOLTABLEENTRY_H