LLVM 23.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
16#include "llvm/MC/MCAsmInfo.h"
17#include "llvm/MC/MCContext.h"
19#include "llvm/MC/MCSection.h"
30
31using namespace llvm;
32
33static bool useCompactUnwind(const Triple &T) {
34 // Only on darwin.
35 if (!T.isOSDarwin())
36 return false;
37
38 // aarch64 always has it.
39 if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)
40 return true;
41
42 // armv7k always has it.
43 if (T.isWatchABI())
44 return true;
45
46 // Use it on newer version of OS X.
47 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
48 return true;
49
50 // And the iOS simulator.
51 if (T.isiOS() && T.isX86())
52 return true;
53
54 // The rest of the simulators always have it.
55 if (T.isSimulatorEnvironment())
56 return true;
57
58 // XROS always has it.
59 if (T.isXROS())
60 return true;
61
62 return false;
63}
64
65void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
66 EHFrameSection = Ctx->getMachOSection(
67 "__TEXT", "__eh_frame",
71
72 if (T.isOSDarwin() &&
73 (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32 ||
74 T.isSimulatorEnvironment()))
76
77 switch (Ctx->emitDwarfUnwindInfo()) {
80 break;
83 break;
87 break;
88 }
89
91
92 TextSection // .text
93 = Ctx->getMachOSection("__TEXT", "__text",
96 DataSection // .data
97 = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
98
99 // BSSSection might not be expected initialized on msvc.
100 BSSSection = nullptr;
101
102 TLSDataSection // .tdata
103 = Ctx->getMachOSection("__DATA", "__thread_data",
106 TLSBSSSection // .tbss
107 = Ctx->getMachOSection("__DATA", "__thread_bss",
110
111 // TODO: Verify datarel below.
112 TLSTLVSection // .tlv
113 = Ctx->getMachOSection("__DATA", "__thread_vars",
116
117 TLSThreadInitSection = Ctx->getMachOSection(
118 "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
120
121 CStringSection // .cstring
122 = Ctx->getMachOSection("__TEXT", "__cstring",
126 = Ctx->getMachOSection("__TEXT","__ustring", 0,
128 FourByteConstantSection // .literal4
129 = Ctx->getMachOSection("__TEXT", "__literal4",
132 EightByteConstantSection // .literal8
133 = Ctx->getMachOSection("__TEXT", "__literal8",
136
137 SixteenByteConstantSection // .literal16
138 = Ctx->getMachOSection("__TEXT", "__literal16",
141
142 ReadOnlySection // .const
143 = Ctx->getMachOSection("__TEXT", "__const", 0,
145
146 // If the target is not powerpc, map the coal sections to the non-coal
147 // sections.
148 //
149 // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
150 // "__TEXT/__const_coal" => section "__TEXT/__const"
151 // "__DATA/__datacoal_nt" => section "__DATA/__data"
152 Triple::ArchType ArchTy = T.getArch();
153
154 ConstDataSection // .const_data
155 = Ctx->getMachOSection("__DATA", "__const", 0,
157
158 if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
160 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
165 = Ctx->getMachOSection("__TEXT", "__const_coal",
168 DataCoalSection = Ctx->getMachOSection(
169 "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());
171 } else {
176 }
177
179 = Ctx->getMachOSection("__DATA","__common",
183 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
185
186
188 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
192 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
195
197 = Ctx->getMachOSection("__DATA", "__thread_ptr",
200
201 AddrSigSection = Ctx->getMachOSection("__DATA", "__llvm_addrsig", 0,
203
204 // Exception Handling.
205 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
207
208 COFFDebugSymbolsSection = nullptr;
209 COFFDebugTypesSection = nullptr;
211
212 if (useCompactUnwind(T)) {
214 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
216
217 if (T.isX86())
218 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF
219 else if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)
220 CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF
221 else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
222 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF
223 }
224
225 // Debug Information.
227 Ctx->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG,
228 SectionKind::getMetadata(), "debug_names_begin");
230 Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
231 SectionKind::getMetadata(), "names_begin");
233 Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
234 SectionKind::getMetadata(), "objc_begin");
235 // 16 character section limit...
237 Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
238 SectionKind::getMetadata(), "namespac_begin");
240 Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
241 SectionKind::getMetadata(), "types_begin");
242
244 Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG,
246
248 Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
249 SectionKind::getMetadata(), "section_abbrev");
251 Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
252 SectionKind::getMetadata(), "section_info");
254 Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
255 SectionKind::getMetadata(), "section_line");
257 Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,
258 SectionKind::getMetadata(), "section_line_str");
260 Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
261 SectionKind::getMetadata(), "section_frame");
263 Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
266 Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
269 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
272 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
275 Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
276 SectionKind::getMetadata(), "info_string");
278 Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG,
279 SectionKind::getMetadata(), "section_str_off");
281 Ctx->getMachOSection("__DWARF", "__debug_addr", MachO::S_ATTR_DEBUG,
282 SectionKind::getMetadata(), "section_info");
284 Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
285 SectionKind::getMetadata(), "section_debug_loc");
287 Ctx->getMachOSection("__DWARF", "__debug_loclists", MachO::S_ATTR_DEBUG,
288 SectionKind::getMetadata(), "section_debug_loc");
289
291 Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
294 Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
295 SectionKind::getMetadata(), "debug_range");
297 Ctx->getMachOSection("__DWARF", "__debug_rnglists", MachO::S_ATTR_DEBUG,
298 SectionKind::getMetadata(), "debug_range");
300 Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG,
301 SectionKind::getMetadata(), "debug_macinfo");
303 Ctx->getMachOSection("__DWARF", "__debug_macro", MachO::S_ATTR_DEBUG,
304 SectionKind::getMetadata(), "debug_macro");
306 Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
309 Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,
312 Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG,
314 StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
316
317 FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
319
320 RemarksSection = Ctx->getMachOSection(
321 "__LLVM", "__remarks", MachO::S_ATTR_DEBUG, SectionKind::getMetadata());
322
323 // The architecture of dsymutil makes it very difficult to copy the Swift
324 // reflection metadata sections into the __TEXT segment, so dsymutil creates
325 // these sections in the __DWARF segment instead.
326 if (!Ctx->getSwift5ReflectionSegmentName().empty()) {
327#define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) \
328 Swift5ReflectionSections \
329 [llvm::binaryformat::Swift5ReflectionSectionKind::KIND] = \
330 Ctx->getMachOSection(Ctx->getSwift5ReflectionSegmentName().data(), \
331 MACHO, 0, SectionKind::getMetadata());
332#include "llvm/BinaryFormat/Swift.def"
333 }
334
336}
337
338void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
339 switch (T.getArch()) {
340 case Triple::mips:
341 case Triple::mipsel:
342 case Triple::mips64:
343 case Triple::mips64el:
344 // We cannot use DW_EH_PE_sdata8 for the large PositionIndependent case
345 // since there is no R_MIPS_PC64 relocation (only a 32-bit version).
346 // In fact DW_EH_PE_sdata4 is enough for us now, and GNU ld doesn't
347 // support pcrel|sdata8 well. Let's use sdata4 for now.
348 if (PositionIndependent)
350 else
351 FDECFIEncoding = Ctx->getAsmInfo()->getCodePointerSize() == 4
354 break;
355 case Triple::ppc64:
356 case Triple::ppc64le:
357 case Triple::aarch64:
359 case Triple::x86_64:
362 break;
363 case Triple::bpfel:
364 case Triple::bpfeb:
366 break;
367 case Triple::hexagon:
369 PositionIndependent ? dwarf::DW_EH_PE_pcrel : dwarf::DW_EH_PE_absptr;
370 break;
371 case Triple::xtensa:
373 break;
374 default:
376 break;
377 }
378
379 unsigned EHSectionType = T.getArch() == Triple::x86_64
382 switch (T.getArch()) {
383 case Triple::x86_64:
384 SFrameABIArch = sframe::ABI::AMD64EndianLittle;
385 break;
386 case Triple::aarch64:
387 SFrameABIArch = sframe::ABI::AArch64EndianLittle;
388 break;
390 SFrameABIArch = sframe::ABI::AArch64EndianBig;
391 break;
392 default:
393 break;
394 }
395
396 // Solaris requires different flags for .eh_frame to seemingly every other
397 // platform.
398 unsigned EHSectionFlags = ELF::SHF_ALLOC;
399 if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
400 EHSectionFlags |= ELF::SHF_WRITE;
401
402 // ELF
403 BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
405
406 TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
408
409 DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
411
413 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
414
416 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
418
419 TLSBSSSection = Ctx->getELFSection(
421
422 DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
424
426 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
428
430 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
432
434 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
436
438 Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS,
440
441 // Exception Handling Sections.
442
443 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
444 // it contains relocatable pointers. In PIC mode, this is probably a big
445 // runtime hit for C++ apps. Either the contents of the LSDA need to be
446 // adjusted or this should be a data section.
447 LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
449
450 COFFDebugSymbolsSection = nullptr;
451 COFFDebugTypesSection = nullptr;
452
453 unsigned DebugSecType = ELF::SHT_PROGBITS;
454
455 // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
456 // to distinguish among sections contain DWARF and ECOFF debug formats.
457 // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
458 if (T.isMIPS())
459 DebugSecType = ELF::SHT_MIPS_DWARF;
460
461 // Debug Info Sections.
463 Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);
464 DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0);
465 DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0);
467 Ctx->getELFSection(".debug_line_str", DebugSecType,
469 DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0);
471 Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);
473 Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);
475 Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);
477 Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);
479 Ctx->getELFSection(".debug_str", DebugSecType,
481 DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0);
483 Ctx->getELFSection(".debug_aranges", DebugSecType, 0);
485 Ctx->getELFSection(".debug_ranges", DebugSecType, 0);
487 Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);
488 DwarfMacroSection = Ctx->getELFSection(".debug_macro", DebugSecType, 0);
489
490 // DWARF5 Experimental Debug Info
491
492 // Accelerator Tables
494 Ctx->getELFSection(".debug_names", ELF::SHT_PROGBITS, 0);
496 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);
498 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);
500 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);
502 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);
503
504 // String Offset and Address Sections
506 Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);
507 DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);
508 DwarfRnglistsSection = Ctx->getELFSection(".debug_rnglists", DebugSecType, 0);
509 DwarfLoclistsSection = Ctx->getELFSection(".debug_loclists", DebugSecType, 0);
510
511 // Fission Sections
513 Ctx->getELFSection(".debug_info.dwo", DebugSecType, ELF::SHF_EXCLUDE);
515 Ctx->getELFSection(".debug_types.dwo", DebugSecType, ELF::SHF_EXCLUDE);
517 Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, ELF::SHF_EXCLUDE);
518 DwarfStrDWOSection = Ctx->getELFSection(
519 ".debug_str.dwo", DebugSecType,
522 Ctx->getELFSection(".debug_line.dwo", DebugSecType, ELF::SHF_EXCLUDE);
524 Ctx->getELFSection(".debug_loc.dwo", DebugSecType, ELF::SHF_EXCLUDE);
525 DwarfStrOffDWOSection = Ctx->getELFSection(".debug_str_offsets.dwo",
526 DebugSecType, ELF::SHF_EXCLUDE);
528 Ctx->getELFSection(".debug_rnglists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
530 Ctx->getELFSection(".debug_macinfo.dwo", DebugSecType, ELF::SHF_EXCLUDE);
532 Ctx->getELFSection(".debug_macro.dwo", DebugSecType, ELF::SHF_EXCLUDE);
533
535 Ctx->getELFSection(".debug_loclists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
536
537 // DWP Sections
539 Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);
541 Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);
542
544 Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
545
547 Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
548
550 Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
551
553 Ctx->getELFSection(".sframe", ELF::SHT_GNU_SFRAME, ELF::SHF_ALLOC);
554
556 Ctx->getELFSection(".llvm.callgraph", ELF::SHT_LLVM_CALL_GRAPH, 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 // Debug Info Sections. The ED name is the same used by the XL compiler.
615 auto InitDebugSection = [this,
616 RootSDSection](StringRef EDName,
617 StringRef LDName) -> MCSectionGOFF * {
618 MCSectionGOFF *ED = Ctx->getGOFFSection(
619 SectionKind::getMetadata(), EDName,
620 GOFF::EDAttr{false, GOFF::ESD_RMODE_64, GOFF::ESD_NS_Parts,
624 RootSDSection);
625 // At least for llc, this function is called twice! (See function
626 // compileModule() in llc.cpp). Since the context is not cleared, the
627 // already allocated section is returned above. We only add the begin symbol
628 // if it is not yet set to avoid an assertion.
629 MCSymbolGOFF *LD = static_cast<MCSymbolGOFF *>(ED->getBeginSymbol());
630 if (!LD) {
631 LD = static_cast<MCSymbolGOFF *>(getContext().getOrCreateSymbol(LDName));
632 LD->setCodeData(GOFF::ESD_EXE_DATA);
633 LD->setWeak(false);
634 LD->setLinkage(GOFF::ESD_LT_XPLink);
635 LD->setExternal(false);
636 ED->setBeginSymbol(LD);
637 } else
638 assert(LD->getName() == LDName && "Wrong label name");
639 return ED;
640 };
641 DwarfAbbrevSection = InitDebugSection("D_ABREV", ".debug_abbrev");
642 DwarfInfoSection = InitDebugSection("D_INFO", ".debug_info");
643 DwarfLineSection = InitDebugSection("D_LINE", ".debug_line");
644 DwarfFrameSection = InitDebugSection("D_FRAME", ".debug_frame");
645 DwarfPubNamesSection = InitDebugSection("D_PBNMS", ".debug_pubnames");
646 DwarfPubTypesSection = InitDebugSection("D_PTYPES", ".debug_pubtypes");
647 DwarfStrSection = InitDebugSection("D_STR", ".debug_str");
648 DwarfLocSection = InitDebugSection("D_LOC", ".debug_loc");
649 DwarfARangesSection = InitDebugSection("D_ARNGE", ".debug_aranges");
650 DwarfRangesSection = InitDebugSection("D_RNGES", ".debug_ranges");
651 DwarfMacinfoSection = InitDebugSection("D_MACIN", ".debug_macinfo");
652
653 // DWARF 5 sections.
654 DwarfDebugNamesSection = InitDebugSection("D_NAMES", ".debug_names");
655 DwarfStrOffSection = InitDebugSection("D_STROFFS", ".debug_str_offsets");
656 DwarfAddrSection = InitDebugSection("D_ADDR", ".debug_addr");
657 DwarfRnglistsSection = InitDebugSection("D_RNGLISTS", ".debug_rnglists");
658 DwarfLoclistsSection = InitDebugSection("D_LOCLISTS", ".debug_loclists");
659 DwarfLineStrSection = InitDebugSection("D_LINESTR", ".debug_line_str");
660
661 // Special GNU sections.
662 DwarfGnuPubNamesSection = InitDebugSection("D_GPBNMS", ".debug_gnu_pubnames");
664 InitDebugSection("D_GPTYPES", ".debug_gnu_pubtypes");
665
666 // Accelerator Tables.
667 DwarfAccelNamesSection = InitDebugSection("D_APPLNMS", ".apple_names");
669 InitDebugSection("D_APPLNMSP", ".apple_namespaces");
670 DwarfAccelTypesSection = InitDebugSection("D_APPLTYPS", ".apple_types");
671 DwarfAccelObjCSection = InitDebugSection("D_APPLOBJC", ".apple_objc");
672}
673
674void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
676 Ctx->getCOFFSection(".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
678
679 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
680 // used to indicate to the linker that the text segment contains thumb instructions
681 // and to set the ISA selection bit for calls accordingly.
682 const bool IsThumb = T.getArch() == Triple::thumb;
683
684 // COFF
685 BSSSection = Ctx->getCOFFSection(
688 TextSection = Ctx->getCOFFSection(
689 ".text",
693 DataSection = Ctx->getCOFFSection(
697 Ctx->getCOFFSection(".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
699
700 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64 ||
701 T.getArch() == Triple::arm || T.getArch() == Triple::thumb) {
702 // On Windows with SEH, the LSDA is emitted into the .xdata section
703 LSDASection = nullptr;
704 } else {
705 LSDASection = Ctx->getCOFFSection(".gcc_except_table",
708 }
709
710 if (T.getArch() == Triple::aarch64) {
712 Ctx->getCOFFSection(".impcall", COFF::IMAGE_SCN_LNK_INFO);
713 } else if (T.getArch() == Triple::x86_64) {
714 // Import Call Optimization on x64 leverages the same metadata as the
715 // retpoline mitigation, hence the unusual section name.
717 Ctx->getCOFFSection(".retplne", COFF::IMAGE_SCN_LNK_INFO);
718 }
719
720 // Debug info.
722 Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
726 Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
730 Ctx->getCOFFSection(".debug$H", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
733
734 DwarfAbbrevSection = Ctx->getCOFFSection(
735 ".debug_abbrev", COFF::IMAGE_SCN_MEM_DISCARDABLE |
738 DwarfInfoSection = Ctx->getCOFFSection(
739 ".debug_info", COFF::IMAGE_SCN_MEM_DISCARDABLE |
742 DwarfLineSection = Ctx->getCOFFSection(
743 ".debug_line", COFF::IMAGE_SCN_MEM_DISCARDABLE |
746 DwarfLineStrSection = Ctx->getCOFFSection(
747 ".debug_line_str", COFF::IMAGE_SCN_MEM_DISCARDABLE |
750 DwarfFrameSection = Ctx->getCOFFSection(
751 ".debug_frame", COFF::IMAGE_SCN_MEM_DISCARDABLE |
754 DwarfPubNamesSection = Ctx->getCOFFSection(
755 ".debug_pubnames", COFF::IMAGE_SCN_MEM_DISCARDABLE |
758 DwarfPubTypesSection = Ctx->getCOFFSection(
759 ".debug_pubtypes", COFF::IMAGE_SCN_MEM_DISCARDABLE |
762 DwarfGnuPubNamesSection = Ctx->getCOFFSection(
763 ".debug_gnu_pubnames", COFF::IMAGE_SCN_MEM_DISCARDABLE |
766 DwarfGnuPubTypesSection = Ctx->getCOFFSection(
767 ".debug_gnu_pubtypes", COFF::IMAGE_SCN_MEM_DISCARDABLE |
770 DwarfStrSection = Ctx->getCOFFSection(
771 ".debug_str", COFF::IMAGE_SCN_MEM_DISCARDABLE |
774 DwarfStrOffSection = Ctx->getCOFFSection(
775 ".debug_str_offsets", COFF::IMAGE_SCN_MEM_DISCARDABLE |
778 DwarfLocSection = Ctx->getCOFFSection(
779 ".debug_loc", COFF::IMAGE_SCN_MEM_DISCARDABLE |
782 DwarfLoclistsSection = Ctx->getCOFFSection(
783 ".debug_loclists", COFF::IMAGE_SCN_MEM_DISCARDABLE |
786 DwarfARangesSection = Ctx->getCOFFSection(
787 ".debug_aranges", COFF::IMAGE_SCN_MEM_DISCARDABLE |
790 DwarfRangesSection = Ctx->getCOFFSection(
791 ".debug_ranges", COFF::IMAGE_SCN_MEM_DISCARDABLE |
794 DwarfRnglistsSection = Ctx->getCOFFSection(
795 ".debug_rnglists", COFF::IMAGE_SCN_MEM_DISCARDABLE |
798 DwarfMacinfoSection = Ctx->getCOFFSection(
799 ".debug_macinfo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
802 DwarfMacroSection = Ctx->getCOFFSection(
803 ".debug_macro", COFF::IMAGE_SCN_MEM_DISCARDABLE |
806 DwarfMacinfoDWOSection = Ctx->getCOFFSection(
807 ".debug_macinfo.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
810 DwarfMacroDWOSection = Ctx->getCOFFSection(
811 ".debug_macro.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
814 DwarfInfoDWOSection = Ctx->getCOFFSection(
815 ".debug_info.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
818 DwarfTypesDWOSection = Ctx->getCOFFSection(
819 ".debug_types.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
822 DwarfAbbrevDWOSection = Ctx->getCOFFSection(
823 ".debug_abbrev.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
826 DwarfStrDWOSection = Ctx->getCOFFSection(
827 ".debug_str.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
830 DwarfLineDWOSection = Ctx->getCOFFSection(
831 ".debug_line.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
834 DwarfLocDWOSection = Ctx->getCOFFSection(
835 ".debug_loc.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
838 DwarfLoclistsDWOSection = Ctx->getCOFFSection(
839 ".debug_loclists.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
842 DwarfStrOffDWOSection = Ctx->getCOFFSection(
843 ".debug_str_offsets.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
846 DwarfRnglistsDWOSection = Ctx->getCOFFSection(
847 ".debug_rnglists.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
850 DwarfAddrSection = Ctx->getCOFFSection(
851 ".debug_addr", COFF::IMAGE_SCN_MEM_DISCARDABLE |
854 DwarfCUIndexSection = Ctx->getCOFFSection(
855 ".debug_cu_index", COFF::IMAGE_SCN_MEM_DISCARDABLE |
858 DwarfTUIndexSection = Ctx->getCOFFSection(
859 ".debug_tu_index", COFF::IMAGE_SCN_MEM_DISCARDABLE |
862 DwarfDebugNamesSection = Ctx->getCOFFSection(
863 ".debug_names", COFF::IMAGE_SCN_MEM_DISCARDABLE |
866 DwarfAccelNamesSection = Ctx->getCOFFSection(
867 ".apple_names", COFF::IMAGE_SCN_MEM_DISCARDABLE |
870 DwarfAccelNamespaceSection = Ctx->getCOFFSection(
871 ".apple_namespaces", COFF::IMAGE_SCN_MEM_DISCARDABLE |
874 DwarfAccelTypesSection = Ctx->getCOFFSection(
875 ".apple_types", COFF::IMAGE_SCN_MEM_DISCARDABLE |
878 DwarfAccelObjCSection = Ctx->getCOFFSection(
879 ".apple_objc", COFF::IMAGE_SCN_MEM_DISCARDABLE |
882
883 DrectveSection = Ctx->getCOFFSection(
885
887 Ctx->getCOFFSection(".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
889
891 Ctx->getCOFFSection(".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
893
894 SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO);
895
897 Ctx->getCOFFSection(".gehcont$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
899
901 Ctx->getCOFFSection(".gfids$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
903
905 Ctx->getCOFFSection(".giats$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
907
909 Ctx->getCOFFSection(".gljmp$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
911
912 TLSDataSection = Ctx->getCOFFSection(
915
916 StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
919
920 // Set IMAGE_SCN_MEM_DISCARDABLE so that lld will not truncate section name.
921 PseudoProbeSection = Ctx->getCOFFSection(
922 ".pseudo_probe", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
925 PseudoProbeDescSection = Ctx->getCOFFSection(
926 ".pseudo_probe_desc", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
929}
930
931void MCObjectFileInfo::initSPIRVMCObjectFileInfo(const Triple &T) {
932 // Put everything in a single binary section.
933 TextSection = Ctx->getSPIRVSection();
934}
935
936void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
937 TextSection = Ctx->getWasmSection(".text", SectionKind::getText());
938 DataSection = Ctx->getWasmSection(".data", SectionKind::getData());
939
941 Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());
943 Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata(),
945 DwarfStrSection = Ctx->getWasmSection(
948 Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());
950 Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata());
951 DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());
953 Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata());
955 Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata());
957 Ctx->getWasmSection(".debug_macro", SectionKind::getMetadata());
958 DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
959 DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
961 Ctx->getWasmSection(".debug_info", SectionKind::getMetadata());
962 DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());
963 DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
964 DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
966 Ctx->getWasmSection(".debug_gnu_pubnames", SectionKind::getMetadata());
968 Ctx->getWasmSection(".debug_gnu_pubtypes", SectionKind::getMetadata());
969
971 Ctx->getWasmSection(".debug_names", SectionKind::getMetadata());
973 Ctx->getWasmSection(".debug_str_offsets", SectionKind::getMetadata());
975 Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata());
977 Ctx->getWasmSection(".debug_rnglists", SectionKind::getMetadata());
979 Ctx->getWasmSection(".debug_loclists", SectionKind::getMetadata());
980
981 // Fission Sections
983 Ctx->getWasmSection(".debug_info.dwo", SectionKind::getMetadata());
985 Ctx->getWasmSection(".debug_types.dwo", SectionKind::getMetadata());
987 Ctx->getWasmSection(".debug_abbrev.dwo", SectionKind::getMetadata());
989 Ctx->getWasmSection(".debug_str.dwo", SectionKind::getMetadata(),
992 Ctx->getWasmSection(".debug_line.dwo", SectionKind::getMetadata());
994 Ctx->getWasmSection(".debug_loc.dwo", SectionKind::getMetadata());
996 Ctx->getWasmSection(".debug_str_offsets.dwo", SectionKind::getMetadata());
998 Ctx->getWasmSection(".debug_rnglists.dwo", SectionKind::getMetadata());
1000 Ctx->getWasmSection(".debug_macinfo.dwo", SectionKind::getMetadata());
1002 Ctx->getWasmSection(".debug_macro.dwo", SectionKind::getMetadata());
1003
1005 Ctx->getWasmSection(".debug_loclists.dwo", SectionKind::getMetadata());
1006
1007 // DWP Sections
1009 Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
1011 Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
1012
1013 // Wasm use data section for LSDA.
1014 // TODO Consider putting each function's exception table in a separate
1015 // section, as in -function-sections, to facilitate lld's --gc-section.
1016 LSDASection = Ctx->getWasmSection(".rodata.gcc_except_table",
1018
1019 // TODO: Define more sections.
1020}
1021
1022void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) {
1023 // The default csect for program code. Functions without a specified section
1024 // get placed into this csect. The choice of csect name is not a property of
1025 // the ABI or object file format, but various tools rely on the section
1026 // name being empty (considering named symbols to be "user symbol names").
1027 TextSection = Ctx->getXCOFFSection(
1028 "..text..", // Use a non-null name to work around an AIX assembler bug...
1030 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD),
1031 /* MultiSymbolsAllowed*/ true);
1032
1033 // ... but use a null name when generating the symbol table.
1034 MCSectionXCOFF *TS = static_cast<MCSectionXCOFF *>(TextSection);
1036 TS->setSymbolTableName("");
1037
1038 DataSection = Ctx->getXCOFFSection(
1039 ".data", SectionKind::getData(),
1040 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD),
1041 /* MultiSymbolsAllowed*/ true);
1042
1043 ReadOnlySection = Ctx->getXCOFFSection(
1044 ".rodata", SectionKind::getReadOnly(),
1045 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
1046 /* MultiSymbolsAllowed*/ true);
1047 ReadOnlySection->setAlignment(Align(4));
1048
1049 ReadOnly8Section = Ctx->getXCOFFSection(
1050 ".rodata.8", SectionKind::getReadOnly(),
1051 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
1052 /* MultiSymbolsAllowed*/ true);
1053 ReadOnly8Section->setAlignment(Align(8));
1054
1055 ReadOnly16Section = Ctx->getXCOFFSection(
1056 ".rodata.16", SectionKind::getReadOnly(),
1057 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
1058 /* MultiSymbolsAllowed*/ true);
1059 ReadOnly16Section->setAlignment(Align(16));
1060
1061 TLSDataSection = Ctx->getXCOFFSection(
1062 ".tdata", SectionKind::getThreadData(),
1063 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TL, XCOFF::XTY_SD),
1064 /* MultiSymbolsAllowed*/ true);
1065
1066 TOCBaseSection = Ctx->getXCOFFSection(
1067 "TOC", SectionKind::getData(),
1068 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TC0,
1069 XCOFF::XTY_SD));
1070
1071 // The TOC-base always has 0 size, but 4 byte alignment.
1072 TOCBaseSection->setAlignment(Align(4));
1073
1074 LSDASection = Ctx->getXCOFFSection(
1075 ".gcc_except_table", SectionKind::getReadOnly(),
1076 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO,
1077 XCOFF::XTY_SD));
1078
1079 CompactUnwindSection = Ctx->getXCOFFSection(
1080 ".eh_info_table", SectionKind::getData(),
1081 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW,
1082 XCOFF::XTY_SD));
1083
1084 // DWARF sections for XCOFF are not csects. They are special STYP_DWARF
1085 // sections, and the individual DWARF sections are distinguished by their
1086 // section subtype.
1087 DwarfAbbrevSection = Ctx->getXCOFFSection(
1088 ".dwabrev", SectionKind::getMetadata(),
1089 /* CsectProperties */ std::nullopt,
1090 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWABREV);
1091
1092 DwarfInfoSection = Ctx->getXCOFFSection(
1093 ".dwinfo", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1094 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWINFO);
1095
1096 DwarfLineSection = Ctx->getXCOFFSection(
1097 ".dwline", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1098 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWLINE);
1099
1100 DwarfFrameSection = Ctx->getXCOFFSection(
1101 ".dwframe", SectionKind::getMetadata(),
1102 /* CsectProperties */ std::nullopt,
1103 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWFRAME);
1104
1105 DwarfPubNamesSection = Ctx->getXCOFFSection(
1106 ".dwpbnms", SectionKind::getMetadata(),
1107 /* CsectProperties */ std::nullopt,
1108 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWPBNMS);
1109
1110 DwarfPubTypesSection = Ctx->getXCOFFSection(
1111 ".dwpbtyp", SectionKind::getMetadata(),
1112 /* CsectProperties */ std::nullopt,
1113 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWPBTYP);
1114
1115 DwarfStrSection = Ctx->getXCOFFSection(
1116 ".dwstr", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1117 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWSTR);
1118
1119 DwarfLocSection = Ctx->getXCOFFSection(
1120 ".dwloc", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1121 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWLOC);
1122
1123 DwarfARangesSection = Ctx->getXCOFFSection(
1124 ".dwarnge", SectionKind::getMetadata(),
1125 /* CsectProperties */ std::nullopt,
1126 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWARNGE);
1127
1128 DwarfRangesSection = Ctx->getXCOFFSection(
1129 ".dwrnges", SectionKind::getMetadata(),
1130 /* CsectProperties */ std::nullopt,
1131 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWRNGES);
1132
1133 DwarfMacinfoSection = Ctx->getXCOFFSection(
1134 ".dwmac", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1135 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWMAC);
1136}
1137
1138void MCObjectFileInfo::initDXContainerObjectFileInfo(const Triple &T) {
1139 // At the moment the DXBC section should end up empty.
1140 TextSection = Ctx->getDXContainerSection("DXBC", SectionKind::getText());
1141}
1142
1144
1146 bool LargeCodeModel) {
1147 PositionIndependent = PIC;
1148 Ctx = &MCCtx;
1149
1150 // Common.
1153
1155
1157
1158 EHFrameSection = nullptr; // Created on demand.
1159 SFrameSection = nullptr; // Created on demand.
1160 CompactUnwindSection = nullptr; // Used only by selected targets.
1161 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
1162 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
1163 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
1164 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
1165
1166 const Triple &TheTriple = Ctx->getTargetTriple();
1167 switch (Ctx->getObjectFileType()) {
1168 case MCContext::IsMachO:
1169 initMachOMCObjectFileInfo(TheTriple);
1170 break;
1171 case MCContext::IsCOFF:
1172 initCOFFMCObjectFileInfo(TheTriple);
1173 break;
1174 case MCContext::IsELF:
1175 initELFMCObjectFileInfo(TheTriple, LargeCodeModel);
1176 break;
1177 case MCContext::IsGOFF:
1178 initGOFFMCObjectFileInfo(TheTriple);
1179 break;
1180 case MCContext::IsSPIRV:
1181 initSPIRVMCObjectFileInfo(TheTriple);
1182 break;
1183 case MCContext::IsWasm:
1184 initWasmMCObjectFileInfo(TheTriple);
1185 break;
1186 case MCContext::IsXCOFF:
1187 initXCOFFMCObjectFileInfo(TheTriple);
1188 break;
1190 initDXContainerObjectFileInfo(TheTriple);
1191 break;
1192 }
1193}
1194
1195MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
1196 uint64_t Hash) const {
1197 switch (Ctx->getTargetTriple().getObjectFormat()) {
1198 case Triple::ELF:
1199 return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0,
1200 utostr(Hash), /*IsComdat=*/true);
1201 case Triple::Wasm:
1202 return Ctx->getWasmSection(Name, SectionKind::getMetadata(), 0,
1204 case Triple::MachO:
1205 case Triple::COFF:
1206 case Triple::GOFF:
1207 case Triple::SPIRV:
1208 case Triple::XCOFF:
1211 report_fatal_error("Cannot get DWARF comdat section for this object file "
1212 "format: not implemented.");
1213 break;
1214 }
1215 llvm_unreachable("Unknown ObjectFormatType");
1216}
1217
1218MCSection *
1220 if (Ctx->getObjectFileType() != MCContext::IsELF)
1221 return CallGraphSection;
1222
1223 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1224 unsigned Flags = ELF::SHF_LINK_ORDER;
1225 StringRef GroupName;
1226 if (const MCSymbol *Group = ElfSec.getGroup()) {
1227 GroupName = Group->getName();
1228 Flags |= ELF::SHF_GROUP;
1229 }
1230
1231 return Ctx->getELFSection(
1232 ".llvm.callgraph", ELF::SHT_LLVM_CALL_GRAPH, Flags, 0, GroupName,
1233 /*IsComdat=*/true, ElfSec.getUniqueID(),
1234 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1235}
1236
1237MCSection *
1239 if ((Ctx->getObjectFileType() != MCContext::IsELF) ||
1240 Ctx->getTargetTriple().isPS4())
1241 return StackSizesSection;
1242
1243 const MCSectionELF &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
1251 return Ctx->getELFSection(
1252 ".stack_sizes", ELF::SHT_PROGBITS, Flags, 0, GroupName, true,
1253 ElfSec.getUniqueID(),
1254 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1255}
1256
1257MCSection *
1259 if (Ctx->getObjectFileType() != MCContext::IsELF)
1260 return nullptr;
1261
1262 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1263 unsigned Flags = ELF::SHF_LINK_ORDER;
1264 StringRef GroupName;
1265 if (const MCSymbol *Group = ElfSec.getGroup()) {
1266 GroupName = Group->getName();
1267 Flags |= ELF::SHF_GROUP;
1268 }
1269
1270 // Use the text section's begin symbol and unique ID to create a separate
1271 // .llvm_bb_addr_map section associated with every unique text section.
1272 return Ctx->getELFSection(
1273 ".llvm_bb_addr_map", ELF::SHT_LLVM_BB_ADDR_MAP, Flags, 0, GroupName, true,
1274 ElfSec.getUniqueID(),
1275 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1276}
1277
1278MCSection *
1280 if (Ctx->getObjectFileType() != MCContext::IsELF)
1281 return nullptr;
1282
1283 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1284 unsigned Flags = ELF::SHF_LINK_ORDER | ELF::SHF_ALLOC;
1285 StringRef GroupName;
1286 if (const MCSymbol *Group = ElfSec.getGroup()) {
1287 GroupName = Group->getName();
1288 Flags |= ELF::SHF_GROUP;
1289 }
1290
1291 return Ctx->getELFSection(
1292 ".kcfi_traps", ELF::SHT_PROGBITS, Flags, 0, GroupName,
1293 /*IsComdat=*/true, ElfSec.getUniqueID(),
1294 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1295}
1296
1297MCSection *
1299 auto ObjFileType = Ctx->getObjectFileType();
1300 if (ObjFileType == MCContext::IsELF) {
1301 const auto &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1302 unsigned Flags = ELF::SHF_LINK_ORDER;
1303 StringRef GroupName;
1304 if (const MCSymbol *Group = ElfSec.getGroup()) {
1305 GroupName = Group->getName();
1306 Flags |= ELF::SHF_GROUP;
1307 }
1308 return Ctx->getELFSection(
1309 PseudoProbeSection->getName(), ELF::SHT_PROGBITS, Flags, 0, GroupName,
1310 true, ElfSec.getUniqueID(),
1311 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1312 } else if (ObjFileType == MCContext::IsCOFF) {
1313 StringRef COMDATSymName = "";
1314 int Selection = 0;
1315 unsigned Characteristics =
1316 static_cast<MCSectionCOFF *>(PseudoProbeSection)->getCharacteristics();
1317 const auto &COFFSec = static_cast<const MCSectionCOFF &>(TextSec);
1318 if (const MCSymbol *COMDATSym = COFFSec.getCOMDATSymbol()) {
1319 // Associate .pseudo_probe to its function section.
1320 COMDATSymName = COMDATSym->getName();
1321 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
1323 }
1324 return Ctx->getCOFFSection(PseudoProbeSection->getName(), Characteristics,
1325 COMDATSymName, Selection, COFFSec.getUniqueID());
1326 }
1327
1328 return PseudoProbeSection;
1329}
1330
1331MCSection *
1333 if (!Ctx->getTargetTriple().supportsCOMDAT() || FuncName.empty())
1335
1336 // Create a separate comdat group for each function's descriptor in order
1337 // for the linker to deduplicate. The duplication, must be from different
1338 // tranlation unit, can come from:
1339 // 1. Inline functions defined in header files;
1340 // 2. ThinLTO imported funcions;
1341 // 3. Weak-linkage definitions.
1342 // Use a concatenation of the section name and the function name as the
1343 // group name so that descriptor-only groups won't be folded with groups of
1344 // code.
1345 auto ObjFileType = Ctx->getObjectFileType();
1346 if (ObjFileType == MCContext::IsELF) {
1347 auto *S = static_cast<MCSectionELF *>(PseudoProbeDescSection);
1348 auto Flags = S->getFlags() | ELF::SHF_GROUP;
1349 return Ctx->getELFSection(S->getName(), S->getType(), Flags,
1350 S->getEntrySize(), S->getName() + "_" + FuncName,
1351 /*IsComdat=*/true);
1352 } else if (ObjFileType == MCContext::IsCOFF) {
1353 auto *S = static_cast<MCSectionCOFF *>(PseudoProbeDescSection);
1354 unsigned Characteristics =
1355 S->getCharacteristics() | COFF::IMAGE_SCN_LNK_COMDAT;
1356 std::string COMDATSymName = (S->getName() + "_" + FuncName).str();
1357 return Ctx->getCOFFSection(S->getName(), Characteristics, COMDATSymName,
1359 }
1360
1362}
1363
1367
1369 const MCSection *TextSec) const {
1370 if (Ctx->getObjectFileType() != MCContext::IsELF)
1371 return nullptr;
1372
1373 // SHF_WRITE for relocations, and let user post-process data in-place.
1375
1376 if (!TextSec)
1377 TextSec = getTextSection();
1378
1379 StringRef GroupName;
1380 const auto &ElfSec = static_cast<const MCSectionELF &>(*TextSec);
1381 if (const MCSymbol *Group = ElfSec.getGroup()) {
1382 GroupName = Group->getName();
1383 Flags |= ELF::SHF_GROUP;
1384 }
1385 return Ctx->getELFSection(
1386 Name, ELF::SHT_PROGBITS, Flags, 0, GroupName, true, ElfSec.getUniqueID(),
1387 static_cast<const MCSymbolELF *>(TextSec->getBeginSymbol()));
1388}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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...
This file contains the MCSymbolGOFF class.
#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
LLVM_ABI MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
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.
MCContext & getContext() const
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:516
static constexpr unsigned NonUniqueID
Definition MCSection.h:521
void setBeginSymbol(MCSymbol *Sym)
Definition MCSection.h:593
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:140
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
@ UnknownObjectFormat
Definition Triple.h:327
#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:1256
@ SHF_STRINGS
Definition ELF.h:1259
@ SHF_EXCLUDE
Definition ELF.h:1284
@ SHF_ALLOC
Definition ELF.h:1250
@ SHF_LINK_ORDER
Definition ELF.h:1265
@ SHF_GROUP
Definition ELF.h:1272
@ SHF_WRITE
Definition ELF.h:1247
@ SHF_TLS
Definition ELF.h:1275
@ SHF_EXECINSTR
Definition ELF.h:1253
@ SHT_PROGBITS
Definition ELF.h:1149
@ SHT_NOBITS
Definition ELF.h:1156
@ SHT_LLVM_CALL_GRAPH
Definition ELF.h:1192
@ SHT_MIPS_DWARF
Definition ELF.h:1228
@ SHT_LLVM_BB_ADDR_MAP
Definition ELF.h:1187
@ SHT_GNU_SFRAME
Definition ELF.h:1196
@ SHT_X86_64_UNWIND
Definition ELF.h:1224
@ 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.
Definition Types.h:26
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:163