LLVM: lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

19

20using namespace llvm;

21using namespace dwarf_linker;

22using namespace dwarf_linker::parallel;

23

25 StringRef Swift5ReflectionSegmentName) {

26 std::string ErrorStr;

27 std::string TripleName;

28

29

30 const Target *TheTarget =

32 if (!TheTarget)

33 return createStringError(std::errc::invalid_argument, ErrorStr.c_str());

34 TripleName = TheTriple.getTriple();

35

36

38 if (!MRI)

40 "no register info for target %s",

41 TripleName.c_str());

42

46 MAI.reset(TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions));

47 if (!MAI)

49 "no asm info for target %s", TripleName.c_str());

50

52 if (!MSTI)

54 "no subtarget info for target %s",

55 TripleName.c_str());

56

57 MC.reset(new MCContext(TheTriple, MAI.get(), MRI.get(), MSTI.get(), nullptr,

58 nullptr, true, Swift5ReflectionSegmentName));

60 MC->setObjectFileInfo(MOFI.get());

61

63 if (!MAB)

65 "no asm backend for target %s",

66 TripleName.c_str());

67

69 if (!MII)

71 "no instr info info for target %s",

72 TripleName.c_str());

73

75 if (!MCE)

77 "no code emitter for target %s",

78 TripleName.c_str());

79

80 switch (OutFileType) {

82 MIP = TheTarget->createMCInstPrinter(TheTriple, MAI->getAssemblerDialect(),

83 *MAI, *MII, *MRI);

85 *MC, std::make_unique<formatted_raw_ostream>(OutFile), MIP,

86 std::unique_ptr(MCE),

87 std::unique_ptr(MAB));

88 break;

89 }

92 TheTriple, *MC, std::unique_ptr(MAB),

93 MAB->createObjectWriter(OutFile), std::unique_ptr(MCE),

94 *MSTI);

95 break;

96 }

97 }

98

99 if (!MS)

101 "no object streamer for target %s",

102 TripleName.c_str());

103

104

106 std::nullopt));

107 if (!TM)

109 "no target machine for target %s",

110 TripleName.c_str());

111

112 Asm.reset(TheTarget->createAsmPrinter(*TM, std::unique_ptr(MS)));

113 if (!Asm)

115 "no asm printer for target %s",

116 TripleName.c_str());

117 Asm->setDwarfUsesRelocationsAcrossSections(false);

118

119 DebugInfoSectionSize = 0;

120

122}

123

125 const SmallVector<std::unique_ptr> &Abbrevs,

126 unsigned DwarfVersion) {

127 MS->switchSection(MOFI->getDwarfAbbrevSection());

128 MC->setDwarfVersion(DwarfVersion);

129 Asm->emitDwarfAbbrevs(Abbrevs);

130}

131

134 MC->setDwarfVersion(Unit.getVersion());

135

136

137

138

139 Asm->emitInt32(Unit.getUnitSize() - 4);

140 Asm->emitInt16(Unit.getVersion());

141

142 if (Unit.getVersion() >= 5) {

143 Asm->emitInt8(dwarf::DW_UT_compile);

144 Asm->emitInt8(Unit.getFormParams().AddrSize);

145

146 Asm->emitInt32(0);

147 DebugInfoSectionSize += 12;

148 } else {

149

150 Asm->emitInt32(0);

151 Asm->emitInt8(Unit.getFormParams().AddrSize);

152 DebugInfoSectionSize += 11;

153 }

154}

155

158 Asm->emitDwarfDIE(Die);

159 DebugInfoSectionSize += Die.getSize();

160}

161

165 if (CUOffsets.empty())

166 return;

167

168 Asm->OutStreamer->switchSection(MOFI->getDwarfDebugNamesSection());

171

172

174 Asm.get(), Table, CUOffsets,

176 -> std::optionalDWARF5AccelTable::UnitIndexAndEncoding {

177 if (CUidToIdx.size() > 1)

178 return {{CUidToIdx[Entry.getUnitID()],

179 {dwarf::DW_IDX_compile_unit, Form}}};

180 return std::nullopt;

181 });

182}

183

186 Asm->OutStreamer->switchSection(MOFI->getDwarfAccelNamespaceSection());

187 auto *SectionBegin = Asm->createTempSymbol("namespac_begin");

188 Asm->OutStreamer->emitLabel(SectionBegin);

190}

191

194 Asm->OutStreamer->switchSection(MOFI->getDwarfAccelNamesSection());

195 auto *SectionBegin = Asm->createTempSymbol("names_begin");

196 Asm->OutStreamer->emitLabel(SectionBegin);

198}

199

202 Asm->OutStreamer->switchSection(MOFI->getDwarfAccelObjCSection());

203 auto *SectionBegin = Asm->createTempSymbol("objc_begin");

204 Asm->OutStreamer->emitLabel(SectionBegin);

206}

207

210 Asm->OutStreamer->switchSection(MOFI->getDwarfAccelTypesSection());

211 auto *SectionBegin = Asm->createTempSymbol("types_begin");

212 Asm->OutStreamer->emitLabel(SectionBegin);

214}

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.

virtual void switchSection(MCSection *Section, uint32_t Subsec=0)

Set the current section where code is being emitted to Section.

DwarfDirectory MCUseDwarfDirectory

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.

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.

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.

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) const

Create a target specific MCStreamer.

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 * createAsmStreamer(MCContext &Ctx, std::unique_ptr< formatted_raw_ostream > OS, MCInstPrinter *IP, std::unique_ptr< MCCodeEmitter > CE, std::unique_ptr< MCAsmBackend > TAB) const

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 emitCompileUnitHeader(DwarfUnit &Unit)

Emit compile unit header.

Error init(Triple TheTriple, StringRef Swift5ReflectionSegmentName)

Initialize AsmPrinter data.

void emitAppleNames(AccelTable< AppleAccelTableStaticOffsetData > &Table)

Emits .apple_names section according to the specified Table.

void emitAbbrevs(const SmallVector< std::unique_ptr< DIEAbbrev > > &Abbrevs, unsigned DwarfVersion)

Emit abbreviations.

void emitAppleTypes(AccelTable< AppleAccelTableStaticTypeData > &Table)

Emits .apple_types section according to the specified Table.

void emitDIE(DIE &Die)

Emit DIE recursively.

void emitAppleNamespaces(AccelTable< AppleAccelTableStaticOffsetData > &Table)

Emits .apple_namespaces section according to the specified Table.

void emitDebugNames(DWARF5AccelTable &Table, DebugNamesUnitsOffsets &CUOffsets, CompUnitIDToIdx &UnitIDToIdxMap)

Emits .debug_names section according to the specified Table.

void emitAppleObjc(AccelTable< AppleAccelTableStaticOffsetData > &Table)

Emits .apple_objc section according to the specified Table.

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)

static const Target * lookupTarget(StringRef Triple, std::string &Error)

lookupTarget - Lookup a target based on a target triple.