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 EHFrameSection = Ctx->getMachOSection(
65 "__TEXT", "__eh_frame",
69
70 if (T.isOSDarwin() &&
71 (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32 ||
72 T.isSimulatorEnvironment()))
74
75 switch (Ctx->emitDwarfUnwindInfo()) {
78 break;
81 break;
85 break;
86 }
87
89
90 TextSection // .text
91 = Ctx->getMachOSection("__TEXT", "__text",
94 DataSection // .data
95 = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
96
97 // BSSSection might not be expected initialized on msvc.
98 BSSSection = nullptr;
99
100 TLSDataSection // .tdata
101 = Ctx->getMachOSection("__DATA", "__thread_data",
104 TLSBSSSection // .tbss
105 = Ctx->getMachOSection("__DATA", "__thread_bss",
108
109 // TODO: Verify datarel below.
110 TLSTLVSection // .tlv
111 = Ctx->getMachOSection("__DATA", "__thread_vars",
114
115 TLSThreadInitSection = Ctx->getMachOSection(
116 "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
118
119 CStringSection // .cstring
120 = Ctx->getMachOSection("__TEXT", "__cstring",
124 = Ctx->getMachOSection("__TEXT","__ustring", 0,
126 FourByteConstantSection // .literal4
127 = Ctx->getMachOSection("__TEXT", "__literal4",
130 EightByteConstantSection // .literal8
131 = Ctx->getMachOSection("__TEXT", "__literal8",
134
135 SixteenByteConstantSection // .literal16
136 = Ctx->getMachOSection("__TEXT", "__literal16",
139
140 ReadOnlySection // .const
141 = Ctx->getMachOSection("__TEXT", "__const", 0,
143
144 // If the target is not powerpc, map the coal sections to the non-coal
145 // sections.
146 //
147 // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
148 // "__TEXT/__const_coal" => section "__TEXT/__const"
149 // "__DATA/__datacoal_nt" => section "__DATA/__data"
150 Triple::ArchType ArchTy = T.getArch();
151
152 ConstDataSection // .const_data
153 = Ctx->getMachOSection("__DATA", "__const", 0,
155
156 if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
158 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
163 = Ctx->getMachOSection("__TEXT", "__const_coal",
166 DataCoalSection = Ctx->getMachOSection(
167 "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());
169 } else {
174 }
175
177 = Ctx->getMachOSection("__DATA","__common",
181 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
183
184
186 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
190 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
193
195 = Ctx->getMachOSection("__DATA", "__thread_ptr",
198
199 AddrSigSection = Ctx->getMachOSection("__DATA", "__llvm_addrsig", 0,
201
202 // Exception Handling.
203 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
205
206 COFFDebugSymbolsSection = nullptr;
207 COFFDebugTypesSection = nullptr;
209
210 if (useCompactUnwind(T)) {
212 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
214
215 if (T.isX86())
216 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF
217 else if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)
218 CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF
219 else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
220 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF
221 }
222
223 // Debug Information.
225 Ctx->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG,
226 SectionKind::getMetadata(), "debug_names_begin");
228 Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
229 SectionKind::getMetadata(), "names_begin");
231 Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
232 SectionKind::getMetadata(), "objc_begin");
233 // 16 character section limit...
235 Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
236 SectionKind::getMetadata(), "namespac_begin");
238 Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
239 SectionKind::getMetadata(), "types_begin");
240
242 Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG,
244
246 Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
247 SectionKind::getMetadata(), "section_abbrev");
249 Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
250 SectionKind::getMetadata(), "section_info");
252 Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
253 SectionKind::getMetadata(), "section_line");
255 Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,
256 SectionKind::getMetadata(), "section_line_str");
258 Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
259 SectionKind::getMetadata(), "section_frame");
261 Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
264 Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
267 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
270 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
273 Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
274 SectionKind::getMetadata(), "info_string");
276 Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG,
277 SectionKind::getMetadata(), "section_str_off");
279 Ctx->getMachOSection("__DWARF", "__debug_addr", MachO::S_ATTR_DEBUG,
280 SectionKind::getMetadata(), "section_info");
282 Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
283 SectionKind::getMetadata(), "section_debug_loc");
285 Ctx->getMachOSection("__DWARF", "__debug_loclists", MachO::S_ATTR_DEBUG,
286 SectionKind::getMetadata(), "section_debug_loc");
287
289 Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
292 Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
293 SectionKind::getMetadata(), "debug_range");
295 Ctx->getMachOSection("__DWARF", "__debug_rnglists", MachO::S_ATTR_DEBUG,
296 SectionKind::getMetadata(), "debug_range");
298 Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG,
299 SectionKind::getMetadata(), "debug_macinfo");
301 Ctx->getMachOSection("__DWARF", "__debug_macro", MachO::S_ATTR_DEBUG,
302 SectionKind::getMetadata(), "debug_macro");
304 Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
307 Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,
310 Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG,
312 StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
314
315 FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
317
318 RemarksSection = Ctx->getMachOSection(
319 "__LLVM", "__remarks", MachO::S_ATTR_DEBUG, SectionKind::getMetadata());
320
321 // The architecture of dsymutil makes it very difficult to copy the Swift
322 // reflection metadata sections into the __TEXT segment, so dsymutil creates
323 // these sections in the __DWARF segment instead.
324 if (!Ctx->getSwift5ReflectionSegmentName().empty()) {
325#define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) \
326 Swift5ReflectionSections \
327 [llvm::binaryformat::Swift5ReflectionSectionKind::KIND] = \
328 Ctx->getMachOSection(Ctx->getSwift5ReflectionSegmentName().data(), \
329 MACHO, 0, SectionKind::getMetadata());
330#include "llvm/BinaryFormat/Swift.def"
331 }
332
334}
335
336void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
337 switch (T.getArch()) {
338 case Triple::mips:
339 case Triple::mipsel:
340 case Triple::mips64:
341 case Triple::mips64el:
342 // We cannot use DW_EH_PE_sdata8 for the large PositionIndependent case
343 // since there is no R_MIPS_PC64 relocation (only a 32-bit version).
344 // In fact DW_EH_PE_sdata4 is enough for us now, and GNU ld doesn't
345 // support pcrel|sdata8 well. Let's use sdata4 for now.
346 if (PositionIndependent)
348 else
349 FDECFIEncoding = Ctx->getAsmInfo()->getCodePointerSize() == 4
352 break;
353 case Triple::ppc64:
354 case Triple::ppc64le:
355 case Triple::aarch64:
357 case Triple::x86_64:
360 break;
361 case Triple::bpfel:
362 case Triple::bpfeb:
364 break;
365 case Triple::hexagon:
367 PositionIndependent ? dwarf::DW_EH_PE_pcrel : dwarf::DW_EH_PE_absptr;
368 break;
369 case Triple::xtensa:
371 break;
372 default:
374 break;
375 }
376
377 unsigned EHSectionType = T.getArch() == Triple::x86_64
380 switch (T.getArch()) {
381 case Triple::x86_64:
382 SFrameABIArch = sframe::ABI::AMD64EndianLittle;
383 break;
384 case Triple::aarch64:
385 SFrameABIArch = sframe::ABI::AArch64EndianLittle;
386 break;
388 SFrameABIArch = sframe::ABI::AArch64EndianBig;
389 break;
390 default:
391 break;
392 }
393
394 // Solaris requires different flags for .eh_frame to seemingly every other
395 // platform.
396 unsigned EHSectionFlags = ELF::SHF_ALLOC;
397 if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
398 EHSectionFlags |= ELF::SHF_WRITE;
399
400 // ELF
401 BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
403
404 TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
406
407 DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
409
411 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
412
414 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
416
417 TLSBSSSection = Ctx->getELFSection(
419
420 DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
422
424 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
426
428 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
430
432 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
434
436 Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS,
438
439 // Exception Handling Sections.
440
441 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
442 // it contains relocatable pointers. In PIC mode, this is probably a big
443 // runtime hit for C++ apps. Either the contents of the LSDA need to be
444 // adjusted or this should be a data section.
445 LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
447
448 COFFDebugSymbolsSection = nullptr;
449 COFFDebugTypesSection = nullptr;
450
451 unsigned DebugSecType = ELF::SHT_PROGBITS;
452
453 // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
454 // to distinguish among sections contain DWARF and ECOFF debug formats.
455 // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
456 if (T.isMIPS())
457 DebugSecType = ELF::SHT_MIPS_DWARF;
458
459 // Debug Info Sections.
461 Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);
462 DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0);
463 DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0);
465 Ctx->getELFSection(".debug_line_str", DebugSecType,
467 DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0);
469 Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);
471 Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);
473 Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);
475 Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);
477 Ctx->getELFSection(".debug_str", DebugSecType,
479 DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0);
481 Ctx->getELFSection(".debug_aranges", DebugSecType, 0);
483 Ctx->getELFSection(".debug_ranges", DebugSecType, 0);
485 Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);
486 DwarfMacroSection = Ctx->getELFSection(".debug_macro", DebugSecType, 0);
487
488 // DWARF5 Experimental Debug Info
489
490 // Accelerator Tables
492 Ctx->getELFSection(".debug_names", ELF::SHT_PROGBITS, 0);
494 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);
496 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);
498 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);
500 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);
501
502 // String Offset and Address Sections
504 Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);
505 DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);
506 DwarfRnglistsSection = Ctx->getELFSection(".debug_rnglists", DebugSecType, 0);
507 DwarfLoclistsSection = Ctx->getELFSection(".debug_loclists", DebugSecType, 0);
508
509 // Fission Sections
511 Ctx->getELFSection(".debug_info.dwo", DebugSecType, ELF::SHF_EXCLUDE);
513 Ctx->getELFSection(".debug_types.dwo", DebugSecType, ELF::SHF_EXCLUDE);
515 Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, ELF::SHF_EXCLUDE);
516 DwarfStrDWOSection = Ctx->getELFSection(
517 ".debug_str.dwo", DebugSecType,
520 Ctx->getELFSection(".debug_line.dwo", DebugSecType, ELF::SHF_EXCLUDE);
522 Ctx->getELFSection(".debug_loc.dwo", DebugSecType, ELF::SHF_EXCLUDE);
523 DwarfStrOffDWOSection = Ctx->getELFSection(".debug_str_offsets.dwo",
524 DebugSecType, ELF::SHF_EXCLUDE);
526 Ctx->getELFSection(".debug_rnglists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
528 Ctx->getELFSection(".debug_macinfo.dwo", DebugSecType, ELF::SHF_EXCLUDE);
530 Ctx->getELFSection(".debug_macro.dwo", DebugSecType, ELF::SHF_EXCLUDE);
531
533 Ctx->getELFSection(".debug_loclists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
534
535 // DWP Sections
537 Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);
539 Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);
540
542 Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
543
545 Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
546
548 Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
549
551 Ctx->getELFSection(".sframe", ELF::SHT_GNU_SFRAME, ELF::SHF_ALLOC);
552
554 Ctx->getELFSection(".llvm.callgraph", ELF::SHT_LLVM_CALL_GRAPH, 0);
555
556 StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);
557
558 PseudoProbeSection = Ctx->getELFSection(".pseudo_probe", DebugSecType, 0);
560 Ctx->getELFSection(".pseudo_probe_desc", DebugSecType, 0);
561
562 LLVMStatsSection = Ctx->getELFSection(".llvm_stats", ELF::SHT_PROGBITS, 0);
563}
564
565void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) {
566 MCSectionGOFF *RootSDSection = Ctx->getGOFFSection(
569
570 MCSectionGOFF *ADAEDSection = Ctx->getGOFFSection(
572 GOFF::EDAttr{false, GOFF::ESD_RMODE_64, GOFF::ESD_NS_Parts,
576 RootSDSection);
577 ADASection = Ctx->getGOFFSection(SectionKind::getData(), "#S",
578 GOFF::PRAttr{false, GOFF::ESD_EXE_DATA,
581 ADAEDSection);
582
583 TextSection = Ctx->getGOFFSection(
589 RootSDSection);
590
591 MCSectionGOFF *PPA2ListEDSection = Ctx->getGOFFSection(
593 GOFF::EDAttr{true, GOFF::ESD_RMODE_64, GOFF::ESD_NS_Parts,
597 RootSDSection);
598 PPA2ListSection = Ctx->getGOFFSection(SectionKind::getData(), ".&ppa2",
599 GOFF::PRAttr{true, GOFF::ESD_EXE_DATA,
602 PPA2ListEDSection);
603
604 IDRLSection = Ctx->getGOFFSection(
605 SectionKind::getData(), "B_IDRL",
610 RootSDSection);
611}
612
613void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
615 Ctx->getCOFFSection(".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
617
618 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
619 // used to indicate to the linker that the text segment contains thumb instructions
620 // and to set the ISA selection bit for calls accordingly.
621 const bool IsThumb = T.getArch() == Triple::thumb;
622
623 // COFF
624 BSSSection = Ctx->getCOFFSection(
627 TextSection = Ctx->getCOFFSection(
628 ".text",
632 DataSection = Ctx->getCOFFSection(
636 Ctx->getCOFFSection(".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
638
639 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64 ||
640 T.getArch() == Triple::arm || T.getArch() == Triple::thumb) {
641 // On Windows with SEH, the LSDA is emitted into the .xdata section
642 LSDASection = nullptr;
643 } else {
644 LSDASection = Ctx->getCOFFSection(".gcc_except_table",
647 }
648
649 if (T.getArch() == Triple::aarch64) {
651 Ctx->getCOFFSection(".impcall", COFF::IMAGE_SCN_LNK_INFO);
652 } else if (T.getArch() == Triple::x86_64) {
653 // Import Call Optimization on x64 leverages the same metadata as the
654 // retpoline mitigation, hence the unusual section name.
656 Ctx->getCOFFSection(".retplne", COFF::IMAGE_SCN_LNK_INFO);
657 }
658
659 // Debug info.
661 Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
665 Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
669 Ctx->getCOFFSection(".debug$H", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
672
673 DwarfAbbrevSection = Ctx->getCOFFSection(
674 ".debug_abbrev", COFF::IMAGE_SCN_MEM_DISCARDABLE |
677 DwarfInfoSection = Ctx->getCOFFSection(
678 ".debug_info", COFF::IMAGE_SCN_MEM_DISCARDABLE |
681 DwarfLineSection = Ctx->getCOFFSection(
682 ".debug_line", COFF::IMAGE_SCN_MEM_DISCARDABLE |
685 DwarfLineStrSection = Ctx->getCOFFSection(
686 ".debug_line_str", COFF::IMAGE_SCN_MEM_DISCARDABLE |
689 DwarfFrameSection = Ctx->getCOFFSection(
690 ".debug_frame", COFF::IMAGE_SCN_MEM_DISCARDABLE |
693 DwarfPubNamesSection = Ctx->getCOFFSection(
694 ".debug_pubnames", COFF::IMAGE_SCN_MEM_DISCARDABLE |
697 DwarfPubTypesSection = Ctx->getCOFFSection(
698 ".debug_pubtypes", COFF::IMAGE_SCN_MEM_DISCARDABLE |
701 DwarfGnuPubNamesSection = Ctx->getCOFFSection(
702 ".debug_gnu_pubnames", COFF::IMAGE_SCN_MEM_DISCARDABLE |
705 DwarfGnuPubTypesSection = Ctx->getCOFFSection(
706 ".debug_gnu_pubtypes", COFF::IMAGE_SCN_MEM_DISCARDABLE |
709 DwarfStrSection = Ctx->getCOFFSection(
710 ".debug_str", COFF::IMAGE_SCN_MEM_DISCARDABLE |
713 DwarfStrOffSection = Ctx->getCOFFSection(
714 ".debug_str_offsets", COFF::IMAGE_SCN_MEM_DISCARDABLE |
717 DwarfLocSection = Ctx->getCOFFSection(
718 ".debug_loc", COFF::IMAGE_SCN_MEM_DISCARDABLE |
721 DwarfLoclistsSection = Ctx->getCOFFSection(
722 ".debug_loclists", COFF::IMAGE_SCN_MEM_DISCARDABLE |
725 DwarfARangesSection = Ctx->getCOFFSection(
726 ".debug_aranges", COFF::IMAGE_SCN_MEM_DISCARDABLE |
729 DwarfRangesSection = Ctx->getCOFFSection(
730 ".debug_ranges", COFF::IMAGE_SCN_MEM_DISCARDABLE |
733 DwarfRnglistsSection = Ctx->getCOFFSection(
734 ".debug_rnglists", COFF::IMAGE_SCN_MEM_DISCARDABLE |
737 DwarfMacinfoSection = Ctx->getCOFFSection(
738 ".debug_macinfo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
741 DwarfMacroSection = Ctx->getCOFFSection(
742 ".debug_macro", COFF::IMAGE_SCN_MEM_DISCARDABLE |
745 DwarfMacinfoDWOSection = Ctx->getCOFFSection(
746 ".debug_macinfo.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
749 DwarfMacroDWOSection = Ctx->getCOFFSection(
750 ".debug_macro.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
753 DwarfInfoDWOSection = Ctx->getCOFFSection(
754 ".debug_info.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
757 DwarfTypesDWOSection = Ctx->getCOFFSection(
758 ".debug_types.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
761 DwarfAbbrevDWOSection = Ctx->getCOFFSection(
762 ".debug_abbrev.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
765 DwarfStrDWOSection = Ctx->getCOFFSection(
766 ".debug_str.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
769 DwarfLineDWOSection = Ctx->getCOFFSection(
770 ".debug_line.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
773 DwarfLocDWOSection = Ctx->getCOFFSection(
774 ".debug_loc.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
777 DwarfLoclistsDWOSection = Ctx->getCOFFSection(
778 ".debug_loclists.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
781 DwarfStrOffDWOSection = Ctx->getCOFFSection(
782 ".debug_str_offsets.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
785 DwarfRnglistsDWOSection = Ctx->getCOFFSection(
786 ".debug_rnglists.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
789 DwarfAddrSection = Ctx->getCOFFSection(
790 ".debug_addr", COFF::IMAGE_SCN_MEM_DISCARDABLE |
793 DwarfCUIndexSection = Ctx->getCOFFSection(
794 ".debug_cu_index", COFF::IMAGE_SCN_MEM_DISCARDABLE |
797 DwarfTUIndexSection = Ctx->getCOFFSection(
798 ".debug_tu_index", COFF::IMAGE_SCN_MEM_DISCARDABLE |
801 DwarfDebugNamesSection = Ctx->getCOFFSection(
802 ".debug_names", COFF::IMAGE_SCN_MEM_DISCARDABLE |
805 DwarfAccelNamesSection = Ctx->getCOFFSection(
806 ".apple_names", COFF::IMAGE_SCN_MEM_DISCARDABLE |
809 DwarfAccelNamespaceSection = Ctx->getCOFFSection(
810 ".apple_namespaces", COFF::IMAGE_SCN_MEM_DISCARDABLE |
813 DwarfAccelTypesSection = Ctx->getCOFFSection(
814 ".apple_types", COFF::IMAGE_SCN_MEM_DISCARDABLE |
817 DwarfAccelObjCSection = Ctx->getCOFFSection(
818 ".apple_objc", COFF::IMAGE_SCN_MEM_DISCARDABLE |
821
822 DrectveSection = Ctx->getCOFFSection(
824
826 Ctx->getCOFFSection(".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
828
830 Ctx->getCOFFSection(".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
832
833 SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO);
834
836 Ctx->getCOFFSection(".gehcont$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
838
840 Ctx->getCOFFSection(".gfids$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
842
844 Ctx->getCOFFSection(".giats$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
846
848 Ctx->getCOFFSection(".gljmp$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
850
851 TLSDataSection = Ctx->getCOFFSection(
854
855 StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
858
859 // Set IMAGE_SCN_MEM_DISCARDABLE so that lld will not truncate section name.
860 PseudoProbeSection = Ctx->getCOFFSection(
861 ".pseudo_probe", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
864 PseudoProbeDescSection = Ctx->getCOFFSection(
865 ".pseudo_probe_desc", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
868}
869
870void MCObjectFileInfo::initSPIRVMCObjectFileInfo(const Triple &T) {
871 // Put everything in a single binary section.
872 TextSection = Ctx->getSPIRVSection();
873}
874
875void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
876 TextSection = Ctx->getWasmSection(".text", SectionKind::getText());
877 DataSection = Ctx->getWasmSection(".data", SectionKind::getData());
878
880 Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());
882 Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata(),
884 DwarfStrSection = Ctx->getWasmSection(
887 Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());
889 Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata());
890 DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());
892 Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata());
894 Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata());
896 Ctx->getWasmSection(".debug_macro", SectionKind::getMetadata());
897 DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
898 DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
900 Ctx->getWasmSection(".debug_info", SectionKind::getMetadata());
901 DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());
902 DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
903 DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
905 Ctx->getWasmSection(".debug_gnu_pubnames", SectionKind::getMetadata());
907 Ctx->getWasmSection(".debug_gnu_pubtypes", SectionKind::getMetadata());
908
910 Ctx->getWasmSection(".debug_names", SectionKind::getMetadata());
912 Ctx->getWasmSection(".debug_str_offsets", SectionKind::getMetadata());
914 Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata());
916 Ctx->getWasmSection(".debug_rnglists", SectionKind::getMetadata());
918 Ctx->getWasmSection(".debug_loclists", SectionKind::getMetadata());
919
920 // Fission Sections
922 Ctx->getWasmSection(".debug_info.dwo", SectionKind::getMetadata());
924 Ctx->getWasmSection(".debug_types.dwo", SectionKind::getMetadata());
926 Ctx->getWasmSection(".debug_abbrev.dwo", SectionKind::getMetadata());
928 Ctx->getWasmSection(".debug_str.dwo", SectionKind::getMetadata(),
931 Ctx->getWasmSection(".debug_line.dwo", SectionKind::getMetadata());
933 Ctx->getWasmSection(".debug_loc.dwo", SectionKind::getMetadata());
935 Ctx->getWasmSection(".debug_str_offsets.dwo", SectionKind::getMetadata());
937 Ctx->getWasmSection(".debug_rnglists.dwo", SectionKind::getMetadata());
939 Ctx->getWasmSection(".debug_macinfo.dwo", SectionKind::getMetadata());
941 Ctx->getWasmSection(".debug_macro.dwo", SectionKind::getMetadata());
942
944 Ctx->getWasmSection(".debug_loclists.dwo", SectionKind::getMetadata());
945
946 // DWP Sections
948 Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
950 Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
951
952 // Wasm use data section for LSDA.
953 // TODO Consider putting each function's exception table in a separate
954 // section, as in -function-sections, to facilitate lld's --gc-section.
955 LSDASection = Ctx->getWasmSection(".rodata.gcc_except_table",
957
958 // TODO: Define more sections.
959}
960
961void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) {
962 // The default csect for program code. Functions without a specified section
963 // get placed into this csect. The choice of csect name is not a property of
964 // the ABI or object file format, but various tools rely on the section
965 // name being empty (considering named symbols to be "user symbol names").
966 TextSection = Ctx->getXCOFFSection(
967 "..text..", // Use a non-null name to work around an AIX assembler bug...
969 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD),
970 /* MultiSymbolsAllowed*/ true);
971
972 // ... but use a null name when generating the symbol table.
973 MCSectionXCOFF *TS = static_cast<MCSectionXCOFF *>(TextSection);
975 TS->setSymbolTableName("");
976
977 DataSection = Ctx->getXCOFFSection(
978 ".data", SectionKind::getData(),
979 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD),
980 /* MultiSymbolsAllowed*/ true);
981
982 ReadOnlySection = Ctx->getXCOFFSection(
983 ".rodata", SectionKind::getReadOnly(),
984 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
985 /* MultiSymbolsAllowed*/ true);
986 ReadOnlySection->setAlignment(Align(4));
987
988 ReadOnly8Section = Ctx->getXCOFFSection(
989 ".rodata.8", SectionKind::getReadOnly(),
990 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
991 /* MultiSymbolsAllowed*/ true);
992 ReadOnly8Section->setAlignment(Align(8));
993
994 ReadOnly16Section = Ctx->getXCOFFSection(
995 ".rodata.16", SectionKind::getReadOnly(),
996 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
997 /* MultiSymbolsAllowed*/ true);
998 ReadOnly16Section->setAlignment(Align(16));
999
1000 TLSDataSection = Ctx->getXCOFFSection(
1001 ".tdata", SectionKind::getThreadData(),
1002 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TL, XCOFF::XTY_SD),
1003 /* MultiSymbolsAllowed*/ true);
1004
1005 TOCBaseSection = Ctx->getXCOFFSection(
1006 "TOC", SectionKind::getData(),
1007 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TC0,
1008 XCOFF::XTY_SD));
1009
1010 // The TOC-base always has 0 size, but 4 byte alignment.
1011 TOCBaseSection->setAlignment(Align(4));
1012
1013 LSDASection = Ctx->getXCOFFSection(
1014 ".gcc_except_table", SectionKind::getReadOnly(),
1015 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO,
1016 XCOFF::XTY_SD));
1017
1018 CompactUnwindSection = Ctx->getXCOFFSection(
1019 ".eh_info_table", SectionKind::getData(),
1020 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW,
1021 XCOFF::XTY_SD));
1022
1023 // DWARF sections for XCOFF are not csects. They are special STYP_DWARF
1024 // sections, and the individual DWARF sections are distinguished by their
1025 // section subtype.
1026 DwarfAbbrevSection = Ctx->getXCOFFSection(
1027 ".dwabrev", SectionKind::getMetadata(),
1028 /* CsectProperties */ std::nullopt,
1029 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWABREV);
1030
1031 DwarfInfoSection = Ctx->getXCOFFSection(
1032 ".dwinfo", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1033 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWINFO);
1034
1035 DwarfLineSection = Ctx->getXCOFFSection(
1036 ".dwline", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1037 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWLINE);
1038
1039 DwarfFrameSection = Ctx->getXCOFFSection(
1040 ".dwframe", SectionKind::getMetadata(),
1041 /* CsectProperties */ std::nullopt,
1042 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWFRAME);
1043
1044 DwarfPubNamesSection = Ctx->getXCOFFSection(
1045 ".dwpbnms", SectionKind::getMetadata(),
1046 /* CsectProperties */ std::nullopt,
1047 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWPBNMS);
1048
1049 DwarfPubTypesSection = Ctx->getXCOFFSection(
1050 ".dwpbtyp", SectionKind::getMetadata(),
1051 /* CsectProperties */ std::nullopt,
1052 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWPBTYP);
1053
1054 DwarfStrSection = Ctx->getXCOFFSection(
1055 ".dwstr", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1056 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWSTR);
1057
1058 DwarfLocSection = Ctx->getXCOFFSection(
1059 ".dwloc", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1060 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWLOC);
1061
1062 DwarfARangesSection = Ctx->getXCOFFSection(
1063 ".dwarnge", SectionKind::getMetadata(),
1064 /* CsectProperties */ std::nullopt,
1065 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWARNGE);
1066
1067 DwarfRangesSection = Ctx->getXCOFFSection(
1068 ".dwrnges", SectionKind::getMetadata(),
1069 /* CsectProperties */ std::nullopt,
1070 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWRNGES);
1071
1072 DwarfMacinfoSection = Ctx->getXCOFFSection(
1073 ".dwmac", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1074 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWMAC);
1075}
1076
1077void MCObjectFileInfo::initDXContainerObjectFileInfo(const Triple &T) {
1078 // At the moment the DXBC section should end up empty.
1079 TextSection = Ctx->getDXContainerSection("DXBC", SectionKind::getText());
1080}
1081
1083
1085 bool LargeCodeModel) {
1086 PositionIndependent = PIC;
1087 Ctx = &MCCtx;
1088
1089 // Common.
1092
1094
1096
1097 EHFrameSection = nullptr; // Created on demand.
1098 SFrameSection = nullptr; // Created on demand.
1099 CompactUnwindSection = nullptr; // Used only by selected targets.
1100 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
1101 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
1102 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
1103 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
1104
1105 const Triple &TheTriple = Ctx->getTargetTriple();
1106 switch (Ctx->getObjectFileType()) {
1107 case MCContext::IsMachO:
1108 initMachOMCObjectFileInfo(TheTriple);
1109 break;
1110 case MCContext::IsCOFF:
1111 initCOFFMCObjectFileInfo(TheTriple);
1112 break;
1113 case MCContext::IsELF:
1114 initELFMCObjectFileInfo(TheTriple, LargeCodeModel);
1115 break;
1116 case MCContext::IsGOFF:
1117 initGOFFMCObjectFileInfo(TheTriple);
1118 break;
1119 case MCContext::IsSPIRV:
1120 initSPIRVMCObjectFileInfo(TheTriple);
1121 break;
1122 case MCContext::IsWasm:
1123 initWasmMCObjectFileInfo(TheTriple);
1124 break;
1125 case MCContext::IsXCOFF:
1126 initXCOFFMCObjectFileInfo(TheTriple);
1127 break;
1129 initDXContainerObjectFileInfo(TheTriple);
1130 break;
1131 }
1132}
1133
1134MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
1135 uint64_t Hash) const {
1136 switch (Ctx->getTargetTriple().getObjectFormat()) {
1137 case Triple::ELF:
1138 return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0,
1139 utostr(Hash), /*IsComdat=*/true);
1140 case Triple::Wasm:
1141 return Ctx->getWasmSection(Name, SectionKind::getMetadata(), 0,
1143 case Triple::MachO:
1144 case Triple::COFF:
1145 case Triple::GOFF:
1146 case Triple::SPIRV:
1147 case Triple::XCOFF:
1150 report_fatal_error("Cannot get DWARF comdat section for this object file "
1151 "format: not implemented.");
1152 break;
1153 }
1154 llvm_unreachable("Unknown ObjectFormatType");
1155}
1156
1157MCSection *
1159 if (Ctx->getObjectFileType() != MCContext::IsELF)
1160 return CallGraphSection;
1161
1162 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1163 unsigned Flags = ELF::SHF_LINK_ORDER;
1164 StringRef GroupName;
1165 if (const MCSymbol *Group = ElfSec.getGroup()) {
1166 GroupName = Group->getName();
1167 Flags |= ELF::SHF_GROUP;
1168 }
1169
1170 return Ctx->getELFSection(
1171 ".llvm.callgraph", ELF::SHT_LLVM_CALL_GRAPH, Flags, 0, GroupName,
1172 /*IsComdat=*/true, ElfSec.getUniqueID(),
1173 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1174}
1175
1176MCSection *
1178 if ((Ctx->getObjectFileType() != MCContext::IsELF) ||
1179 Ctx->getTargetTriple().isPS4())
1180 return StackSizesSection;
1181
1182 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1183 unsigned Flags = ELF::SHF_LINK_ORDER;
1184 StringRef GroupName;
1185 if (const MCSymbol *Group = ElfSec.getGroup()) {
1186 GroupName = Group->getName();
1187 Flags |= ELF::SHF_GROUP;
1188 }
1189
1190 return Ctx->getELFSection(
1191 ".stack_sizes", ELF::SHT_PROGBITS, Flags, 0, GroupName, true,
1192 ElfSec.getUniqueID(),
1193 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1194}
1195
1196MCSection *
1198 if (Ctx->getObjectFileType() != MCContext::IsELF)
1199 return nullptr;
1200
1201 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1202 unsigned Flags = ELF::SHF_LINK_ORDER;
1203 StringRef GroupName;
1204 if (const MCSymbol *Group = ElfSec.getGroup()) {
1205 GroupName = Group->getName();
1206 Flags |= ELF::SHF_GROUP;
1207 }
1208
1209 // Use the text section's begin symbol and unique ID to create a separate
1210 // .llvm_bb_addr_map section associated with every unique text section.
1211 return Ctx->getELFSection(
1212 ".llvm_bb_addr_map", ELF::SHT_LLVM_BB_ADDR_MAP, Flags, 0, GroupName, true,
1213 ElfSec.getUniqueID(),
1214 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1215}
1216
1217MCSection *
1219 if (Ctx->getObjectFileType() != MCContext::IsELF)
1220 return nullptr;
1221
1222 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1223 unsigned Flags = ELF::SHF_LINK_ORDER | ELF::SHF_ALLOC;
1224 StringRef GroupName;
1225 if (const MCSymbol *Group = ElfSec.getGroup()) {
1226 GroupName = Group->getName();
1227 Flags |= ELF::SHF_GROUP;
1228 }
1229
1230 return Ctx->getELFSection(
1231 ".kcfi_traps", ELF::SHT_PROGBITS, Flags, 0, GroupName,
1232 /*IsComdat=*/true, ElfSec.getUniqueID(),
1233 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1234}
1235
1236MCSection *
1238 auto ObjFileType = Ctx->getObjectFileType();
1239 if (ObjFileType == MCContext::IsELF) {
1240 const auto &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1241 unsigned Flags = ELF::SHF_LINK_ORDER;
1242 StringRef GroupName;
1243 if (const MCSymbol *Group = ElfSec.getGroup()) {
1244 GroupName = Group->getName();
1245 Flags |= ELF::SHF_GROUP;
1246 }
1247 return Ctx->getELFSection(
1248 PseudoProbeSection->getName(), ELF::SHT_PROGBITS, Flags, 0, GroupName,
1249 true, ElfSec.getUniqueID(),
1250 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1251 } else if (ObjFileType == MCContext::IsCOFF) {
1252 StringRef COMDATSymName = "";
1253 int Selection = 0;
1254 unsigned Characteristics =
1255 static_cast<MCSectionCOFF *>(PseudoProbeSection)->getCharacteristics();
1256 const auto &COFFSec = static_cast<const MCSectionCOFF &>(TextSec);
1257 if (const MCSymbol *COMDATSym = COFFSec.getCOMDATSymbol()) {
1258 // Associate .pseudo_probe to its function section.
1259 COMDATSymName = COMDATSym->getName();
1260 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
1262 }
1263 return Ctx->getCOFFSection(PseudoProbeSection->getName(), Characteristics,
1264 COMDATSymName, Selection, COFFSec.getUniqueID());
1265 }
1266
1267 return PseudoProbeSection;
1268}
1269
1270MCSection *
1272 if (!Ctx->getTargetTriple().supportsCOMDAT() || FuncName.empty())
1274
1275 // Create a separate comdat group for each function's descriptor in order
1276 // for the linker to deduplicate. The duplication, must be from different
1277 // tranlation unit, can come from:
1278 // 1. Inline functions defined in header files;
1279 // 2. ThinLTO imported funcions;
1280 // 3. Weak-linkage definitions.
1281 // Use a concatenation of the section name and the function name as the
1282 // group name so that descriptor-only groups won't be folded with groups of
1283 // code.
1284 auto ObjFileType = Ctx->getObjectFileType();
1285 if (ObjFileType == MCContext::IsELF) {
1286 auto *S = static_cast<MCSectionELF *>(PseudoProbeDescSection);
1287 auto Flags = S->getFlags() | ELF::SHF_GROUP;
1288 return Ctx->getELFSection(S->getName(), S->getType(), Flags,
1289 S->getEntrySize(), S->getName() + "_" + FuncName,
1290 /*IsComdat=*/true);
1291 } else if (ObjFileType == MCContext::IsCOFF) {
1292 auto *S = static_cast<MCSectionCOFF *>(PseudoProbeDescSection);
1293 unsigned Characteristics =
1294 S->getCharacteristics() | COFF::IMAGE_SCN_LNK_COMDAT;
1295 std::string COMDATSymName = (S->getName() + "_" + FuncName).str();
1296 return Ctx->getCOFFSection(S->getName(), Characteristics, COMDATSymName,
1298 }
1299
1301}
1302
1306
1308 const MCSection *TextSec) const {
1309 if (Ctx->getObjectFileType() != MCContext::IsELF)
1310 return nullptr;
1311
1312 // SHF_WRITE for relocations, and let user post-process data in-place.
1314
1315 if (!TextSec)
1316 TextSec = getTextSection();
1317
1318 StringRef GroupName;
1319 const auto &ElfSec = static_cast<const MCSectionELF &>(*TextSec);
1320 if (const MCSymbol *Group = ElfSec.getGroup()) {
1321 GroupName = Group->getName();
1322 Flags |= ELF::SHF_GROUP;
1323 }
1324 return Ctx->getELFSection(
1325 Name, ELF::SHT_PROGBITS, Flags, 0, GroupName, true, ElfSec.getUniqueID(),
1326 static_cast<const MCSymbolELF *>(TextSec->getBeginSymbol()));
1327}
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.
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:517
static constexpr unsigned NonUniqueID
Definition MCSection.h:522
MCSymbol * getBeginSymbol()
Definition MCSection.h:589
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:320
#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
@ SHF_MERGE
Definition ELF.h:1254
@ SHF_STRINGS
Definition ELF.h:1257
@ SHF_EXCLUDE
Definition ELF.h:1282
@ SHF_ALLOC
Definition ELF.h:1248
@ SHF_LINK_ORDER
Definition ELF.h:1263
@ SHF_GROUP
Definition ELF.h:1270
@ SHF_WRITE
Definition ELF.h:1245
@ SHF_TLS
Definition ELF.h:1273
@ SHF_EXECINSTR
Definition ELF.h:1251
@ SHT_PROGBITS
Definition ELF.h:1147
@ SHT_NOBITS
Definition ELF.h:1154
@ SHT_LLVM_CALL_GRAPH
Definition ELF.h:1190
@ SHT_MIPS_DWARF
Definition ELF.h:1226
@ SHT_LLVM_BB_ADDR_MAP
Definition ELF.h:1185
@ SHT_GNU_SFRAME
Definition ELF.h:1194
@ SHT_X86_64_UNWIND
Definition ELF.h:1222
@ 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:879
@ DW_EH_PE_sdata4
Definition Dwarf.h:876
@ DW_EH_PE_sdata8
Definition Dwarf.h:877
@ DW_EH_PE_absptr
Definition Dwarf.h:868
@ 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