21namespace dwarflinker_parallel {
26 std::string TripleName;
39 "no register info for target %s",
46 "no asm info for target %s", TripleName.c_str());
51 "no subtarget info for target %s",
54 MC.reset(
new MCContext(TheTriple, MAI.get(), MRI.get(), MSTI.get(),
nullptr,
55 nullptr,
true, Swift5ReflectionSegmentName));
57 MC->setObjectFileInfo(MOFI.get());
62 "no asm backend for target %s",
68 "no instr info info for target %s",
74 "no code emitter for target %s",
77 switch (OutFileType) {
82 *MC, std::make_unique<formatted_raw_ostream>(OutFile),
true,
true, MIP,
83 std::unique_ptr<MCCodeEmitter>(MCE), std::unique_ptr<MCAsmBackend>(MAB),
89 TheTriple, *MC, std::unique_ptr<MCAsmBackend>(MAB),
99 "no object streamer for target %s",
107 "no target machine for target %s",
110 Asm.reset(TheTarget->
createAsmPrinter(*TM, std::unique_ptr<MCStreamer>(MS)));
113 "no asm printer for target %s",
115 Asm->setDwarfUsesRelocationsAcrossSections(
false);
117 DebugInfoSectionSize = 0;
123 MCSection *SwiftASTSection = MOFI->getDwarfSwiftASTSection();
134 MOFI->getSwift5ReflectionSection(ReflSectionKind);
135 if (ReflectionSection ==
nullptr)
147 if (
MCSection *Section = switchSection(SecName)) {
156 .
Case(
"debug_info", MC->getObjectFileInfo()->getDwarfInfoSection())
157 .
Case(
"debug_abbrev", MC->getObjectFileInfo()->getDwarfAbbrevSection())
158 .
Case(
"debug_line", MC->getObjectFileInfo()->getDwarfLineSection())
159 .
Case(
"debug_loc", MC->getObjectFileInfo()->getDwarfLocSection())
160 .
Case(
"debug_ranges", MC->getObjectFileInfo()->getDwarfRangesSection())
161 .
Case(
"debug_frame", MC->getObjectFileInfo()->getDwarfFrameSection())
162 .
Case(
"debug_aranges", MC->getObjectFileInfo()->getDwarfARangesSection())
163 .
Case(
"debug_rnglists",
164 MC->getObjectFileInfo()->getDwarfRnglistsSection())
165 .
Case(
"debug_loclists",
166 MC->getObjectFileInfo()->getDwarfLoclistsSection())
167 .
Case(
"debug_macro", MC->getObjectFileInfo()->getDwarfMacroSection())
168 .
Case(
"debug_macinfo", MC->getObjectFileInfo()->getDwarfMacinfoSection())
169 .
Case(
"debug_addr", MC->getObjectFileInfo()->getDwarfAddrSection())
170 .
Case(
"debug_str", MC->getObjectFileInfo()->getDwarfStrSection())
171 .
Case(
"debug_line_str", MC->getObjectFileInfo()->getDwarfLineStrSection())
172 .
Case(
"debug_str_offsets",
173 MC->getObjectFileInfo()->getDwarfStrOffSection())
174 .
Case(
"debug_pubnames",
175 MC->getObjectFileInfo()->getDwarfPubNamesSection())
176 .
Case(
"debug_pubtypes",
177 MC->getObjectFileInfo()->getDwarfPubTypesSection())
178 .
Case(
"debug_names", MC->getObjectFileInfo()->getDwarfDebugNamesSection())
179 .
Case(
"apple_names", MC->getObjectFileInfo()->getDwarfAccelNamesSection())
180 .
Case(
"apple_namespac",
181 MC->getObjectFileInfo()->getDwarfAccelNamespaceSection())
182 .
Case(
"apple_objc", MC->getObjectFileInfo()->getDwarfAccelObjCSection())
183 .
Case(
"apple_types", MC->getObjectFileInfo()->getDwarfAccelTypesSection())
189 const SmallVector<std::unique_ptr<DIEAbbrev>> &Abbrevs,
190 unsigned DwarfVersion) {
192 MC->setDwarfVersion(DwarfVersion);
193 Asm->emitDwarfAbbrevs(Abbrevs);
198 MC->setDwarfVersion(Unit.getVersion());
203 Asm->emitInt32(Unit.getUnitSize() - 4);
204 Asm->emitInt16(Unit.getVersion());
206 if (Unit.getVersion() >= 5) {
207 Asm->emitInt8(dwarf::DW_UT_compile);
208 Asm->emitInt8(Unit.getFormParams().AddrSize);
211 DebugInfoSectionSize += 12;
215 Asm->emitInt8(Unit.getFormParams().AddrSize);
216 DebugInfoSectionSize += 11;
222 Asm->emitDwarfDIE(Die);
223 DebugInfoSectionSize += Die.
getSize();
229 if (CUOffsets.empty())
232 Asm->OutStreamer->switchSection(MOFI->getDwarfDebugNamesSection());
238 Asm.get(), Table, CUOffsets,
240 -> std::optional<DWARF5AccelTable::UnitIndexAndEncoding> {
241 if (CUidToIdx.size() > 1)
242 return {{CUidToIdx[Entry.getUnitID()],
243 {dwarf::DW_IDX_compile_unit, Form}}};
248void DwarfEmitterImpl::emitAppleNamespaces(
250 Asm->OutStreamer->switchSection(MOFI->getDwarfAccelNamespaceSection());
251 auto *SectionBegin = Asm->createTempSymbol(
"namespac_begin");
252 Asm->OutStreamer->emitLabel(SectionBegin);
256void DwarfEmitterImpl::emitAppleNames(
258 Asm->OutStreamer->switchSection(MOFI->getDwarfAccelNamesSection());
259 auto *SectionBegin = Asm->createTempSymbol(
"names_begin");
260 Asm->OutStreamer->emitLabel(SectionBegin);
264void DwarfEmitterImpl::emitAppleObjc(
266 Asm->OutStreamer->switchSection(MOFI->getDwarfAccelObjCSection());
267 auto *SectionBegin = Asm->createTempSymbol(
"objc_begin");
268 Asm->OutStreamer->emitLabel(SectionBegin);
272void DwarfEmitterImpl::emitAppleTypes(
274 Asm->OutStreamer->switchSection(MOFI->getDwarfAccelTypesSection());
275 auto *SectionBegin = Asm->createTempSymbol(
"types_begin");
276 Asm->OutStreamer->emitLabel(SectionBegin);
This class holds an abstract representation of an Accelerator Table, consisting of a sequence of buck...
static dwarf::Form BestForm(bool IsSigned, uint64_t Int)
Choose the best form for integer.
A structured debug information entry.
The Data class implementation for DWARF v5 accelerator table.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
std::unique_ptr< MCObjectWriter > createObjectWriter(raw_pwrite_stream &OS) const
Create a new MCObjectWriter instance for use by the assembler backend to emit the final object file.
Context object for machine code objects.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
void setAlignment(Align Value)
virtual void switchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
virtual void emitBytes(StringRef Data)
Emit the bytes in Data into the output.
bool MCIncrementalLinkerCompatible
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Target - Wrapper for Target specific information.
MCCodeEmitter * createMCCodeEmitter(const MCInstrInfo &II, MCContext &Ctx) const
createMCCodeEmitter - Create a target specific code emitter.
MCObjectFileInfo * createMCObjectFileInfo(MCContext &Ctx, bool PIC, bool LargeCodeModel=false) const
Create a MCObjectFileInfo implementation for the specified target triple.
MCSubtargetInfo * createMCSubtargetInfo(StringRef TheTriple, StringRef CPU, StringRef Features) const
createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
MCStreamer * createAsmStreamer(MCContext &Ctx, std::unique_ptr< formatted_raw_ostream > OS, bool IsVerboseAsm, bool UseDwarfDirectory, MCInstPrinter *InstPrint, std::unique_ptr< MCCodeEmitter > &&CE, std::unique_ptr< MCAsmBackend > &&TAB, bool ShowInst) const
MCAsmBackend * createMCAsmBackend(const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options) const
createMCAsmBackend - Create a target specific assembly parser.
MCRegisterInfo * createMCRegInfo(StringRef TT) const
createMCRegInfo - Create a MCRegisterInfo implementation.
TargetMachine * createTargetMachine(StringRef TT, StringRef CPU, StringRef Features, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM=std::nullopt, CodeGenOptLevel OL=CodeGenOptLevel::Default, bool JIT=false) const
createTargetMachine - Create a target specific machine implementation for the specified Triple.
MCAsmInfo * createMCAsmInfo(const MCRegisterInfo &MRI, StringRef TheTriple, const MCTargetOptions &Options) const
createMCAsmInfo - Create a MCAsmInfo implementation for the specified target triple.
MCInstPrinter * createMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI) const
MCStreamer * createMCObjectStreamer(const Triple &T, MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter, const MCSubtargetInfo &STI, bool RelaxAll, bool IncrementalLinkerCompatible, bool DWARFMustBeAtTheEnd) const
Create a target specific MCStreamer.
AsmPrinter * createAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > &&Streamer) const
createAsmPrinter - Create a target specific assembly printer pass.
MCInstrInfo * createMCInstrInfo() const
createMCInstrInfo - Create a MCInstrInfo implementation.
Triple - Helper class for working with autoconf configuration names.
const std::string & getTriple() const
void emitDIE(DIE &Die)
Emit DIE recursively.
void emitCompileUnitHeader(DwarfUnit &Unit)
Emit compile unit header.
Error init(Triple TheTriple, StringRef Swift5ReflectionSegmentName)
Initialize AsmPrinter data.
void emitSwiftReflectionSection(llvm::binaryformat::Swift5ReflectionSectionKind ReflSectionKind, StringRef Buffer, uint32_t Alignment, uint32_t) override
Emit the swift reflection section stored in Buffer.
void emitDebugNames(DWARF5AccelTable &Table, DebugNamesUnitsOffsets &CUOffsets, CompUnitIDToIdx &UnitIDToIdxMap)
Emits .debug_names section according to the specified Table.
void emitAbbrevs(const SmallVector< std::unique_ptr< DIEAbbrev > > &Abbrevs, unsigned DwarfVersion)
Emit abbreviations.
void emitSwiftAST(StringRef Buffer) override
Emit the swift_ast section stored in Buffer.
void emitSectionContents(StringRef SecData, StringRef SecName) override
Emit specified section data.
Base class for all Dwarf units(Compile unit/Type table unit).
std::vector< std::variant< MCSymbol *, uint64_t > > DebugNamesUnitsOffsets
MCTargetOptions InitMCTargetOptionsFromFlags()
This is an optimization pass for GlobalISel generic memory operations.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
void emitAppleAccelTable(AsmPrinter *Asm, AccelTable< DataT > &Contents, StringRef Prefix, const MCSymbol *SecBegin)
Emit an Apple Accelerator Table consisting of entries in the specified AccelTable.
void emitDWARF5AccelTable(AsmPrinter *Asm, DWARF5AccelTable &Contents, const DwarfDebug &DD, ArrayRef< std::unique_ptr< DwarfCompileUnit > > CUs)
This struct is a compact representation of a valid (non-zero power of two) alignment.
static const Target * lookupTarget(StringRef Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.