1//===-- MCObjectFileInfo.cpp - Object File Information --------------------===//
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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/MC/MCObjectFileInfo.h"
10#include "llvm/ADT/StringExtras.h"
11#include "llvm/BinaryFormat/COFF.h"
12#include "llvm/BinaryFormat/ELF.h"
13#include "llvm/BinaryFormat/Wasm.h"
14#include "llvm/MC/MCAsmInfo.h"
15#include "llvm/MC/MCContext.h"
16#include "llvm/MC/MCSection.h"
17#include "llvm/MC/MCSectionCOFF.h"
18#include "llvm/MC/MCSectionDXContainer.h"
19#include "llvm/MC/MCSectionELF.h"
20#include "llvm/MC/MCSectionGOFF.h"
21#include "llvm/MC/MCSectionMachO.h"
22#include "llvm/MC/MCSectionSPIRV.h"
23#include "llvm/MC/MCSectionWasm.h"
24#include "llvm/MC/MCSectionXCOFF.h"
25#include "llvm/Support/Casting.h"
26#include "llvm/TargetParser/Triple.h"
27
28using namespace llvm;
29
30static bool useCompactUnwind(const Triple &T) {
31 // Only on darwin.
32 if (!T.isOSDarwin())
33 return false;
34
35 // aarch64 always has it.
36 if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)
37 return true;
38
39 // armv7k always has it.
40 if (T.isWatchABI())
41 return true;
42
43 // Use it on newer version of OS X.
44 if (T.isMacOSX() && !T.isMacOSXVersionLT(Major: 10, Minor: 6))
45 return true;
46
47 // And the iOS simulator.
48 if (T.isiOS() && T.isX86())
49 return true;
50
51 // The rest of the simulators always have it.
52 if (T.isSimulatorEnvironment())
53 return true;
54
55 // XROS always has it.
56 if (T.isXROS())
57 return true;
58
59 return false;
60}
61
62void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
63 // MachO
64 SupportsWeakOmittedEHFrame = false;
65
66 EHFrameSection = Ctx->getMachOSection(
67 Segment: "__TEXT", Section: "__eh_frame",
68 TypeAndAttributes: MachO::S_COALESCED | MachO::S_ATTR_NO_TOC |
69 MachO::S_ATTR_STRIP_STATIC_SYMS | MachO::S_ATTR_LIVE_SUPPORT,
70 K: SectionKind::getReadOnly());
71
72 if (T.isOSDarwin() &&
73 (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32 ||
74 T.isSimulatorEnvironment()))
75 SupportsCompactUnwindWithoutEHFrame = true;
76
77 switch (Ctx->emitDwarfUnwindInfo()) {
78 case EmitDwarfUnwindType::Always:
79 OmitDwarfIfHaveCompactUnwind = false;
80 break;
81 case EmitDwarfUnwindType::NoCompactUnwind:
82 OmitDwarfIfHaveCompactUnwind = true;
83 break;
84 case EmitDwarfUnwindType::Default:
85 OmitDwarfIfHaveCompactUnwind =
86 T.isWatchABI() || SupportsCompactUnwindWithoutEHFrame;
87 break;
88 }
89
90 FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
91
92 TextSection // .text
93 = Ctx->getMachOSection(Segment: "__TEXT", Section: "__text",
94 TypeAndAttributes: MachO::S_ATTR_PURE_INSTRUCTIONS,
95 K: SectionKind::getText());
96 DataSection // .data
97 = Ctx->getMachOSection(Segment: "__DATA", Section: "__data", TypeAndAttributes: 0, K: SectionKind::getData());
98
99 // BSSSection might not be expected initialized on msvc.
100 BSSSection = nullptr;
101
102 TLSDataSection // .tdata
103 = Ctx->getMachOSection(Segment: "__DATA", Section: "__thread_data",
104 TypeAndAttributes: MachO::S_THREAD_LOCAL_REGULAR,
105 K: SectionKind::getData());
106 TLSBSSSection // .tbss
107 = Ctx->getMachOSection(Segment: "__DATA", Section: "__thread_bss",
108 TypeAndAttributes: MachO::S_THREAD_LOCAL_ZEROFILL,
109 K: SectionKind::getThreadBSS());
110
111 // TODO: Verify datarel below.
112 TLSTLVSection // .tlv
113 = Ctx->getMachOSection(Segment: "__DATA", Section: "__thread_vars",
114 TypeAndAttributes: MachO::S_THREAD_LOCAL_VARIABLES,
115 K: SectionKind::getData());
116
117 TLSThreadInitSection = Ctx->getMachOSection(
118 Segment: "__DATA", Section: "__thread_init", TypeAndAttributes: MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
119 K: SectionKind::getData());
120
121 CStringSection // .cstring
122 = Ctx->getMachOSection(Segment: "__TEXT", Section: "__cstring",
123 TypeAndAttributes: MachO::S_CSTRING_LITERALS,
124 K: SectionKind::getMergeable1ByteCString());
125 UStringSection
126 = Ctx->getMachOSection(Segment: "__TEXT",Section: "__ustring", TypeAndAttributes: 0,
127 K: SectionKind::getMergeable2ByteCString());
128 FourByteConstantSection // .literal4
129 = Ctx->getMachOSection(Segment: "__TEXT", Section: "__literal4",
130 TypeAndAttributes: MachO::S_4BYTE_LITERALS,
131 K: SectionKind::getMergeableConst4());
132 EightByteConstantSection // .literal8
133 = Ctx->getMachOSection(Segment: "__TEXT", Section: "__literal8",
134 TypeAndAttributes: MachO::S_8BYTE_LITERALS,
135 K: SectionKind::getMergeableConst8());
136
137 SixteenByteConstantSection // .literal16
138 = Ctx->getMachOSection(Segment: "__TEXT", Section: "__literal16",
139 TypeAndAttributes: MachO::S_16BYTE_LITERALS,
140 K: SectionKind::getMergeableConst16());
141
142 ReadOnlySection // .const
143 = Ctx->getMachOSection(Segment: "__TEXT", Section: "__const", TypeAndAttributes: 0,
144 K: SectionKind::getReadOnly());
145
146 // If the target is not powerpc, map the coal sections to the non-coal
147 // sections.
148 //
149 // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
150 // "__TEXT/__const_coal" => section "__TEXT/__const"
151 // "__DATA/__datacoal_nt" => section "__DATA/__data"
152 Triple::ArchType ArchTy = T.getArch();
153
154 ConstDataSection // .const_data
155 = Ctx->getMachOSection(Segment: "__DATA", Section: "__const", TypeAndAttributes: 0,
156 K: SectionKind::getReadOnlyWithRel());
157
158 if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
159 TextCoalSection
160 = Ctx->getMachOSection(Segment: "__TEXT", Section: "__textcoal_nt",
161 TypeAndAttributes: MachO::S_COALESCED |
162 MachO::S_ATTR_PURE_INSTRUCTIONS,
163 K: SectionKind::getText());
164 ConstTextCoalSection
165 = Ctx->getMachOSection(Segment: "__TEXT", Section: "__const_coal",
166 TypeAndAttributes: MachO::S_COALESCED,
167 K: SectionKind::getReadOnly());
168 DataCoalSection = Ctx->getMachOSection(
169 Segment: "__DATA", Section: "__datacoal_nt", TypeAndAttributes: MachO::S_COALESCED, K: SectionKind::getData());
170 ConstDataCoalSection = DataCoalSection;
171 } else {
172 TextCoalSection = TextSection;
173 ConstTextCoalSection = ReadOnlySection;
174 DataCoalSection = DataSection;
175 ConstDataCoalSection = ConstDataSection;
176 }
177
178 DataCommonSection
179 = Ctx->getMachOSection(Segment: "__DATA",Section: "__common",
180 TypeAndAttributes: MachO::S_ZEROFILL,
181 K: SectionKind::getBSS());
182 DataBSSSection
183 = Ctx->getMachOSection(Segment: "__DATA",Section: "__bss", TypeAndAttributes: MachO::S_ZEROFILL,
184 K: SectionKind::getBSS());
185
186
187 LazySymbolPointerSection
188 = Ctx->getMachOSection(Segment: "__DATA", Section: "__la_symbol_ptr",
189 TypeAndAttributes: MachO::S_LAZY_SYMBOL_POINTERS,
190 K: SectionKind::getMetadata());
191 NonLazySymbolPointerSection
192 = Ctx->getMachOSection(Segment: "__DATA", Section: "__nl_symbol_ptr",
193 TypeAndAttributes: MachO::S_NON_LAZY_SYMBOL_POINTERS,
194 K: SectionKind::getMetadata());
195
196 ThreadLocalPointerSection
197 = Ctx->getMachOSection(Segment: "__DATA", Section: "__thread_ptr",
198 TypeAndAttributes: MachO::S_THREAD_LOCAL_VARIABLE_POINTERS,
199 K: SectionKind::getMetadata());
200
201 AddrSigSection = Ctx->getMachOSection(Segment: "__DATA", Section: "__llvm_addrsig", TypeAndAttributes: 0,
202 K: SectionKind::getData());
203
204 // Exception Handling.
205 LSDASection = Ctx->getMachOSection(Segment: "__TEXT", Section: "__gcc_except_tab", TypeAndAttributes: 0,
206 K: SectionKind::getReadOnlyWithRel());
207
208 COFFDebugSymbolsSection = nullptr;
209 COFFDebugTypesSection = nullptr;
210 COFFGlobalTypeHashesSection = nullptr;
211
212 if (useCompactUnwind(T)) {
213 CompactUnwindSection =
214 Ctx->getMachOSection(Segment: "__LD", Section: "__compact_unwind", TypeAndAttributes: MachO::S_ATTR_DEBUG,
215 K: SectionKind::getReadOnly());
216
217 if (T.isX86())
218 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF
219 else if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)
220 CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF
221 else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
222 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF
223 }
224
225 // Debug Information.
226 DwarfDebugNamesSection =
227 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_names", TypeAndAttributes: MachO::S_ATTR_DEBUG,
228 K: SectionKind::getMetadata(), BeginSymName: "debug_names_begin");
229 DwarfAccelNamesSection =
230 Ctx->getMachOSection(Segment: "__DWARF", Section: "__apple_names", TypeAndAttributes: MachO::S_ATTR_DEBUG,
231 K: SectionKind::getMetadata(), BeginSymName: "names_begin");
232 DwarfAccelObjCSection =
233 Ctx->getMachOSection(Segment: "__DWARF", Section: "__apple_objc", TypeAndAttributes: MachO::S_ATTR_DEBUG,
234 K: SectionKind::getMetadata(), BeginSymName: "objc_begin");
235 // 16 character section limit...
236 DwarfAccelNamespaceSection =
237 Ctx->getMachOSection(Segment: "__DWARF", Section: "__apple_namespac", TypeAndAttributes: MachO::S_ATTR_DEBUG,
238 K: SectionKind::getMetadata(), BeginSymName: "namespac_begin");
239 DwarfAccelTypesSection =
240 Ctx->getMachOSection(Segment: "__DWARF", Section: "__apple_types", TypeAndAttributes: MachO::S_ATTR_DEBUG,
241 K: SectionKind::getMetadata(), BeginSymName: "types_begin");
242
243 DwarfSwiftASTSection =
244 Ctx->getMachOSection(Segment: "__DWARF", Section: "__swift_ast", TypeAndAttributes: MachO::S_ATTR_DEBUG,
245 K: SectionKind::getMetadata());
246
247 DwarfAbbrevSection =
248 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_abbrev", TypeAndAttributes: MachO::S_ATTR_DEBUG,
249 K: SectionKind::getMetadata(), BeginSymName: "section_abbrev");
250 DwarfInfoSection =
251 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_info", TypeAndAttributes: MachO::S_ATTR_DEBUG,
252 K: SectionKind::getMetadata(), BeginSymName: "section_info");
253 DwarfLineSection =
254 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_line", TypeAndAttributes: MachO::S_ATTR_DEBUG,
255 K: SectionKind::getMetadata(), BeginSymName: "section_line");
256 DwarfLineStrSection =
257 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_line_str", TypeAndAttributes: MachO::S_ATTR_DEBUG,
258 K: SectionKind::getMetadata(), BeginSymName: "section_line_str");
259 DwarfFrameSection =
260 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_frame", TypeAndAttributes: MachO::S_ATTR_DEBUG,
261 K: SectionKind::getMetadata(), BeginSymName: "section_frame");
262 DwarfPubNamesSection =
263 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_pubnames", TypeAndAttributes: MachO::S_ATTR_DEBUG,
264 K: SectionKind::getMetadata());
265 DwarfPubTypesSection =
266 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_pubtypes", TypeAndAttributes: MachO::S_ATTR_DEBUG,
267 K: SectionKind::getMetadata());
268 DwarfGnuPubNamesSection =
269 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_gnu_pubn", TypeAndAttributes: MachO::S_ATTR_DEBUG,
270 K: SectionKind::getMetadata());
271 DwarfGnuPubTypesSection =
272 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_gnu_pubt", TypeAndAttributes: MachO::S_ATTR_DEBUG,
273 K: SectionKind::getMetadata());
274 DwarfStrSection =
275 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_str", TypeAndAttributes: MachO::S_ATTR_DEBUG,
276 K: SectionKind::getMetadata(), BeginSymName: "info_string");
277 DwarfStrOffSection =
278 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_str_offs", TypeAndAttributes: MachO::S_ATTR_DEBUG,
279 K: SectionKind::getMetadata(), BeginSymName: "section_str_off");
280 DwarfAddrSection =
281 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_addr", TypeAndAttributes: MachO::S_ATTR_DEBUG,
282 K: SectionKind::getMetadata(), BeginSymName: "section_info");
283 DwarfLocSection =
284 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_loc", TypeAndAttributes: MachO::S_ATTR_DEBUG,
285 K: SectionKind::getMetadata(), BeginSymName: "section_debug_loc");
286 DwarfLoclistsSection =
287 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_loclists", TypeAndAttributes: MachO::S_ATTR_DEBUG,
288 K: SectionKind::getMetadata(), BeginSymName: "section_debug_loc");
289
290 DwarfARangesSection =
291 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_aranges", TypeAndAttributes: MachO::S_ATTR_DEBUG,
292 K: SectionKind::getMetadata());
293 DwarfRangesSection =
294 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_ranges", TypeAndAttributes: MachO::S_ATTR_DEBUG,
295 K: SectionKind::getMetadata(), BeginSymName: "debug_range");
296 DwarfRnglistsSection =
297 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_rnglists", TypeAndAttributes: MachO::S_ATTR_DEBUG,
298 K: SectionKind::getMetadata(), BeginSymName: "debug_range");
299 DwarfMacinfoSection =
300 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_macinfo", TypeAndAttributes: MachO::S_ATTR_DEBUG,
301 K: SectionKind::getMetadata(), BeginSymName: "debug_macinfo");
302 DwarfMacroSection =
303 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_macro", TypeAndAttributes: MachO::S_ATTR_DEBUG,
304 K: SectionKind::getMetadata(), BeginSymName: "debug_macro");
305 DwarfDebugInlineSection =
306 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_inlined", TypeAndAttributes: MachO::S_ATTR_DEBUG,
307 K: SectionKind::getMetadata());
308 DwarfCUIndexSection =
309 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_cu_index", TypeAndAttributes: MachO::S_ATTR_DEBUG,
310 K: SectionKind::getMetadata());
311 DwarfTUIndexSection =
312 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_tu_index", TypeAndAttributes: MachO::S_ATTR_DEBUG,
313 K: SectionKind::getMetadata());
314 StackMapSection = Ctx->getMachOSection(Segment: "__LLVM_STACKMAPS", Section: "__llvm_stackmaps",
315 TypeAndAttributes: 0, K: SectionKind::getMetadata());
316
317 FaultMapSection = Ctx->getMachOSection(Segment: "__LLVM_FAULTMAPS", Section: "__llvm_faultmaps",
318 TypeAndAttributes: 0, K: SectionKind::getMetadata());
319
320 RemarksSection = Ctx->getMachOSection(
321 Segment: "__LLVM", Section: "__remarks", TypeAndAttributes: MachO::S_ATTR_DEBUG, K: SectionKind::getMetadata());
322
323 // The architecture of dsymutil makes it very difficult to copy the Swift
324 // reflection metadata sections into the __TEXT segment, so dsymutil creates
325 // these sections in the __DWARF segment instead.
326 if (!Ctx->getSwift5ReflectionSegmentName().empty()) {
327#define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) \
328 Swift5ReflectionSections \
329 [llvm::binaryformat::Swift5ReflectionSectionKind::KIND] = \
330 Ctx->getMachOSection(Ctx->getSwift5ReflectionSegmentName().data(), \
331 MACHO, 0, SectionKind::getMetadata());
332#include "llvm/BinaryFormat/Swift.def"
333 }
334
335 TLSExtraDataSection = TLSTLVSection;
336}
337
338void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
339 switch (T.getArch()) {
340 case Triple::mips:
341 case Triple::mipsel:
342 case Triple::mips64:
343 case Triple::mips64el:
344 // We cannot use DW_EH_PE_sdata8 for the large PositionIndependent case
345 // since there is no R_MIPS_PC64 relocation (only a 32-bit version).
346 if (PositionIndependent && !Large)
347 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
348 else
349 FDECFIEncoding = Ctx->getAsmInfo()->getCodePointerSize() == 4
350 ? dwarf::DW_EH_PE_sdata4
351 : dwarf::DW_EH_PE_sdata8;
352 break;
353 case Triple::ppc64:
354 case Triple::ppc64le:
355 case Triple::aarch64:
356 case Triple::aarch64_be:
357 case Triple::x86_64:
358 FDECFIEncoding = dwarf::DW_EH_PE_pcrel |
359 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
360 break;
361 case Triple::bpfel:
362 case Triple::bpfeb:
363 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
364 break;
365 case Triple::hexagon:
366 FDECFIEncoding =
367 PositionIndependent ? dwarf::DW_EH_PE_pcrel : dwarf::DW_EH_PE_absptr;
368 break;
369 case Triple::xtensa:
370 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
371 break;
372 default:
373 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
374 break;
375 }
376
377 unsigned EHSectionType = T.getArch() == Triple::x86_64
378 ? ELF::SHT_X86_64_UNWIND
379 : ELF::SHT_PROGBITS;
380
381 // Solaris requires different flags for .eh_frame to seemingly every other
382 // platform.
383 unsigned EHSectionFlags = ELF::SHF_ALLOC;
384 if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
385 EHSectionFlags |= ELF::SHF_WRITE;
386
387 // ELF
388 BSSSection = Ctx->getELFSection(Section: ".bss", Type: ELF::SHT_NOBITS,
389 Flags: ELF::SHF_WRITE | ELF::SHF_ALLOC);
390
391 TextSection = Ctx->getELFSection(Section: ".text", Type: ELF::SHT_PROGBITS,
392 Flags: ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
393
394 DataSection = Ctx->getELFSection(Section: ".data", Type: ELF::SHT_PROGBITS,
395 Flags: ELF::SHF_WRITE | ELF::SHF_ALLOC);
396
397 ReadOnlySection =
398 Ctx->getELFSection(Section: ".rodata", Type: ELF::SHT_PROGBITS, Flags: ELF::SHF_ALLOC);
399
400 TLSDataSection =
401 Ctx->getELFSection(Section: ".tdata", Type: ELF::SHT_PROGBITS,
402 Flags: ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
403
404 TLSBSSSection = Ctx->getELFSection(
405 Section: ".tbss", Type: ELF::SHT_NOBITS, Flags: ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
406
407 DataRelROSection = Ctx->getELFSection(Section: ".data.rel.ro", Type: ELF::SHT_PROGBITS,
408 Flags: ELF::SHF_ALLOC | ELF::SHF_WRITE);
409
410 MergeableConst4Section =
411 Ctx->getELFSection(Section: ".rodata.cst4", Type: ELF::SHT_PROGBITS,
412 Flags: ELF::SHF_ALLOC | ELF::SHF_MERGE, EntrySize: 4);
413
414 MergeableConst8Section =
415 Ctx->getELFSection(Section: ".rodata.cst8", Type: ELF::SHT_PROGBITS,
416 Flags: ELF::SHF_ALLOC | ELF::SHF_MERGE, EntrySize: 8);
417
418 MergeableConst16Section =
419 Ctx->getELFSection(Section: ".rodata.cst16", Type: ELF::SHT_PROGBITS,
420 Flags: ELF::SHF_ALLOC | ELF::SHF_MERGE, EntrySize: 16);
421
422 MergeableConst32Section =
423 Ctx->getELFSection(Section: ".rodata.cst32", Type: ELF::SHT_PROGBITS,
424 Flags: ELF::SHF_ALLOC | ELF::SHF_MERGE, EntrySize: 32);
425
426 // Exception Handling Sections.
427
428 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
429 // it contains relocatable pointers. In PIC mode, this is probably a big
430 // runtime hit for C++ apps. Either the contents of the LSDA need to be
431 // adjusted or this should be a data section.
432 LSDASection = Ctx->getELFSection(Section: ".gcc_except_table", Type: ELF::SHT_PROGBITS,
433 Flags: ELF::SHF_ALLOC);
434
435 COFFDebugSymbolsSection = nullptr;
436 COFFDebugTypesSection = nullptr;
437
438 unsigned DebugSecType = ELF::SHT_PROGBITS;
439
440 // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
441 // to distinguish among sections contain DWARF and ECOFF debug formats.
442 // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
443 if (T.isMIPS())
444 DebugSecType = ELF::SHT_MIPS_DWARF;
445
446 // Debug Info Sections.
447 DwarfAbbrevSection =
448 Ctx->getELFSection(Section: ".debug_abbrev", Type: DebugSecType, Flags: 0);
449 DwarfInfoSection = Ctx->getELFSection(Section: ".debug_info", Type: DebugSecType, Flags: 0);
450 DwarfLineSection = Ctx->getELFSection(Section: ".debug_line", Type: DebugSecType, Flags: 0);
451 DwarfLineStrSection =
452 Ctx->getELFSection(Section: ".debug_line_str", Type: DebugSecType,
453 Flags: ELF::SHF_MERGE | ELF::SHF_STRINGS, EntrySize: 1);
454 DwarfFrameSection = Ctx->getELFSection(Section: ".debug_frame", Type: DebugSecType, Flags: 0);
455 DwarfPubNamesSection =
456 Ctx->getELFSection(Section: ".debug_pubnames", Type: DebugSecType, Flags: 0);
457 DwarfPubTypesSection =
458 Ctx->getELFSection(Section: ".debug_pubtypes", Type: DebugSecType, Flags: 0);
459 DwarfGnuPubNamesSection =
460 Ctx->getELFSection(Section: ".debug_gnu_pubnames", Type: DebugSecType, Flags: 0);
461 DwarfGnuPubTypesSection =
462 Ctx->getELFSection(Section: ".debug_gnu_pubtypes", Type: DebugSecType, Flags: 0);
463 DwarfStrSection =
464 Ctx->getELFSection(Section: ".debug_str", Type: DebugSecType,
465 Flags: ELF::SHF_MERGE | ELF::SHF_STRINGS, EntrySize: 1);
466 DwarfLocSection = Ctx->getELFSection(Section: ".debug_loc", Type: DebugSecType, Flags: 0);
467 DwarfARangesSection =
468 Ctx->getELFSection(Section: ".debug_aranges", Type: DebugSecType, Flags: 0);
469 DwarfRangesSection =
470 Ctx->getELFSection(Section: ".debug_ranges", Type: DebugSecType, Flags: 0);
471 DwarfMacinfoSection =
472 Ctx->getELFSection(Section: ".debug_macinfo", Type: DebugSecType, Flags: 0);
473 DwarfMacroSection = Ctx->getELFSection(Section: ".debug_macro", Type: DebugSecType, Flags: 0);
474
475 // DWARF5 Experimental Debug Info
476
477 // Accelerator Tables
478 DwarfDebugNamesSection =
479 Ctx->getELFSection(Section: ".debug_names", Type: ELF::SHT_PROGBITS, Flags: 0);
480 DwarfAccelNamesSection =
481 Ctx->getELFSection(Section: ".apple_names", Type: ELF::SHT_PROGBITS, Flags: 0);
482 DwarfAccelObjCSection =
483 Ctx->getELFSection(Section: ".apple_objc", Type: ELF::SHT_PROGBITS, Flags: 0);
484 DwarfAccelNamespaceSection =
485 Ctx->getELFSection(Section: ".apple_namespaces", Type: ELF::SHT_PROGBITS, Flags: 0);
486 DwarfAccelTypesSection =
487 Ctx->getELFSection(Section: ".apple_types", Type: ELF::SHT_PROGBITS, Flags: 0);
488
489 // String Offset and Address Sections
490 DwarfStrOffSection =
491 Ctx->getELFSection(Section: ".debug_str_offsets", Type: DebugSecType, Flags: 0);
492 DwarfAddrSection = Ctx->getELFSection(Section: ".debug_addr", Type: DebugSecType, Flags: 0);
493 DwarfRnglistsSection = Ctx->getELFSection(Section: ".debug_rnglists", Type: DebugSecType, Flags: 0);
494 DwarfLoclistsSection = Ctx->getELFSection(Section: ".debug_loclists", Type: DebugSecType, Flags: 0);
495
496 // Fission Sections
497 DwarfInfoDWOSection =
498 Ctx->getELFSection(Section: ".debug_info.dwo", Type: DebugSecType, Flags: ELF::SHF_EXCLUDE);
499 DwarfTypesDWOSection =
500 Ctx->getELFSection(Section: ".debug_types.dwo", Type: DebugSecType, Flags: ELF::SHF_EXCLUDE);
501 DwarfAbbrevDWOSection =
502 Ctx->getELFSection(Section: ".debug_abbrev.dwo", Type: DebugSecType, Flags: ELF::SHF_EXCLUDE);
503 DwarfStrDWOSection = Ctx->getELFSection(
504 Section: ".debug_str.dwo", Type: DebugSecType,
505 Flags: ELF::SHF_MERGE | ELF::SHF_STRINGS | ELF::SHF_EXCLUDE, EntrySize: 1);
506 DwarfLineDWOSection =
507 Ctx->getELFSection(Section: ".debug_line.dwo", Type: DebugSecType, Flags: ELF::SHF_EXCLUDE);
508 DwarfLocDWOSection =
509 Ctx->getELFSection(Section: ".debug_loc.dwo", Type: DebugSecType, Flags: ELF::SHF_EXCLUDE);
510 DwarfStrOffDWOSection = Ctx->getELFSection(Section: ".debug_str_offsets.dwo",
511 Type: DebugSecType, Flags: ELF::SHF_EXCLUDE);
512 DwarfRnglistsDWOSection =
513 Ctx->getELFSection(Section: ".debug_rnglists.dwo", Type: DebugSecType, Flags: ELF::SHF_EXCLUDE);
514 DwarfMacinfoDWOSection =
515 Ctx->getELFSection(Section: ".debug_macinfo.dwo", Type: DebugSecType, Flags: ELF::SHF_EXCLUDE);
516 DwarfMacroDWOSection =
517 Ctx->getELFSection(Section: ".debug_macro.dwo", Type: DebugSecType, Flags: ELF::SHF_EXCLUDE);
518
519 DwarfLoclistsDWOSection =
520 Ctx->getELFSection(Section: ".debug_loclists.dwo", Type: DebugSecType, Flags: ELF::SHF_EXCLUDE);
521
522 // DWP Sections
523 DwarfCUIndexSection =
524 Ctx->getELFSection(Section: ".debug_cu_index", Type: DebugSecType, Flags: 0);
525 DwarfTUIndexSection =
526 Ctx->getELFSection(Section: ".debug_tu_index", Type: DebugSecType, Flags: 0);
527
528 StackMapSection =
529 Ctx->getELFSection(Section: ".llvm_stackmaps", Type: ELF::SHT_PROGBITS, Flags: ELF::SHF_ALLOC);
530
531 FaultMapSection =
532 Ctx->getELFSection(Section: ".llvm_faultmaps", Type: ELF::SHT_PROGBITS, Flags: ELF::SHF_ALLOC);
533
534 EHFrameSection =
535 Ctx->getELFSection(Section: ".eh_frame", Type: EHSectionType, Flags: EHSectionFlags);
536
537 StackSizesSection = Ctx->getELFSection(Section: ".stack_sizes", Type: ELF::SHT_PROGBITS, Flags: 0);
538
539 PseudoProbeSection = Ctx->getELFSection(Section: ".pseudo_probe", Type: DebugSecType, Flags: 0);
540 PseudoProbeDescSection =
541 Ctx->getELFSection(Section: ".pseudo_probe_desc", Type: DebugSecType, Flags: 0);
542
543 LLVMStatsSection = Ctx->getELFSection(Section: ".llvm_stats", Type: ELF::SHT_PROGBITS, Flags: 0);
544}
545
546void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) {
547 TextSection =
548 Ctx->getGOFFSection(Section: ".text", Kind: SectionKind::getText(), Parent: nullptr, SubsectionId: nullptr);
549 BSSSection =
550 Ctx->getGOFFSection(Section: ".bss", Kind: SectionKind::getBSS(), Parent: nullptr, SubsectionId: nullptr);
551 PPA1Section =
552 Ctx->getGOFFSection(Section: ".ppa1", Kind: SectionKind::getMetadata(), Parent: TextSection,
553 SubsectionId: MCConstantExpr::create(Value: GOFF::SK_PPA1, Ctx&: *Ctx));
554 PPA2Section =
555 Ctx->getGOFFSection(Section: ".ppa2", Kind: SectionKind::getMetadata(), Parent: TextSection,
556 SubsectionId: MCConstantExpr::create(Value: GOFF::SK_PPA2, Ctx&: *Ctx));
557
558 PPA2ListSection =
559 Ctx->getGOFFSection(Section: ".ppa2list", Kind: SectionKind::getData(),
560 Parent: nullptr, SubsectionId: nullptr);
561
562 ADASection =
563 Ctx->getGOFFSection(Section: ".ada", Kind: SectionKind::getData(), Parent: nullptr, SubsectionId: nullptr);
564 IDRLSection =
565 Ctx->getGOFFSection(Section: "B_IDRL", Kind: SectionKind::getData(), Parent: nullptr, SubsectionId: nullptr);
566}
567
568void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
569 EHFrameSection =
570 Ctx->getCOFFSection(Section: ".eh_frame", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
571 COFF::IMAGE_SCN_MEM_READ,
572 Kind: SectionKind::getData());
573
574 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
575 // used to indicate to the linker that the text segment contains thumb instructions
576 // and to set the ISA selection bit for calls accordingly.
577 const bool IsThumb = T.getArch() == Triple::thumb;
578
579 // COFF
580 BSSSection = Ctx->getCOFFSection(
581 Section: ".bss", Characteristics: COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
582 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
583 Kind: SectionKind::getBSS());
584 TextSection = Ctx->getCOFFSection(
585 Section: ".text",
586 Characteristics: (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |
587 COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
588 COFF::IMAGE_SCN_MEM_READ,
589 Kind: SectionKind::getText());
590 DataSection = Ctx->getCOFFSection(
591 Section: ".data", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
592 COFF::IMAGE_SCN_MEM_WRITE,
593 Kind: SectionKind::getData());
594 ReadOnlySection = Ctx->getCOFFSection(
595 Section: ".rdata", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
596 Kind: SectionKind::getReadOnly());
597
598 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64 ||
599 T.getArch() == Triple::arm || T.getArch() == Triple::thumb) {
600 // On Windows with SEH, the LSDA is emitted into the .xdata section
601 LSDASection = nullptr;
602 } else {
603 LSDASection = Ctx->getCOFFSection(Section: ".gcc_except_table",
604 Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
605 COFF::IMAGE_SCN_MEM_READ,
606 Kind: SectionKind::getReadOnly());
607 }
608
609 // Debug info.
610 COFFDebugSymbolsSection =
611 Ctx->getCOFFSection(Section: ".debug$S", Characteristics: (COFF::IMAGE_SCN_MEM_DISCARDABLE |
612 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
613 COFF::IMAGE_SCN_MEM_READ),
614 Kind: SectionKind::getMetadata());
615 COFFDebugTypesSection =
616 Ctx->getCOFFSection(Section: ".debug$T", Characteristics: (COFF::IMAGE_SCN_MEM_DISCARDABLE |
617 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
618 COFF::IMAGE_SCN_MEM_READ),
619 Kind: SectionKind::getMetadata());
620 COFFGlobalTypeHashesSection = Ctx->getCOFFSection(
621 Section: ".debug$H",
622 Characteristics: (COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
623 COFF::IMAGE_SCN_MEM_READ),
624 Kind: SectionKind::getMetadata());
625
626 DwarfAbbrevSection = Ctx->getCOFFSection(
627 Section: ".debug_abbrev",
628 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
629 COFF::IMAGE_SCN_MEM_READ,
630 Kind: SectionKind::getMetadata(), BeginSymName: "section_abbrev");
631 DwarfInfoSection = Ctx->getCOFFSection(
632 Section: ".debug_info",
633 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
634 COFF::IMAGE_SCN_MEM_READ,
635 Kind: SectionKind::getMetadata(), BeginSymName: "section_info");
636 DwarfLineSection = Ctx->getCOFFSection(
637 Section: ".debug_line",
638 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
639 COFF::IMAGE_SCN_MEM_READ,
640 Kind: SectionKind::getMetadata(), BeginSymName: "section_line");
641 DwarfLineStrSection = Ctx->getCOFFSection(
642 Section: ".debug_line_str",
643 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
644 COFF::IMAGE_SCN_MEM_READ,
645 Kind: SectionKind::getMetadata(), BeginSymName: "section_line_str");
646 DwarfFrameSection = Ctx->getCOFFSection(
647 Section: ".debug_frame",
648 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
649 COFF::IMAGE_SCN_MEM_READ,
650 Kind: SectionKind::getMetadata());
651 DwarfPubNamesSection = Ctx->getCOFFSection(
652 Section: ".debug_pubnames",
653 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
654 COFF::IMAGE_SCN_MEM_READ,
655 Kind: SectionKind::getMetadata());
656 DwarfPubTypesSection = Ctx->getCOFFSection(
657 Section: ".debug_pubtypes",
658 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
659 COFF::IMAGE_SCN_MEM_READ,
660 Kind: SectionKind::getMetadata());
661 DwarfGnuPubNamesSection = Ctx->getCOFFSection(
662 Section: ".debug_gnu_pubnames",
663 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
664 COFF::IMAGE_SCN_MEM_READ,
665 Kind: SectionKind::getMetadata());
666 DwarfGnuPubTypesSection = Ctx->getCOFFSection(
667 Section: ".debug_gnu_pubtypes",
668 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
669 COFF::IMAGE_SCN_MEM_READ,
670 Kind: SectionKind::getMetadata());
671 DwarfStrSection = Ctx->getCOFFSection(
672 Section: ".debug_str",
673 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
674 COFF::IMAGE_SCN_MEM_READ,
675 Kind: SectionKind::getMetadata(), BeginSymName: "info_string");
676 DwarfStrOffSection = Ctx->getCOFFSection(
677 Section: ".debug_str_offsets",
678 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
679 COFF::IMAGE_SCN_MEM_READ,
680 Kind: SectionKind::getMetadata(), BeginSymName: "section_str_off");
681 DwarfLocSection = Ctx->getCOFFSection(
682 Section: ".debug_loc",
683 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
684 COFF::IMAGE_SCN_MEM_READ,
685 Kind: SectionKind::getMetadata(), BeginSymName: "section_debug_loc");
686 DwarfLoclistsSection = Ctx->getCOFFSection(
687 Section: ".debug_loclists",
688 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
689 COFF::IMAGE_SCN_MEM_READ,
690 Kind: SectionKind::getMetadata(), BeginSymName: "section_debug_loclists");
691 DwarfARangesSection = Ctx->getCOFFSection(
692 Section: ".debug_aranges",
693 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
694 COFF::IMAGE_SCN_MEM_READ,
695 Kind: SectionKind::getMetadata());
696 DwarfRangesSection = Ctx->getCOFFSection(
697 Section: ".debug_ranges",
698 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
699 COFF::IMAGE_SCN_MEM_READ,
700 Kind: SectionKind::getMetadata(), BeginSymName: "debug_range");
701 DwarfRnglistsSection = Ctx->getCOFFSection(
702 Section: ".debug_rnglists",
703 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
704 COFF::IMAGE_SCN_MEM_READ,
705 Kind: SectionKind::getMetadata(), BeginSymName: "debug_rnglists");
706 DwarfMacinfoSection = Ctx->getCOFFSection(
707 Section: ".debug_macinfo",
708 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
709 COFF::IMAGE_SCN_MEM_READ,
710 Kind: SectionKind::getMetadata(), BeginSymName: "debug_macinfo");
711 DwarfMacroSection = Ctx->getCOFFSection(
712 Section: ".debug_macro",
713 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
714 COFF::IMAGE_SCN_MEM_READ,
715 Kind: SectionKind::getMetadata(), BeginSymName: "debug_macro");
716 DwarfMacinfoDWOSection = Ctx->getCOFFSection(
717 Section: ".debug_macinfo.dwo",
718 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
719 COFF::IMAGE_SCN_MEM_READ,
720 Kind: SectionKind::getMetadata(), BeginSymName: "debug_macinfo.dwo");
721 DwarfMacroDWOSection = Ctx->getCOFFSection(
722 Section: ".debug_macro.dwo",
723 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
724 COFF::IMAGE_SCN_MEM_READ,
725 Kind: SectionKind::getMetadata(), BeginSymName: "debug_macro.dwo");
726 DwarfInfoDWOSection = Ctx->getCOFFSection(
727 Section: ".debug_info.dwo",
728 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
729 COFF::IMAGE_SCN_MEM_READ,
730 Kind: SectionKind::getMetadata(), BeginSymName: "section_info_dwo");
731 DwarfTypesDWOSection = Ctx->getCOFFSection(
732 Section: ".debug_types.dwo",
733 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
734 COFF::IMAGE_SCN_MEM_READ,
735 Kind: SectionKind::getMetadata(), BeginSymName: "section_types_dwo");
736 DwarfAbbrevDWOSection = Ctx->getCOFFSection(
737 Section: ".debug_abbrev.dwo",
738 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
739 COFF::IMAGE_SCN_MEM_READ,
740 Kind: SectionKind::getMetadata(), BeginSymName: "section_abbrev_dwo");
741 DwarfStrDWOSection = Ctx->getCOFFSection(
742 Section: ".debug_str.dwo",
743 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
744 COFF::IMAGE_SCN_MEM_READ,
745 Kind: SectionKind::getMetadata(), BeginSymName: "skel_string");
746 DwarfLineDWOSection = Ctx->getCOFFSection(
747 Section: ".debug_line.dwo",
748 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
749 COFF::IMAGE_SCN_MEM_READ,
750 Kind: SectionKind::getMetadata());
751 DwarfLocDWOSection = Ctx->getCOFFSection(
752 Section: ".debug_loc.dwo",
753 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
754 COFF::IMAGE_SCN_MEM_READ,
755 Kind: SectionKind::getMetadata(), BeginSymName: "skel_loc");
756 DwarfStrOffDWOSection = Ctx->getCOFFSection(
757 Section: ".debug_str_offsets.dwo",
758 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
759 COFF::IMAGE_SCN_MEM_READ,
760 Kind: SectionKind::getMetadata(), BeginSymName: "section_str_off_dwo");
761 DwarfAddrSection = Ctx->getCOFFSection(
762 Section: ".debug_addr",
763 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
764 COFF::IMAGE_SCN_MEM_READ,
765 Kind: SectionKind::getMetadata(), BeginSymName: "addr_sec");
766 DwarfCUIndexSection = Ctx->getCOFFSection(
767 Section: ".debug_cu_index",
768 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
769 COFF::IMAGE_SCN_MEM_READ,
770 Kind: SectionKind::getMetadata());
771 DwarfTUIndexSection = Ctx->getCOFFSection(
772 Section: ".debug_tu_index",
773 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
774 COFF::IMAGE_SCN_MEM_READ,
775 Kind: SectionKind::getMetadata());
776 DwarfDebugNamesSection = Ctx->getCOFFSection(
777 Section: ".debug_names",
778 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
779 COFF::IMAGE_SCN_MEM_READ,
780 Kind: SectionKind::getMetadata(), BeginSymName: "debug_names_begin");
781 DwarfAccelNamesSection = Ctx->getCOFFSection(
782 Section: ".apple_names",
783 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
784 COFF::IMAGE_SCN_MEM_READ,
785 Kind: SectionKind::getMetadata(), BeginSymName: "names_begin");
786 DwarfAccelNamespaceSection = Ctx->getCOFFSection(
787 Section: ".apple_namespaces",
788 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
789 COFF::IMAGE_SCN_MEM_READ,
790 Kind: SectionKind::getMetadata(), BeginSymName: "namespac_begin");
791 DwarfAccelTypesSection = Ctx->getCOFFSection(
792 Section: ".apple_types",
793 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
794 COFF::IMAGE_SCN_MEM_READ,
795 Kind: SectionKind::getMetadata(), BeginSymName: "types_begin");
796 DwarfAccelObjCSection = Ctx->getCOFFSection(
797 Section: ".apple_objc",
798 Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
799 COFF::IMAGE_SCN_MEM_READ,
800 Kind: SectionKind::getMetadata(), BeginSymName: "objc_begin");
801
802 DrectveSection = Ctx->getCOFFSection(
803 Section: ".drectve", Characteristics: COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
804 Kind: SectionKind::getMetadata());
805
806 PDataSection = Ctx->getCOFFSection(
807 Section: ".pdata", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
808 Kind: SectionKind::getData());
809
810 XDataSection = Ctx->getCOFFSection(
811 Section: ".xdata", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
812 Kind: SectionKind::getData());
813
814 SXDataSection = Ctx->getCOFFSection(Section: ".sxdata", Characteristics: COFF::IMAGE_SCN_LNK_INFO,
815 Kind: SectionKind::getMetadata());
816
817 GEHContSection = Ctx->getCOFFSection(Section: ".gehcont$y",
818 Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
819 COFF::IMAGE_SCN_MEM_READ,
820 Kind: SectionKind::getMetadata());
821
822 GFIDsSection = Ctx->getCOFFSection(Section: ".gfids$y",
823 Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
824 COFF::IMAGE_SCN_MEM_READ,
825 Kind: SectionKind::getMetadata());
826
827 GIATsSection = Ctx->getCOFFSection(Section: ".giats$y",
828 Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
829 COFF::IMAGE_SCN_MEM_READ,
830 Kind: SectionKind::getMetadata());
831
832 GLJMPSection = Ctx->getCOFFSection(Section: ".gljmp$y",
833 Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
834 COFF::IMAGE_SCN_MEM_READ,
835 Kind: SectionKind::getMetadata());
836
837 TLSDataSection = Ctx->getCOFFSection(
838 Section: ".tls$", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
839 COFF::IMAGE_SCN_MEM_WRITE,
840 Kind: SectionKind::getData());
841
842 StackMapSection = Ctx->getCOFFSection(Section: ".llvm_stackmaps",
843 Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
844 COFF::IMAGE_SCN_MEM_READ,
845 Kind: SectionKind::getReadOnly());
846}
847
848void MCObjectFileInfo::initSPIRVMCObjectFileInfo(const Triple &T) {
849 // Put everything in a single binary section.
850 TextSection = Ctx->getSPIRVSection();
851}
852
853void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
854 TextSection = Ctx->getWasmSection(Section: ".text", K: SectionKind::getText());
855 DataSection = Ctx->getWasmSection(Section: ".data", K: SectionKind::getData());
856
857 DwarfLineSection =
858 Ctx->getWasmSection(Section: ".debug_line", K: SectionKind::getMetadata());
859 DwarfLineStrSection =
860 Ctx->getWasmSection(Section: ".debug_line_str", K: SectionKind::getMetadata(),
861 Flags: wasm::WASM_SEG_FLAG_STRINGS);
862 DwarfStrSection = Ctx->getWasmSection(
863 Section: ".debug_str", K: SectionKind::getMetadata(), Flags: wasm::WASM_SEG_FLAG_STRINGS);
864 DwarfLocSection =
865 Ctx->getWasmSection(Section: ".debug_loc", K: SectionKind::getMetadata());
866 DwarfAbbrevSection =
867 Ctx->getWasmSection(Section: ".debug_abbrev", K: SectionKind::getMetadata());
868 DwarfARangesSection = Ctx->getWasmSection(Section: ".debug_aranges", K: SectionKind::getMetadata());
869 DwarfRangesSection =
870 Ctx->getWasmSection(Section: ".debug_ranges", K: SectionKind::getMetadata());
871 DwarfMacinfoSection =
872 Ctx->getWasmSection(Section: ".debug_macinfo", K: SectionKind::getMetadata());
873 DwarfMacroSection =
874 Ctx->getWasmSection(Section: ".debug_macro", K: SectionKind::getMetadata());
875 DwarfCUIndexSection = Ctx->getWasmSection(Section: ".debug_cu_index", K: SectionKind::getMetadata());
876 DwarfTUIndexSection = Ctx->getWasmSection(Section: ".debug_tu_index", K: SectionKind::getMetadata());
877 DwarfInfoSection =
878 Ctx->getWasmSection(Section: ".debug_info", K: SectionKind::getMetadata());
879 DwarfFrameSection = Ctx->getWasmSection(Section: ".debug_frame", K: SectionKind::getMetadata());
880 DwarfPubNamesSection = Ctx->getWasmSection(Section: ".debug_pubnames", K: SectionKind::getMetadata());
881 DwarfPubTypesSection = Ctx->getWasmSection(Section: ".debug_pubtypes", K: SectionKind::getMetadata());
882 DwarfGnuPubNamesSection =
883 Ctx->getWasmSection(Section: ".debug_gnu_pubnames", K: SectionKind::getMetadata());
884 DwarfGnuPubTypesSection =
885 Ctx->getWasmSection(Section: ".debug_gnu_pubtypes", K: SectionKind::getMetadata());
886
887 DwarfDebugNamesSection =
888 Ctx->getWasmSection(Section: ".debug_names", K: SectionKind::getMetadata());
889 DwarfStrOffSection =
890 Ctx->getWasmSection(Section: ".debug_str_offsets", K: SectionKind::getMetadata());
891 DwarfAddrSection =
892 Ctx->getWasmSection(Section: ".debug_addr", K: SectionKind::getMetadata());
893 DwarfRnglistsSection =
894 Ctx->getWasmSection(Section: ".debug_rnglists", K: SectionKind::getMetadata());
895 DwarfLoclistsSection =
896 Ctx->getWasmSection(Section: ".debug_loclists", K: SectionKind::getMetadata());
897
898 // Fission Sections
899 DwarfInfoDWOSection =
900 Ctx->getWasmSection(Section: ".debug_info.dwo", K: SectionKind::getMetadata());
901 DwarfTypesDWOSection =
902 Ctx->getWasmSection(Section: ".debug_types.dwo", K: SectionKind::getMetadata());
903 DwarfAbbrevDWOSection =
904 Ctx->getWasmSection(Section: ".debug_abbrev.dwo", K: SectionKind::getMetadata());
905 DwarfStrDWOSection =
906 Ctx->getWasmSection(Section: ".debug_str.dwo", K: SectionKind::getMetadata(),
907 Flags: wasm::WASM_SEG_FLAG_STRINGS);
908 DwarfLineDWOSection =
909 Ctx->getWasmSection(Section: ".debug_line.dwo", K: SectionKind::getMetadata());
910 DwarfLocDWOSection =
911 Ctx->getWasmSection(Section: ".debug_loc.dwo", K: SectionKind::getMetadata());
912 DwarfStrOffDWOSection =
913 Ctx->getWasmSection(Section: ".debug_str_offsets.dwo", K: SectionKind::getMetadata());
914 DwarfRnglistsDWOSection =
915 Ctx->getWasmSection(Section: ".debug_rnglists.dwo", K: SectionKind::getMetadata());
916 DwarfMacinfoDWOSection =
917 Ctx->getWasmSection(Section: ".debug_macinfo.dwo", K: SectionKind::getMetadata());
918 DwarfMacroDWOSection =
919 Ctx->getWasmSection(Section: ".debug_macro.dwo", K: SectionKind::getMetadata());
920
921 DwarfLoclistsDWOSection =
922 Ctx->getWasmSection(Section: ".debug_loclists.dwo", K: SectionKind::getMetadata());
923
924 // DWP Sections
925 DwarfCUIndexSection =
926 Ctx->getWasmSection(Section: ".debug_cu_index", K: SectionKind::getMetadata());
927 DwarfTUIndexSection =
928 Ctx->getWasmSection(Section: ".debug_tu_index", K: SectionKind::getMetadata());
929
930 // Wasm use data section for LSDA.
931 // TODO Consider putting each function's exception table in a separate
932 // section, as in -function-sections, to facilitate lld's --gc-section.
933 LSDASection = Ctx->getWasmSection(Section: ".rodata.gcc_except_table",
934 K: SectionKind::getReadOnlyWithRel());
935
936 // TODO: Define more sections.
937}
938
939void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) {
940 // The default csect for program code. Functions without a specified section
941 // get placed into this csect. The choice of csect name is not a property of
942 // the ABI or object file format, but various tools rely on the section
943 // name being empty (considering named symbols to be "user symbol names").
944 TextSection = Ctx->getXCOFFSection(
945 Section: "..text..", // Use a non-null name to work around an AIX assembler bug...
946 K: SectionKind::getText(),
947 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD),
948 /* MultiSymbolsAllowed*/ true);
949
950 // ... but use a null name when generating the symbol table.
951 MCSectionXCOFF *TS = static_cast<MCSectionXCOFF *>(TextSection);
952 TS->getQualNameSymbol()->setSymbolTableName("");
953 TS->setSymbolTableName("");
954
955 DataSection = Ctx->getXCOFFSection(
956 Section: ".data", K: SectionKind::getData(),
957 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD),
958 /* MultiSymbolsAllowed*/ true);
959
960 ReadOnlySection = Ctx->getXCOFFSection(
961 Section: ".rodata", K: SectionKind::getReadOnly(),
962 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
963 /* MultiSymbolsAllowed*/ true);
964 ReadOnlySection->setAlignment(Align(4));
965
966 ReadOnly8Section = Ctx->getXCOFFSection(
967 Section: ".rodata.8", K: SectionKind::getReadOnly(),
968 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
969 /* MultiSymbolsAllowed*/ true);
970 ReadOnly8Section->setAlignment(Align(8));
971
972 ReadOnly16Section = Ctx->getXCOFFSection(
973 Section: ".rodata.16", K: SectionKind::getReadOnly(),
974 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
975 /* MultiSymbolsAllowed*/ true);
976 ReadOnly16Section->setAlignment(Align(16));
977
978 TLSDataSection = Ctx->getXCOFFSection(
979 Section: ".tdata", K: SectionKind::getThreadData(),
980 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TL, XCOFF::XTY_SD),
981 /* MultiSymbolsAllowed*/ true);
982
983 TOCBaseSection = Ctx->getXCOFFSection(
984 Section: "TOC", K: SectionKind::getData(),
985 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TC0,
986 XCOFF::XTY_SD));
987
988 // The TOC-base always has 0 size, but 4 byte alignment.
989 TOCBaseSection->setAlignment(Align(4));
990
991 LSDASection = Ctx->getXCOFFSection(
992 Section: ".gcc_except_table", K: SectionKind::getReadOnly(),
993 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO,
994 XCOFF::XTY_SD));
995
996 CompactUnwindSection = Ctx->getXCOFFSection(
997 Section: ".eh_info_table", K: SectionKind::getData(),
998 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW,
999 XCOFF::XTY_SD));
1000
1001 // DWARF sections for XCOFF are not csects. They are special STYP_DWARF
1002 // sections, and the individual DWARF sections are distinguished by their
1003 // section subtype.
1004 DwarfAbbrevSection = Ctx->getXCOFFSection(
1005 Section: ".dwabrev", K: SectionKind::getMetadata(),
1006 /* CsectProperties */ CsectProp: std::nullopt,
1007 /* MultiSymbolsAllowed */ true, BeginSymName: ".dwabrev", DwarfSubtypeFlags: XCOFF::SSUBTYP_DWABREV);
1008
1009 DwarfInfoSection = Ctx->getXCOFFSection(
1010 Section: ".dwinfo", K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt,
1011 /* MultiSymbolsAllowed */ true, BeginSymName: ".dwinfo", DwarfSubtypeFlags: XCOFF::SSUBTYP_DWINFO);
1012
1013 DwarfLineSection = Ctx->getXCOFFSection(
1014 Section: ".dwline", K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt,
1015 /* MultiSymbolsAllowed */ true, BeginSymName: ".dwline", DwarfSubtypeFlags: XCOFF::SSUBTYP_DWLINE);
1016
1017 DwarfFrameSection = Ctx->getXCOFFSection(
1018 Section: ".dwframe", K: SectionKind::getMetadata(),
1019 /* CsectProperties */ CsectProp: std::nullopt,
1020 /* MultiSymbolsAllowed */ true, BeginSymName: ".dwframe", DwarfSubtypeFlags: XCOFF::SSUBTYP_DWFRAME);
1021
1022 DwarfPubNamesSection = Ctx->getXCOFFSection(
1023 Section: ".dwpbnms", K: SectionKind::getMetadata(),
1024 /* CsectProperties */ CsectProp: std::nullopt,
1025 /* MultiSymbolsAllowed */ true, BeginSymName: ".dwpbnms", DwarfSubtypeFlags: XCOFF::SSUBTYP_DWPBNMS);
1026
1027 DwarfPubTypesSection = Ctx->getXCOFFSection(
1028 Section: ".dwpbtyp", K: SectionKind::getMetadata(),
1029 /* CsectProperties */ CsectProp: std::nullopt,
1030 /* MultiSymbolsAllowed */ true, BeginSymName: ".dwpbtyp", DwarfSubtypeFlags: XCOFF::SSUBTYP_DWPBTYP);
1031
1032 DwarfStrSection = Ctx->getXCOFFSection(
1033 Section: ".dwstr", K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt,
1034 /* MultiSymbolsAllowed */ true, BeginSymName: ".dwstr", DwarfSubtypeFlags: XCOFF::SSUBTYP_DWSTR);
1035
1036 DwarfLocSection = Ctx->getXCOFFSection(
1037 Section: ".dwloc", K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt,
1038 /* MultiSymbolsAllowed */ true, BeginSymName: ".dwloc", DwarfSubtypeFlags: XCOFF::SSUBTYP_DWLOC);
1039
1040 DwarfARangesSection = Ctx->getXCOFFSection(
1041 Section: ".dwarnge", K: SectionKind::getMetadata(),
1042 /* CsectProperties */ CsectProp: std::nullopt,
1043 /* MultiSymbolsAllowed */ true, BeginSymName: ".dwarnge", DwarfSubtypeFlags: XCOFF::SSUBTYP_DWARNGE);
1044
1045 DwarfRangesSection = Ctx->getXCOFFSection(
1046 Section: ".dwrnges", K: SectionKind::getMetadata(),
1047 /* CsectProperties */ CsectProp: std::nullopt,
1048 /* MultiSymbolsAllowed */ true, BeginSymName: ".dwrnges", DwarfSubtypeFlags: XCOFF::SSUBTYP_DWRNGES);
1049
1050 DwarfMacinfoSection = Ctx->getXCOFFSection(
1051 Section: ".dwmac", K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt,
1052 /* MultiSymbolsAllowed */ true, BeginSymName: ".dwmac", DwarfSubtypeFlags: XCOFF::SSUBTYP_DWMAC);
1053}
1054
1055void MCObjectFileInfo::initDXContainerObjectFileInfo(const Triple &T) {
1056 // At the moment the DXBC section should end up empty.
1057 TextSection = Ctx->getDXContainerSection(Section: "DXBC", K: SectionKind::getText());
1058}
1059
1060MCObjectFileInfo::~MCObjectFileInfo() = default;
1061
1062void MCObjectFileInfo::initMCObjectFileInfo(MCContext &MCCtx, bool PIC,
1063 bool LargeCodeModel) {
1064 PositionIndependent = PIC;
1065 Ctx = &MCCtx;
1066
1067 // Common.
1068 SupportsWeakOmittedEHFrame = true;
1069 SupportsCompactUnwindWithoutEHFrame = false;
1070 OmitDwarfIfHaveCompactUnwind = false;
1071
1072 FDECFIEncoding = dwarf::DW_EH_PE_absptr;
1073
1074 CompactUnwindDwarfEHFrameOnly = 0;
1075
1076 EHFrameSection = nullptr; // Created on demand.
1077 CompactUnwindSection = nullptr; // Used only by selected targets.
1078 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
1079 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
1080 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
1081 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
1082
1083 Triple TheTriple = Ctx->getTargetTriple();
1084 switch (Ctx->getObjectFileType()) {
1085 case MCContext::IsMachO:
1086 initMachOMCObjectFileInfo(T: TheTriple);
1087 break;
1088 case MCContext::IsCOFF:
1089 initCOFFMCObjectFileInfo(T: TheTriple);
1090 break;
1091 case MCContext::IsELF:
1092 initELFMCObjectFileInfo(T: TheTriple, Large: LargeCodeModel);
1093 break;
1094 case MCContext::IsGOFF:
1095 initGOFFMCObjectFileInfo(T: TheTriple);
1096 break;
1097 case MCContext::IsSPIRV:
1098 initSPIRVMCObjectFileInfo(T: TheTriple);
1099 break;
1100 case MCContext::IsWasm:
1101 initWasmMCObjectFileInfo(T: TheTriple);
1102 break;
1103 case MCContext::IsXCOFF:
1104 initXCOFFMCObjectFileInfo(T: TheTriple);
1105 break;
1106 case MCContext::IsDXContainer:
1107 initDXContainerObjectFileInfo(T: TheTriple);
1108 break;
1109 }
1110}
1111
1112MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
1113 uint64_t Hash) const {
1114 switch (Ctx->getTargetTriple().getObjectFormat()) {
1115 case Triple::ELF:
1116 return Ctx->getELFSection(Section: Name, Type: ELF::SHT_PROGBITS, Flags: ELF::SHF_GROUP, EntrySize: 0,
1117 Group: utostr(X: Hash), /*IsComdat=*/true);
1118 case Triple::Wasm:
1119 return Ctx->getWasmSection(Section: Name, K: SectionKind::getMetadata(), Flags: 0,
1120 Group: utostr(X: Hash), UniqueID: MCContext::GenericSectionID);
1121 case Triple::MachO:
1122 case Triple::COFF:
1123 case Triple::GOFF:
1124 case Triple::SPIRV:
1125 case Triple::XCOFF:
1126 case Triple::DXContainer:
1127 case Triple::UnknownObjectFormat:
1128 report_fatal_error(reason: "Cannot get DWARF comdat section for this object file "
1129 "format: not implemented.");
1130 break;
1131 }
1132 llvm_unreachable("Unknown ObjectFormatType");
1133}
1134
1135MCSection *
1136MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const {
1137 if ((Ctx->getObjectFileType() != MCContext::IsELF) ||
1138 Ctx->getTargetTriple().isPS4())
1139 return StackSizesSection;
1140
1141 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1142 unsigned Flags = ELF::SHF_LINK_ORDER;
1143 StringRef GroupName;
1144 if (const MCSymbol *Group = ElfSec.getGroup()) {
1145 GroupName = Group->getName();
1146 Flags |= ELF::SHF_GROUP;
1147 }
1148
1149 return Ctx->getELFSection(Section: ".stack_sizes", Type: ELF::SHT_PROGBITS, Flags, EntrySize: 0,
1150 Group: GroupName, IsComdat: true, UniqueID: ElfSec.getUniqueID(),
1151 LinkedToSym: cast<MCSymbolELF>(Val: TextSec.getBeginSymbol()));
1152}
1153
1154MCSection *
1155MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const {
1156 if (Ctx->getObjectFileType() != MCContext::IsELF)
1157 return nullptr;
1158
1159 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1160 unsigned Flags = ELF::SHF_LINK_ORDER;
1161 StringRef GroupName;
1162 if (const MCSymbol *Group = ElfSec.getGroup()) {
1163 GroupName = Group->getName();
1164 Flags |= ELF::SHF_GROUP;
1165 }
1166
1167 // Use the text section's begin symbol and unique ID to create a separate
1168 // .llvm_bb_addr_map section associated with every unique text section.
1169 return Ctx->getELFSection(Section: ".llvm_bb_addr_map", Type: ELF::SHT_LLVM_BB_ADDR_MAP,
1170 Flags, EntrySize: 0, Group: GroupName, IsComdat: true, UniqueID: ElfSec.getUniqueID(),
1171 LinkedToSym: cast<MCSymbolELF>(Val: TextSec.getBeginSymbol()));
1172}
1173
1174MCSection *
1175MCObjectFileInfo::getKCFITrapSection(const MCSection &TextSec) const {
1176 if (Ctx->getObjectFileType() != MCContext::IsELF)
1177 return nullptr;
1178
1179 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1180 unsigned Flags = ELF::SHF_LINK_ORDER | ELF::SHF_ALLOC;
1181 StringRef GroupName;
1182 if (const MCSymbol *Group = ElfSec.getGroup()) {
1183 GroupName = Group->getName();
1184 Flags |= ELF::SHF_GROUP;
1185 }
1186
1187 return Ctx->getELFSection(Section: ".kcfi_traps", Type: ELF::SHT_PROGBITS, Flags, EntrySize: 0,
1188 Group: GroupName,
1189 /*IsComdat=*/true, UniqueID: ElfSec.getUniqueID(),
1190 LinkedToSym: cast<MCSymbolELF>(Val: TextSec.getBeginSymbol()));
1191}
1192
1193MCSection *
1194MCObjectFileInfo::getPseudoProbeSection(const MCSection &TextSec) const {
1195 if (Ctx->getObjectFileType() != MCContext::IsELF)
1196 return PseudoProbeSection;
1197
1198 const auto &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1199 unsigned Flags = ELF::SHF_LINK_ORDER;
1200 StringRef GroupName;
1201 if (const MCSymbol *Group = ElfSec.getGroup()) {
1202 GroupName = Group->getName();
1203 Flags |= ELF::SHF_GROUP;
1204 }
1205
1206 return Ctx->getELFSection(Section: PseudoProbeSection->getName(), Type: ELF::SHT_PROGBITS,
1207 Flags, EntrySize: 0, Group: GroupName, IsComdat: true, UniqueID: ElfSec.getUniqueID(),
1208 LinkedToSym: cast<MCSymbolELF>(Val: TextSec.getBeginSymbol()));
1209}
1210
1211MCSection *
1212MCObjectFileInfo::getPseudoProbeDescSection(StringRef FuncName) const {
1213 if (Ctx->getObjectFileType() == MCContext::IsELF) {
1214 // Create a separate comdat group for each function's descriptor in order
1215 // for the linker to deduplicate. The duplication, must be from different
1216 // tranlation unit, can come from:
1217 // 1. Inline functions defined in header files;
1218 // 2. ThinLTO imported funcions;
1219 // 3. Weak-linkage definitions.
1220 // Use a concatenation of the section name and the function name as the
1221 // group name so that descriptor-only groups won't be folded with groups of
1222 // code.
1223 if (Ctx->getTargetTriple().supportsCOMDAT() && !FuncName.empty()) {
1224 auto *S = static_cast<MCSectionELF *>(PseudoProbeDescSection);
1225 auto Flags = S->getFlags() | ELF::SHF_GROUP;
1226 return Ctx->getELFSection(Section: S->getName(), Type: S->getType(), Flags,
1227 EntrySize: S->getEntrySize(),
1228 Group: S->getName() + "_" + FuncName,
1229 /*IsComdat=*/true);
1230 }
1231 }
1232 return PseudoProbeDescSection;
1233}
1234
1235MCSection *MCObjectFileInfo::getLLVMStatsSection() const {
1236 return LLVMStatsSection;
1237}
1238
1239MCSection *MCObjectFileInfo::getPCSection(StringRef Name,
1240 const MCSection *TextSec) const {
1241 if (Ctx->getObjectFileType() != MCContext::IsELF)
1242 return nullptr;
1243
1244 // SHF_WRITE for relocations, and let user post-process data in-place.
1245 unsigned Flags = ELF::SHF_WRITE | ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER;
1246
1247 if (!TextSec)
1248 TextSec = getTextSection();
1249
1250 StringRef GroupName;
1251 const auto &ElfSec = static_cast<const MCSectionELF &>(*TextSec);
1252 if (const MCSymbol *Group = ElfSec.getGroup()) {
1253 GroupName = Group->getName();
1254 Flags |= ELF::SHF_GROUP;
1255 }
1256 return Ctx->getELFSection(Section: Name, Type: ELF::SHT_PROGBITS, Flags, EntrySize: 0, Group: GroupName, IsComdat: true,
1257 UniqueID: ElfSec.getUniqueID(),
1258 LinkedToSym: cast<MCSymbolELF>(Val: TextSec->getBeginSymbol()));
1259}
1260

source code of llvm/lib/MC/MCObjectFileInfo.cpp