1 //===- GdbIndex.cpp -------------------------------------------------------===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
15 //===----------------------------------------------------------------------===//
19 #include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h"
20 #include "llvm/Object/ELFObjectFile.h"
23 using namespace llvm::object;
25 using namespace lld::elf;
27 std::pair<bool, GdbSymbol *> GdbHashTab::add(uint32_t Hash, size_t Offset) {
28 GdbSymbol *&Sym = Map[Offset];
31 Sym = make<GdbSymbol>(Hash, Offset);
35 void GdbHashTab::finalizeContents() {
36 uint32_t Size = std::max<uint32_t>(1024, NextPowerOf2(Map.size() * 4 / 3));
37 uint32_t Mask = Size - 1;
41 GdbSymbol *Sym = P.second;
42 uint32_t I = Sym->NameHash & Mask;
43 uint32_t Step = ((Sym->NameHash * 17) & Mask) | 1;
46 I = (I + Step) & Mask;