]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/ELF/GdbIndex.h
Update lld to trunk r290819 and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lld / ELF / GdbIndex.h
1 //===- GdbIndex.h --------------------------------------------*- C++ -*-===//
2 //
3 //                             The LLVM Linker
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===-------------------------------------------------------------------===//
9
10 #ifndef LLD_ELF_GDB_INDEX_H
11 #define LLD_ELF_GDB_INDEX_H
12
13 #include "InputFiles.h"
14 #include "llvm/Object/ELF.h"
15 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
16
17 namespace lld {
18 namespace elf {
19
20 template <class ELFT> class InputSection;
21
22 // Struct represents single entry of address area of gdb index.
23 template <class ELFT> struct AddressEntry {
24   InputSectionBase<ELFT> *Section;
25   uint64_t LowAddress;
26   uint64_t HighAddress;
27   size_t CuIndex;
28 };
29
30 // GdbIndexBuilder is a helper class used for extracting data required
31 // for building .gdb_index section from objects.
32 template <class ELFT> class GdbIndexBuilder : public llvm::LoadedObjectInfo {
33   typedef typename ELFT::uint uintX_t;
34
35   InputSection<ELFT> *DebugInfoSec;
36
37   std::unique_ptr<llvm::DWARFContext> Dwarf;
38
39 public:
40   GdbIndexBuilder(InputSection<ELFT> *DebugInfoSec);
41
42   // Extracts the compilation units. Each first element of pair is a offset of a
43   // CU in the .debug_info section and second is the length of that CU.
44   std::vector<std::pair<uintX_t, uintX_t>> readCUList();
45
46   // Extracts the vector of address area entries. Accepts global index of last
47   // parsed CU.
48   std::vector<AddressEntry<ELFT>> readAddressArea(size_t CurrentCU);
49
50   // Method extracts public names and types. It returns list of name and
51   // gnu_pub* kind pairs.
52   std::vector<std::pair<StringRef, uint8_t>> readPubNamesAndTypes();
53
54 private:
55   // Method returns section file offset as a load addres for DWARF parser. That
56   // allows to find the target section index for address ranges.
57   uint64_t
58   getSectionLoadAddress(const llvm::object::SectionRef &Sec) const override;
59   std::unique_ptr<llvm::LoadedObjectInfo> clone() const override;
60 };
61
62 // Element of GdbHashTab hash table.
63 struct GdbSymbol {
64   GdbSymbol(uint32_t Hash, size_t Offset)
65       : NameHash(Hash), NameOffset(Offset) {}
66   uint32_t NameHash;
67   size_t NameOffset;
68   size_t CuVectorIndex;
69 };
70
71 // This class manages the hashed symbol table for the .gdb_index section.
72 // The hash value for a table entry is computed by applying an iterative hash
73 // function to the symbol's name.
74 class GdbHashTab final {
75 public:
76   std::pair<bool, GdbSymbol *> add(uint32_t Hash, size_t Offset);
77
78   size_t getCapacity() { return Table.size(); }
79   GdbSymbol *getSymbol(size_t I) { return Table[I]; }
80
81 private:
82   void expand();
83
84   GdbSymbol **findSlot(uint32_t Hash, size_t Offset);
85
86   llvm::BumpPtrAllocator Alloc;
87   std::vector<GdbSymbol *> Table;
88
89   // Size keeps the amount of filled entries in Table.
90   size_t Size = 0;
91
92   // Initial size must be a power of 2.
93   static const int32_t InitialSize = 1024;
94 };
95
96 } // namespace elf
97 } // namespace lld
98
99 #endif