]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/ELF/GdbIndex.cpp
dts: Update our device tree sources file fomr Linux 4.13
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lld / ELF / GdbIndex.cpp
1 //===- GdbIndex.cpp -------------------------------------------------------===//
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 // The -gdb-index option instructs the linker to emit a .gdb_index section.
11 // The section contains information to make gdb startup faster.
12 // The format of the section is described at
13 // https://sourceware.org/gdb/onlinedocs/gdb/Index-Section-Format.html.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #include "GdbIndex.h"
18 #include "Memory.h"
19 #include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h"
20 #include "llvm/Object/ELFObjectFile.h"
21
22 using namespace llvm;
23 using namespace llvm::object;
24 using namespace lld;
25 using namespace lld::elf;
26
27 std::pair<bool, GdbSymbol *> GdbHashTab::add(uint32_t Hash, size_t Offset) {
28   GdbSymbol *&Sym = Map[Offset];
29   if (Sym)
30     return {false, Sym};
31   Sym = make<GdbSymbol>(Hash, Offset);
32   return {true, Sym};
33 }
34
35 void GdbHashTab::finalizeContents() {
36   uint32_t Size = std::max<uint32_t>(1024, NextPowerOf2(Map.size() * 4 / 3));
37   uint32_t Mask = Size - 1;
38   Table.resize(Size);
39
40   for (auto &P : Map) {
41     GdbSymbol *Sym = P.second;
42     uint32_t I = Sym->NameHash & Mask;
43     uint32_t Step = ((Sym->NameHash * 17) & Mask) | 1;
44
45     while (Table[I])
46       I = (I + Step) & Mask;
47     Table[I] = Sym;
48   }
49 }