LLVM  10.0.0
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 
10 #include "llvm/ADT/StringExtras.h"
11 #include "llvm/ADT/Triple.h"
12 #include "llvm/BinaryFormat/COFF.h"
13 #include "llvm/BinaryFormat/ELF.h"
14 #include "llvm/MC/MCAsmInfo.h"
15 #include "llvm/MC/MCContext.h"
16 #include "llvm/MC/MCSection.h"
17 #include "llvm/MC/MCSectionCOFF.h"
18 #include "llvm/MC/MCSectionELF.h"
19 #include "llvm/MC/MCSectionMachO.h"
20 #include "llvm/MC/MCSectionWasm.h"
21 #include "llvm/MC/MCSectionXCOFF.h"
22 
23 using namespace llvm;
24 
25 static bool useCompactUnwind(const Triple &T) {
26  // Only on darwin.
27  if (!T.isOSDarwin())
28  return false;
29 
30  // aarch64 always has it.
32  return true;
33 
34  // armv7k always has it.
35  if (T.isWatchABI())
36  return true;
37 
38  // Use it on newer version of OS X.
39  if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
40  return true;
41 
42  // And the iOS simulator.
43  if (T.isiOS() && T.isX86())
44  return true;
45 
46  return false;
47 }
48 
49 void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
50  // MachO
52 
54  "__TEXT", "__eh_frame",
58 
59  if (T.isOSDarwin() &&
62 
63  if (T.isWatchABI())
65 
67 
68  // .comm doesn't support alignment before Leopard.
69  if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
71 
72  TextSection // .text
73  = Ctx->getMachOSection("__TEXT", "__text",
76  DataSection // .data
77  = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
78 
79  // BSSSection might not be expected initialized on msvc.
80  BSSSection = nullptr;
81 
82  TLSDataSection // .tdata
83  = Ctx->getMachOSection("__DATA", "__thread_data",
86  TLSBSSSection // .tbss
87  = Ctx->getMachOSection("__DATA", "__thread_bss",
90 
91  // TODO: Verify datarel below.
92  TLSTLVSection // .tlv
93  = Ctx->getMachOSection("__DATA", "__thread_vars",
96 
98  "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
100 
101  CStringSection // .cstring
102  = Ctx->getMachOSection("__TEXT", "__cstring",
106  = Ctx->getMachOSection("__TEXT","__ustring", 0,
108  FourByteConstantSection // .literal4
109  = Ctx->getMachOSection("__TEXT", "__literal4",
112  EightByteConstantSection // .literal8
113  = Ctx->getMachOSection("__TEXT", "__literal8",
116 
117  SixteenByteConstantSection // .literal16
118  = Ctx->getMachOSection("__TEXT", "__literal16",
121 
122  ReadOnlySection // .const
123  = Ctx->getMachOSection("__TEXT", "__const", 0,
125 
126  // If the target is not powerpc, map the coal sections to the non-coal
127  // sections.
128  //
129  // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
130  // "__TEXT/__const_coal" => section "__TEXT/__const"
131  // "__DATA/__datacoal_nt" => section "__DATA/__data"
132  Triple::ArchType ArchTy = T.getArch();
133 
134  ConstDataSection // .const_data
135  = Ctx->getMachOSection("__DATA", "__const", 0,
137 
138  if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
140  = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
145  = Ctx->getMachOSection("__TEXT", "__const_coal",
149  "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());
151  } else {
156  }
157 
159  = Ctx->getMachOSection("__DATA","__common",
163  = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
165 
166 
168  = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
172  = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
175 
177  = Ctx->getMachOSection("__DATA", "__thread_ptr",
180 
181  // Exception Handling.
182  LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
184 
185  COFFDebugSymbolsSection = nullptr;
186  COFFDebugTypesSection = nullptr;
187  COFFGlobalTypeHashesSection = nullptr;
188 
189  if (useCompactUnwind(T)) {
191  Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
193 
194  if (T.isX86())
195  CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF
196  else if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)
197  CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF
198  else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
199  CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF
200  }
201 
202  // Debug Information.
204  Ctx->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG,
205  SectionKind::getMetadata(), "debug_names_begin");
207  Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
208  SectionKind::getMetadata(), "names_begin");
210  Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
211  SectionKind::getMetadata(), "objc_begin");
212  // 16 character section limit...
214  Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
215  SectionKind::getMetadata(), "namespac_begin");
217  Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
218  SectionKind::getMetadata(), "types_begin");
219 
221  Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG,
223 
225  Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
226  SectionKind::getMetadata(), "section_abbrev");
228  Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
229  SectionKind::getMetadata(), "section_info");
231  Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
232  SectionKind::getMetadata(), "section_line");
234  Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,
235  SectionKind::getMetadata(), "section_line_str");
237  Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
240  Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
243  Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
246  Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
249  Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
252  Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
253  SectionKind::getMetadata(), "info_string");
255  Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG,
256  SectionKind::getMetadata(), "section_str_off");
258  Ctx->getMachOSection("__DWARF", "__debug_addr", MachO::S_ATTR_DEBUG,
259  SectionKind::getMetadata(), "section_info");
261  Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
262  SectionKind::getMetadata(), "section_debug_loc");
264  Ctx->getMachOSection("__DWARF", "__debug_loclists", MachO::S_ATTR_DEBUG,
265  SectionKind::getMetadata(), "section_debug_loc");
266 
268  Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
271  Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
272  SectionKind::getMetadata(), "debug_range");
274  Ctx->getMachOSection("__DWARF", "__debug_rnglists", MachO::S_ATTR_DEBUG,
275  SectionKind::getMetadata(), "debug_range");
277  Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG,
278  SectionKind::getMetadata(), "debug_macinfo");
280  Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
283  Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,
286  Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG,
288  StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
290 
291  FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
293 
295  "__LLVM", "__remarks", MachO::S_ATTR_DEBUG, SectionKind::getMetadata());
296 
298 }
299 
300 void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
301  switch (T.getArch()) {
302  case Triple::mips:
303  case Triple::mipsel:
304  case Triple::mips64:
305  case Triple::mips64el:
306  // We cannot use DW_EH_PE_sdata8 for the large PositionIndependent case
307  // since there is no R_MIPS_PC64 relocation (only a 32-bit version).
308  if (PositionIndependent && !Large)
310  else
314  break;
315  case Triple::ppc64:
316  case Triple::ppc64le:
317  case Triple::x86_64:
320  break;
321  case Triple::bpfel:
322  case Triple::bpfeb:
324  break;
325  case Triple::hexagon:
327  PositionIndependent ? dwarf::DW_EH_PE_pcrel : dwarf::DW_EH_PE_absptr;
328  break;
329  default:
331  break;
332  }
333 
334  unsigned EHSectionType = T.getArch() == Triple::x86_64
337 
338  // Solaris requires different flags for .eh_frame to seemingly every other
339  // platform.
340  unsigned EHSectionFlags = ELF::SHF_ALLOC;
341  if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
342  EHSectionFlags |= ELF::SHF_WRITE;
343 
344  // ELF
347 
350 
353 
356 
358  Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
360 
363 
364  DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
366 
368  Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
369  ELF::SHF_ALLOC | ELF::SHF_MERGE, 4, "");
370 
372  Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
373  ELF::SHF_ALLOC | ELF::SHF_MERGE, 8, "");
374 
376  Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
377  ELF::SHF_ALLOC | ELF::SHF_MERGE, 16, "");
378 
380  Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS,
381  ELF::SHF_ALLOC | ELF::SHF_MERGE, 32, "");
382 
383  // Exception Handling Sections.
384 
385  // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
386  // it contains relocatable pointers. In PIC mode, this is probably a big
387  // runtime hit for C++ apps. Either the contents of the LSDA need to be
388  // adjusted or this should be a data section.
389  LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
391 
392  COFFDebugSymbolsSection = nullptr;
393  COFFDebugTypesSection = nullptr;
394 
395  unsigned DebugSecType = ELF::SHT_PROGBITS;
396 
397  // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
398  // to distinguish among sections contain DWARF and ECOFF debug formats.
399  // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
400  if (T.isMIPS())
401  DebugSecType = ELF::SHT_MIPS_DWARF;
402 
403  // Debug Info Sections.
405  Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);
406  DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0);
407  DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0);
409  Ctx->getELFSection(".debug_line_str", DebugSecType,
411  DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0);
413  Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);
415  Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);
417  Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);
419  Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);
421  Ctx->getELFSection(".debug_str", DebugSecType,
423  DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0);
425  Ctx->getELFSection(".debug_aranges", DebugSecType, 0);
427  Ctx->getELFSection(".debug_ranges", DebugSecType, 0);
429  Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);
430 
431  // DWARF5 Experimental Debug Info
432 
433  // Accelerator Tables
435  Ctx->getELFSection(".debug_names", ELF::SHT_PROGBITS, 0);
437  Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);
439  Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);
441  Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);
443  Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);
444 
445  // String Offset and Address Sections
447  Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);
448  DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);
449  DwarfRnglistsSection = Ctx->getELFSection(".debug_rnglists", DebugSecType, 0);
450  DwarfLoclistsSection = Ctx->getELFSection(".debug_loclists", DebugSecType, 0);
451 
452  // Fission Sections
454  Ctx->getELFSection(".debug_info.dwo", DebugSecType, ELF::SHF_EXCLUDE);
456  Ctx->getELFSection(".debug_types.dwo", DebugSecType, ELF::SHF_EXCLUDE);
458  Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, ELF::SHF_EXCLUDE);
460  ".debug_str.dwo", DebugSecType,
463  Ctx->getELFSection(".debug_line.dwo", DebugSecType, ELF::SHF_EXCLUDE);
465  Ctx->getELFSection(".debug_loc.dwo", DebugSecType, ELF::SHF_EXCLUDE);
466  DwarfStrOffDWOSection = Ctx->getELFSection(".debug_str_offsets.dwo",
467  DebugSecType, ELF::SHF_EXCLUDE);
469  Ctx->getELFSection(".debug_rnglists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
471  Ctx->getELFSection(".debug_macinfo.dwo", DebugSecType, ELF::SHF_EXCLUDE);
472 
474  Ctx->getELFSection(".debug_loclists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
475 
476  // DWP Sections
478  Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);
480  Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);
481 
483  Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
484 
486  Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
487 
489  Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
490 
491  StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);
492 }
493 
494 void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
499 
500  // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
501  // used to indicate to the linker that the text segment contains thumb instructions
502  // and to set the ISA selection bit for calls accordingly.
503  const bool IsThumb = T.getArch() == Triple::thumb;
504 
506 
507  // COFF
508  BSSSection = Ctx->getCOFFSection(
513  ".text",
525 
526  if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64) {
527  // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
528  LSDASection = nullptr;
529  } else {
530  LSDASection = Ctx->getCOFFSection(".gcc_except_table",
534  }
535 
536  // Debug info.
548  ".debug$H",
552 
554  ".debug_abbrev",
557  SectionKind::getMetadata(), "section_abbrev");
559  ".debug_info",
562  SectionKind::getMetadata(), "section_info");
564  ".debug_line",
567  SectionKind::getMetadata(), "section_line");
569  ".debug_line_str",
572  SectionKind::getMetadata(), "section_line_str");
574  ".debug_frame",
579  ".debug_pubnames",
584  ".debug_pubtypes",
589  ".debug_gnu_pubnames",
594  ".debug_gnu_pubtypes",
599  ".debug_str",
602  SectionKind::getMetadata(), "info_string");
604  ".debug_str_offsets",
607  SectionKind::getMetadata(), "section_str_off");
609  ".debug_loc",
612  SectionKind::getMetadata(), "section_debug_loc");
614  ".debug_aranges",
619  ".debug_ranges",
622  SectionKind::getMetadata(), "debug_range");
624  ".debug_macinfo",
627  SectionKind::getMetadata(), "debug_macinfo");
629  ".debug_macinfo.dwo",
632  SectionKind::getMetadata(), "debug_macinfo.dwo");
634  ".debug_info.dwo",
637  SectionKind::getMetadata(), "section_info_dwo");
639  ".debug_types.dwo",
642  SectionKind::getMetadata(), "section_types_dwo");
644  ".debug_abbrev.dwo",
647  SectionKind::getMetadata(), "section_abbrev_dwo");
649  ".debug_str.dwo",
652  SectionKind::getMetadata(), "skel_string");
654  ".debug_line.dwo",
659  ".debug_loc.dwo",
662  SectionKind::getMetadata(), "skel_loc");
664  ".debug_str_offsets.dwo",
667  SectionKind::getMetadata(), "section_str_off_dwo");
669  ".debug_addr",
672  SectionKind::getMetadata(), "addr_sec");
674  ".debug_cu_index",
679  ".debug_tu_index",
684  ".debug_names",
687  SectionKind::getMetadata(), "debug_names_begin");
689  ".apple_names",
692  SectionKind::getMetadata(), "names_begin");
694  ".apple_namespaces",
697  SectionKind::getMetadata(), "namespac_begin");
699  ".apple_types",
702  SectionKind::getMetadata(), "types_begin");
704  ".apple_objc",
707  SectionKind::getMetadata(), "objc_begin");
708 
712 
716 
720 
723 
724  GFIDsSection = Ctx->getCOFFSection(".gfids$y",
728 
729  GLJMPSection = Ctx->getCOFFSection(".gljmp$y",
733 
738 
739  StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
743 }
744 
745 void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
748 
750  Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());
752  Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata());
754  Ctx->getWasmSection(".debug_str", SectionKind::getMetadata());
756  Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());
758  Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata());
759  DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());
761  Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata());
763  Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata());
765  DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
766  DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
768  Ctx->getWasmSection(".debug_info", SectionKind::getMetadata());
770  DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
771  DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
772 
773  // Wasm use data section for LSDA.
774  // TODO Consider putting each function's exception table in a separate
775  // section, as in -function-sections, to facilitate lld's --gc-section.
776  LSDASection = Ctx->getWasmSection(".rodata.gcc_except_table",
778 
779  // TODO: Define more sections.
780 }
781 
782 void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) {
783  // The default csect for program code. Functions without a specified section
784  // get placed into this csect. The choice of csect name is not a property of
785  // the ABI or object file format. For example, the XL compiler uses an unnamed
786  // csect for program code.
790 
794 
798 }
799 
800 void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
801  MCContext &ctx,
802  bool LargeCodeModel) {
803  PositionIndependent = PIC;
804  Ctx = &ctx;
805 
806  // Common.
811 
813 
815 
816  EHFrameSection = nullptr; // Created on demand.
817  CompactUnwindSection = nullptr; // Used only by selected targets.
818  DwarfAccelNamesSection = nullptr; // Used only by selected targets.
819  DwarfAccelObjCSection = nullptr; // Used only by selected targets.
820  DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
821  DwarfAccelTypesSection = nullptr; // Used only by selected targets.
822 
823  TT = TheTriple;
824 
825  switch (TT.getObjectFormat()) {
826  case Triple::MachO:
827  Env = IsMachO;
828  initMachOMCObjectFileInfo(TT);
829  break;
830  case Triple::COFF:
831  if (!TT.isOSWindows())
833  "Cannot initialize MC for non-Windows COFF object files.");
834 
835  Env = IsCOFF;
836  initCOFFMCObjectFileInfo(TT);
837  break;
838  case Triple::ELF:
839  Env = IsELF;
840  initELFMCObjectFileInfo(TT, LargeCodeModel);
841  break;
842  case Triple::Wasm:
843  Env = IsWasm;
844  initWasmMCObjectFileInfo(TT);
845  break;
846  case Triple::XCOFF:
847  Env = IsXCOFF;
848  initXCOFFMCObjectFileInfo(TT);
849  break;
851  report_fatal_error("Cannot initialize MC for unknown object file format.");
852  break;
853  }
854 }
855 
856 MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
857  uint64_t Hash) const {
858  switch (TT.getObjectFormat()) {
859  case Triple::ELF:
860  return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0,
861  utostr(Hash));
862  case Triple::MachO:
863  case Triple::COFF:
864  case Triple::Wasm:
865  case Triple::XCOFF:
867  report_fatal_error("Cannot get DWARF comdat section for this object file "
868  "format: not implemented.");
869  break;
870  }
871  llvm_unreachable("Unknown ObjectFormatType");
872 }
873 
874 MCSection *
876  if (Env != IsELF)
877  return StackSizesSection;
878 
879  const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
880  unsigned Flags = ELF::SHF_LINK_ORDER;
881  StringRef GroupName;
882  if (const MCSymbol *Group = ElfSec.getGroup()) {
883  GroupName = Group->getName();
884  Flags |= ELF::SHF_GROUP;
885  }
886 
887  const MCSymbol *Link = TextSec.getBeginSymbol();
889  unsigned UniqueID = It.first->second;
890 
891  return Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, Flags, 0,
892  GroupName, UniqueID, cast<MCSymbolELF>(Link));
893 }
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:318
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (macOS, iOS, tvOS or watchOS).
Definition: Triple.h:482
MCSection * DwarfLoclistsDWOSection
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
MCSection * MergeableConst4Section
static SectionKind getData()
Definition: SectionKind.h:201
MCSection * DwarfStrOffSection
The DWARF v5 string offset and address table sections.
S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.
Definition: MachO.h:131
S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine instructions.
Definition: MachO.h:181
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
This class represents lattice values for constants.
Definition: AllocatorList.h:23
bool isMacOSX() const
isMacOSX - Is this a Mac OS X triple.
Definition: Triple.h:454
MCSection * DwarfPubTypesSection
MCSection * DwarfGnuPubTypesSection
Section for newer gnu pubtypes.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
MCSection * StackMapSection
StackMap section.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
MCSection * SixteenByteConstantSection
MCSection * DwarfRnglistsSection
The DWARF v5 range list section.
MCSection * TextSection
Section directive for standard text.
MCSection * ConstTextCoalSection
bool isX86() const
Tests whether the target is x86 (32- or 64-bit).
Definition: Triple.h:735
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K)
Definition: MCContext.h:487
S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section in files with the MY_DYLDLINK f...
Definition: MachO.h:187
MCSection * LazySymbolPointerSection
static SectionKind getMergeableConst8()
Definition: SectionKind.h:192
static SectionKind getMergeableConst16()
Definition: SectionKind.h:193
static SectionKind getMergeable1ByteCString()
Definition: SectionKind.h:182
S_THREAD_LOCAL_VARIABLES - Section with thread local variable structure data.
Definition: MachO.h:164
Read Write Data.
Definition: XCOFF.h:43
static SectionKind getMergeableConst4()
Definition: SectionKind.h:191
static bool useCompactUnwind(const Triple &T)
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID, const char *BeginSymName=nullptr)
Definition: MCContext.cpp:435
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:195
MCSection * MergeableConst32Section
MCSection * DwarfDebugNamesSection
Accelerator table sections.
S_4BYTE_LITERALS - Section with 4 byte literals.
Definition: MachO.h:125
static SectionKind getBSS()
Definition: SectionKind.h:197
MCSection * COFFDebugTypesSection
MCSection * MergeableConst16Section
MCSection * DwarfPubNamesSection
S_8BYTE_LITERALS - Section with 8 byte literals.
Definition: MachO.h:127
MCSection * EightByteConstantSection
MCSection * getStackSizesSection(const MCSection &TextSec) const
bool isOSSolaris() const
Definition: Triple.h:512
MCSection * TLSDataSection
Section directive for Thread Local data. ELF, MachO, COFF, and Wasm.
Context object for machine code objects.
Definition: MCContext.h:65
MCSectionXCOFF * getXCOFFSection(StringRef Section, XCOFF::StorageMappingClass MappingClass, XCOFF::SymbolType CSectType, XCOFF::StorageClass StorageClass, SectionKind K, const char *BeginSymName=nullptr)
Definition: MCContext.cpp:539
const MCSection * DwarfDebugInlineSection
MCSectionMachO * getMachOSection(StringRef Segment, StringRef Section, unsigned TypeAndAttributes, unsigned Reserved2, SectionKind K, const char *BeginSymName=nullptr)
Return the MCSection for the specified mach-o section.
Definition: MCContext.cpp:286
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:297
MCSection * ConstDataCoalSection
MCSection * DrectveSection
COFF specific sections.
bool isiOS() const
Is this an iOS triple.
Definition: Triple.h:463
MCSection * DwarfAccelNamesSection
MCSection * DataSection
Section directive for standard data.
SectionCharacteristics
Definition: COFF.h:283
S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks.
Definition: MachO.h:191
bool isOSWindows() const
Tests whether the OS is Windows.
Definition: Triple.h:539
MCSection * ThreadLocalPointerSection
MCSection * DwarfLineStrSection
Program Code.
Definition: XCOFF.h:31
const MCSymbolELF * getGroup() const
Definition: MCSectionELF.h:75
MCSection * DwarfSwiftASTSection
MCSection * TLSTLVSection
Section for thread local structure information.
S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
Definition: MachO.h:161
bool isWatchABI() const
Definition: Triple.h:477
MCSection * RemarksSection
Remarks section.
MCSection * DwarfAccelNamespaceSection
MCSection * DwarfMacinfoDWOSection
S_THREAD_LOCAL_REGULAR - Thread local data section.
Definition: MachO.h:159
unsigned size() const
Definition: DenseMap.h:99
bool SupportsCompactUnwindWithoutEHFrame
True if the target object file supports emitting a compact unwind section without an associated EH fr...
S_CSTRING_LITERALS - Section with literal C strings.
Definition: MachO.h:123
bool CommDirectiveSupportsAlignment
True if .comm supports alignment.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:43
MCSection * COFFDebugSymbolsSection
MCSection * DwarfAbbrevSection
MCSection * EHFrameSection
EH frame section.
MCSection * DwarfLoclistsSection
The DWARF v5 locations list section.
S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.
Definition: MachO.h:133
MCSection * DwarfTypesDWOSection
static SectionKind getThreadBSS()
Definition: SectionKind.h:195
MCSection * DwarfRangesSection
S_THREAD_LOCAL_VARIABLE_POINTERS - Section with pointers to thread local structures.
Definition: MachO.h:167
static SectionKind getMetadata()
Definition: SectionKind.h:178
static SectionKind getReadOnlyWithRel()
Definition: SectionKind.h:202
MCSymbol * getBeginSymbol()
Definition: MCSection.h:115
MCSection * DwarfARangesSection
MCSection * CompactUnwindSection
If exception handling is supported by the target and the target can support a compact representation ...
MCSection * DwarfAccelTypesSection
S_THREAD_LOCAL_INIT_FUNCTION_POINTERS - Section with thread local variable initialization pointers to...
Definition: MachO.h:170
DenseMap< const MCSymbol *, unsigned > StackSizesUniquing
std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:223
MCSection * DwarfStrOffDWOSection
S_16BYTE_LITERALS - Section with only 16 byte literals.
Definition: MachO.h:152
MCSection * DwarfGnuPubNamesSection
Section for newer gnu pubnames.
bool isMIPS() const
Tests whether the target is MIPS (little and big endian, 32- or 64-bit).
Definition: Triple.h:720
MCSection * DwarfAbbrevDWOSection
MCSection * FaultMapSection
FaultMap section.
bool OmitDwarfIfHaveCompactUnwind
OmitDwarfIfHaveCompactUnwind - True if the target object file supports having some functions with com...
MCSection * FourByteConstantSection
Read Only Constant.
Definition: XCOFF.h:32
Csect definition for initialized storage.
Definition: XCOFF.h:146
static SectionKind getMergeable2ByteCString()
Definition: SectionKind.h:185
void InitMCObjectFileInfo(const Triple &TT, bool PIC, MCContext &ctx, bool LargeCodeModel=false)
unsigned FDECFIEncoding
FDE CFI encoding.
MCSection * LSDASection
If exception handling is supported by the target, this is the section the Language Specific Data Area...
MCSection * TLSExtraDataSection
Extra TLS Variable Data section.
ObjectFormatType getObjectFormat() const
getFormat - Get the object format for this triple.
Definition: Triple.h:327
unsigned CompactUnwindDwarfEHFrameOnly
Compact unwind encoding indicating that we should emit only an EH frame.
MCSection * StackSizesSection
Section containing metadata on function stack sizes.
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:27
S_ATTR_DEBUG - A debug section.
Definition: MachO.h:196
S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be in a ranlib table of contents...
Definition: MachO.h:184
bool isMacOSXVersionLT(unsigned Major, unsigned Minor=0, unsigned Micro=0) const
isMacOSXVersionLT - Comparison function for checking OS X version compatibility, which handles suppor...
Definition: Triple.h:439
MCSection * DwarfAccelObjCSection
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
Definition: MCAsmInfo.h:411
S_COALESCED - Section contains symbols that are to be coalesced.
Definition: MachO.h:144
MCSection * COFFGlobalTypeHashesSection
MCSection * TLSBSSSection
Section directive for Thread Local uninitialized data.
MCSection * NonLazySymbolPointerSection
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:424
const MCSection * TLSThreadInitSection
Section for thread local data initialization functions.
MCSection * DwarfRnglistsDWOSection
The DWARF v5 range and location list sections for fission.
bool SupportsWeakOmittedEHFrame
True if target object file supports a weak_definition of constant 0 for an omitted EH frame...
MCSection * BSSSection
Section that is default initialized to zero.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
MCSection * ReadOnlySection
Section that is readonly and can contain arbitrary initialized data.
S_ZEROFILL - Zero fill on demand section.
Definition: MachO.h:121
MCSection * DwarfMacinfoSection
static SectionKind getReadOnly()
Definition: SectionKind.h:181
static SectionKind getText()
Definition: SectionKind.h:179
MCSection * MergeableConst8Section