2017-08-17 21:26:39 +00:00
|
|
|
//===- llvm/CodeGen/AddressPool.cpp - Dwarf Debug Framework ---------------===//
|
2014-04-25 06:22:32 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2014-04-23 21:04:59 +00:00
|
|
|
|
|
|
|
#include "AddressPool.h"
|
2017-08-17 21:26:39 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2014-04-23 21:04:59 +00:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2017-08-17 21:26:39 +00:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
2014-04-23 21:04:59 +00:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2018-03-23 23:58:19 +00:00
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
2017-08-17 21:26:39 +00:00
|
|
|
#include <utility>
|
2014-04-23 21:04:59 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
unsigned AddressPool::getIndex(const MCSymbol *Sym, bool TLS) {
|
2014-04-26 17:27:38 +00:00
|
|
|
HasBeenUsed = true;
|
2014-04-23 21:04:59 +00:00
|
|
|
auto IterBool =
|
|
|
|
Pool.insert(std::make_pair(Sym, AddressPoolEntry(Pool.size(), TLS)));
|
|
|
|
return IterBool.first->second.Number;
|
|
|
|
}
|
|
|
|
|
2018-08-01 05:48:06 +00:00
|
|
|
|
|
|
|
void AddressPool::emitHeader(AsmPrinter &Asm, MCSection *Section) {
|
|
|
|
static const uint8_t AddrSize = Asm.getDataLayout().getPointerSize();
|
|
|
|
Asm.OutStreamer->SwitchSection(Section);
|
|
|
|
|
|
|
|
uint64_t Length = sizeof(uint16_t) // version
|
|
|
|
+ sizeof(uint8_t) // address_size
|
|
|
|
+ sizeof(uint8_t) // segment_selector_size
|
|
|
|
+ AddrSize * Pool.size(); // entries
|
|
|
|
Asm.emitInt32(Length); // TODO: Support DWARF64 format.
|
|
|
|
Asm.emitInt16(Asm.getDwarfVersion());
|
|
|
|
Asm.emitInt8(AddrSize);
|
|
|
|
Asm.emitInt8(0); // TODO: Support non-zero segment_selector_size.
|
|
|
|
}
|
|
|
|
|
2014-04-23 21:04:59 +00:00
|
|
|
// Emit addresses into the section given.
|
2015-05-21 19:20:38 +00:00
|
|
|
void AddressPool::emit(AsmPrinter &Asm, MCSection *AddrSection) {
|
2018-08-01 05:48:06 +00:00
|
|
|
if (Asm.getDwarfVersion() >= 5)
|
|
|
|
emitHeader(Asm, AddrSection);
|
|
|
|
|
2014-04-23 21:04:59 +00:00
|
|
|
if (Pool.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Start the dwarf addr section.
|
2015-04-24 19:11:51 +00:00
|
|
|
Asm.OutStreamer->SwitchSection(AddrSection);
|
2014-04-23 21:04:59 +00:00
|
|
|
|
|
|
|
// Order the address pool entries by ID
|
|
|
|
SmallVector<const MCExpr *, 64> Entries(Pool.size());
|
|
|
|
|
|
|
|
for (const auto &I : Pool)
|
|
|
|
Entries[I.second.Number] =
|
|
|
|
I.second.TLS
|
|
|
|
? Asm.getObjFileLowering().getDebugThreadLocalSymbol(I.first)
|
2015-05-30 01:25:56 +00:00
|
|
|
: MCSymbolRefExpr::create(I.first, Asm.OutContext);
|
2014-04-23 21:04:59 +00:00
|
|
|
|
|
|
|
for (const MCExpr *Entry : Entries)
|
2015-04-24 19:11:51 +00:00
|
|
|
Asm.OutStreamer->EmitValue(Entry, Asm.getDataLayout().getPointerSize());
|
2014-04-23 21:04:59 +00:00
|
|
|
}
|