brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · bb55fc7 Raw
71 lines · cpp
1//===- llvm/CodeGen/AddressPool.cpp - Dwarf Debug Framework ---------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "AddressPool.h"10#include "llvm/ADT/SmallVector.h"11#include "llvm/CodeGen/AsmPrinter.h"12#include "llvm/MC/MCAsmInfo.h"13#include "llvm/MC/MCStreamer.h"14#include "llvm/Target/TargetLoweringObjectFile.h"15 16using namespace llvm;17 18unsigned AddressPool::getIndex(const MCSymbol *Sym, bool TLS) {19  resetUsedFlag(true);20  auto IterBool = Pool.try_emplace(Sym, Pool.size(), TLS);21  return IterBool.first->second.Number;22}23 24MCSymbol *AddressPool::emitHeader(AsmPrinter &Asm, MCSection *Section) {25  static const uint8_t AddrSize = Asm.MAI->getCodePointerSize();26 27  MCSymbol *EndLabel =28      Asm.emitDwarfUnitLength("debug_addr", "Length of contribution");29  Asm.OutStreamer->AddComment("DWARF version number");30  Asm.emitInt16(Asm.getDwarfVersion());31  Asm.OutStreamer->AddComment("Address size");32  Asm.emitInt8(AddrSize);33  Asm.OutStreamer->AddComment("Segment selector size");34  Asm.emitInt8(0); // TODO: Support non-zero segment_selector_size.35 36  return EndLabel;37}38 39// Emit addresses into the section given.40void AddressPool::emit(AsmPrinter &Asm, MCSection *AddrSection) {41  if (isEmpty())42    return;43 44  // Start the dwarf addr section.45  Asm.OutStreamer->switchSection(AddrSection);46 47  MCSymbol *EndLabel = nullptr;48 49  if (Asm.getDwarfVersion() >= 5)50    EndLabel = emitHeader(Asm, AddrSection);51 52  // Define the symbol that marks the start of the contribution.53  // It is referenced via DW_AT_addr_base.54  Asm.OutStreamer->emitLabel(AddressTableBaseSym);55 56  // Order the address pool entries by ID57  SmallVector<const MCExpr *, 64> Entries(Pool.size());58 59  for (const auto &I : Pool)60    Entries[I.second.Number] =61        I.second.TLS62            ? Asm.getObjFileLowering().getDebugThreadLocalSymbol(I.first)63            : MCSymbolRefExpr::create(I.first, Asm.OutContext);64 65  for (const MCExpr *Entry : Entries)66    Asm.OutStreamer->emitValue(Entry, Asm.MAI->getCodePointerSize());67 68  if (EndLabel)69    Asm.OutStreamer->emitLabel(EndLabel);70}71