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()) {
82 break;
85 break;
89 break;
90 }
91
93
94 TextSection // .text
95 = Ctx->getMachOSection("__TEXT", "__text",
98 DataSection // .data
99 = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
100
101 // BSSSection might not be expected initialized on msvc.
102 BSSSection = nullptr;
103
104 TLSDataSection // .tdata
105 = Ctx->getMachOSection("__DATA", "__thread_data",
108 TLSBSSSection // .tbss
109 = Ctx->getMachOSection("__DATA", "__thread_bss",
112
113 // TODO: Verify datarel below.
114 TLSTLVSection // .tlv
115 = Ctx->getMachOSection("__DATA", "__thread_vars",
118
119 TLSThreadInitSection = Ctx->getMachOSection(
120 "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
122
123 CStringSection // .cstring
124 = Ctx->getMachOSection("__TEXT", "__cstring",
128 = Ctx->getMachOSection("__TEXT","__ustring", 0,
130 FourByteConstantSection // .literal4
131 = Ctx->getMachOSection("__TEXT", "__literal4",
134 EightByteConstantSection // .literal8
135 = Ctx->getMachOSection("__TEXT", "__literal8",
138
139 SixteenByteConstantSection // .literal16
140 = Ctx->getMachOSection("__TEXT", "__literal16",
143
144 ReadOnlySection // .const
145 = Ctx->getMachOSection("__TEXT", "__const", 0,
147
148 // If the target is not powerpc, map the coal sections to the non-coal
149 // sections.
150 //
151 // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
152 // "__TEXT/__const_coal" => section "__TEXT/__const"
153 // "__DATA/__datacoal_nt" => section "__DATA/__data"
154 Triple::ArchType ArchTy = T.getArch();
155
156 ConstDataSection // .const_data
157 = Ctx->getMachOSection("__DATA", "__const", 0,
159
160 if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
162 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
167 = Ctx->getMachOSection("__TEXT", "__const_coal",
170 DataCoalSection = Ctx->getMachOSection(
171 "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());
173 } else {
178 }
179
181 = Ctx->getMachOSection("__DATA","__common",
185 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
187
188
190 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
194 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
197
199 = Ctx->getMachOSection("__DATA", "__thread_ptr",
202
203 AddrSigSection = Ctx->getMachOSection("__DATA", "__llvm_addrsig", 0,
205
206 // Exception Handling.
207 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
209
210 COFFDebugSymbolsSection = nullptr;
211 COFFDebugTypesSection = nullptr;
213
214 if (useCompactUnwind(T)) {
216 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
218
219 if (T.isX86())
220 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF
221 else if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)
222 CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF
223 else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
224 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF
225 }
226
227 // Debug Information.
229 Ctx->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG,
230 SectionKind::getMetadata(), "debug_names_begin");
232 Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
233 SectionKind::getMetadata(), "names_begin");
235 Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
236 SectionKind::getMetadata(), "objc_begin");
237 // 16 character section limit...
239 Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
240 SectionKind::getMetadata(), "namespac_begin");
242 Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
243 SectionKind::getMetadata(), "types_begin");
244
246 Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG,
248
250 Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
251 SectionKind::getMetadata(), "section_abbrev");
253 Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
254 SectionKind::getMetadata(), "section_info");
256 Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
257 SectionKind::getMetadata(), "section_line");
259 Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,
260 SectionKind::getMetadata(), "section_line_str");
262 Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
263 SectionKind::getMetadata(), "section_frame");
265 Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
268 Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
271 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
274 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
277 Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
278 SectionKind::getMetadata(), "info_string");
280 Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG,
281 SectionKind::getMetadata(), "section_str_off");
283 Ctx->getMachOSection("__DWARF", "__debug_addr", MachO::S_ATTR_DEBUG,
284 SectionKind::getMetadata(), "section_info");
286 Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
287 SectionKind::getMetadata(), "section_debug_loc");
289 Ctx->getMachOSection("__DWARF", "__debug_loclists", MachO::S_ATTR_DEBUG,
290 SectionKind::getMetadata(), "section_debug_loc");
291
293 Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
296 Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
297 SectionKind::getMetadata(), "debug_range");
299 Ctx->getMachOSection("__DWARF", "__debug_rnglists", MachO::S_ATTR_DEBUG,
300 SectionKind::getMetadata(), "debug_range");
302 Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG,
303 SectionKind::getMetadata(), "debug_macinfo");
305 Ctx->getMachOSection("__DWARF", "__debug_macro", MachO::S_ATTR_DEBUG,
306 SectionKind::getMetadata(), "debug_macro");
308 Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
311 Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,
314 Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG,
316 StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
318
319 FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
321
322 RemarksSection = Ctx->getMachOSection(
323 "__LLVM", "__remarks", MachO::S_ATTR_DEBUG, SectionKind::getMetadata());
324
326 Ctx->getMachOSection("__PSEUDO_PROBE", "__probes",
330 Ctx->getMachOSection("__PSEUDO_PROBE", "__probe_descs",
333
334 // The architecture of dsymutil makes it very difficult to copy the Swift
335 // reflection metadata sections into the __TEXT segment, so dsymutil creates
336 // these sections in the __DWARF segment instead.
337 if (!Ctx->getSwift5ReflectionSegmentName().empty()) {
338#define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) \
339 Swift5ReflectionSections \
340 [llvm::binaryformat::Swift5ReflectionSectionKind::KIND] = \
341 Ctx->getMachOSection(Ctx->getSwift5ReflectionSegmentName().data(), \
342 MACHO, 0, SectionKind::getMetadata());
343#include "llvm/BinaryFormat/Swift.def"
344 }
345
347}
348
349void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
350 switch (T.getArch()) {
351 case Triple::mips:
352 case Triple::mipsel:
353 case Triple::mips64:
354 case Triple::mips64el:
355 // We cannot use DW_EH_PE_sdata8 for the large PositionIndependent case
356 // since there is no R_MIPS_PC64 relocation (only a 32-bit version).
357 // In fact DW_EH_PE_sdata4 is enough for us now, and GNU ld doesn't
358 // support pcrel|sdata8 well. Let's use sdata4 for now.
359 if (PositionIndependent)
361 else
362 FDECFIEncoding = Ctx->getAsmInfo().getCodePointerSize() == 4
365 break;
366 case Triple::ppc64:
367 case Triple::ppc64le:
368 case Triple::aarch64:
370 case Triple::x86_64:
373 break;
374 case Triple::bpfel:
375 case Triple::bpfeb:
377 break;
378 case Triple::hexagon:
380 PositionIndependent ? dwarf::DW_EH_PE_pcrel : dwarf::DW_EH_PE_absptr;
381 break;
382 case Triple::xtensa:
384 break;
385 default:
387 break;
388 }
389
390 unsigned EHSectionType = T.getArch() == Triple::x86_64
393 switch (T.getArch()) {
394 case Triple::x86_64:
395 SFrameABIArch = sframe::ABI::AMD64EndianLittle;
396 break;
397 case Triple::aarch64:
398 SFrameABIArch = sframe::ABI::AArch64EndianLittle;
399 break;
401 SFrameABIArch = sframe::ABI::AArch64EndianBig;
402 break;
403 default:
404 break;
405 }
406
407 // Solaris requires different flags for .eh_frame to seemingly every other
408 // platform.
409 unsigned EHSectionFlags = ELF::SHF_ALLOC;
410 if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
411 EHSectionFlags |= ELF::SHF_WRITE;
412
413 // ELF
414 BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
416
417 TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
419
420 DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
422
424 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
425
427 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
429
430 TLSBSSSection = Ctx->getELFSection(
432
433 DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
435
436 unsigned MergeableCstFlags = ELF::SHF_ALLOC | ELF::SHF_MERGE;
437 StringRef CstPrefix = ".rodata";
438 if (Large && T.getArch() == Triple::x86_64) {
439 MergeableCstFlags |= ELF::SHF_X86_64_LARGE;
440 CstPrefix = ".lrodata";
441 }
442
443 MergeableConst4Section = Ctx->getELFSection(
444 CstPrefix + ".cst4", ELF::SHT_PROGBITS, MergeableCstFlags, 4);
445
446 MergeableConst8Section = Ctx->getELFSection(
447 CstPrefix + ".cst8", ELF::SHT_PROGBITS, MergeableCstFlags, 8);
448
449 MergeableConst16Section = Ctx->getELFSection(
450 CstPrefix + ".cst16", ELF::SHT_PROGBITS, MergeableCstFlags, 16);
451
452 MergeableConst32Section = Ctx->getELFSection(
453 CstPrefix + ".cst32", ELF::SHT_PROGBITS, MergeableCstFlags, 32);
454
455 // Exception Handling Sections.
456
457 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
458 // it contains relocatable pointers. In PIC mode, this is probably a big
459 // runtime hit for C++ apps. Either the contents of the LSDA need to be
460 // adjusted or this should be a data section.
461 LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
463
464 COFFDebugSymbolsSection = nullptr;
465 COFFDebugTypesSection = nullptr;
466
467 unsigned DebugSecType = ELF::SHT_PROGBITS;
468
469 // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
470 // to distinguish among sections contain DWARF and ECOFF debug formats.
471 // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
472 if (T.isMIPS())
473 DebugSecType = ELF::SHT_MIPS_DWARF;
474
475 // Debug Info Sections.
477 Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);
478 DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0);
479 DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0);
481 Ctx->getELFSection(".debug_line_str", DebugSecType,
483 DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0);
485 Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);
487 Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);
489 Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);
491 Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);
493 Ctx->getELFSection(".debug_str", DebugSecType,
495 DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0);
497 Ctx->getELFSection(".debug_aranges", DebugSecType, 0);
499 Ctx->getELFSection(".debug_ranges", DebugSecType, 0);
501 Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);
502 DwarfMacroSection = Ctx->getELFSection(".debug_macro", DebugSecType, 0);
503
504 // DWARF5 Experimental Debug Info
505
506 // Accelerator Tables
508 Ctx->getELFSection(".debug_names", ELF::SHT_PROGBITS, 0);
510 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);
512 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);
514 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);
516 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);
517
518 // String Offset and Address Sections
520 Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);
521 DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);
522 DwarfRnglistsSection = Ctx->getELFSection(".debug_rnglists", DebugSecType, 0);
523 DwarfLoclistsSection = Ctx->getELFSection(".debug_loclists", DebugSecType, 0);
524
525 // Fission Sections
527 Ctx->getELFSection(".debug_info.dwo", DebugSecType, ELF::SHF_EXCLUDE);
529 Ctx->getELFSection(".debug_types.dwo", DebugSecType, ELF::SHF_EXCLUDE);
531 Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, ELF::SHF_EXCLUDE);
532 DwarfStrDWOSection = Ctx->getELFSection(
533 ".debug_str.dwo", DebugSecType,
536 Ctx->getELFSection(".debug_line.dwo", DebugSecType, ELF::SHF_EXCLUDE);
538 Ctx->getELFSection(".debug_loc.dwo", DebugSecType, ELF::SHF_EXCLUDE);
539 DwarfStrOffDWOSection = Ctx->getELFSection(".debug_str_offsets.dwo",
540 DebugSecType, ELF::SHF_EXCLUDE);
542 Ctx->getELFSection(".debug_rnglists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
544 Ctx->getELFSection(".debug_macinfo.dwo", DebugSecType, ELF::SHF_EXCLUDE);
546 Ctx->getELFSection(".debug_macro.dwo", DebugSecType, ELF::SHF_EXCLUDE);
547
549 Ctx->getELFSection(".debug_loclists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
550
551 // DWP Sections
553 Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);
555 Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);
556
558 Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
559
561 Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
562
564 Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
565
567 Ctx->getELFSection(".sframe", ELF::SHT_GNU_SFRAME, ELF::SHF_ALLOC);
568
570 Ctx->getELFSection(".llvm.callgraph", ELF::SHT_LLVM_CALL_GRAPH, 0);
571
572 StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);
573
574 PseudoProbeSection = Ctx->getELFSection(".pseudo_probe", DebugSecType, 0);
576 Ctx->getELFSection(".pseudo_probe_desc", DebugSecType, 0);
577
578 LLVMStatsSection = Ctx->getELFSection(".llvm_stats", ELF::SHT_PROGBITS, 0);
579}
580
581void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) {
582 MCSectionGOFF *RootSDSection = Ctx->getGOFFSection(
585
586 MCSectionGOFF *ADAEDSection = Ctx->getGOFFSection(
588 GOFF::EDAttr{false, GOFF::ESD_RMODE_64, GOFF::ESD_NS_Parts,
592 RootSDSection);
593 ADASection = Ctx->getGOFFSection(SectionKind::getData(), "#S",
594 GOFF::PRAttr{false, GOFF::ESD_EXE_DATA,
597 ADAEDSection);
598
599 TextSection = Ctx->getGOFFSection(
605 RootSDSection);
606
607 MCSectionGOFF *PPA2ListEDSection = Ctx->getGOFFSection(
609 GOFF::EDAttr{true, GOFF::ESD_RMODE_64, GOFF::ESD_NS_Parts,
613 RootSDSection);
614 PPA2ListSection = Ctx->getGOFFSection(SectionKind::getData(), ".&ppa2",
615 GOFF::PRAttr{true, GOFF::ESD_EXE_DATA,
618 PPA2ListEDSection);
619
620 IDRLSection = Ctx->getGOFFSection(
621 SectionKind::getData(), "B_IDRL",
626 RootSDSection);
627
628 // Debug Info Sections. The ED name is the same used by the XL compiler.
629 auto InitDebugSection = [this,
630 RootSDSection](StringRef EDName,
631 StringRef LDName) -> MCSectionGOFF * {
632 MCSectionGOFF *ED = Ctx->getGOFFSection(
633 SectionKind::getMetadata(), EDName,
634 GOFF::EDAttr{false, GOFF::ESD_RMODE_64, GOFF::ESD_NS_Parts,
638 RootSDSection);
639 // At least for llc, this function is called twice! (See function
640 // compileModule() in llc.cpp). Since the context is not cleared, the
641 // already allocated section is returned above. We only add the begin symbol
642 // if it is not yet set to avoid an assertion.
643 MCSymbolGOFF *LD = static_cast<MCSymbolGOFF *>(ED->getBeginSymbol());
644 if (!LD) {
645 LD = static_cast<MCSymbolGOFF *>(getContext().getOrCreateSymbol(LDName));
646 LD->setCodeData(GOFF::ESD_EXE_DATA);
647 LD->setWeak(false);
648 LD->setLinkage(GOFF::ESD_LT_XPLink);
649 LD->setExternal(false);
650 ED->setBeginSymbol(LD);
651 } else
652 assert(LD->getName() == LDName && "Wrong label name");
653 return ED;
654 };
655 DwarfAbbrevSection = InitDebugSection("D_ABREV", ".debug_abbrev");
656 DwarfInfoSection = InitDebugSection("D_INFO", ".debug_info");
657 DwarfLineSection = InitDebugSection("D_LINE", ".debug_line");
658 DwarfFrameSection = InitDebugSection("D_FRAME", ".debug_frame");
659 DwarfPubNamesSection = InitDebugSection("D_PBNMS", ".debug_pubnames");
660 DwarfPubTypesSection = InitDebugSection("D_PTYPES", ".debug_pubtypes");
661 DwarfStrSection = InitDebugSection("D_STR", ".debug_str");
662 DwarfLocSection = InitDebugSection("D_LOC", ".debug_loc");
663 DwarfARangesSection = InitDebugSection("D_ARNGE", ".debug_aranges");
664 DwarfRangesSection = InitDebugSection("D_RNGES", ".debug_ranges");
665 DwarfMacinfoSection = InitDebugSection("D_MACIN", ".debug_macinfo");
666
667 // DWARF 5 sections.
668 DwarfDebugNamesSection = InitDebugSection("D_NAMES", ".debug_names");
669 DwarfStrOffSection = InitDebugSection("D_STROFFS", ".debug_str_offsets");
670 DwarfAddrSection = InitDebugSection("D_ADDR", ".debug_addr");
671 DwarfRnglistsSection = InitDebugSection("D_RNGLISTS", ".debug_rnglists");
672 DwarfLoclistsSection = InitDebugSection("D_LOCLISTS", ".debug_loclists");
673 DwarfLineStrSection = InitDebugSection("D_LINESTR", ".debug_line_str");
674
675 // Special GNU sections.
676 DwarfGnuPubNamesSection = InitDebugSection("D_GPBNMS", ".debug_gnu_pubnames");
678 InitDebugSection("D_GPTYPES", ".debug_gnu_pubtypes");
679
680 // Accelerator Tables.
681 DwarfAccelNamesSection = InitDebugSection("D_APPLNMS", ".apple_names");
683 InitDebugSection("D_APPLNMSP", ".apple_namespaces");
684 DwarfAccelTypesSection = InitDebugSection("D_APPLTYPS", ".apple_types");
685 DwarfAccelObjCSection = InitDebugSection("D_APPLOBJC", ".apple_objc");
686}
687
688void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
690 Ctx->getCOFFSection(".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
692
693 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
694 // used to indicate to the linker that the text segment contains thumb instructions
695 // and to set the ISA selection bit for calls accordingly.
696 const bool IsThumb = T.getArch() == Triple::thumb;
697
698 // COFF
699 BSSSection = Ctx->getCOFFSection(
702 TextSection = Ctx->getCOFFSection(
703 ".text",
707 DataSection = Ctx->getCOFFSection(
711 Ctx->getCOFFSection(".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
713
714 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64 ||
715 T.getArch() == Triple::arm || T.getArch() == Triple::thumb) {
716 // On Windows with SEH, the LSDA is emitted into the .xdata section
717 LSDASection = nullptr;
718 } else {
719 LSDASection = Ctx->getCOFFSection(".gcc_except_table",
722 }
723
724 if (T.getArch() == Triple::aarch64) {
726 Ctx->getCOFFSection(".impcall", COFF::IMAGE_SCN_LNK_INFO);
727 } else if (T.getArch() == Triple::x86_64) {
728 // Import Call Optimization on x64 leverages the same metadata as the
729 // retpoline mitigation, hence the unusual section name.
731 Ctx->getCOFFSection(".retplne", COFF::IMAGE_SCN_LNK_INFO);
732 }
733
734 // Debug info.
736 Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
740 Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
744 Ctx->getCOFFSection(".debug$H", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
747
748 DwarfAbbrevSection = Ctx->getCOFFSection(
749 ".debug_abbrev", COFF::IMAGE_SCN_MEM_DISCARDABLE |
752 DwarfInfoSection = Ctx->getCOFFSection(
753 ".debug_info", COFF::IMAGE_SCN_MEM_DISCARDABLE |
756 DwarfLineSection = Ctx->getCOFFSection(
757 ".debug_line", COFF::IMAGE_SCN_MEM_DISCARDABLE |
760 DwarfLineStrSection = Ctx->getCOFFSection(
761 ".debug_line_str", COFF::IMAGE_SCN_MEM_DISCARDABLE |
764 DwarfFrameSection = Ctx->getCOFFSection(
765 ".debug_frame", COFF::IMAGE_SCN_MEM_DISCARDABLE |
768 DwarfPubNamesSection = Ctx->getCOFFSection(
769 ".debug_pubnames", COFF::IMAGE_SCN_MEM_DISCARDABLE |
772 DwarfPubTypesSection = Ctx->getCOFFSection(
773 ".debug_pubtypes", COFF::IMAGE_SCN_MEM_DISCARDABLE |
776 DwarfGnuPubNamesSection = Ctx->getCOFFSection(
777 ".debug_gnu_pubnames", COFF::IMAGE_SCN_MEM_DISCARDABLE |
780 DwarfGnuPubTypesSection = Ctx->getCOFFSection(
781 ".debug_gnu_pubtypes", COFF::IMAGE_SCN_MEM_DISCARDABLE |
784 DwarfStrSection = Ctx->getCOFFSection(
785 ".debug_str", COFF::IMAGE_SCN_MEM_DISCARDABLE |
788 DwarfStrOffSection = Ctx->getCOFFSection(
789 ".debug_str_offsets", COFF::IMAGE_SCN_MEM_DISCARDABLE |
792 DwarfLocSection = Ctx->getCOFFSection(
793 ".debug_loc", COFF::IMAGE_SCN_MEM_DISCARDABLE |
796 DwarfLoclistsSection = Ctx->getCOFFSection(
797 ".debug_loclists", COFF::IMAGE_SCN_MEM_DISCARDABLE |
800 DwarfARangesSection = Ctx->getCOFFSection(
801 ".debug_aranges", COFF::IMAGE_SCN_MEM_DISCARDABLE |
804 DwarfRangesSection = Ctx->getCOFFSection(
805 ".debug_ranges", COFF::IMAGE_SCN_MEM_DISCARDABLE |
808 DwarfRnglistsSection = Ctx->getCOFFSection(
809 ".debug_rnglists", COFF::IMAGE_SCN_MEM_DISCARDABLE |
812 DwarfMacinfoSection = Ctx->getCOFFSection(
813 ".debug_macinfo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
816 DwarfMacroSection = Ctx->getCOFFSection(
817 ".debug_macro", COFF::IMAGE_SCN_MEM_DISCARDABLE |
820 DwarfMacinfoDWOSection = Ctx->getCOFFSection(
821 ".debug_macinfo.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
825 DwarfMacroDWOSection = Ctx->getCOFFSection(
826 ".debug_macro.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
830 DwarfInfoDWOSection = Ctx->getCOFFSection(
831 ".debug_info.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
835 DwarfTypesDWOSection = Ctx->getCOFFSection(
836 ".debug_types.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
840 DwarfAbbrevDWOSection = Ctx->getCOFFSection(
841 ".debug_abbrev.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
845 DwarfStrDWOSection = Ctx->getCOFFSection(
846 ".debug_str.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
850 DwarfLineDWOSection = Ctx->getCOFFSection(
851 ".debug_line.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
855 DwarfLocDWOSection = Ctx->getCOFFSection(
856 ".debug_loc.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
860 DwarfLoclistsDWOSection = Ctx->getCOFFSection(
861 ".debug_loclists.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
865 DwarfStrOffDWOSection = Ctx->getCOFFSection(
866 ".debug_str_offsets.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
870 DwarfRnglistsDWOSection = Ctx->getCOFFSection(
871 ".debug_rnglists.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
875 DwarfAddrSection = Ctx->getCOFFSection(
876 ".debug_addr", COFF::IMAGE_SCN_MEM_DISCARDABLE |
879 DwarfCUIndexSection = Ctx->getCOFFSection(
880 ".debug_cu_index", COFF::IMAGE_SCN_MEM_DISCARDABLE |
883 DwarfTUIndexSection = Ctx->getCOFFSection(
884 ".debug_tu_index", COFF::IMAGE_SCN_MEM_DISCARDABLE |
887 DwarfDebugNamesSection = Ctx->getCOFFSection(
888 ".debug_names", COFF::IMAGE_SCN_MEM_DISCARDABLE |
891 DwarfAccelNamesSection = Ctx->getCOFFSection(
892 ".apple_names", COFF::IMAGE_SCN_MEM_DISCARDABLE |
895 DwarfAccelNamespaceSection = Ctx->getCOFFSection(
896 ".apple_namespaces", COFF::IMAGE_SCN_MEM_DISCARDABLE |
899 DwarfAccelTypesSection = Ctx->getCOFFSection(
900 ".apple_types", COFF::IMAGE_SCN_MEM_DISCARDABLE |
903 DwarfAccelObjCSection = Ctx->getCOFFSection(
904 ".apple_objc", COFF::IMAGE_SCN_MEM_DISCARDABLE |
907
908 DrectveSection = Ctx->getCOFFSection(
910
912 Ctx->getCOFFSection(".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
914
916 Ctx->getCOFFSection(".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
918
919 SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO);
920
922 Ctx->getCOFFSection(".gehcont$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
924
926 Ctx->getCOFFSection(".gfids$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
928
930 Ctx->getCOFFSection(".giats$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
932
934 Ctx->getCOFFSection(".gljmp$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
936
937 TLSDataSection = Ctx->getCOFFSection(
940
941 StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
944
945 // Set IMAGE_SCN_MEM_DISCARDABLE so that lld will not truncate section name.
946 PseudoProbeSection = Ctx->getCOFFSection(
947 ".pseudo_probe", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
950 PseudoProbeDescSection = Ctx->getCOFFSection(
951 ".pseudo_probe_desc", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
954}
955
956void MCObjectFileInfo::initSPIRVMCObjectFileInfo(const Triple &T) {
957 // Put everything in a single binary section.
958 TextSection = Ctx->getSPIRVSection();
959}
960
961void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
962 TextSection = Ctx->getWasmSection(".text", SectionKind::getText());
963 DataSection = Ctx->getWasmSection(".data", SectionKind::getData());
964
966 Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());
968 Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata(),
970 DwarfStrSection = Ctx->getWasmSection(
973 Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());
975 Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata());
976 DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());
978 Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata());
980 Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata());
982 Ctx->getWasmSection(".debug_macro", SectionKind::getMetadata());
983 DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
984 DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
986 Ctx->getWasmSection(".debug_info", SectionKind::getMetadata());
987 DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());
988 DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
989 DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
991 Ctx->getWasmSection(".debug_gnu_pubnames", SectionKind::getMetadata());
993 Ctx->getWasmSection(".debug_gnu_pubtypes", SectionKind::getMetadata());
994
996 Ctx->getWasmSection(".debug_names", SectionKind::getMetadata());
998 Ctx->getWasmSection(".debug_str_offsets", SectionKind::getMetadata());
1000 Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata());
1002 Ctx->getWasmSection(".debug_rnglists", SectionKind::getMetadata());
1004 Ctx->getWasmSection(".debug_loclists", SectionKind::getMetadata());
1005
1006 // Fission Sections
1008 Ctx->getWasmSection(".debug_info.dwo", SectionKind::getMetadata());
1010 Ctx->getWasmSection(".debug_types.dwo", SectionKind::getMetadata());
1012 Ctx->getWasmSection(".debug_abbrev.dwo", SectionKind::getMetadata());
1014 Ctx->getWasmSection(".debug_str.dwo", SectionKind::getMetadata(),
1017 Ctx->getWasmSection(".debug_line.dwo", SectionKind::getMetadata());
1019 Ctx->getWasmSection(".debug_loc.dwo", SectionKind::getMetadata());
1021 Ctx->getWasmSection(".debug_str_offsets.dwo", SectionKind::getMetadata());
1023 Ctx->getWasmSection(".debug_rnglists.dwo", SectionKind::getMetadata());
1025 Ctx->getWasmSection(".debug_macinfo.dwo", SectionKind::getMetadata());
1027 Ctx->getWasmSection(".debug_macro.dwo", SectionKind::getMetadata());
1028
1030 Ctx->getWasmSection(".debug_loclists.dwo", SectionKind::getMetadata());
1031
1032 // DWP Sections
1034 Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
1036 Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
1037
1038 // Wasm use data section for LSDA.
1039 // TODO Consider putting each function's exception table in a separate
1040 // section, as in -function-sections, to facilitate lld's --gc-section.
1041 LSDASection = Ctx->getWasmSection(".rodata.gcc_except_table",
1043
1044 // TODO: Define more sections.
1045}
1046
1047void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) {
1048 // The default csect for program code. Functions without a specified section
1049 // get placed into this csect. The choice of csect name is not a property of
1050 // the ABI or object file format, but various tools rely on the section
1051 // name being empty (considering named symbols to be "user symbol names").
1052 TextSection = Ctx->getXCOFFSection(
1053 "..text..", // Use a non-null name to work around an AIX assembler bug...
1055 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD),
1056 /* MultiSymbolsAllowed*/ true);
1057
1058 // ... but use a null name when generating the symbol table.
1059 MCSectionXCOFF *TS = static_cast<MCSectionXCOFF *>(TextSection);
1061 TS->setSymbolTableName("");
1062
1063 DataSection = Ctx->getXCOFFSection(
1064 ".data", SectionKind::getData(),
1065 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD),
1066 /* MultiSymbolsAllowed*/ true);
1067
1068 ReadOnlySection = Ctx->getXCOFFSection(
1069 ".rodata", SectionKind::getReadOnly(),
1070 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
1071 /* MultiSymbolsAllowed*/ true);
1072 ReadOnlySection->setAlignment(Align(4));
1073
1074 ReadOnly8Section = Ctx->getXCOFFSection(
1075 ".rodata.8", SectionKind::getReadOnly(),
1076 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
1077 /* MultiSymbolsAllowed*/ true);
1078 ReadOnly8Section->setAlignment(Align(8));
1079
1080 ReadOnly16Section = Ctx->getXCOFFSection(
1081 ".rodata.16", SectionKind::getReadOnly(),
1082 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
1083 /* MultiSymbolsAllowed*/ true);
1084 ReadOnly16Section->setAlignment(Align(16));
1085
1086 TLSDataSection = Ctx->getXCOFFSection(
1087 ".tdata", SectionKind::getThreadData(),
1088 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TL, XCOFF::XTY_SD),
1089 /* MultiSymbolsAllowed*/ true);
1090
1091 TOCBaseSection = Ctx->getXCOFFSection(
1092 "TOC", SectionKind::getData(),
1093 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TC0,
1094 XCOFF::XTY_SD));
1095
1096 // The TOC-base always has 0 size, but 4 byte alignment.
1097 TOCBaseSection->setAlignment(Align(4));
1098
1099 LSDASection = Ctx->getXCOFFSection(
1100 ".gcc_except_table", SectionKind::getReadOnly(),
1101 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO,
1102 XCOFF::XTY_SD));
1103
1104 CompactUnwindSection = Ctx->getXCOFFSection(
1105 ".eh_info_table", SectionKind::getData(),
1106 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW,
1107 XCOFF::XTY_SD));
1108
1109 // DWARF sections for XCOFF are not csects. They are special STYP_DWARF
1110 // sections, and the individual DWARF sections are distinguished by their
1111 // section subtype.
1112 DwarfAbbrevSection = Ctx->getXCOFFSection(
1113 ".dwabrev", SectionKind::getMetadata(),
1114 /* CsectProperties */ std::nullopt,
1115 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWABREV);
1116
1117 DwarfInfoSection = Ctx->getXCOFFSection(
1118 ".dwinfo", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1119 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWINFO);
1120
1121 DwarfLineSection = Ctx->getXCOFFSection(
1122 ".dwline", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1123 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWLINE);
1124
1125 DwarfFrameSection = Ctx->getXCOFFSection(
1126 ".dwframe", SectionKind::getMetadata(),
1127 /* CsectProperties */ std::nullopt,
1128 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWFRAME);
1129
1130 DwarfPubNamesSection = Ctx->getXCOFFSection(
1131 ".dwpbnms", SectionKind::getMetadata(),
1132 /* CsectProperties */ std::nullopt,
1133 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWPBNMS);
1134
1135 DwarfPubTypesSection = Ctx->getXCOFFSection(
1136 ".dwpbtyp", SectionKind::getMetadata(),
1137 /* CsectProperties */ std::nullopt,
1138 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWPBTYP);
1139
1140 DwarfStrSection = Ctx->getXCOFFSection(
1141 ".dwstr", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1142 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWSTR);
1143
1144 DwarfLocSection = Ctx->getXCOFFSection(
1145 ".dwloc", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1146 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWLOC);
1147
1148 DwarfARangesSection = Ctx->getXCOFFSection(
1149 ".dwarnge", SectionKind::getMetadata(),
1150 /* CsectProperties */ std::nullopt,
1151 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWARNGE);
1152
1153 DwarfRangesSection = Ctx->getXCOFFSection(
1154 ".dwrnges", SectionKind::getMetadata(),
1155 /* CsectProperties */ std::nullopt,
1156 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWRNGES);
1157
1158 DwarfMacinfoSection = Ctx->getXCOFFSection(
1159 ".dwmac", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,
1160 /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWMAC);
1161}
1162
1163void MCObjectFileInfo::initDXContainerObjectFileInfo(const Triple &T) {
1164 // At the moment the DXBC section should end up empty.
1165 TextSection = Ctx->getDXContainerSection("DXBC", SectionKind::getText());
1166}
1167
1169
1171 bool LargeCodeModel) {
1172 PositionIndependent = PIC;
1173 Ctx = &MCCtx;
1174
1175 // Common.
1178
1180
1182
1183 EHFrameSection = nullptr; // Created on demand.
1184 SFrameSection = nullptr; // Created on demand.
1185 CompactUnwindSection = nullptr; // Used only by selected targets.
1186 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
1187 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
1188 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
1189 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
1190
1191 const Triple &TheTriple = Ctx->getTargetTriple();
1192 switch (Ctx->getObjectFileType()) {
1193 case MCContext::IsMachO:
1194 initMachOMCObjectFileInfo(TheTriple);
1195 break;
1196 case MCContext::IsCOFF:
1197 initCOFFMCObjectFileInfo(TheTriple);
1198 break;
1199 case MCContext::IsELF:
1200 initELFMCObjectFileInfo(TheTriple, LargeCodeModel);
1201 break;
1202 case MCContext::IsGOFF:
1203 initGOFFMCObjectFileInfo(TheTriple);
1204 break;
1205 case MCContext::IsSPIRV:
1206 initSPIRVMCObjectFileInfo(TheTriple);
1207 break;
1208 case MCContext::IsWasm:
1209 initWasmMCObjectFileInfo(TheTriple);
1210 break;
1211 case MCContext::IsXCOFF:
1212 initXCOFFMCObjectFileInfo(TheTriple);
1213 break;
1215 initDXContainerObjectFileInfo(TheTriple);
1216 break;
1217 }
1218}
1219
1220MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
1221 uint64_t Hash) const {
1222 switch (Ctx->getTargetTriple().getObjectFormat()) {
1223 case Triple::ELF:
1224 return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0,
1225 utostr(Hash), /*IsComdat=*/true);
1226 case Triple::Wasm:
1227 return Ctx->getWasmSection(Name, SectionKind::getMetadata(), 0,
1229 case Triple::MachO:
1230 case Triple::COFF:
1231 case Triple::GOFF:
1232 case Triple::SPIRV:
1233 case Triple::XCOFF:
1236 report_fatal_error("Cannot get DWARF comdat section for this object file "
1237 "format: not implemented.");
1238 break;
1239 }
1240 llvm_unreachable("Unknown ObjectFormatType");
1241}
1242
1243MCSection *
1245 if (Ctx->getObjectFileType() != MCContext::IsELF)
1246 return CallGraphSection;
1247
1248 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1249 unsigned Flags = ELF::SHF_LINK_ORDER;
1250 StringRef GroupName;
1251 if (const MCSymbol *Group = ElfSec.getGroup()) {
1252 GroupName = Group->getName();
1253 Flags |= ELF::SHF_GROUP;
1254 }
1255
1256 return Ctx->getELFSection(
1257 ".llvm.callgraph", ELF::SHT_LLVM_CALL_GRAPH, Flags, 0, GroupName,
1258 /*IsComdat=*/true, ElfSec.getUniqueID(),
1259 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1260}
1261
1262MCSection *
1264 if ((Ctx->getObjectFileType() != MCContext::IsELF) ||
1265 Ctx->getTargetTriple().isPS4())
1266 return StackSizesSection;
1267
1268 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1269 unsigned Flags = ELF::SHF_LINK_ORDER;
1270 StringRef GroupName;
1271 if (const MCSymbol *Group = ElfSec.getGroup()) {
1272 GroupName = Group->getName();
1273 Flags |= ELF::SHF_GROUP;
1274 }
1275
1276 return Ctx->getELFSection(
1277 ".stack_sizes", ELF::SHT_PROGBITS, Flags, 0, GroupName, true,
1278 ElfSec.getUniqueID(),
1279 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1280}
1281
1282MCSection *
1284 constexpr StringLiteral Name = ".llvm_bb_addr_map";
1285 if (Ctx->getObjectFileType() == MCContext::IsELF) {
1286 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1287 unsigned Flags = ELF::SHF_LINK_ORDER;
1288 StringRef GroupName;
1289 if (const MCSymbol *Group = ElfSec.getGroup()) {
1290 GroupName = Group->getName();
1291 Flags |= ELF::SHF_GROUP;
1292 }
1293
1294 // Use the text section's begin symbol and unique ID to create a separate
1295 // .llvm_bb_addr_map section associated with every unique text section.
1296 return Ctx->getELFSection(
1297 Name, ELF::SHT_LLVM_BB_ADDR_MAP, Flags, 0, GroupName, true,
1298 ElfSec.getUniqueID(),
1299 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1300 } else if (Ctx->getObjectFileType() == MCContext::IsCOFF) {
1301 StringRef COMDATSymName;
1302 int Selection = 0;
1303 unsigned Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1306 const auto &COFFSec = static_cast<const MCSectionCOFF &>(TextSec);
1307 if (const MCSymbol *COMDATSym = COFFSec.getCOMDATSymbol()) {
1308 if (!Ctx->getAsmInfo().hasCOFFAssociativeComdats())
1309 report_fatal_error("BB address map requires associative COMDAT "
1310 "support for COMDAT functions");
1311 COMDATSymName = COMDATSym->getName();
1312 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
1314 }
1315 return Ctx->getCOFFSection(Name, Characteristics, COMDATSymName, Selection,
1316 COFFSec.getUniqueID());
1317 }
1318
1319 return nullptr;
1320}
1321
1322MCSection *
1324 if (Ctx->getObjectFileType() != MCContext::IsELF)
1325 return nullptr;
1326
1327 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1328 unsigned Flags = ELF::SHF_LINK_ORDER | ELF::SHF_ALLOC;
1329 StringRef GroupName;
1330 if (const MCSymbol *Group = ElfSec.getGroup()) {
1331 GroupName = Group->getName();
1332 Flags |= ELF::SHF_GROUP;
1333 }
1334
1335 return Ctx->getELFSection(
1336 ".kcfi_traps", ELF::SHT_PROGBITS, Flags, 0, GroupName,
1337 /*IsComdat=*/true, ElfSec.getUniqueID(),
1338 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1339}
1340
1341MCSection *
1343 auto ObjFileType = Ctx->getObjectFileType();
1344 if (ObjFileType == MCContext::IsELF) {
1345 const auto &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1346 unsigned Flags = ELF::SHF_LINK_ORDER;
1347 StringRef GroupName;
1348 if (const MCSymbol *Group = ElfSec.getGroup()) {
1349 GroupName = Group->getName();
1350 Flags |= ELF::SHF_GROUP;
1351 }
1352 return Ctx->getELFSection(
1353 PseudoProbeSection->getName(), ELF::SHT_PROGBITS, Flags, 0, GroupName,
1354 true, ElfSec.getUniqueID(),
1355 static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1356 } else if (ObjFileType == MCContext::IsCOFF) {
1357 StringRef COMDATSymName = "";
1358 int Selection = 0;
1359 unsigned Characteristics =
1360 static_cast<MCSectionCOFF *>(PseudoProbeSection)->getCharacteristics();
1361 const auto &COFFSec = static_cast<const MCSectionCOFF &>(TextSec);
1362 if (const MCSymbol *COMDATSym = COFFSec.getCOMDATSymbol()) {
1363 // Associate .pseudo_probe to its function section.
1364 COMDATSymName = COMDATSym->getName();
1365 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
1367 }
1368 return Ctx->getCOFFSection(PseudoProbeSection->getName(), Characteristics,
1369 COMDATSymName, Selection, COFFSec.getUniqueID());
1370 }
1371
1372 return PseudoProbeSection;
1373}
1374
1375MCSection *
1377 uint64_t FuncHash) const {
1378 if (!Ctx->getTargetTriple().supportsCOMDAT() || FuncName.empty())
1380
1381 // Create a separate comdat group for each function's descriptor in order
1382 // for the linker to deduplicate. The duplication, must be from different
1383 // translation unit, can come from:
1384 // 1. Inline functions defined in header files;
1385 // 2. ThinLTO imported functions;
1386 // 3. Weak-linkage definitions.
1387 // Use a concatenation of the section name, function name, and function hash
1388 // as the group name so that descriptors with different hashes (due to user
1389 // code not following ODR or compiler codegen inconsistencies) get separate
1390 // COMDAT sections instead of being silently dropped (ELF) or causing linker
1391 // errors (COFF). Duplicate GUIDs with mismatching hashes are detected
1392 // during descriptor decoding and reported by llvm-profgen.
1393 auto ObjFileType = Ctx->getObjectFileType();
1394 if (ObjFileType == MCContext::IsELF) {
1395 auto *S = static_cast<MCSectionELF *>(PseudoProbeDescSection);
1396 auto Flags = S->getFlags() | ELF::SHF_GROUP;
1397 return Ctx->getELFSection(
1398 S->getName(), S->getType(), Flags, S->getEntrySize(),
1399 S->getName() + "_" + FuncName + "." + Twine::utohexstr(FuncHash),
1400 /*IsComdat=*/true);
1401 } else if (ObjFileType == MCContext::IsCOFF) {
1402 auto *S = static_cast<MCSectionCOFF *>(PseudoProbeDescSection);
1403 unsigned Characteristics =
1404 S->getCharacteristics() | COFF::IMAGE_SCN_LNK_COMDAT;
1405 std::string COMDATSymName =
1406 (S->getName() + "_" + FuncName + "." + Twine::utohexstr(FuncHash))
1407 .str();
1408 return Ctx->getCOFFSection(S->getName(), Characteristics, COMDATSymName,
1410 }
1411
1413}
1414
1418
1420 const MCSection *TextSec) const {
1421 if (Ctx->getObjectFileType() != MCContext::IsELF)
1422 return nullptr;
1423
1424 // SHF_WRITE for relocations, and let user post-process data in-place.
1426
1427 if (!TextSec)
1428 TextSec = getTextSection();
1429
1430 StringRef GroupName;
1431 const auto &ElfSec = static_cast<const MCSectionELF &>(*TextSec);
1432 if (const MCSymbol *Group = ElfSec.getGroup()) {
1433 GroupName = Group->getName();
1434 Flags |= ELF::SHF_GROUP;
1435 }
1436 return Ctx->getELFSection(
1437 Name, ELF::SHT_PROGBITS, Flags, 0, GroupName, true, ElfSec.getUniqueID(),
1438 static_cast<const MCSymbolELF *>(TextSec->getBeginSymbol()));
1439}
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