2017-08-18 05:26:39 +08:00
|
|
|
//===- llvm/CodeGen/AddressPool.cpp - Dwarf Debug Framework ---------------===//
|
2014-04-25 14:22:32 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-04-25 14:22:32 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2014-04-24 05:04:59 +08:00
|
|
|
|
|
|
|
#include "AddressPool.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2014-04-24 05:04:59 +08:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
2014-04-24 05:04:59 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2018-03-24 07:58:19 +08:00
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include <utility>
|
2014-04-24 05:04:59 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
unsigned AddressPool::getIndex(const MCSymbol *Sym, bool TLS) {
|
2014-04-27 01:27:38 +08:00
|
|
|
HasBeenUsed = true;
|
2014-04-24 05:04:59 +08:00
|
|
|
auto IterBool =
|
|
|
|
Pool.insert(std::make_pair(Sym, AddressPoolEntry(Pool.size(), TLS)));
|
|
|
|
return IterBool.first->second.Number;
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:27:57 +08:00
|
|
|
MCSymbol *AddressPool::emitHeader(AsmPrinter &Asm, MCSection *Section) {
|
2018-08-01 13:48:06 +08:00
|
|
|
static const uint8_t AddrSize = Asm.getDataLayout().getPointerSize();
|
2019-01-24 11:27:57 +08:00
|
|
|
StringRef Prefix = "debug_addr_";
|
|
|
|
MCSymbol *BeginLabel = Asm.createTempSymbol(Prefix + "start");
|
|
|
|
MCSymbol *EndLabel = Asm.createTempSymbol(Prefix + "end");
|
|
|
|
|
2018-12-24 15:09:50 +08:00
|
|
|
Asm.OutStreamer->AddComment("Length of contribution");
|
2019-01-24 11:27:57 +08:00
|
|
|
Asm.EmitLabelDifference(EndLabel, BeginLabel,
|
|
|
|
4); // TODO: Support DWARF64 format.
|
|
|
|
Asm.OutStreamer->EmitLabel(BeginLabel);
|
2018-12-24 15:09:50 +08:00
|
|
|
Asm.OutStreamer->AddComment("DWARF version number");
|
2018-08-01 13:48:06 +08:00
|
|
|
Asm.emitInt16(Asm.getDwarfVersion());
|
2018-12-24 15:09:50 +08:00
|
|
|
Asm.OutStreamer->AddComment("Address size");
|
2018-08-01 13:48:06 +08:00
|
|
|
Asm.emitInt8(AddrSize);
|
2018-12-24 15:09:50 +08:00
|
|
|
Asm.OutStreamer->AddComment("Segment selector size");
|
2018-08-01 13:48:06 +08:00
|
|
|
Asm.emitInt8(0); // TODO: Support non-zero segment_selector_size.
|
2019-01-24 11:27:57 +08:00
|
|
|
|
|
|
|
return EndLabel;
|
2018-08-01 13:48:06 +08:00
|
|
|
}
|
|
|
|
|
2014-04-24 05:04:59 +08:00
|
|
|
// Emit addresses into the section given.
|
2015-05-22 03:20:38 +08:00
|
|
|
void AddressPool::emit(AsmPrinter &Asm, MCSection *AddrSection) {
|
2018-10-20 14:02:15 +08:00
|
|
|
if (isEmpty())
|
|
|
|
return;
|
|
|
|
|
2018-09-20 17:17:36 +08:00
|
|
|
// Start the dwarf addr section.
|
|
|
|
Asm.OutStreamer->SwitchSection(AddrSection);
|
|
|
|
|
2019-01-24 11:27:57 +08:00
|
|
|
MCSymbol *EndLabel = nullptr;
|
|
|
|
|
2018-08-01 13:48:06 +08:00
|
|
|
if (Asm.getDwarfVersion() >= 5)
|
2019-01-24 11:27:57 +08:00
|
|
|
EndLabel = emitHeader(Asm, AddrSection);
|
2018-08-01 13:48:06 +08:00
|
|
|
|
2018-09-20 17:17:36 +08:00
|
|
|
// Define the symbol that marks the start of the contribution.
|
|
|
|
// It is referenced via DW_AT_addr_base.
|
|
|
|
Asm.OutStreamer->EmitLabel(AddressTableBaseSym);
|
|
|
|
|
2014-04-24 05:04:59 +08: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 09:25:56 +08:00
|
|
|
: MCSymbolRefExpr::create(I.first, Asm.OutContext);
|
2014-04-24 05:04:59 +08:00
|
|
|
|
|
|
|
for (const MCExpr *Entry : Entries)
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm.OutStreamer->EmitValue(Entry, Asm.getDataLayout().getPointerSize());
|
2019-01-24 11:27:57 +08:00
|
|
|
|
|
|
|
if (EndLabel)
|
|
|
|
Asm.OutStreamer->EmitLabel(EndLabel);
|
2014-04-24 05:04:59 +08:00
|
|
|
}
|