1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
|
//===- DwarfEmitterImpl.h ---------------------------------------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_DWARFLINKERPARALLEL_DWARFEMITTERIMPL_H
#define LLVM_LIB_DWARFLINKERPARALLEL_DWARFEMITTERIMPL_H
#include "DWARFLinkerCompileUnit.h"
#include "llvm/BinaryFormat/Swift.h"
#include "llvm/CodeGen/AccelTable.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/DWARFLinkerParallel/DWARFLinker.h"
#include "llvm/DWARFLinkerParallel/StringTable.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/Target/TargetMachine.h"
namespace llvm {
/// User of DwarfEmitterImpl should call initialization code
/// for AsmPrinter:
///
/// InitializeAllTargetInfos();
/// InitializeAllTargetMCs();
/// InitializeAllTargets();
/// InitializeAllAsmPrinters();
template <typename DataT> class AccelTable;
class MCCodeEmitter;
class DWARFDebugMacro;
namespace dwarflinker_parallel {
struct UnitStartSymbol {
unsigned UnitID = 0;
MCSymbol *Symbol = 0;
};
using UnitStartSymbolsTy = SmallVector<UnitStartSymbol>;
using Offset2UnitMapTy = DenseMap<uint64_t, CompileUnit *>;
struct RangeAttrPatch;
struct LocAttrPatch;
/// The Dwarf emission logic.
///
/// All interactions with the MC layer that is used to build the debug
/// information binary representation are handled in this class.
class DwarfEmitterImpl : public ExtraDwarfEmitter {
public:
DwarfEmitterImpl(DWARFLinker::OutputFileType OutFileType,
raw_pwrite_stream &OutFile,
std::function<StringRef(StringRef Input)> Translator,
DWARFLinker::MessageHandlerTy Warning)
: OutFile(OutFile), OutFileType(OutFileType), Translator(Translator),
WarningHandler(Warning) {}
Error init(Triple TheTriple, StringRef Swift5ReflectionSegmentName);
/// Dump the file to the disk.
void finish() override { MS->finish(); }
AsmPrinter &getAsmPrinter() const override { return *Asm; }
/// Set the current output section to debug_info and change
/// the MC Dwarf version to \p DwarfVersion.
void switchToDebugInfoSection(unsigned DwarfVersion) {}
/// Emit the swift_ast section stored in \p Buffer.
void emitSwiftAST(StringRef Buffer) override {}
/// Emit the swift reflection section stored in \p Buffer.
void emitSwiftReflectionSection(
llvm::binaryformat::Swift5ReflectionSectionKind ReflSectionKind,
StringRef Buffer, uint32_t Alignment, uint32_t Size) override {}
void emitPaperTrailWarningsDie(DIE &Die) {}
void emitSectionContents(StringRef SecData, StringRef SecName) override {}
MCSymbol *emitTempSym(StringRef SecName, StringRef SymName) override {
return nullptr;
}
void emitAbbrevs(const SmallVector<std::unique_ptr<DIEAbbrev>> &Abbrevs,
unsigned DwarfVersion) {}
void emitStrings(const StringTable &Strings) {}
void emitLineStrings(const StringTable &Strings) {}
void emitDebugNames(AccelTable<DWARF5AccelTableStaticData> &,
UnitStartSymbolsTy &UnitOffsets) {}
void emitAppleNamespaces(AccelTable<AppleAccelTableStaticOffsetData> &) {}
void emitAppleNames(AccelTable<AppleAccelTableStaticOffsetData> &) {}
void emitAppleObjc(AccelTable<AppleAccelTableStaticOffsetData> &) {}
void emitAppleTypes(AccelTable<AppleAccelTableStaticTypeData> &) {}
MCSymbol *emitDwarfDebugRangeListHeader(const CompileUnit &Unit) {
return nullptr;
}
void emitDwarfDebugRangeListFragment(const CompileUnit &Unit,
const AddressRanges &LinkedRanges,
RangeAttrPatch &Patch) {}
void emitDwarfDebugRangeListFooter(const CompileUnit &Unit,
MCSymbol *EndLabel) {}
MCSymbol *emitDwarfDebugLocListHeader(const CompileUnit &Unit) {
return nullptr;
}
void emitDwarfDebugLocListFragment(
const CompileUnit &Unit,
const DWARFLocationExpressionsVector &LinkedLocationExpression,
LocAttrPatch &Patch) {}
void emitDwarfDebugLocListFooter(const CompileUnit &Unit,
MCSymbol *EndLabel) {}
void emitDwarfDebugArangesTable(const CompileUnit &Unit,
const AddressRanges &LinkedRanges) {}
void translateLineTable(DataExtractor LineData, uint64_t Offset) {}
void emitLineTableForUnit(MCDwarfLineTableParams Params,
StringRef PrologueBytes, unsigned MinInstLength,
std::vector<DWARFDebugLine::Row> &Rows,
unsigned AdddressSize) {}
void emitLineTableForUnit(const DWARFDebugLine::LineTable &LineTable,
const CompileUnit &Unit, const StringTable &Strings,
const StringTable &LineTableStrings) {}
void emitPubNamesForUnit(const CompileUnit &Unit) {}
void emitPubTypesForUnit(const CompileUnit &Unit) {}
void emitCIE(StringRef CIEBytes) {}
void emitFDE(uint32_t CIEOffset, uint32_t AddreSize, uint64_t Address,
StringRef Bytes) {}
void emitCompileUnitHeader(CompileUnit &Unit, unsigned DwarfVersion) {}
void emitDIE(DIE &Die) {}
void emitMacroTables(DWARFContext *Context,
const Offset2UnitMapTy &UnitMacroMap,
StringTable &Strings) {}
/// Returns size of generated .debug_line section.
uint64_t getDebugLineSectionSize() const { return LineSectionSize; }
/// Returns size of generated .debug_frame section.
uint64_t getDebugFrameSectionSize() const { return FrameSectionSize; }
/// Returns size of generated .debug_ranges section.
uint64_t getDebugRangesSectionSize() const { return RangesSectionSize; }
/// Returns size of generated .debug_rnglists section.
uint64_t getDebugRngListsSectionSize() const { return RngListsSectionSize; }
/// Returns size of generated .debug_info section.
uint64_t getDebugInfoSectionSize() const { return DebugInfoSectionSize; }
/// Returns size of generated .debug_macinfo section.
uint64_t getDebugMacInfoSectionSize() const { return MacInfoSectionSize; }
/// Returns size of generated .debug_macro section.
uint64_t getDebugMacroSectionSize() const { return MacroSectionSize; }
/// Returns size of generated .debug_loc section.
uint64_t getDebugLocSectionSize() const { return LocSectionSize; }
/// Returns size of generated .debug_loclists section.
uint64_t getDebugLocListsSectionSize() const { return LocListsSectionSize; }
private:
inline void warn(const Twine &Warning, StringRef Context = "") {
if (WarningHandler)
WarningHandler(Warning, Context, nullptr);
}
void emitMacroTableImpl(const DWARFDebugMacro *MacroTable,
const Offset2UnitMapTy &UnitMacroMap,
StringPool &StringPool, uint64_t &OutOffset) {}
/// Emit piece of .debug_ranges for \p LinkedRanges.
void emitDwarfDebugRangesTableFragment(const CompileUnit &Unit,
const AddressRanges &LinkedRanges,
RangeAttrPatch &Patch) {}
/// Emit piece of .debug_rnglists for \p LinkedRanges.
void emitDwarfDebugRngListsTableFragment(const CompileUnit &Unit,
const AddressRanges &LinkedRanges,
RangeAttrPatch &Patch) {}
/// Emit piece of .debug_loc for \p LinkedRanges.
void emitDwarfDebugLocTableFragment(
const CompileUnit &Unit,
const DWARFLocationExpressionsVector &LinkedLocationExpression,
LocAttrPatch &Patch) {}
/// Emit piece of .debug_loclists for \p LinkedRanges.
void emitDwarfDebugLocListsTableFragment(
const CompileUnit &Unit,
const DWARFLocationExpressionsVector &LinkedLocationExpression,
LocAttrPatch &Patch) {}
/// \defgroup MCObjects MC layer objects constructed by the streamer
/// @{
std::unique_ptr<MCRegisterInfo> MRI;
std::unique_ptr<MCAsmInfo> MAI;
std::unique_ptr<MCObjectFileInfo> MOFI;
std::unique_ptr<MCContext> MC;
MCAsmBackend *MAB; // Owned by MCStreamer
std::unique_ptr<MCInstrInfo> MII;
std::unique_ptr<MCSubtargetInfo> MSTI;
MCInstPrinter *MIP; // Owned by AsmPrinter
MCCodeEmitter *MCE; // Owned by MCStreamer
MCStreamer *MS; // Owned by AsmPrinter
std::unique_ptr<TargetMachine> TM;
std::unique_ptr<AsmPrinter> Asm;
/// @}
/// The output file we stream the linked Dwarf to.
raw_pwrite_stream &OutFile;
DWARFLinker::OutputFileType OutFileType = DWARFLinker::OutputFileType::Object;
std::function<StringRef(StringRef Input)> Translator;
uint64_t RangesSectionSize = 0;
uint64_t RngListsSectionSize = 0;
uint64_t LocSectionSize = 0;
uint64_t LocListsSectionSize = 0;
uint64_t LineSectionSize = 0;
uint64_t FrameSectionSize = 0;
uint64_t DebugInfoSectionSize = 0;
uint64_t MacInfoSectionSize = 0;
uint64_t MacroSectionSize = 0;
/// Keep track of emitted CUs and their Unique ID.
struct EmittedUnit {
unsigned ID;
MCSymbol *LabelBegin;
};
std::vector<EmittedUnit> EmittedUnitsTy;
/// Emit the pubnames or pubtypes section contribution for \p
/// Unit into \p Sec. The data is provided in \p Names.
void emitPubSectionForUnit(MCSection *Sec, StringRef Name,
const CompileUnit &Unit,
const std::vector<CompileUnit::AccelInfo> &Names);
DWARFLinker::MessageHandlerTy WarningHandler = nullptr;
};
} // end namespace dwarflinker_parallel
} // end namespace llvm
#endif // LLVM_LIB_DWARFLINKERPARALLEL_DWARFEMITTERIMPL_H
|