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"
29#include "llvm/MC/SectionKind.h"
31
32using namespace llvm;
33
34static bool useCompactUnwind(const Triple &T) {
35 // Only on darwin.
36 if (!T.isOSDarwin())
37 return false;
38
39 // aarch64 always has it.
40 if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)
41 return true;
42
43 // armv7k always has it.
44 if (T.isWatchABI())
45 return true;
46
47 // Use it on newer version of OS X.
48 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
49 return true;
50
51 // And the iOS simulator.
52 if (T.isiOS() && T.isX86())
53 return true;
54
55 // The rest of the simulators always have it.
56 if (T.isSimulatorEnvironment())
57 return true;
58
59 // XROS always has it.
60 if (T.isXROS())
61 return true;
62
63 return false;
64}
65
66void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
67 EHFrameSection = Ctx->getMachOSection(
68 "__TEXT", "__eh_frame",
72
73 if (T.isOSDarwin() &&
74 (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32 ||
75 T.isSimulatorEnvironment()))
77
78 switch (Ctx->emitDwarfUnwindInfo()) {
81 break;
84 break;
88 break;
89 }
90
92
93 TextSection // .text
94 = Ctx->getMachOSection("__TEXT", "__text",
97 DataSection // .data
98 = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
99
100 // BSSSection might not be expected initialized on msvc.
101 BSSSection = nullptr;
102
103 TLSDataSection // .tdata
104 = Ctx->getMachOSection("__DATA", "__thread_data",
107 TLSBSSSection // .tbss
108 = Ctx->getMachOSection("__DATA", "__thread_bss",
111
112 // TODO: Verify datarel below.
113 TLSTLVSection // .tlv
114 = Ctx->getMachOSection("__DATA", "__thread_vars",
117
118 TLSThreadInitSection = Ctx->getMachOSection(
119 "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
121
122 CStringSection // .cstring
123 = Ctx->getMachOSection("__TEXT", "__cstring",
127 = Ctx->getMachOSection("__TEXT","__ustring", 0,
129 FourByteConstantSection // .literal4
130 = Ctx->getMachOSection("__TEXT", "__literal4",
133 EightByteConstantSection // .literal8
134 = Ctx->getMachOSection("__TEXT", "__literal8",
137
138 SixteenByteConstantSection // .literal16
139 = Ctx->getMachOSection("__TEXT", "__literal16",
142
143 ReadOnlySection // .const
144 = Ctx->getMachOSection("__TEXT", "__const", 0,
146
147 // If the target is not powerpc, map the coal sections to the non-coal
148 // sections.
149 //
150 // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
151 // "__TEXT/__const_coal" => section "__TEXT/__const"
152 // "__DATA/__datacoal_nt" => section "__DATA/__data"
153 Triple::ArchType ArchTy = T.getArch();
154
155 ConstDataSection // .const_data
156 = Ctx->getMachOSection("__DATA", "__const", 0,
158
159 if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
161 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
166 = Ctx->getMachOSection("__TEXT", "__const_coal",
169 DataCoalSection = Ctx->getMachOSection(
170 "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());
172 } else {
177 }
178
180 = Ctx->getMachOSection("__DATA","__common",
184 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
186
187
189 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
193 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
196
198 = Ctx->getMachOSection("__DATA", "__thread_ptr",
201
202 AddrSigSection = Ctx->getMachOSection("__DATA", "__llvm_addrsig", 0,
204
205 // Exception Handling.
206 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
208
209 COFFDebugSymbolsSection = nullptr;
210 COFFDebugTypesSection = nullptr;
212
213 if (useCompactUnwind(T)) {
215 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
217
218 if (T.isX86())
219 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF
220 else if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)
221 CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF
222 else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
223 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF
224 }
225
226 // Debug Information.
228 Ctx->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG,
229 SectionKind::getMetadata(), "debug_names_begin");
231 Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
232 SectionKind::getMetadata(), "names_begin");
234 Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
235 SectionKind::getMetadata(), "objc_begin");
236 // 16 character section limit...
238 Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
239 SectionKind::getMetadata(), "namespac_begin");
241 Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
242 SectionKind::getMetadata(), "types_begin");
243
245 Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG,
247
249 Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
250 SectionKind::getMetadata(), "section_abbrev");
252 Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
253 SectionKind::getMetadata(), "section_info");
255 Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
256 SectionKind::getMetadata(), "section_line");
258 Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,
259 SectionKind::getMetadata(), "section_line_str");
261 Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
262 SectionKind::getMetadata(), "section_frame");
264 Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
267 Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
270 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
273 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
276 Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
277 SectionKind::getMetadata(), "info_string");
279 Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG,
280 SectionKind::getMetadata(), "section_str_off");
282 Ctx->getMachOSection("__DWARF", "__debug_addr", MachO::S_ATTR_DEBUG,
283 SectionKind::getMetadata(), "section_info");
285 Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
286 SectionKind::getMetadata(), "section_debug_loc");
288 Ctx->getMachOSection("__DWARF", "__debug_loclists", MachO::S_ATTR_DEBUG,
289 SectionKind::getMetadata(), "section_debug_loc");
290
292 Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
295 Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
296 SectionKind::getMetadata(), "debug_range");
298 Ctx->getMachOSection("__DWARF", "__debug_rnglists", MachO::S_ATTR_DEBUG,
299 SectionKind::getMetadata(), "debug_range");
301 Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG,
302 SectionKind::getMetadata(), "debug_macinfo");
304 Ctx->getMachOSection("__DWARF", "__debug_macro", MachO::S_ATTR_DEBUG,
305 SectionKind::getMetadata(), "debug_macro");
307 Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
310 Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,
313 Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG,
315 StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
317
318 FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
320
321 RemarksSection = Ctx->getMachOSection(
322 "__LLVM", "__remarks", MachO::S_ATTR_DEBUG, SectionKind::getMetadata());
323
325 Ctx->getMachOSection("__PSEUDO_PROBE", "__probes",
329 Ctx->getMachOSection("__PSEUDO_PROBE", "__probe_descs",
332
333 // The architecture of dsymutil makes it very difficult to copy the Swift
334 // reflection metadata sections into the __TEXT segment, so dsymutil creates
335 // these sections in the __DWARF segment instead.
336 if (!Ctx->getSwift5ReflectionSegmentName().empty()) {
337#define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) \
338 Swift5ReflectionSections \
339 [llvm::binaryformat::Swift5ReflectionSectionKind::KIND] = \
340 Ctx->getMachOSection(Ctx->getSwift5ReflectionSegmentName().data(), \
341 MACHO, 0, SectionKind::getMetadata());
342#include "llvm/BinaryFormat/Swift.def"
343 }
344
346}
347
348void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
349 switch (T.getArch()) {
350 case Triple::mips:
351 case Triple::mipsel:
352 case Triple::mips64:
353 case Triple::mips64el:
354 // We cannot use DW_EH_PE_sdata8 for the large PositionIndependent case
355 // since there is no R_MIPS_PC64 relocation (only a 32-bit version).
356 // In fact DW_EH_PE_sdata4 is enough for us now, and GNU ld doesn't
357 // support pcrel|sdata8 well. Let's use sdata4 for now.
358 if (PositionIndependent)
360 else
361 FDECFIEncoding = Ctx->getAsmInfo().getCodePointerSize() == 4
364 break;
365 case Triple::ppc64:
366 case Triple::ppc64le:
367 case Triple::aarch64:
369 case Triple::x86_64:
372 break;
373 case Triple::bpfel:
374 case Triple::bpfeb:
376 break;
377 case Triple::hexagon:
379 PositionIndependent ? dwarf::DW_EH_PE_pcrel : dwarf::DW_EH_PE_absptr;
380 break;
381 case Triple::xtensa:
383 break;
384 default:
386 break;
387 }
388
389 unsigned EHSectionType = T.getArch() == Triple::x86_64
392 switch (T.getArch()) {
393 case Triple::x86_64:
394 SFrameABIArch = sframe::ABI::AMD64EndianLittle;
395 break;
396 case Triple::aarch64:
397 SFrameABIArch = sframe::ABI::AArch64EndianLittle;
398 break;
400 SFrameABIArch = sframe::ABI::AArch64EndianBig;
401 break;
402 default:
403 break;
404 }
405
406 // Solaris requires different flags for .eh_frame to seemingly every other
407 // platform.
408 unsigned EHSectionFlags = ELF::SHF_ALLOC;
409 if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
410 EHSectionFlags |= ELF::SHF_WRITE;
411
412 // ELF
413 BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
415
416 TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
418
419 DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
421
423 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
424
426 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
428
429 TLSBSSSection = Ctx->getELFSection(
431
432 DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
434
435 unsigned MergeableCstFlags = ELF::SHF_ALLOC | ELF::SHF_MERGE;
436 StringRef CstPrefix = ".rodata";
437 if (Large && T.getArch() == Triple::x86_64) {
438 MergeableCstFlags |= ELF::SHF_X86_64_LARGE;
439 CstPrefix = ".lrodata";
440 }
441
442 MergeableConst4Section = Ctx->getELFSection(
443 (CstPrefix + ".cst4").str(), ELF::SHT_PROGBITS, MergeableCstFlags, 4);
444
445 MergeableConst8Section = Ctx->getELFSection(
446 (CstPrefix + ".cst8").str(), ELF::SHT_PROGBITS, MergeableCstFlags, 8);
447
448 MergeableConst16Section = Ctx->getELFSection(
449 (CstPrefix + ".cst16").str(), ELF::SHT_PROGBITS, MergeableCstFlags, 16);
450
451 MergeableConst32Section = Ctx->getELFSection(
452 (CstPrefix + ".cst32").str(), ELF::SHT_PROGBITS, MergeableCstFlags, 32);
453
454 // Exception Handling Sections.
455
456 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
457 // it contains relocatable pointers. In PIC mode, this is probably a big
458 // runtime hit for C++ apps. Either the contents of the LSDA need to be
459 // adjusted or this should be a data section.
460 LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
462
463 COFFDebugSymbolsSection = nullptr;
464 COFFDebugTypesSection = nullptr;
465
466 unsigned DebugSecType = ELF::SHT_PROGBITS;
467
468 // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
469 // to distinguish among sections contain DWARF and ECOFF debug formats.
470 // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
471 if (T.isMIPS())
472 DebugSecType = ELF::SHT_MIPS_DWARF;
473
474 // Debug Info Sections.
476 Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);
477 DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0);
478 DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0);
480 Ctx->getELFSection(".debug_line_str", DebugSecType,
482 DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0);
484 Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);
486 Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);
488 Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);
490 Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);
492 Ctx->getELFSection(".debug_str", DebugSecType,
494 DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0);
496 Ctx->getELFSection(".debug_aranges", DebugSecType, 0);
498 Ctx->getELFSection(".debug_ranges", DebugSecType, 0);
500 Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);
501 DwarfMacroSection = Ctx->getELFSection(".debug_macro", DebugSecType, 0);
502
503 // DWARF5 Experimental Debug Info
504
505 // Accelerator Tables
507 Ctx->getELFSection(".debug_names", ELF::SHT_PROGBITS, 0);
509 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);
511 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);
513 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);
515 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);
516
517 // String Offset and Address Sections
519 Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);
520 DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);
521 DwarfRnglistsSection = Ctx->getELFSection(".debug_rnglists", DebugSecType, 0);
522 DwarfLoclistsSection = Ctx->getELFSection(".debug_loclists", DebugSecType, 0);
523
524 // Fission Sections
526 Ctx->getELFSection(".debug_info.dwo", DebugSecType, ELF::SHF_EXCLUDE);
528 Ctx->getELFSection(".debug_types.dwo", DebugSecType, ELF::SHF_EXCLUDE);
530 Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, ELF::SHF_EXCLUDE);
531 DwarfStrDWOSection = Ctx->getELFSection(
532 ".debug_str.dwo", DebugSecType,
535 Ctx->getELFSection(".debug_line.dwo", DebugSecType, ELF::SHF_EXCLUDE);
537 Ctx->getELFSection(".debug_loc.dwo", DebugSecType, ELF::SHF_EXCLUDE);
538 DwarfStrOffDWOSection = Ctx->getELFSection(".debug_str_offsets.dwo",
539 DebugSecType, ELF::SHF_EXCLUDE);
541 Ctx->getELFSection(".debug_rnglists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
543 Ctx->getELFSection(".debug_macinfo.dwo", DebugSecType, ELF::SHF_EXCLUDE);
545 Ctx->getELFSection(".debug_macro.dwo", DebugSecType, ELF::SHF_EXCLUDE);
546
548 Ctx->getELFSection(".debug_loclists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
549
550 // DWP Sections
552 Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);
554 Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);
555
557 Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
558
560 Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
561
563 Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
564
566 Ctx->getELFSection(".sframe", ELF::SHT_GNU_SFRAME, ELF::SHF_ALLOC);
567
569 Ctx->getELFSection(".llvm.callgraph", ELF::SHT_LLVM_CALL_GRAPH, 0);
570
571 StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);
572
573 PseudoProbeSection = Ctx->getELFSection(".pseudo_probe", DebugSecType, 0);
575 Ctx->getELFSection(".pseudo_probe_desc", DebugSecType, 0);
576
577 LLVMStatsSection = Ctx->getELFSection(".llvm_stats", ELF::SHT_PROGBITS, 0);
578}
579
580void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) {
581 MCSectionGOFF *RootSDSection = Ctx->getGOFFSection(
584
585 MCSectionGOFF *ADAEDSection = Ctx->getGOFFSection(
587 GOFF::EDAttr{false, GOFF::ESD_RMODE_64, GOFF::ESD_NS_Parts,
591 RootSDSection);
592 ADASection = Ctx->getGOFFSection(SectionKind::getData(), "#S",
593 GOFF::PRAttr{false, GOFF::ESD_EXE_DATA,
596 ADAEDSection);
597
598 TextSection = Ctx->getGOFFSection(
604 RootSDSection);
605
606 MCSectionGOFF *PPA2ListEDSection = Ctx->getGOFFSection(
608 GOFF::EDAttr{true, GOFF::ESD_RMODE_64, GOFF::ESD_NS_Parts,
612 RootSDSection);
613 PPA2ListSection = Ctx->getGOFFSection(SectionKind::getData(), ".&ppa2",
614 GOFF::PRAttr{true, GOFF::ESD_EXE_DATA,
617 PPA2ListEDSection);
618
619 IDRLSection = Ctx->getGOFFSection(
620 SectionKind::getData(), "B_IDRL",
625 RootSDSection);
626
627 // Debug Info Sections. The ED name is the same used by the XL compiler.
628 auto InitDebugSection = [this,
629 RootSDSection](StringRef EDName,
630 StringRef LDName) -> MCSectionGOFF * {
631 MCSectionGOFF *ED = Ctx->getGOFFSection(
632 SectionKind::getMetadata(), EDName,
633 GOFF::EDAttr{false, GOFF::ESD_RMODE_64, GOFF::ESD_NS_Parts,
637 RootSDSection);
638 // At least for llc, this function is called twice! (See function
639 // compileModule() in llc.cpp). Since the context is not cleared, the
640 // already allocated section is returned above. We only add the begin symbol
641 // if it is not yet set to avoid an assertion.
642 MCSymbolGOFF *LD = static_cast<MCSymbolGOFF *>(ED->getBeginSymbol());
643 if (!LD) {
644 LD = static_cast<MCSymbolGOFF *>(getContext().getOrCreateSymbol(LDName));
645 LD->setCodeData(GOFF::ESD_EXE_DATA);
646 LD->setWeak(false);
647 LD->setLinkage(GOFF::ESD_LT_XPLink);
648 LD->setExternal(false);
649 ED->setBeginSymbol(LD);
650 } else
651 assert(LD->getName() == LDName && "Wrong label name");
652 return ED;
653 };
654 DwarfAbbrevSection = InitDebugSection("D_ABREV", ".debug_abbrev");
655 DwarfInfoSection = InitDebugSection("D_INFO", ".debug_info");
656 DwarfLineSection = InitDebugSection("D_LINE", ".debug_line");
657 DwarfFrameSection = InitDebugSection("D_FRAME", ".debug_frame");
658 DwarfPubNamesSection = InitDebugSection("D_PBNMS", ".debug_pubnames");
659 DwarfPubTypesSection = InitDebugSection("D_PTYPES", ".debug_pubtypes");
660 DwarfStrSection = InitDebugSection("D_STR", ".debug_str");
661 DwarfLocSection = InitDebugSection("D_LOC", ".debug_loc");
662 DwarfARangesSection = InitDebugSection("D_ARNGE", ".debug_aranges");
663 DwarfRangesSection = InitDebugSection("D_RNGES", ".debug_ranges");
664 DwarfMacinfoSection = InitDebugSection("D_MACIN", ".debug_macinfo");
665
666 // DWARF 5 sections.
667 DwarfDebugNamesSection = InitDebugSection("D_NAMES", ".debug_names");
668 DwarfStrOffSection = InitDebugSection("D_STROFFS", ".debug_str_offsets");
669 DwarfAddrSection = InitDebugSection("D_ADDR", ".debug_addr");
670 DwarfRnglistsSection = InitDebugSection("D_RNGLISTS", ".debug_rnglists");
671 DwarfLoclistsSection = InitDebugSection("D_LOCLISTS", ".debug_loclists");
672 DwarfLineStrSection = InitDebugSection("D_LINESTR", ".debug_line_str");
673
674 // Special GNU sections.
675 DwarfGnuPubNamesSection = InitDebugSection("D_GPBNMS", ".debug_gnu_pubnames");
677 InitDebugSection("D_GPTYPES", ".debug_gnu_pubtypes");
678
679 // Accelerator Tables.
680 DwarfAccelNamesSection = InitDebugSection("D_APPLNMS", ".apple_names");
682 InitDebugSection("D_APPLNMSP", ".apple_namespaces");
683 DwarfAccelTypesSection = InitDebugSection("D_APPLTYPS", ".apple_types");
684 DwarfAccelObjCSection = InitDebugSection("D_APPLOBJC", ".apple_objc");
685}
686
687void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
689 Ctx->getCOFFSection(".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
691
692 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
693 // used to indicate to the linker that the text segment contains thumb instructions
694 // and to set the ISA selection bit for calls accordingly.
695 const bool IsThumb = T.getArch() == Triple::thumb;
696
697 // COFF
698 BSSSection = Ctx->getCOFFSection(
701 TextSection = Ctx->getCOFFSection(
702 ".text",
706 DataSection = Ctx->getCOFFSection(
710 Ctx->getCOFFSection(".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
712
713 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64 ||
714 T.getArch() == Triple::arm || T.getArch() == Triple::thumb) {
715 // On Windows with SEH, the LSDA is emitted into the .xdata section
716 LSDASection = nullptr;
717 } else {
718 LSDASection = Ctx->getCOFFSection(".gcc_except_table",
721 }
722
723 if (T.getArch() == Triple::aarch64) {
725 Ctx->getCOFFSection(".impcall", COFF::IMAGE_SCN_LNK_INFO);
726 } else if (T.getArch() == Triple::x86_64) {
727 // Import Call Optimization on x64 leverages the same metadata as the
728 // retpoline mitigation, hence the unusual section name.
730 Ctx->getCOFFSection(".retplne", COFF::IMAGE_SCN_LNK_INFO);
731 }
732
733 // Debug info.
735 Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
739 Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
743 Ctx->getCOFFSection(".debug$H", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
746
747 DwarfAbbrevSection = Ctx->getCOFFSection(
748 ".debug_abbrev", COFF::IMAGE_SCN_MEM_DISCARDABLE |
751 DwarfInfoSection = Ctx->getCOFFSection(
752 ".debug_info", COFF::IMAGE_SCN_MEM_DISCARDABLE |
755 DwarfLineSection = Ctx->getCOFFSection(
756 ".debug_line", COFF::IMAGE_SCN_MEM_DISCARDABLE |
759 DwarfLineStrSection = Ctx->getCOFFSection(
760 ".debug_line_str", COFF::IMAGE_SCN_MEM_DISCARDABLE |
763 DwarfFrameSection = Ctx->getCOFFSection(
764 ".debug_frame", COFF::IMAGE_SCN_MEM_DISCARDABLE |
767 DwarfPubNamesSection = Ctx->getCOFFSection(
768 ".debug_pubnames", COFF::IMAGE_SCN_MEM_DISCARDABLE |
771 DwarfPubTypesSection = Ctx->getCOFFSection(
772 ".debug_pubtypes", COFF::IMAGE_SCN_MEM_DISCARDABLE |
775 DwarfGnuPubNamesSection = Ctx->getCOFFSection(
776 ".debug_gnu_pubnames", COFF::IMAGE_SCN_MEM_DISCARDABLE |
779 DwarfGnuPubTypesSection = Ctx->getCOFFSection(
780 ".debug_gnu_pubtypes", COFF::IMAGE_SCN_MEM_DISCARDABLE |
783 DwarfStrSection = Ctx->getCOFFSection(
784 ".debug_str", COFF::IMAGE_SCN_MEM_DISCARDABLE |
787 DwarfStrOffSection = Ctx->getCOFFSection(
788 ".debug_str_offsets", COFF::IMAGE_SCN_MEM_DISCARDABLE |
791 DwarfLocSection = Ctx->getCOFFSection(
792 ".debug_loc", COFF::IMAGE_SCN_MEM_DISCARDABLE |
795 DwarfLoclistsSection = Ctx->getCOFFSection(
796 ".debug_loclists", COFF::IMAGE_SCN_MEM_DISCARDABLE |
799 DwarfARangesSection = Ctx->getCOFFSection(
800 ".debug_aranges", COFF::IMAGE_SCN_MEM_DISCARDABLE |
803 DwarfRangesSection = Ctx->getCOFFSection(
804 ".debug_ranges", COFF::IMAGE_SCN_MEM_DISCARDABLE |
807 DwarfRnglistsSection = Ctx->getCOFFSection(
808 ".debug_rnglists", COFF::IMAGE_SCN_MEM_DISCARDABLE |
811 DwarfMacinfoSection = Ctx->getCOFFSection(
812 ".debug_macinfo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
815 DwarfMacroSection = Ctx->getCOFFSection(
816 ".debug_macro", COFF::IMAGE_SCN_MEM_DISCARDABLE |
819 DwarfMacinfoDWOSection = Ctx->getCOFFSection(
820 ".debug_macinfo.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
824 DwarfMacroDWOSection = Ctx->getCOFFSection(
825 ".debug_macro.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
829 DwarfInfoDWOSection = Ctx->getCOFFSection(
830 ".debug_info.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
834 DwarfTypesDWOSection = Ctx->getCOFFSection(
835 ".debug_types.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
839 DwarfAbbrevDWOSection = Ctx->getCOFFSection(
840 ".debug_abbrev.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
844 DwarfStrDWOSection = Ctx->getCOFFSection(
845 ".debug_str.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
849 DwarfLineDWOSection = Ctx->getCOFFSection(
850 ".debug_line.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
854 DwarfLocDWOSection = Ctx->getCOFFSection(
855 ".debug_loc.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
859 DwarfLoclistsDWOSection = Ctx->getCOFFSection(
860 ".debug_loclists.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
864 DwarfStrOffDWOSection = Ctx->getCOFFSection(
865 ".debug_str_offsets.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
869 DwarfRnglistsDWOSection = Ctx->getCOFFSection(
870 ".debug_rnglists.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
874 DwarfAddrSection = Ctx->getCOFFSection(
875 ".debug_addr", COFF::IMAGE_SCN_MEM_DISCARDABLE |
878 DwarfCUIndexSection = Ctx->getCOFFSection(
879 ".debug_cu_index", COFF::IMAGE_SCN_MEM_DISCARDABLE |
882 DwarfTUIndexSection = Ctx->getCOFFSection(
883 ".debug_tu_index", COFF::IMAGE_SCN_MEM_DISCARDABLE |
886 DwarfDebugNamesSection = Ctx->getCOFFSection(
887 ".debug_names", COFF::IMAGE_SCN_MEM_DISCARDABLE |
890 DwarfAccelNamesSection = Ctx->getCOFFSection(
891 ".apple_names", COFF::IMAGE_SCN_MEM_DISCARDABLE |
894 DwarfAccelNamespaceSection = Ctx->getCOFFSection(
895 ".apple_namespaces", COFF::IMAGE_SCN_MEM_DISCARDABLE |
898 DwarfAccelTypesSection = Ctx->getCOFFSection(
899 ".apple_types", COFF::IMAGE_SCN_MEM_DISCARDABLE |
902 DwarfAccelObjCSection = Ctx->getCOFFSection(
903 ".apple_objc", COFF::IMAGE_SCN_MEM_DISCARDABLE |
906
907 DrectveSection = Ctx->getCOFFSection(
909
911 Ctx->getCOFFSection(".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
913
915 Ctx->getCOFFSection(".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
917
918 SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO);
919
921 Ctx->getCOFFSection(".gehcont$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
923
925 Ctx->getCOFFSection(".gfids$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
927
929 Ctx->getCOFFSection(".giats$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
931
933 Ctx->getCOFFSection(".gljmp$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
935
936 TLSDataSection = Ctx->getCOFFSection(
939
940 StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
943
944 // Set IMAGE_SCN_MEM_DISCARDABLE so that lld will not truncate section name.
945 PseudoProbeSection = Ctx->getCOFFSection(
946 ".pseudo_probe", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
949 PseudoProbeDescSection = Ctx->getCOFFSection(
950 ".pseudo_probe_desc", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
953}
954
955void MCObjectFileInfo::initSPIRVMCObjectFileInfo(const Triple &T) {
956 // Put everything in a single binary section.
957 TextSection = Ctx->getSPIRVSection();
958}
959
960void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
961 TextSection = Ctx->getWasmSection(".text", SectionKind::getText());
962 DataSection = Ctx->getWasmSection(".data", SectionKind::getData());
963
965 Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());
967 Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata(),
969 DwarfStrSection = Ctx->getWasmSection(
972 Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());
974 Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata());
975 DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());
977 Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata());
979 Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata());
981 Ctx->getWasmSection(".debug_macro", SectionKind::getMetadata());
982 DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
983 DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
985 Ctx->getWasmSection(".debug_info", SectionKind::getMetadata());
986 DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());
987 DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
988 DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
990 Ctx->getWasmSection(".debug_gnu_pubnames", SectionKind::getMetadata());
992 Ctx->getWasmSection(".debug_gnu_pubtypes", SectionKind::getMetadata());
993
995 Ctx->getWasmSection(".debug_names", SectionKind::getMetadata());
997 Ctx->getWasmSection(".debug_str_offsets", SectionKind::getMetadata());
999 Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata());
1001 Ctx->getWasmSection(".debug_rnglists", SectionKind::getMetadata());
1003 Ctx->getWasmSection(".debug_loclists", SectionKind::getMetadata());
1004
1005 // Fission Sections
1007 Ctx->getWasmSection(".debug_info.dwo", SectionKind::getMetadata());
1009 Ctx->getWasmSection(".debug_types.dwo", SectionKind::getMetadata());
1011 Ctx->getWasmSection(".debug_abbrev.dwo", SectionKind::getMetadata());
1013 Ctx->getWasmSection(".debug_str.dwo", SectionKind::getMetadata(),
1016 Ctx->getWasmSection(".debug_line.dwo", SectionKind::getMetadata());
1018 Ctx->getWasmSection(".debug_loc.dwo", SectionKind::getMetadata());
1020 Ctx->getWasmSection(".debug_str_offsets.dwo", SectionKind::getMetadata());
1022 Ctx->getWasmSection(".debug_rnglists.dwo", SectionKind::getMetadata());
1024 Ctx->getWasmSection(".debug_macinfo.dwo", SectionKind::getMetadata());
1026 Ctx->getWasmSection(".debug_macro.dwo", SectionKind::getMetadata());
1027
1029 Ctx->getWasmSection(".debug_loclists.dwo", SectionKind::getMetadata());
1030
1031 // DWP Sections
1033 Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
1035 Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
1036
1037 // Wasm use data section for LSDA.
1038 // TODO Consider putting each function's exception table in a separate
1039 // section, as in -function-sections, to facilitate lld's --gc-section.
1040 LSDASection = Ctx->getWasmSection(".rodata.gcc_except_table",
1042
1043 // TODO: Define more sections.
1044}
1045
1046void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) {
1047 // The default csect for program code. Functions without a specified section
1048 // get placed into this csect. The choice of csect name is not a property of
1049 // the ABI or object file format, but various tools rely on the section
1050 // name being empty (considering named symbols to be "user symbol names").
1051 TextSection = Ctx->getXCOFFSection(
1052 "..text..", // Use a non-null name to work around an AIX assembler bug...
1054 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD),
1055 /* MultiSymbolsAllowed*/ true);
1056
1057 // ... but use a null name when generating the symbol table.
1058 MCSectionXCOFF *TS = static_cast<MCSectionXCOFF *>(TextSection);
1060 TS->setSymbolTableName("");
1061
1062 DataSection = Ctx->getXCOFFSection(
1063 ".data", SectionKind::getData(),
1064 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD),
1065 /* MultiSymbolsAllowed*/ true);
1066
1067 ReadOnlySection = Ctx->getXCOFFSection(
1068 ".rodata", SectionKind::getReadOnly(),
1069 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
1070 /* MultiSymbolsAllowed*/ true);
1071 ReadOnlySection->setAlignment(Align(4));
1072
1073 ReadOnly8Section = Ctx->getXCOFFSection(
1074 ".rodata.8", SectionKind::getReadOnly(),
1075 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
1076 /* MultiSymbolsAllowed*/ true);
1077 ReadOnly8Section->setAlignment(Align(8));
1078
1079 ReadOnly16Section = Ctx->getXCOFFSection(
1080 ".rodata.16", SectionKind::getReadOnly(),
1081 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
1082 /* MultiSymbolsAllowed*/ true);
1083 ReadOnly16Section->setAlignment(Align(16));
1084
1085 TLSDataSection = Ctx->getXCOFFSection(
1086 ".tdata", SectionKind::getThreadData(),
1087 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TL, XCOFF::XTY_SD),
1088 /* MultiSymbolsAllowed*/ true);
1089
1090 TOCBaseSection = Ctx->getXCOFFSection(
1091 "TOC", SectionKind::getData(),
1092 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TC0,
1093 XCOFF::XTY_SD));
1094
1095 // The TOC-base always has 0 size, but 4 byte alignment.
1096 TOCBaseSection->setAlignment(Align(4));
1097
1098 LSDASection = Ctx->getXCOFFSection(
1099 ".gcc_except_table", SectionKind::getReadOnly(),
1100 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO,
1101 XCOFF::XTY_SD));
1102
1103 CompactUnwindSection = Ctx->getXCOFFSection(
1104 ".eh_info_table", SectionKind::getData(),
1105 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW,
1106 XCOFF::XTY_SD));
1107
1108 // DWARF sections for XCOFF are not csects. They are special STYP_DWARF
1109 // sections, and the individual DWARF sections are distinguished by their
1110 // section subtype.
1111 DwarfAbbrevSection = Ctx->getXCOFFSection(
1112 ".dwabrev", SectionKind::getMetadata(),
1113 /* CsectProperties */ std::nullopt,
1114 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWABREV);
1115
1116 DwarfInfoSection = Ctx->getXCOFFSection(
1117 ".dwinfo", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1118 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWINFO);
1119
1120 DwarfLineSection = Ctx->getXCOFFSection(
1121 ".dwline", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1122 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWLINE);
1123
1124 DwarfFrameSection = Ctx->getXCOFFSection(
1125 ".dwframe", SectionKind::getMetadata(),
1126 /* CsectProperties */ std::nullopt,
1127 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWFRAME);
1128
1129 DwarfPubNamesSection = Ctx->getXCOFFSection(
1130 ".dwpbnms", SectionKind::getMetadata(),
1131 /* CsectProperties */ std::nullopt,
1132 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWPBNMS);
1133
1134 DwarfPubTypesSection = Ctx->getXCOFFSection(
1135 ".dwpbtyp", SectionKind::getMetadata(),
1136 /* CsectProperties */ std::nullopt,
1137 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWPBTYP);
1138
1139 DwarfStrSection = Ctx->getXCOFFSection(
1140 ".dwstr", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1141 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWSTR);
1142
1143 DwarfLocSection = Ctx->getXCOFFSection(
1144 ".dwloc", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1145 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWLOC);
1146
1147 DwarfARangesSection = Ctx->getXCOFFSection(
1148 ".dwarnge", SectionKind::getMetadata(),
1149 /* CsectProperties */ std::nullopt,
1150 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWARNGE);
1151
1152 DwarfRangesSection = Ctx->getXCOFFSection(
1153 ".dwrnges", SectionKind::getMetadata(),
1154 /* CsectProperties */ std::nullopt,
1155 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWRNGES);
1156
1157 DwarfMacinfoSection = Ctx->getXCOFFSection(
1158 ".dwmac", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1159 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWMAC);
1160}
1161
1162void MCObjectFileInfo::initDXContainerObjectFileInfo(const Triple &T) {
1163 // At the moment the DXBC section should end up empty.
1164 TextSection = Ctx->getDXContainerSection("DXBC", SectionKind::getText());
1165}
1166
1168
1170 bool LargeCodeModel) {
1171 PositionIndependent = PIC;
1172 Ctx = &MCCtx;
1173
1174 // Common.
1177
1179
1181
1182 EHFrameSection = nullptr; // Created on demand.
1183 SFrameSection = nullptr; // Created on demand.
1184 CompactUnwindSection = nullptr; // Used only by selected targets.
1185 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
1186 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
1187 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
1188 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
1189
1190 const Triple &TheTriple = Ctx->getTargetTriple();
1191 switch (Ctx->getObjectFileType()) {
1192 case MCContext::IsMachO:
1193 initMachOMCObjectFileInfo(TheTriple);
1194 break;
1195 case MCContext::IsCOFF:
1196 initCOFFMCObjectFileInfo(TheTriple);
1197 break;
1198 case MCContext::IsELF:
1199 initELFMCObjectFileInfo(TheTriple, LargeCodeModel);
1200 break;
1201 case MCContext::IsGOFF:
1202 initGOFFMCObjectFileInfo(TheTriple);
1203 break;
1204 case MCContext::IsSPIRV:
1205 initSPIRVMCObjectFileInfo(TheTriple);
1206 break;
1207 case MCContext::IsWasm:
1208 initWasmMCObjectFileInfo(TheTriple);
1209 break;
1210 case MCContext::IsXCOFF:
1211 initXCOFFMCObjectFileInfo(TheTriple);
1212 break;
1214 initDXContainerObjectFileInfo(TheTriple);
1215 break;
1216 }
1217}
1218
1219MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
1220 uint64_t Hash) const {
1221 switch (Ctx->getTargetTriple().getObjectFormat()) {
1222 case Triple::ELF:
1223 return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0,
1224 utostr(Hash), /*IsComdat=*/true);
1225 case Triple::Wasm:
1226 return Ctx->getWasmSection(Name, SectionKind::getMetadata(), 0,
1228 case Triple::MachO:
1229 case Triple::COFF:
1230 case Triple::GOFF:
1231 case Triple::SPIRV:
1232 case Triple::XCOFF:
1235 report_fatal_error("Cannot get DWARF comdat section for this object file "
1236 "format: not implemented.");
1237 break;
1238 }
1239 llvm_unreachable("Unknown ObjectFormatType");
1240}
1241
1242MCSection *
1244 if (Ctx->getObjectFileType() != MCContext::IsELF)
1245 return CallGraphSection;
1246
1247 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1248 unsigned Flags = ELF::SHF_LINK_ORDER;
1249 StringRef GroupName;
1250 if (const MCSymbol *Group = ElfSec.getGroup()) {
1251 GroupName = Group->getName();
1252 Flags |= ELF::SHF_GROUP;
1253 }
1254
1255 return Ctx->getELFSection(
1256 ".llvm.callgraph", ELF::SHT_LLVM_CALL_GRAPH, Flags, 0, GroupName,
1257 /*IsComdat=*/true, ElfSec.getUniqueID(),
1258 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1259}
1260
1261MCSection *
1263 if ((Ctx->getObjectFileType() != MCContext::IsELF) ||
1264 Ctx->getTargetTriple().isPS4())
1265 return StackSizesSection;
1266
1267 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1268 unsigned Flags = ELF::SHF_LINK_ORDER;
1269 StringRef GroupName;
1270 if (const MCSymbol *Group = ElfSec.getGroup()) {
1271 GroupName = Group->getName();
1272 Flags |= ELF::SHF_GROUP;
1273 }
1274
1275 return Ctx->getELFSection(
1276 ".stack_sizes", ELF::SHT_PROGBITS, Flags, 0, GroupName, true,
1277 ElfSec.getUniqueID(),
1278 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1279}
1280
1281MCSection *
1283 constexpr StringLiteral Name = ".llvm_bb_addr_map";
1284 if (Ctx->getObjectFileType() == MCContext::IsELF) {
1285 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1286 unsigned Flags = ELF::SHF_LINK_ORDER;
1287 StringRef GroupName;
1288 if (const MCSymbol *Group = ElfSec.getGroup()) {
1289 GroupName = Group->getName();
1290 Flags |= ELF::SHF_GROUP;
1291 }
1292
1293 // Use the text section's begin symbol and unique ID to create a separate
1294 // .llvm_bb_addr_map section associated with every unique text section.
1295 return Ctx->getELFSection(
1296 Name, ELF::SHT_LLVM_BB_ADDR_MAP, Flags, 0, GroupName, true,
1297 ElfSec.getUniqueID(),
1298 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1299 } else if (Ctx->getObjectFileType() == MCContext::IsCOFF) {
1300 StringRef COMDATSymName;
1301 int Selection = 0;
1302 unsigned Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1305 const auto &COFFSec = static_cast<const MCSectionCOFF &>(TextSec);
1306 if (const MCSymbol *COMDATSym = COFFSec.getCOMDATSymbol()) {
1307 if (!Ctx->getAsmInfo().hasCOFFAssociativeComdats())
1308 report_fatal_error("BB address map requires associative COMDAT "
1309 "support for COMDAT functions");
1310 COMDATSymName = COMDATSym->getName();
1311 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
1313 }
1314 return Ctx->getCOFFSection(Name, Characteristics, COMDATSymName, Selection,
1315 COFFSec.getUniqueID());
1316 }
1317
1318 return nullptr;
1319}
1320
1321MCSection *
1323 if (Ctx->getObjectFileType() != MCContext::IsELF)
1324 return nullptr;
1325
1326 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1327 unsigned Flags = ELF::SHF_LINK_ORDER | ELF::SHF_ALLOC;
1328 StringRef GroupName;
1329 if (const MCSymbol *Group = ElfSec.getGroup()) {
1330 GroupName = Group->getName();
1331 Flags |= ELF::SHF_GROUP;
1332 }
1333
1334 return Ctx->getELFSection(
1335 ".kcfi_traps", ELF::SHT_PROGBITS, Flags, 0, GroupName,
1336 /*IsComdat=*/true, ElfSec.getUniqueID(),
1337 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1338}
1339
1340MCSection *
1342 auto ObjFileType = Ctx->getObjectFileType();
1343 if (ObjFileType == MCContext::IsELF) {
1344 const auto &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1345 unsigned Flags = ELF::SHF_LINK_ORDER;
1346 StringRef GroupName;
1347 if (const MCSymbol *Group = ElfSec.getGroup()) {
1348 GroupName = Group->getName();
1349 Flags |= ELF::SHF_GROUP;
1350 }
1351 return Ctx->getELFSection(
1352 PseudoProbeSection->getName(), ELF::SHT_PROGBITS, Flags, 0, GroupName,
1353 true, ElfSec.getUniqueID(),
1354 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1355 } else if (ObjFileType == MCContext::IsCOFF) {
1356 StringRef COMDATSymName = "";
1357 int Selection = 0;
1358 unsigned Characteristics =
1359 static_cast<MCSectionCOFF *>(PseudoProbeSection)->getCharacteristics();
1360 const auto &COFFSec = static_cast<const MCSectionCOFF &>(TextSec);
1361 if (const MCSymbol *COMDATSym = COFFSec.getCOMDATSymbol()) {
1362 // Associate .pseudo_probe to its function section.
1363 COMDATSymName = COMDATSym->getName();
1364 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
1366 }
1367 return Ctx->getCOFFSection(PseudoProbeSection->getName(), Characteristics,
1368 COMDATSymName, Selection, COFFSec.getUniqueID());
1369 }
1370
1371 return PseudoProbeSection;
1372}
1373
1374MCSection *
1376 uint64_t FuncHash) const {
1377 if (!Ctx->getTargetTriple().supportsCOMDAT() || FuncName.empty())
1379
1380 // Create a separate comdat group for each function's descriptor in order
1381 // for the linker to deduplicate. The duplication, must be from different
1382 // translation unit, can come from:
1383 // 1. Inline functions defined in header files;
1384 // 2. ThinLTO imported functions;
1385 // 3. Weak-linkage definitions.
1386 // Use a concatenation of the section name, function name, and function hash
1387 // as the group name so that descriptors with different hashes (due to user
1388 // code not following ODR or compiler codegen inconsistencies) get separate
1389 // COMDAT sections instead of being silently dropped (ELF) or causing linker
1390 // errors (COFF). Duplicate GUIDs with mismatching hashes are detected
1391 // during descriptor decoding and reported by llvm-profgen.
1392 auto ObjFileType = Ctx->getObjectFileType();
1393 if (ObjFileType == MCContext::IsELF) {
1394 auto *S = static_cast<MCSectionELF *>(PseudoProbeDescSection);
1395 auto Flags = S->getFlags() | ELF::SHF_GROUP;
1396 return Ctx->getELFSection(
1397 S->getName(), S->getType(), Flags, S->getEntrySize(),
1398 S->getName() + "_" + FuncName + "." + Twine::utohexstr(FuncHash),
1399 /*IsComdat=*/true);
1400 } else if (ObjFileType == MCContext::IsCOFF) {
1401 auto *S = static_cast<MCSectionCOFF *>(PseudoProbeDescSection);
1402 unsigned Characteristics =
1403 S->getCharacteristics() | COFF::IMAGE_SCN_LNK_COMDAT;
1404 std::string COMDATSymName =
1405 (S->getName() + "_" + FuncName + "." + Twine::utohexstr(FuncHash))
1406 .str();
1407 return Ctx->getCOFFSection(S->getName(), Characteristics, COMDATSymName,
1409 }
1410
1412}
1413
1417
1419 const MCSection *TextSec) const {
1420 if (Ctx->getObjectFileType() != MCContext::IsELF)
1421 return nullptr;
1422
1423 // SHF_WRITE for relocations, and let user post-process data in-place.
1425
1426 if (!TextSec)
1427 TextSec = getTextSection();
1428
1429 StringRef GroupName;
1430 const auto &ElfSec = static_cast<const MCSectionELF &>(*TextSec);
1431 if (const MCSymbol *Group = ElfSec.getGroup()) {
1432 GroupName = Group->getName();
1433 Flags |= ELF::SHF_GROUP;
1434 }
1435 return Ctx->getELFSection(
1436 Name, ELF::SHT_PROGBITS, Flags, 0, GroupName, true, ElfSec.getUniqueID(),
1437 static_cast<const MCSymbolELF *>(TextSec->getBeginSymbol()));
1438}
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, uint64_t FuncHash) 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:573
static constexpr unsigned NonUniqueID
Definition MCSection.h:578
void setBeginSymbol(MCSymbol *Sym)
Definition MCSection.h:650
MCSymbol * getBeginSymbol()
Definition MCSection.h:646
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()
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:882
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
@ UnknownObjectFormat
Definition Triple.h:332
static Twine utohexstr(uint64_t Val)
Definition Twine.h:385
#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:1257
@ SHF_STRINGS
Definition ELF.h:1260
@ SHF_EXCLUDE
Definition ELF.h:1285
@ SHF_ALLOC
Definition ELF.h:1251
@ SHF_LINK_ORDER
Definition ELF.h:1266
@ SHF_GROUP
Definition ELF.h:1273
@ SHF_X86_64_LARGE
Definition ELF.h:1314
@ SHF_WRITE
Definition ELF.h:1248
@ SHF_TLS
Definition ELF.h:1276
@ SHF_EXECINSTR
Definition ELF.h:1254
@ SHT_PROGBITS
Definition ELF.h:1150
@ SHT_NOBITS
Definition ELF.h:1157
@ SHT_LLVM_CALL_GRAPH
Definition ELF.h:1193
@ SHT_MIPS_DWARF
Definition ELF.h:1229
@ SHT_LLVM_BB_ADDR_MAP
Definition ELF.h:1188
@ SHT_GNU_SFRAME
Definition ELF.h:1197
@ SHT_X86_64_UNWIND
Definition ELF.h:1225
@ 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_DEAD_STRIP
S_ATTR_NO_DEAD_STRIP - No dead stripping.
Definition MachO.h:200
@ 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:885
@ DW_EH_PE_sdata4
Definition Dwarf.h:882
@ DW_EH_PE_sdata8
Definition Dwarf.h:883
@ DW_EH_PE_absptr
Definition Dwarf.h:874
@ WASM_SEG_FLAG_STRINGS
Definition Wasm.h:238
This is an optimization pass for GlobalISel generic memory operations.
FuncHash
Definition InstrProf.h:78
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