LLVM 22.0.0git
MCObjectFileInfo.cpp
Go to the documentation of this file.
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
15#include "llvm/MC/MCAsmInfo.h"
16#include "llvm/MC/MCContext.h"
18#include "llvm/MC/MCSection.h"
28
29using namespace llvm;
30
31static bool useCompactUnwind(const Triple &T) {
32 // Only on darwin.
33 if (!T.isOSDarwin())
34 return false;
35
36 // aarch64 always has it.
37 if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)
38 return true;
39
40 // armv7k always has it.
41 if (T.isWatchABI())
42 return true;
43
44 // Use it on newer version of OS X.
45 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
46 return true;
47
48 // And the iOS simulator.
49 if (T.isiOS() && T.isX86())
50 return true;
51
52 // The rest of the simulators always have it.
53 if (T.isSimulatorEnvironment())
54 return true;
55
56 // XROS always has it.
57 if (T.isXROS())
58 return true;
59
60 return false;
61}
62
63void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
64 // MachO
66
67 EHFrameSection = Ctx->getMachOSection(
68 "__TEXT", "__eh_frame",
72
73 if (T.isOSDarwin() &&
74 (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32 ||
75 T.isSimulatorEnvironment()))
77
78 switch (Ctx->emitDwarfUnwindInfo()) {
81 break;
84 break;
88 break;
89 }
90
92
93 TextSection // .text
94 = Ctx->getMachOSection("__TEXT", "__text",
97 DataSection // .data
98 = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
99
100 // BSSSection might not be expected initialized on msvc.
101 BSSSection = nullptr;
102
103 TLSDataSection // .tdata
104 = Ctx->getMachOSection("__DATA", "__thread_data",
107 TLSBSSSection // .tbss
108 = Ctx->getMachOSection("__DATA", "__thread_bss",
111
112 // TODO: Verify datarel below.
113 TLSTLVSection // .tlv
114 = Ctx->getMachOSection("__DATA", "__thread_vars",
117
118 TLSThreadInitSection = Ctx->getMachOSection(
119 "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
121
122 CStringSection // .cstring
123 = Ctx->getMachOSection("__TEXT", "__cstring",
127 = Ctx->getMachOSection("__TEXT","__ustring", 0,
129 FourByteConstantSection // .literal4
130 = Ctx->getMachOSection("__TEXT", "__literal4",
133 EightByteConstantSection // .literal8
134 = Ctx->getMachOSection("__TEXT", "__literal8",
137
138 SixteenByteConstantSection // .literal16
139 = Ctx->getMachOSection("__TEXT", "__literal16",
142
143 ReadOnlySection // .const
144 = Ctx->getMachOSection("__TEXT", "__const", 0,
146
147 // If the target is not powerpc, map the coal sections to the non-coal
148 // sections.
149 //
150 // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
151 // "__TEXT/__const_coal" => section "__TEXT/__const"
152 // "__DATA/__datacoal_nt" => section "__DATA/__data"
153 Triple::ArchType ArchTy = T.getArch();
154
155 ConstDataSection // .const_data
156 = Ctx->getMachOSection("__DATA", "__const", 0,
158
159 if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
161 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
166 = Ctx->getMachOSection("__TEXT", "__const_coal",
169 DataCoalSection = Ctx->getMachOSection(
170 "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());
172 } else {
177 }
178
180 = Ctx->getMachOSection("__DATA","__common",
184 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
186
187
189 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
193 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
196
198 = Ctx->getMachOSection("__DATA", "__thread_ptr",
201
202 AddrSigSection = Ctx->getMachOSection("__DATA", "__llvm_addrsig", 0,
204
205 // Exception Handling.
206 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
208
209 COFFDebugSymbolsSection = nullptr;
210 COFFDebugTypesSection = nullptr;
212
213 if (useCompactUnwind(T)) {
215 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
217
218 if (T.isX86())
219 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF
220 else if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)
221 CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF
222 else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
223 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF
224 }
225
226 // Debug Information.
228 Ctx->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG,
229 SectionKind::getMetadata(), "debug_names_begin");
231 Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
232 SectionKind::getMetadata(), "names_begin");
234 Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
235 SectionKind::getMetadata(), "objc_begin");
236 // 16 character section limit...
238 Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
239 SectionKind::getMetadata(), "namespac_begin");
241 Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
242 SectionKind::getMetadata(), "types_begin");
243
245 Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG,
247
249 Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
250 SectionKind::getMetadata(), "section_abbrev");
252 Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
253 SectionKind::getMetadata(), "section_info");
255 Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
256 SectionKind::getMetadata(), "section_line");
258 Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,
259 SectionKind::getMetadata(), "section_line_str");
261 Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
262 SectionKind::getMetadata(), "section_frame");
264 Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
267 Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
270 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
273 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
276 Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
277 SectionKind::getMetadata(), "info_string");
279 Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG,
280 SectionKind::getMetadata(), "section_str_off");
282 Ctx->getMachOSection("__DWARF", "__debug_addr", MachO::S_ATTR_DEBUG,
283 SectionKind::getMetadata(), "section_info");
285 Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
286 SectionKind::getMetadata(), "section_debug_loc");
288 Ctx->getMachOSection("__DWARF", "__debug_loclists", MachO::S_ATTR_DEBUG,
289 SectionKind::getMetadata(), "section_debug_loc");
290
292 Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
295 Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
296 SectionKind::getMetadata(), "debug_range");
298 Ctx->getMachOSection("__DWARF", "__debug_rnglists", MachO::S_ATTR_DEBUG,
299 SectionKind::getMetadata(), "debug_range");
301 Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG,
302 SectionKind::getMetadata(), "debug_macinfo");
304 Ctx->getMachOSection("__DWARF", "__debug_macro", MachO::S_ATTR_DEBUG,
305 SectionKind::getMetadata(), "debug_macro");
307 Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
310 Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,
313 Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG,
315 StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
317
318 FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
320
321 RemarksSection = Ctx->getMachOSection(
322 "__LLVM", "__remarks", MachO::S_ATTR_DEBUG, SectionKind::getMetadata());
323
324 // The architecture of dsymutil makes it very difficult to copy the Swift
325 // reflection metadata sections into the __TEXT segment, so dsymutil creates
326 // these sections in the __DWARF segment instead.
327 if (!Ctx->getSwift5ReflectionSegmentName().empty()) {
328#define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) \
329 Swift5ReflectionSections \
330 [llvm::binaryformat::Swift5ReflectionSectionKind::KIND] = \
331 Ctx->getMachOSection(Ctx->getSwift5ReflectionSegmentName().data(), \
332 MACHO, 0, SectionKind::getMetadata());
333#include "llvm/BinaryFormat/Swift.def"
334 }
335
337}
338
339void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
340 switch (T.getArch()) {
341 case Triple::mips:
342 case Triple::mipsel:
343 case Triple::mips64:
344 case Triple::mips64el:
345 // We cannot use DW_EH_PE_sdata8 for the large PositionIndependent case
346 // since there is no R_MIPS_PC64 relocation (only a 32-bit version).
347 // In fact DW_EH_PE_sdata4 is enough for us now, and GNU ld doesn't
348 // support pcrel|sdata8 well. Let's use sdata4 for now.
349 if (PositionIndependent)
351 else
352 FDECFIEncoding = Ctx->getAsmInfo()->getCodePointerSize() == 4
355 break;
356 case Triple::ppc64:
357 case Triple::ppc64le:
358 case Triple::aarch64:
360 case Triple::x86_64:
363 break;
364 case Triple::bpfel:
365 case Triple::bpfeb:
367 break;
368 case Triple::hexagon:
370 PositionIndependent ? dwarf::DW_EH_PE_pcrel : dwarf::DW_EH_PE_absptr;
371 break;
372 case Triple::xtensa:
374 break;
375 default:
377 break;
378 }
379
380 unsigned EHSectionType = T.getArch() == Triple::x86_64
383 switch (T.getArch()) {
384 case Triple::x86_64:
385 SFrameABIArch = sframe::ABI::AMD64EndianLittle;
386 break;
387 case Triple::aarch64:
388 SFrameABIArch = sframe::ABI::AArch64EndianLittle;
389 break;
391 SFrameABIArch = sframe::ABI::AArch64EndianBig;
392 break;
393 default:
394 break;
395 }
396
397 // Solaris requires different flags for .eh_frame to seemingly every other
398 // platform.
399 unsigned EHSectionFlags = ELF::SHF_ALLOC;
400 if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
401 EHSectionFlags |= ELF::SHF_WRITE;
402
403 // ELF
404 BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
406
407 TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
409
410 DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
412
414 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
415
417 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
419
420 TLSBSSSection = Ctx->getELFSection(
422
423 DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
425
427 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
429
431 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
433
435 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
437
439 Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS,
441
442 // Exception Handling Sections.
443
444 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
445 // it contains relocatable pointers. In PIC mode, this is probably a big
446 // runtime hit for C++ apps. Either the contents of the LSDA need to be
447 // adjusted or this should be a data section.
448 LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
450
451 COFFDebugSymbolsSection = nullptr;
452 COFFDebugTypesSection = nullptr;
453
454 unsigned DebugSecType = ELF::SHT_PROGBITS;
455
456 // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
457 // to distinguish among sections contain DWARF and ECOFF debug formats.
458 // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
459 if (T.isMIPS())
460 DebugSecType = ELF::SHT_MIPS_DWARF;
461
462 // Debug Info Sections.
464 Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);
465 DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0);
466 DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0);
468 Ctx->getELFSection(".debug_line_str", DebugSecType,
470 DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0);
472 Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);
474 Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);
476 Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);
478 Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);
480 Ctx->getELFSection(".debug_str", DebugSecType,
482 DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0);
484 Ctx->getELFSection(".debug_aranges", DebugSecType, 0);
486 Ctx->getELFSection(".debug_ranges", DebugSecType, 0);
488 Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);
489 DwarfMacroSection = Ctx->getELFSection(".debug_macro", DebugSecType, 0);
490
491 // DWARF5 Experimental Debug Info
492
493 // Accelerator Tables
495 Ctx->getELFSection(".debug_names", ELF::SHT_PROGBITS, 0);
497 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);
499 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);
501 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);
503 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);
504
505 // String Offset and Address Sections
507 Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);
508 DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);
509 DwarfRnglistsSection = Ctx->getELFSection(".debug_rnglists", DebugSecType, 0);
510 DwarfLoclistsSection = Ctx->getELFSection(".debug_loclists", DebugSecType, 0);
511
512 // Fission Sections
514 Ctx->getELFSection(".debug_info.dwo", DebugSecType, ELF::SHF_EXCLUDE);
516 Ctx->getELFSection(".debug_types.dwo", DebugSecType, ELF::SHF_EXCLUDE);
518 Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, ELF::SHF_EXCLUDE);
519 DwarfStrDWOSection = Ctx->getELFSection(
520 ".debug_str.dwo", DebugSecType,
523 Ctx->getELFSection(".debug_line.dwo", DebugSecType, ELF::SHF_EXCLUDE);
525 Ctx->getELFSection(".debug_loc.dwo", DebugSecType, ELF::SHF_EXCLUDE);
526 DwarfStrOffDWOSection = Ctx->getELFSection(".debug_str_offsets.dwo",
527 DebugSecType, ELF::SHF_EXCLUDE);
529 Ctx->getELFSection(".debug_rnglists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
531 Ctx->getELFSection(".debug_macinfo.dwo", DebugSecType, ELF::SHF_EXCLUDE);
533 Ctx->getELFSection(".debug_macro.dwo", DebugSecType, ELF::SHF_EXCLUDE);
534
536 Ctx->getELFSection(".debug_loclists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
537
538 // DWP Sections
540 Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);
542 Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);
543
545 Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
546
548 Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
549
551 Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
552
554 Ctx->getELFSection(".sframe", ELF::SHT_GNU_SFRAME, ELF::SHF_ALLOC);
555
556 CallGraphSection = Ctx->getELFSection(".callgraph", ELF::SHT_PROGBITS, 0);
557
558 StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);
559
560 PseudoProbeSection = Ctx->getELFSection(".pseudo_probe", DebugSecType, 0);
562 Ctx->getELFSection(".pseudo_probe_desc", DebugSecType, 0);
563
564 LLVMStatsSection = Ctx->getELFSection(".llvm_stats", ELF::SHT_PROGBITS, 0);
565}
566
567void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) {
568 MCSectionGOFF *RootSDSection = Ctx->getGOFFSection(
571
572 MCSectionGOFF *ADAEDSection = Ctx->getGOFFSection(
574 GOFF::EDAttr{false, GOFF::ESD_RMODE_64, GOFF::ESD_NS_Parts,
578 RootSDSection);
579 ADASection = Ctx->getGOFFSection(SectionKind::getData(), "#S",
580 GOFF::PRAttr{false, GOFF::ESD_EXE_DATA,
583 ADAEDSection);
584
585 TextSection = Ctx->getGOFFSection(
591 RootSDSection);
592
593 MCSectionGOFF *PPA2ListEDSection = Ctx->getGOFFSection(
595 GOFF::EDAttr{true, GOFF::ESD_RMODE_64, GOFF::ESD_NS_Parts,
599 RootSDSection);
600 PPA2ListSection = Ctx->getGOFFSection(SectionKind::getData(), ".&ppa2",
601 GOFF::PRAttr{true, GOFF::ESD_EXE_DATA,
604 PPA2ListEDSection);
605
606 IDRLSection = Ctx->getGOFFSection(
607 SectionKind::getData(), "B_IDRL",
612 RootSDSection);
613}
614
615void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
617 Ctx->getCOFFSection(".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
619
620 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
621 // used to indicate to the linker that the text segment contains thumb instructions
622 // and to set the ISA selection bit for calls accordingly.
623 const bool IsThumb = T.getArch() == Triple::thumb;
624
625 // COFF
626 BSSSection = Ctx->getCOFFSection(
629 TextSection = Ctx->getCOFFSection(
630 ".text",
634 DataSection = Ctx->getCOFFSection(
638 Ctx->getCOFFSection(".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
640
641 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64 ||
642 T.getArch() == Triple::arm || T.getArch() == Triple::thumb) {
643 // On Windows with SEH, the LSDA is emitted into the .xdata section
644 LSDASection = nullptr;
645 } else {
646 LSDASection = Ctx->getCOFFSection(".gcc_except_table",
649 }
650
651 if (T.getArch() == Triple::aarch64) {
653 Ctx->getCOFFSection(".impcall", COFF::IMAGE_SCN_LNK_INFO);
654 } else if (T.getArch() == Triple::x86_64) {
655 // Import Call Optimization on x64 leverages the same metadata as the
656 // retpoline mitigation, hence the unusual section name.
658 Ctx->getCOFFSection(".retplne", COFF::IMAGE_SCN_LNK_INFO);
659 }
660
661 // Debug info.
663 Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
667 Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
671 Ctx->getCOFFSection(".debug$H", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
674
675 DwarfAbbrevSection = Ctx->getCOFFSection(
676 ".debug_abbrev", COFF::IMAGE_SCN_MEM_DISCARDABLE |
679 DwarfInfoSection = Ctx->getCOFFSection(
680 ".debug_info", COFF::IMAGE_SCN_MEM_DISCARDABLE |
683 DwarfLineSection = Ctx->getCOFFSection(
684 ".debug_line", COFF::IMAGE_SCN_MEM_DISCARDABLE |
687 DwarfLineStrSection = Ctx->getCOFFSection(
688 ".debug_line_str", COFF::IMAGE_SCN_MEM_DISCARDABLE |
691 DwarfFrameSection = Ctx->getCOFFSection(
692 ".debug_frame", COFF::IMAGE_SCN_MEM_DISCARDABLE |
695 DwarfPubNamesSection = Ctx->getCOFFSection(
696 ".debug_pubnames", COFF::IMAGE_SCN_MEM_DISCARDABLE |
699 DwarfPubTypesSection = Ctx->getCOFFSection(
700 ".debug_pubtypes", COFF::IMAGE_SCN_MEM_DISCARDABLE |
703 DwarfGnuPubNamesSection = Ctx->getCOFFSection(
704 ".debug_gnu_pubnames", COFF::IMAGE_SCN_MEM_DISCARDABLE |
707 DwarfGnuPubTypesSection = Ctx->getCOFFSection(
708 ".debug_gnu_pubtypes", COFF::IMAGE_SCN_MEM_DISCARDABLE |
711 DwarfStrSection = Ctx->getCOFFSection(
712 ".debug_str", COFF::IMAGE_SCN_MEM_DISCARDABLE |
715 DwarfStrOffSection = Ctx->getCOFFSection(
716 ".debug_str_offsets", COFF::IMAGE_SCN_MEM_DISCARDABLE |
719 DwarfLocSection = Ctx->getCOFFSection(
720 ".debug_loc", COFF::IMAGE_SCN_MEM_DISCARDABLE |
723 DwarfLoclistsSection = Ctx->getCOFFSection(
724 ".debug_loclists", COFF::IMAGE_SCN_MEM_DISCARDABLE |
727 DwarfARangesSection = Ctx->getCOFFSection(
728 ".debug_aranges", COFF::IMAGE_SCN_MEM_DISCARDABLE |
731 DwarfRangesSection = Ctx->getCOFFSection(
732 ".debug_ranges", COFF::IMAGE_SCN_MEM_DISCARDABLE |
735 DwarfRnglistsSection = Ctx->getCOFFSection(
736 ".debug_rnglists", COFF::IMAGE_SCN_MEM_DISCARDABLE |
739 DwarfMacinfoSection = Ctx->getCOFFSection(
740 ".debug_macinfo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
743 DwarfMacroSection = Ctx->getCOFFSection(
744 ".debug_macro", COFF::IMAGE_SCN_MEM_DISCARDABLE |
747 DwarfMacinfoDWOSection = Ctx->getCOFFSection(
748 ".debug_macinfo.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
751 DwarfMacroDWOSection = Ctx->getCOFFSection(
752 ".debug_macro.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
755 DwarfInfoDWOSection = Ctx->getCOFFSection(
756 ".debug_info.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
759 DwarfTypesDWOSection = Ctx->getCOFFSection(
760 ".debug_types.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
763 DwarfAbbrevDWOSection = Ctx->getCOFFSection(
764 ".debug_abbrev.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
767 DwarfStrDWOSection = Ctx->getCOFFSection(
768 ".debug_str.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
771 DwarfLineDWOSection = Ctx->getCOFFSection(
772 ".debug_line.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
775 DwarfLocDWOSection = Ctx->getCOFFSection(
776 ".debug_loc.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
779 DwarfLoclistsDWOSection = Ctx->getCOFFSection(
780 ".debug_loclists.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
783 DwarfStrOffDWOSection = Ctx->getCOFFSection(
784 ".debug_str_offsets.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
787 DwarfRnglistsDWOSection = Ctx->getCOFFSection(
788 ".debug_rnglists.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
791 DwarfAddrSection = Ctx->getCOFFSection(
792 ".debug_addr", COFF::IMAGE_SCN_MEM_DISCARDABLE |
795 DwarfCUIndexSection = Ctx->getCOFFSection(
796 ".debug_cu_index", COFF::IMAGE_SCN_MEM_DISCARDABLE |
799 DwarfTUIndexSection = Ctx->getCOFFSection(
800 ".debug_tu_index", COFF::IMAGE_SCN_MEM_DISCARDABLE |
803 DwarfDebugNamesSection = Ctx->getCOFFSection(
804 ".debug_names", COFF::IMAGE_SCN_MEM_DISCARDABLE |
807 DwarfAccelNamesSection = Ctx->getCOFFSection(
808 ".apple_names", COFF::IMAGE_SCN_MEM_DISCARDABLE |
811 DwarfAccelNamespaceSection = Ctx->getCOFFSection(
812 ".apple_namespaces", COFF::IMAGE_SCN_MEM_DISCARDABLE |
815 DwarfAccelTypesSection = Ctx->getCOFFSection(
816 ".apple_types", COFF::IMAGE_SCN_MEM_DISCARDABLE |
819 DwarfAccelObjCSection = Ctx->getCOFFSection(
820 ".apple_objc", COFF::IMAGE_SCN_MEM_DISCARDABLE |
823
824 DrectveSection = Ctx->getCOFFSection(
826
828 Ctx->getCOFFSection(".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
830
832 Ctx->getCOFFSection(".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
834
835 SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO);
836
838 Ctx->getCOFFSection(".gehcont$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
840
842 Ctx->getCOFFSection(".gfids$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
844
846 Ctx->getCOFFSection(".giats$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
848
850 Ctx->getCOFFSection(".gljmp$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
852
853 TLSDataSection = Ctx->getCOFFSection(
856
857 StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
860
861 // Set IMAGE_SCN_MEM_DISCARDABLE so that lld will not truncate section name.
862 PseudoProbeSection = Ctx->getCOFFSection(
863 ".pseudo_probe", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
866 PseudoProbeDescSection = Ctx->getCOFFSection(
867 ".pseudo_probe_desc", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
870}
871
872void MCObjectFileInfo::initSPIRVMCObjectFileInfo(const Triple &T) {
873 // Put everything in a single binary section.
874 TextSection = Ctx->getSPIRVSection();
875}
876
877void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
878 TextSection = Ctx->getWasmSection(".text", SectionKind::getText());
879 DataSection = Ctx->getWasmSection(".data", SectionKind::getData());
880
882 Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());
884 Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata(),
886 DwarfStrSection = Ctx->getWasmSection(
889 Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());
891 Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata());
892 DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());
894 Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata());
896 Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata());
898 Ctx->getWasmSection(".debug_macro", SectionKind::getMetadata());
899 DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
900 DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
902 Ctx->getWasmSection(".debug_info", SectionKind::getMetadata());
903 DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());
904 DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
905 DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
907 Ctx->getWasmSection(".debug_gnu_pubnames", SectionKind::getMetadata());
909 Ctx->getWasmSection(".debug_gnu_pubtypes", SectionKind::getMetadata());
910
912 Ctx->getWasmSection(".debug_names", SectionKind::getMetadata());
914 Ctx->getWasmSection(".debug_str_offsets", SectionKind::getMetadata());
916 Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata());
918 Ctx->getWasmSection(".debug_rnglists", SectionKind::getMetadata());
920 Ctx->getWasmSection(".debug_loclists", SectionKind::getMetadata());
921
922 // Fission Sections
924 Ctx->getWasmSection(".debug_info.dwo", SectionKind::getMetadata());
926 Ctx->getWasmSection(".debug_types.dwo", SectionKind::getMetadata());
928 Ctx->getWasmSection(".debug_abbrev.dwo", SectionKind::getMetadata());
930 Ctx->getWasmSection(".debug_str.dwo", SectionKind::getMetadata(),
933 Ctx->getWasmSection(".debug_line.dwo", SectionKind::getMetadata());
935 Ctx->getWasmSection(".debug_loc.dwo", SectionKind::getMetadata());
937 Ctx->getWasmSection(".debug_str_offsets.dwo", SectionKind::getMetadata());
939 Ctx->getWasmSection(".debug_rnglists.dwo", SectionKind::getMetadata());
941 Ctx->getWasmSection(".debug_macinfo.dwo", SectionKind::getMetadata());
943 Ctx->getWasmSection(".debug_macro.dwo", SectionKind::getMetadata());
944
946 Ctx->getWasmSection(".debug_loclists.dwo", SectionKind::getMetadata());
947
948 // DWP Sections
950 Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
952 Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
953
954 // Wasm use data section for LSDA.
955 // TODO Consider putting each function's exception table in a separate
956 // section, as in -function-sections, to facilitate lld's --gc-section.
957 LSDASection = Ctx->getWasmSection(".rodata.gcc_except_table",
959
960 // TODO: Define more sections.
961}
962
963void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) {
964 // The default csect for program code. Functions without a specified section
965 // get placed into this csect. The choice of csect name is not a property of
966 // the ABI or object file format, but various tools rely on the section
967 // name being empty (considering named symbols to be "user symbol names").
968 TextSection = Ctx->getXCOFFSection(
969 "..text..", // Use a non-null name to work around an AIX assembler bug...
971 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD),
972 /* MultiSymbolsAllowed*/ true);
973
974 // ... but use a null name when generating the symbol table.
975 MCSectionXCOFF *TS = static_cast<MCSectionXCOFF *>(TextSection);
977 TS->setSymbolTableName("");
978
979 DataSection = Ctx->getXCOFFSection(
980 ".data", SectionKind::getData(),
981 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD),
982 /* MultiSymbolsAllowed*/ true);
983
984 ReadOnlySection = Ctx->getXCOFFSection(
985 ".rodata", SectionKind::getReadOnly(),
986 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
987 /* MultiSymbolsAllowed*/ true);
988 ReadOnlySection->setAlignment(Align(4));
989
990 ReadOnly8Section = Ctx->getXCOFFSection(
991 ".rodata.8", SectionKind::getReadOnly(),
992 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
993 /* MultiSymbolsAllowed*/ true);
994 ReadOnly8Section->setAlignment(Align(8));
995
996 ReadOnly16Section = Ctx->getXCOFFSection(
997 ".rodata.16", SectionKind::getReadOnly(),
998 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
999 /* MultiSymbolsAllowed*/ true);
1000 ReadOnly16Section->setAlignment(Align(16));
1001
1002 TLSDataSection = Ctx->getXCOFFSection(
1003 ".tdata", SectionKind::getThreadData(),
1004 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TL, XCOFF::XTY_SD),
1005 /* MultiSymbolsAllowed*/ true);
1006
1007 TOCBaseSection = Ctx->getXCOFFSection(
1008 "TOC", SectionKind::getData(),
1009 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TC0,
1010 XCOFF::XTY_SD));
1011
1012 // The TOC-base always has 0 size, but 4 byte alignment.
1013 TOCBaseSection->setAlignment(Align(4));
1014
1015 LSDASection = Ctx->getXCOFFSection(
1016 ".gcc_except_table", SectionKind::getReadOnly(),
1017 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO,
1018 XCOFF::XTY_SD));
1019
1020 CompactUnwindSection = Ctx->getXCOFFSection(
1021 ".eh_info_table", SectionKind::getData(),
1022 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW,
1023 XCOFF::XTY_SD));
1024
1025 // DWARF sections for XCOFF are not csects. They are special STYP_DWARF
1026 // sections, and the individual DWARF sections are distinguished by their
1027 // section subtype.
1028 DwarfAbbrevSection = Ctx->getXCOFFSection(
1029 ".dwabrev", SectionKind::getMetadata(),
1030 /* CsectProperties */ std::nullopt,
1031 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWABREV);
1032
1033 DwarfInfoSection = Ctx->getXCOFFSection(
1034 ".dwinfo", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1035 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWINFO);
1036
1037 DwarfLineSection = Ctx->getXCOFFSection(
1038 ".dwline", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1039 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWLINE);
1040
1041 DwarfFrameSection = Ctx->getXCOFFSection(
1042 ".dwframe", SectionKind::getMetadata(),
1043 /* CsectProperties */ std::nullopt,
1044 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWFRAME);
1045
1046 DwarfPubNamesSection = Ctx->getXCOFFSection(
1047 ".dwpbnms", SectionKind::getMetadata(),
1048 /* CsectProperties */ std::nullopt,
1049 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWPBNMS);
1050
1051 DwarfPubTypesSection = Ctx->getXCOFFSection(
1052 ".dwpbtyp", SectionKind::getMetadata(),
1053 /* CsectProperties */ std::nullopt,
1054 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWPBTYP);
1055
1056 DwarfStrSection = Ctx->getXCOFFSection(
1057 ".dwstr", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1058 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWSTR);
1059
1060 DwarfLocSection = Ctx->getXCOFFSection(
1061 ".dwloc", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1062 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWLOC);
1063
1064 DwarfARangesSection = Ctx->getXCOFFSection(
1065 ".dwarnge", SectionKind::getMetadata(),
1066 /* CsectProperties */ std::nullopt,
1067 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWARNGE);
1068
1069 DwarfRangesSection = Ctx->getXCOFFSection(
1070 ".dwrnges", SectionKind::getMetadata(),
1071 /* CsectProperties */ std::nullopt,
1072 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWRNGES);
1073
1074 DwarfMacinfoSection = Ctx->getXCOFFSection(
1075 ".dwmac", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1076 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWMAC);
1077}
1078
1079void MCObjectFileInfo::initDXContainerObjectFileInfo(const Triple &T) {
1080 // At the moment the DXBC section should end up empty.
1081 TextSection = Ctx->getDXContainerSection("DXBC", SectionKind::getText());
1082}
1083
1085
1087 bool LargeCodeModel) {
1088 PositionIndependent = PIC;
1089 Ctx = &MCCtx;
1090
1091 // Common.
1095
1097
1099
1100 EHFrameSection = nullptr; // Created on demand.
1101 SFrameSection = nullptr; // Created on demand.
1102 CompactUnwindSection = nullptr; // Used only by selected targets.
1103 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
1104 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
1105 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
1106 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
1107
1108 const Triple &TheTriple = Ctx->getTargetTriple();
1109 switch (Ctx->getObjectFileType()) {
1110 case MCContext::IsMachO:
1111 initMachOMCObjectFileInfo(TheTriple);
1112 break;
1113 case MCContext::IsCOFF:
1114 initCOFFMCObjectFileInfo(TheTriple);
1115 break;
1116 case MCContext::IsELF:
1117 initELFMCObjectFileInfo(TheTriple, LargeCodeModel);
1118 break;
1119 case MCContext::IsGOFF:
1120 initGOFFMCObjectFileInfo(TheTriple);
1121 break;
1122 case MCContext::IsSPIRV:
1123 initSPIRVMCObjectFileInfo(TheTriple);
1124 break;
1125 case MCContext::IsWasm:
1126 initWasmMCObjectFileInfo(TheTriple);
1127 break;
1128 case MCContext::IsXCOFF:
1129 initXCOFFMCObjectFileInfo(TheTriple);
1130 break;
1132 initDXContainerObjectFileInfo(TheTriple);
1133 break;
1134 }
1135}
1136
1137MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
1138 uint64_t Hash) const {
1139 switch (Ctx->getTargetTriple().getObjectFormat()) {
1140 case Triple::ELF:
1141 return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0,
1142 utostr(Hash), /*IsComdat=*/true);
1143 case Triple::Wasm:
1144 return Ctx->getWasmSection(Name, SectionKind::getMetadata(), 0,
1146 case Triple::MachO:
1147 case Triple::COFF:
1148 case Triple::GOFF:
1149 case Triple::SPIRV:
1150 case Triple::XCOFF:
1153 report_fatal_error("Cannot get DWARF comdat section for this object file "
1154 "format: not implemented.");
1155 break;
1156 }
1157 llvm_unreachable("Unknown ObjectFormatType");
1158}
1159
1160MCSection *
1162 if (Ctx->getObjectFileType() != MCContext::IsELF)
1163 return CallGraphSection;
1164
1165 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1166 unsigned Flags = ELF::SHF_LINK_ORDER;
1167 StringRef GroupName;
1168 if (const MCSymbol *Group = ElfSec.getGroup()) {
1169 GroupName = Group->getName();
1170 Flags |= ELF::SHF_GROUP;
1171 }
1172
1173 return Ctx->getELFSection(
1174 ".callgraph", ELF::SHT_PROGBITS, Flags, 0, GroupName, true,
1175 ElfSec.getUniqueID(),
1176 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1177}
1178
1179MCSection *
1181 if ((Ctx->getObjectFileType() != MCContext::IsELF) ||
1182 Ctx->getTargetTriple().isPS4())
1183 return StackSizesSection;
1184
1185 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1186 unsigned Flags = ELF::SHF_LINK_ORDER;
1187 StringRef GroupName;
1188 if (const MCSymbol *Group = ElfSec.getGroup()) {
1189 GroupName = Group->getName();
1190 Flags |= ELF::SHF_GROUP;
1191 }
1192
1193 return Ctx->getELFSection(
1194 ".stack_sizes", ELF::SHT_PROGBITS, Flags, 0, GroupName, true,
1195 ElfSec.getUniqueID(),
1196 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1197}
1198
1199MCSection *
1201 if (Ctx->getObjectFileType() != MCContext::IsELF)
1202 return nullptr;
1203
1204 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1205 unsigned Flags = ELF::SHF_LINK_ORDER;
1206 StringRef GroupName;
1207 if (const MCSymbol *Group = ElfSec.getGroup()) {
1208 GroupName = Group->getName();
1209 Flags |= ELF::SHF_GROUP;
1210 }
1211
1212 // Use the text section's begin symbol and unique ID to create a separate
1213 // .llvm_bb_addr_map section associated with every unique text section.
1214 return Ctx->getELFSection(
1215 ".llvm_bb_addr_map", ELF::SHT_LLVM_BB_ADDR_MAP, Flags, 0, GroupName, true,
1216 ElfSec.getUniqueID(),
1217 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1218}
1219
1220MCSection *
1222 if (Ctx->getObjectFileType() != MCContext::IsELF)
1223 return nullptr;
1224
1225 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1226 unsigned Flags = ELF::SHF_LINK_ORDER | ELF::SHF_ALLOC;
1227 StringRef GroupName;
1228 if (const MCSymbol *Group = ElfSec.getGroup()) {
1229 GroupName = Group->getName();
1230 Flags |= ELF::SHF_GROUP;
1231 }
1232
1233 return Ctx->getELFSection(
1234 ".kcfi_traps", ELF::SHT_PROGBITS, Flags, 0, GroupName,
1235 /*IsComdat=*/true, ElfSec.getUniqueID(),
1236 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1237}
1238
1239MCSection *
1241 auto ObjFileType = Ctx->getObjectFileType();
1242 if (ObjFileType == MCContext::IsELF) {
1243 const auto &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1244 unsigned Flags = ELF::SHF_LINK_ORDER;
1245 StringRef GroupName;
1246 if (const MCSymbol *Group = ElfSec.getGroup()) {
1247 GroupName = Group->getName();
1248 Flags |= ELF::SHF_GROUP;
1249 }
1250 return Ctx->getELFSection(
1251 PseudoProbeSection->getName(), ELF::SHT_PROGBITS, Flags, 0, GroupName,
1252 true, ElfSec.getUniqueID(),
1253 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1254 } else if (ObjFileType == MCContext::IsCOFF) {
1255 StringRef COMDATSymName = "";
1256 int Selection = 0;
1257 unsigned Characteristics =
1258 static_cast<MCSectionCOFF *>(PseudoProbeSection)->getCharacteristics();
1259 const auto &COFFSec = static_cast<const MCSectionCOFF &>(TextSec);
1260 if (const MCSymbol *COMDATSym = COFFSec.getCOMDATSymbol()) {
1261 // Associate .pseudo_probe to its function section.
1262 COMDATSymName = COMDATSym->getName();
1263 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
1265 }
1266 return Ctx->getCOFFSection(PseudoProbeSection->getName(), Characteristics,
1267 COMDATSymName, Selection, COFFSec.getUniqueID());
1268 }
1269
1270 return PseudoProbeSection;
1271}
1272
1273MCSection *
1275 if (!Ctx->getTargetTriple().supportsCOMDAT() || FuncName.empty())
1277
1278 // Create a separate comdat group for each function's descriptor in order
1279 // for the linker to deduplicate. The duplication, must be from different
1280 // tranlation unit, can come from:
1281 // 1. Inline functions defined in header files;
1282 // 2. ThinLTO imported funcions;
1283 // 3. Weak-linkage definitions.
1284 // Use a concatenation of the section name and the function name as the
1285 // group name so that descriptor-only groups won't be folded with groups of
1286 // code.
1287 auto ObjFileType = Ctx->getObjectFileType();
1288 if (ObjFileType == MCContext::IsELF) {
1289 auto *S = static_cast<MCSectionELF *>(PseudoProbeDescSection);
1290 auto Flags = S->getFlags() | ELF::SHF_GROUP;
1291 return Ctx->getELFSection(S->getName(), S->getType(), Flags,
1292 S->getEntrySize(), S->getName() + "_" + FuncName,
1293 /*IsComdat=*/true);
1294 } else if (ObjFileType == MCContext::IsCOFF) {
1295 auto *S = static_cast<MCSectionCOFF *>(PseudoProbeDescSection);
1296 unsigned Characteristics =
1297 S->getCharacteristics() | COFF::IMAGE_SCN_LNK_COMDAT;
1298 std::string COMDATSymName = (S->getName() + "_" + FuncName).str();
1299 return Ctx->getCOFFSection(S->getName(), Characteristics, COMDATSymName,
1301 }
1302
1304}
1305
1309
1311 const MCSection *TextSec) const {
1312 if (Ctx->getObjectFileType() != MCContext::IsELF)
1313 return nullptr;
1314
1315 // SHF_WRITE for relocations, and let user post-process data in-place.
1317
1318 if (!TextSec)
1319 TextSec = getTextSection();
1320
1321 StringRef GroupName;
1322 const auto &ElfSec = static_cast<const MCSectionELF &>(*TextSec);
1323 if (const MCSymbol *Group = ElfSec.getGroup()) {
1324 GroupName = Group->getName();
1325 Flags |= ELF::SHF_GROUP;
1326 }
1327 return Ctx->getELFSection(
1328 Name, ELF::SHT_PROGBITS, Flags, 0, GroupName, true, ElfSec.getUniqueID(),
1329 static_cast<const MCSymbolELF *>(TextSec->getBeginSymbol()));
1330}
amdgpu AMDGPU DAG DAG Pattern Instruction Selection
static bool useCompactUnwind(const Triple &T)
This file declares the MCSectionGOFF class, which contains all of the necessary machine code sections...
#define T
PassInstrumentationCallbacks PIC
This file contains data-structure definitions and constants to support unwinding based on ....
This file contains some functions that are useful when dealing with strings.
Context object for machine code objects.
Definition MCContext.h:83
MCSection * NonLazySymbolPointerSection
MCSection * TLSBSSSection
Section directive for Thread Local uninitialized data.
MCSection * CallGraphSection
Section containing call graph metadata.
MCSection * DwarfDebugNamesSection
Accelerator table sections.
const MCSection * TLSThreadInitSection
Section for thread local data initialization functions.
MCSection * DwarfStrOffSection
The DWARF v5 string offset and address table sections.
MCSection * MergeableConst16Section
MCSection * COFFGlobalTypeHashesSection
MCSection * SFrameSection
SFrame section.
MCSection * DwarfGnuPubTypesSection
Section for newer gnu pubtypes.
MCSection * getLLVMStatsSection() const
MCSection * TextSection
Section directive for standard text.
MCSection * TLSDataSection
Section directive for Thread Local data. ELF, MachO, COFF, and Wasm.
MCSection * ThreadLocalPointerSection
MCSection * LSDASection
If exception handling is supported by the target, this is the section the Language Specific Data Area...
MCSection * CompactUnwindSection
If exception handling is supported by the target and the target can support a compact representation ...
MCSection * COFFDebugSymbolsSection
MCSection * getPseudoProbeDescSection(StringRef FuncName) const
MCSection * DwarfLoclistsSection
The DWARF v5 locations list section.
MCSection * PseudoProbeSection
Section for pseudo probe information used by AutoFDO.
MCSection * FourByteConstantSection
MCSection * getStackSizesSection(const MCSection &TextSec) const
MCSection * DwarfRnglistsSection
The DWARF v5 range list section.
const MCSection * DwarfDebugInlineSection
MCSection * getBBAddrMapSection(const MCSection &TextSec) const
MCSection * LazySymbolPointerSection
MCSection * RemarksSection
Remarks section.
MCSection * getPseudoProbeSection(const MCSection &TextSec) const
MCSection * TLSExtraDataSection
Extra TLS Variable Data section.
MCSection * EHFrameSection
EH frame section.
bool OmitDwarfIfHaveCompactUnwind
OmitDwarfIfHaveCompactUnwind - True if the target object file supports having some functions with com...
MCSection * DrectveSection
COFF specific sections.
MCSection * FaultMapSection
FaultMap section.
MCSection * getKCFITrapSection(const MCSection &TextSec) const
MCSection * TLSTLVSection
Section for thread local structure information.
void initMCObjectFileInfo(MCContext &MCCtx, bool PIC, bool LargeCodeModel=false)
MCSection * DwarfRnglistsDWOSection
The DWARF v5 range and location list sections for fission.
MCSection * ImportCallSection
If import call optimization is supported by the target, this is the section to emit import call data ...
MCSection * MergeableConst32Section
MCSection * SixteenByteConstantSection
MCSection * getPCSection(StringRef Name, const MCSection *TextSec) const
std::optional< sframe::ABI > SFrameABIArch
SFrame ABI architecture byte.
bool SupportsCompactUnwindWithoutEHFrame
True if the target object file supports emitting a compact unwind section without an associated EH fr...
MCSection * ReadOnlySection
Section that is readonly and can contain arbitrary initialized data.
unsigned FDECFIEncoding
FDE CFI encoding.
bool SupportsWeakOmittedEHFrame
True if target object file supports a weak_definition of constant 0 for an omitted EH frame.
MCSection * DwarfLoclistsDWOSection
MCSection * getCallGraphSection(const MCSection &TextSec) const
MCSection * BSSSection
Section that is default initialized to zero.
MCSection * EightByteConstantSection
MCSection * StackSizesSection
Section containing metadata on function stack sizes.
unsigned CompactUnwindDwarfEHFrameOnly
Compact unwind encoding indicating that we should emit only an EH frame.
MCSection * getTextSection() const
MCSection * DwarfGnuPubNamesSection
Section for newer gnu pubnames.
MCSection * StackMapSection
StackMap section.
MCSection * DwarfAccelNamespaceSection
MCSection * DataSection
Section directive for standard data.
This represents a section on Windows.
This represents a section on linux, lots of unix variants and some bare metal systems.
unsigned getFlags() const
unsigned getUniqueID() const
const MCSymbolELF * getGroup() const
void setSymbolTableName(StringRef STN)
MCSymbolXCOFF * getQualNameSymbol() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:521
static constexpr unsigned NonUniqueID
Definition MCSection.h:526
MCSymbol * getBeginSymbol()
Definition MCSection.h:593
void setSymbolTableName(StringRef STN)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
static SectionKind getThreadData()
static SectionKind getMetadata()
static SectionKind getMergeable2ByteCString()
static SectionKind getMergeableConst4()
static SectionKind getText()
static SectionKind getReadOnlyWithRel()
static SectionKind getData()
static SectionKind getMergeableConst8()
static SectionKind getBSS()
static SectionKind getThreadBSS()
static SectionKind getMergeableConst16()
static SectionKind getMergeable1ByteCString()
static SectionKind getReadOnly()
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:143
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
@ UnknownObjectFormat
Definition Triple.h:318
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
SectionCharacteristics
Definition COFF.h:298
@ IMAGE_SCN_LNK_REMOVE
Definition COFF.h:308
@ IMAGE_SCN_CNT_CODE
Definition COFF.h:303
@ IMAGE_SCN_MEM_READ
Definition COFF.h:336
@ IMAGE_SCN_MEM_EXECUTE
Definition COFF.h:335
@ IMAGE_SCN_CNT_UNINITIALIZED_DATA
Definition COFF.h:305
@ IMAGE_SCN_MEM_DISCARDABLE
Definition COFF.h:331
@ IMAGE_SCN_LNK_INFO
Definition COFF.h:307
@ IMAGE_SCN_MEM_16BIT
Definition COFF.h:312
@ IMAGE_SCN_CNT_INITIALIZED_DATA
Definition COFF.h:304
@ IMAGE_SCN_LNK_COMDAT
Definition COFF.h:309
@ IMAGE_SCN_MEM_WRITE
Definition COFF.h:337
@ IMAGE_COMDAT_SELECT_ASSOCIATIVE
Definition COFF.h:459
@ IMAGE_COMDAT_SELECT_EXACT_MATCH
Definition COFF.h:458
@ SHT_PROGBITS
Definition ELF.h:1143
@ SHT_NOBITS
Definition ELF.h:1150
@ SHT_MIPS_DWARF
Definition ELF.h:1221
@ SHT_LLVM_BB_ADDR_MAP
Definition ELF.h:1181
@ SHT_GNU_SFRAME
Definition ELF.h:1189
@ SHT_X86_64_UNWIND
Definition ELF.h:1217
@ SHF_MERGE
Definition ELF.h:1249
@ SHF_STRINGS
Definition ELF.h:1252
@ SHF_EXCLUDE
Definition ELF.h:1277
@ SHF_ALLOC
Definition ELF.h:1243
@ SHF_LINK_ORDER
Definition ELF.h:1258
@ SHF_GROUP
Definition ELF.h:1265
@ SHF_WRITE
Definition ELF.h:1240
@ SHF_TLS
Definition ELF.h:1268
@ SHF_EXECINSTR
Definition ELF.h:1246
@ ESD_LB_Deferred
Definition GOFF.h:129
@ ESD_LB_NoLoad
Definition GOFF.h:130
@ ESD_LB_Initial
Definition GOFF.h:128
constexpr StringLiteral CLASS_WSA
@ ESD_BA_Concatenate
Definition GOFF.h:98
@ ESD_BA_Merge
Definition GOFF.h:99
@ ESD_TS_Structured
Definition GOFF.h:93
@ ESD_TS_ByteOriented
Definition GOFF.h:92
@ ESD_EXE_DATA
Definition GOFF.h:111
@ ESD_RQ_1
Definition GOFF.h:70
@ ESD_RQ_0
Definition GOFF.h:69
@ ESD_ALIGN_Doubleword
Definition GOFF.h:148
@ ESD_ALIGN_Quadword
Definition GOFF.h:149
constexpr StringLiteral CLASS_PPA2
@ ESD_BSC_Section
Definition GOFF.h:136
@ ESD_LT_OS
Definition GOFF.h:142
@ ESD_LT_XPLink
Definition GOFF.h:142
@ ESD_NS_Parts
Definition GOFF.h:65
@ ESD_NS_NormalName
Definition GOFF.h:63
@ ESD_TA_Rent
Definition GOFF.h:106
constexpr StringLiteral CLASS_CODE
@ ESD_RMODE_64
Definition GOFF.h:88
@ S_THREAD_LOCAL_VARIABLE_POINTERS
S_THREAD_LOCAL_VARIABLE_POINTERS - Section with pointers to thread local structures.
Definition MachO.h:175
@ S_16BYTE_LITERALS
S_16BYTE_LITERALS - Section with only 16 byte literals.
Definition MachO.h:160
@ S_THREAD_LOCAL_INIT_FUNCTION_POINTERS
S_THREAD_LOCAL_INIT_FUNCTION_POINTERS - Section with thread local variable initialization pointers to...
Definition MachO.h:178
@ S_COALESCED
S_COALESCED - Section contains symbols that are to be coalesced.
Definition MachO.h:152
@ S_THREAD_LOCAL_ZEROFILL
S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
Definition MachO.h:169
@ S_LAZY_SYMBOL_POINTERS
S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.
Definition MachO.h:141
@ S_CSTRING_LITERALS
S_CSTRING_LITERALS - Section with literal C strings.
Definition MachO.h:131
@ S_THREAD_LOCAL_REGULAR
S_THREAD_LOCAL_REGULAR - Thread local data section.
Definition MachO.h:167
@ S_ZEROFILL
S_ZEROFILL - Zero fill on demand section.
Definition MachO.h:129
@ S_NON_LAZY_SYMBOL_POINTERS
S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.
Definition MachO.h:139
@ S_4BYTE_LITERALS
S_4BYTE_LITERALS - Section with 4 byte literals.
Definition MachO.h:133
@ S_8BYTE_LITERALS
S_8BYTE_LITERALS - Section with 8 byte literals.
Definition MachO.h:135
@ S_THREAD_LOCAL_VARIABLES
S_THREAD_LOCAL_VARIABLES - Section with thread local variable structure data.
Definition MachO.h:172
@ S_ATTR_DEBUG
S_ATTR_DEBUG - A debug section.
Definition MachO.h:207
@ S_ATTR_NO_TOC
S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be in a ranlib table of contents.
Definition MachO.h:195
@ S_ATTR_LIVE_SUPPORT
S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks.
Definition MachO.h:202
@ S_ATTR_PURE_INSTRUCTIONS
S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine instructions.
Definition MachO.h:192
@ S_ATTR_STRIP_STATIC_SYMS
S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section in files with the MY_DYLDLINK f...
Definition MachO.h:198
@ SSUBTYP_DWARNGE
DWARF aranges section.
Definition XCOFF.h:160
@ SSUBTYP_DWFRAME
DWARF frame section.
Definition XCOFF.h:165
@ SSUBTYP_DWABREV
DWARF abbrev section.
Definition XCOFF.h:161
@ SSUBTYP_DWINFO
DWARF info section.
Definition XCOFF.h:156
@ SSUBTYP_DWRNGES
DWARF ranges section.
Definition XCOFF.h:163
@ SSUBTYP_DWLOC
DWARF loc section.
Definition XCOFF.h:164
@ SSUBTYP_DWMAC
DWARF macinfo section.
Definition XCOFF.h:166
@ SSUBTYP_DWPBNMS
DWARF pubnames section.
Definition XCOFF.h:158
@ SSUBTYP_DWPBTYP
DWARF pubtypes section.
Definition XCOFF.h:159
@ SSUBTYP_DWLINE
DWARF line section.
Definition XCOFF.h:157
@ SSUBTYP_DWSTR
DWARF str section.
Definition XCOFF.h:162
@ XMC_TC0
TOC Anchor for TOC Addressability.
Definition XCOFF.h:119
@ XMC_RW
Read Write Data.
Definition XCOFF.h:118
@ XMC_TL
Initialized thread-local variable.
Definition XCOFF.h:127
@ XMC_RO
Read Only Constant.
Definition XCOFF.h:107
@ XMC_PR
Program Code.
Definition XCOFF.h:106
@ XTY_SD
Csect definition for initialized storage.
Definition XCOFF.h:243
@ DW_EH_PE_pcrel
Definition Dwarf.h:872
@ DW_EH_PE_sdata4
Definition Dwarf.h:869
@ DW_EH_PE_sdata8
Definition Dwarf.h:870
@ DW_EH_PE_absptr
Definition Dwarf.h:861
@ WASM_SEG_FLAG_STRINGS
Definition Wasm.h:229
This is an optimization pass for GlobalISel generic memory operations.
std::string utostr(uint64_t X, bool isNeg=false)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:167