2016-10-20 17:19:48 +08:00
|
|
|
//===- GdbIndex.cpp -------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2017-03-29 08:09:40 +08:00
|
|
|
// The -gdb-index option instructs the linker to emit a .gdb_index section.
|
|
|
|
// The section contains information to make gdb startup faster.
|
|
|
|
// The format of the section is described at
|
|
|
|
// https://sourceware.org/gdb/onlinedocs/gdb/Index-Section-Format.html.
|
2016-10-20 17:19:48 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "GdbIndex.h"
|
2017-03-02 05:08:21 +08:00
|
|
|
#include "Memory.h"
|
2016-12-17 18:18:05 +08:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h"
|
2016-12-15 17:08:13 +08:00
|
|
|
#include "llvm/Object/ELFObjectFile.h"
|
2016-10-20 17:19:48 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::object;
|
2017-03-02 06:03:17 +08:00
|
|
|
using namespace lld;
|
2016-12-15 17:08:13 +08:00
|
|
|
using namespace lld::elf;
|
2016-10-20 17:19:48 +08:00
|
|
|
|
2016-12-15 20:07:53 +08:00
|
|
|
std::pair<bool, GdbSymbol *> GdbHashTab::add(uint32_t Hash, size_t Offset) {
|
2017-03-02 06:24:46 +08:00
|
|
|
GdbSymbol *&Sym = Map[Offset];
|
2017-03-02 05:08:21 +08:00
|
|
|
if (Sym)
|
|
|
|
return {false, Sym};
|
|
|
|
Sym = make<GdbSymbol>(Hash, Offset);
|
|
|
|
return {true, Sym};
|
2016-12-15 20:07:53 +08:00
|
|
|
}
|
|
|
|
|
2017-03-02 05:08:21 +08:00
|
|
|
void GdbHashTab::finalizeContents() {
|
2017-03-03 01:55:29 +08:00
|
|
|
uint32_t Size = std::max<uint32_t>(1024, NextPowerOf2(Map.size() * 4 / 3));
|
|
|
|
uint32_t Mask = Size - 1;
|
|
|
|
Table.resize(Size);
|
2017-03-02 05:08:21 +08:00
|
|
|
|
|
|
|
for (auto &P : Map) {
|
|
|
|
GdbSymbol *Sym = P.second;
|
2017-03-03 01:55:29 +08:00
|
|
|
uint32_t I = Sym->NameHash & Mask;
|
|
|
|
uint32_t Step = ((Sym->NameHash * 17) & Mask) | 1;
|
2017-03-02 05:08:21 +08:00
|
|
|
|
2017-03-03 01:55:29 +08:00
|
|
|
while (Table[I])
|
|
|
|
I = (I + Step) & Mask;
|
|
|
|
Table[I] = Sym;
|
2016-12-15 20:07:53 +08:00
|
|
|
}
|
|
|
|
}
|