2017-08-17 23:26:39 +02:00
|
|
|
//===- llvm/CodeGen/AddressPool.cpp - Dwarf Debug Framework ---------------===//
|
2014-04-25 08:22:32 +02:00
|
|
|
//
|
2019-01-19 09:50:56 +01: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 08:22:32 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2014-04-23 23:04:59 +02:00
|
|
|
|
|
|
|
#include "AddressPool.h"
|
2017-08-17 23:26:39 +02:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2014-04-23 23:04:59 +02:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2017-08-17 23:26:39 +02:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
2014-04-23 23:04:59 +02:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2018-03-24 00:58:19 +01:00
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
2017-08-17 23:26:39 +02:00
|
|
|
#include <utility>
|
2014-04-23 23:04:59 +02:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
unsigned AddressPool::getIndex(const MCSymbol *Sym, bool TLS) {
|
2014-04-26 19:27:38 +02:00
|
|
|
HasBeenUsed = true;
|
2014-04-23 23:04:59 +02:00
|
|
|
auto IterBool =
|
|
|
|
Pool.insert(std::make_pair(Sym, AddressPoolEntry(Pool.size(), TLS)));
|
|
|
|
return IterBool.first->second.Number;
|
|
|
|
}
|
|
|
|
|
2019-01-24 04:27:57 +01:00
|
|
|
MCSymbol *AddressPool::emitHeader(AsmPrinter &Asm, MCSection *Section) {
|
2018-08-01 07:48:06 +02:00
|
|
|
static const uint8_t AddrSize = Asm.getDataLayout().getPointerSize();
|
2019-01-24 04:27:57 +01:00
|
|
|
|
2021-02-26 02:39:45 +01:00
|
|
|
MCSymbol *EndLabel =
|
|
|
|
Asm.emitDwarfUnitLength("debug_addr", "Length of contribution");
|
2018-12-24 08:09:50 +01:00
|
|
|
Asm.OutStreamer->AddComment("DWARF version number");
|
2018-08-01 07:48:06 +02:00
|
|
|
Asm.emitInt16(Asm.getDwarfVersion());
|
2018-12-24 08:09:50 +01:00
|
|
|
Asm.OutStreamer->AddComment("Address size");
|
2018-08-01 07:48:06 +02:00
|
|
|
Asm.emitInt8(AddrSize);
|
2018-12-24 08:09:50 +01:00
|
|
|
Asm.OutStreamer->AddComment("Segment selector size");
|
2018-08-01 07:48:06 +02:00
|
|
|
Asm.emitInt8(0); // TODO: Support non-zero segment_selector_size.
|
2019-01-24 04:27:57 +01:00
|
|
|
|
|
|
|
return EndLabel;
|
2018-08-01 07:48:06 +02:00
|
|
|
}
|
|
|
|
|
2014-04-23 23:04:59 +02:00
|
|
|
// Emit addresses into the section given.
|
2015-05-21 21:20:38 +02:00
|
|
|
void AddressPool::emit(AsmPrinter &Asm, MCSection *AddrSection) {
|
2018-10-20 08:02:15 +02:00
|
|
|
if (isEmpty())
|
|
|
|
return;
|
|
|
|
|
2018-09-20 11:17:36 +02:00
|
|
|
// Start the dwarf addr section.
|
|
|
|
Asm.OutStreamer->SwitchSection(AddrSection);
|
|
|
|
|
2019-01-24 04:27:57 +01:00
|
|
|
MCSymbol *EndLabel = nullptr;
|
|
|
|
|
2018-08-01 07:48:06 +02:00
|
|
|
if (Asm.getDwarfVersion() >= 5)
|
2019-01-24 04:27:57 +01:00
|
|
|
EndLabel = emitHeader(Asm, AddrSection);
|
2018-08-01 07:48:06 +02:00
|
|
|
|
2018-09-20 11:17:36 +02:00
|
|
|
// Define the symbol that marks the start of the contribution.
|
|
|
|
// It is referenced via DW_AT_addr_base.
|
2020-02-15 04:21:58 +01:00
|
|
|
Asm.OutStreamer->emitLabel(AddressTableBaseSym);
|
2018-09-20 11:17:36 +02:00
|
|
|
|
2014-04-23 23:04:59 +02: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 03:25:56 +02:00
|
|
|
: MCSymbolRefExpr::create(I.first, Asm.OutContext);
|
2014-04-23 23:04:59 +02:00
|
|
|
|
|
|
|
for (const MCExpr *Entry : Entries)
|
2020-02-15 07:40:47 +01:00
|
|
|
Asm.OutStreamer->emitValue(Entry, Asm.getDataLayout().getPointerSize());
|
2019-01-24 04:27:57 +01:00
|
|
|
|
|
|
|
if (EndLabel)
|
2020-02-15 04:21:58 +01:00
|
|
|
Asm.OutStreamer->emitLabel(EndLabel);
|
2014-04-23 23:04:59 +02:00
|
|
|
}
|