Line data Source code
1 : //===- llvm/CodeGen/AddressPool.cpp - Dwarf Debug Framework ---------------===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 :
10 : #include "AddressPool.h"
11 : #include "llvm/ADT/SmallVector.h"
12 : #include "llvm/CodeGen/AsmPrinter.h"
13 : #include "llvm/IR/DataLayout.h"
14 : #include "llvm/MC/MCStreamer.h"
15 : #include "llvm/Target/TargetLoweringObjectFile.h"
16 : #include <utility>
17 :
18 : using namespace llvm;
19 :
20 100 : unsigned AddressPool::getIndex(const MCSymbol *Sym, bool TLS) {
21 100 : HasBeenUsed = true;
22 : auto IterBool =
23 200 : Pool.insert(std::make_pair(Sym, AddressPoolEntry(Pool.size(), TLS)));
24 100 : return IterBool.first->second.Number;
25 : }
26 :
27 :
28 6 : void AddressPool::emitHeader(AsmPrinter &Asm, MCSection *Section) {
29 6 : static const uint8_t AddrSize = Asm.getDataLayout().getPointerSize();
30 : uint64_t Length = sizeof(uint16_t) // version
31 : + sizeof(uint8_t) // address_size
32 : + sizeof(uint8_t) // segment_selector_size
33 6 : + AddrSize * Pool.size(); // entries
34 6 : Asm.emitInt32(Length); // TODO: Support DWARF64 format.
35 6 : Asm.emitInt16(Asm.getDwarfVersion());
36 6 : Asm.emitInt8(AddrSize);
37 6 : Asm.emitInt8(0); // TODO: Support non-zero segment_selector_size.
38 6 : }
39 :
40 : // Emit addresses into the section given.
41 37 : void AddressPool::emit(AsmPrinter &Asm, MCSection *AddrSection) {
42 : // Start the dwarf addr section.
43 37 : Asm.OutStreamer->SwitchSection(AddrSection);
44 :
45 37 : if (Asm.getDwarfVersion() >= 5)
46 6 : emitHeader(Asm, AddrSection);
47 :
48 : // Define the symbol that marks the start of the contribution.
49 : // It is referenced via DW_AT_addr_base.
50 37 : Asm.OutStreamer->EmitLabel(AddressTableBaseSym);
51 :
52 37 : if (Pool.empty())
53 3 : return;
54 :
55 : // Order the address pool entries by ID
56 34 : SmallVector<const MCExpr *, 64> Entries(Pool.size());
57 :
58 120 : for (const auto &I : Pool)
59 172 : Entries[I.second.Number] =
60 86 : I.second.TLS
61 86 : ? Asm.getObjFileLowering().getDebugThreadLocalSymbol(I.first)
62 84 : : MCSymbolRefExpr::create(I.first, Asm.OutContext);
63 :
64 120 : for (const MCExpr *Entry : Entries)
65 86 : Asm.OutStreamer->EmitValue(Entry, Asm.getDataLayout().getPointerSize());
66 : }
|