LLVM  7.0.0
MCObjectFileInfo.cpp
Go to the documentation of this file.
1 //===-- MCObjectFileInfo.cpp - Object File Information --------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 #include "llvm/ADT/StringExtras.h"
12 #include "llvm/ADT/Triple.h"
13 #include "llvm/BinaryFormat/COFF.h"
14 #include "llvm/BinaryFormat/ELF.h"
15 #include "llvm/MC/MCAsmInfo.h"
16 #include "llvm/MC/MCContext.h"
17 #include "llvm/MC/MCSection.h"
18 #include "llvm/MC/MCSectionCOFF.h"
19 #include "llvm/MC/MCSectionELF.h"
20 #include "llvm/MC/MCSectionMachO.h"
21 #include "llvm/MC/MCSectionWasm.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.
31  if (T.getArch() == Triple::aarch64)
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() &&
44  (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86))
45  return true;
46 
47  return false;
48 }
49 
50 void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
51  // MachO
53 
55  "__TEXT", "__eh_frame",
59 
60  if (T.isOSDarwin() && T.getArch() == Triple::aarch64)
62 
63  if (T.isWatchABI())
65 
71 
72  // .comm doesn't support alignment before Leopard.
73  if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
75 
76  TextSection // .text
77  = Ctx->getMachOSection("__TEXT", "__text",
80  DataSection // .data
81  = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
82 
83  // BSSSection might not be expected initialized on msvc.
84  BSSSection = nullptr;
85 
86  TLSDataSection // .tdata
87  = Ctx->getMachOSection("__DATA", "__thread_data",
90  TLSBSSSection // .tbss
91  = Ctx->getMachOSection("__DATA", "__thread_bss",
94 
95  // TODO: Verify datarel below.
96  TLSTLVSection // .tlv
97  = Ctx->getMachOSection("__DATA", "__thread_vars",
100 
102  "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
104 
105  CStringSection // .cstring
106  = Ctx->getMachOSection("__TEXT", "__cstring",
110  = Ctx->getMachOSection("__TEXT","__ustring", 0,
112  FourByteConstantSection // .literal4
113  = Ctx->getMachOSection("__TEXT", "__literal4",
116  EightByteConstantSection // .literal8
117  = Ctx->getMachOSection("__TEXT", "__literal8",
120 
121  SixteenByteConstantSection // .literal16
122  = Ctx->getMachOSection("__TEXT", "__literal16",
125 
126  ReadOnlySection // .const
127  = Ctx->getMachOSection("__TEXT", "__const", 0,
129 
130  // If the target is not powerpc, map the coal sections to the non-coal
131  // sections.
132  //
133  // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
134  // "__TEXT/__const_coal" => section "__TEXT/__const"
135  // "__DATA/__datacoal_nt" => section "__DATA/__data"
136  Triple::ArchType ArchTy = T.getArch();
137 
138  ConstDataSection // .const_data
139  = Ctx->getMachOSection("__DATA", "__const", 0,
141 
142  if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
144  = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
149  = Ctx->getMachOSection("__TEXT", "__const_coal",
153  "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());
155  } else {
160  }
161 
163  = Ctx->getMachOSection("__DATA","__common",
167  = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
169 
170 
172  = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
176  = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
179 
181  = Ctx->getMachOSection("__DATA", "__thread_ptr",
184 
185  // Exception Handling.
186  LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
188 
189  COFFDebugSymbolsSection = nullptr;
190  COFFDebugTypesSection = nullptr;
191  COFFGlobalTypeHashesSection = nullptr;
192 
193  if (useCompactUnwind(T)) {
195  Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
197 
198  if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
199  CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF
200  else if (T.getArch() == Triple::aarch64)
201  CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF
202  else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
203  CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF
204  }
205 
206  // Debug Information.
208  Ctx->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG,
209  SectionKind::getMetadata(), "debug_names_begin");
211  Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
212  SectionKind::getMetadata(), "names_begin");
214  Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
215  SectionKind::getMetadata(), "objc_begin");
216  // 16 character section limit...
218  Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
219  SectionKind::getMetadata(), "namespac_begin");
221  Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
222  SectionKind::getMetadata(), "types_begin");
223 
225  Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG,
227 
229  Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
230  SectionKind::getMetadata(), "section_abbrev");
232  Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
233  SectionKind::getMetadata(), "section_info");
235  Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
236  SectionKind::getMetadata(), "section_line");
238  Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,
239  SectionKind::getMetadata(), "section_line_str");
241  Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
244  Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
247  Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
250  Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
253  Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
256  Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
257  SectionKind::getMetadata(), "info_string");
259  Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG,
260  SectionKind::getMetadata(), "section_str_off");
262  Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
263  SectionKind::getMetadata(), "section_debug_loc");
265  Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
268  Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
269  SectionKind::getMetadata(), "debug_range");
271  Ctx->getMachOSection("__DWARF", "__debug_rnglists", MachO::S_ATTR_DEBUG,
272  SectionKind::getMetadata(), "debug_range");
274  Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG,
275  SectionKind::getMetadata(), "debug_macinfo");
277  Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
280  Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,
283  Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG,
285  StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
287 
288  FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
290 
292 }
293 
294 void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
295  switch (T.getArch()) {
296  case Triple::mips:
297  case Triple::mipsel:
299  break;
300  case Triple::mips64:
301  case Triple::mips64el:
303  break;
304  case Triple::ppc64:
305  case Triple::ppc64le:
306  case Triple::x86_64:
309  break;
310  case Triple::bpfel:
311  case Triple::bpfeb:
313  break;
314  default:
316  break;
317  }
318 
319  switch (T.getArch()) {
320  case Triple::arm:
321  case Triple::armeb:
322  case Triple::thumb:
323  case Triple::thumbeb:
325  break;
326  // Fallthrough if not using EHABI
328  case Triple::ppc:
329  case Triple::x86:
330  PersonalityEncoding = PositionIndependent
335  LSDAEncoding = PositionIndependent
338  TTypeEncoding = PositionIndependent
342  break;
343  case Triple::x86_64:
344  if (PositionIndependent) {
352  } else {
357  }
358  break;
359  case Triple::hexagon:
364  if (PositionIndependent) {
369  }
370  break;
371  case Triple::aarch64:
372  case Triple::aarch64_be:
373  // The small model guarantees static code/data size < 4GB, but not where it
374  // will be in memory. Most of these could end up >2GB away so even a signed
375  // pc-relative 32-bit address is insufficient, theoretically.
376  if (PositionIndependent) {
382  } else {
386  }
387  break;
388  case Triple::lanai:
392  break;
393  case Triple::mips:
394  case Triple::mipsel:
395  case Triple::mips64:
396  case Triple::mips64el:
397  // MIPS uses indirect pointer to refer personality functions and types, so
398  // that the eh_frame section can be read-only. DW.ref.personality will be
399  // generated for relocation.
401  // FIXME: The N64 ABI probably ought to use DW_EH_PE_sdata8 but we can't
402  // identify N64 from just a triple.
405  // We don't support PC-relative LSDA references in GAS so we use the default
406  // DW_EH_PE_absptr for those.
407 
408  // FreeBSD must be explicit about the data size and using pcrel since it's
409  // assembler/linker won't do the automatic conversion that the Linux tools
410  // do.
411  if (T.isOSFreeBSD()) {
414  }
415  break;
416  case Triple::ppc64:
417  case Triple::ppc64le:
423  break;
424  case Triple::sparcel:
425  case Triple::sparc:
426  if (PositionIndependent) {
432  } else {
436  }
437  break;
438  case Triple::sparcv9:
440  if (PositionIndependent) {
445  } else {
448  }
449  break;
450  case Triple::systemz:
451  // All currently-defined code models guarantee that 4-byte PC-relative
452  // values will be in range.
453  if (PositionIndependent) {
459  } else {
463  }
464  break;
465  default:
466  break;
467  }
468 
469  unsigned EHSectionType = T.getArch() == Triple::x86_64
472 
473  // Solaris requires different flags for .eh_frame to seemingly every other
474  // platform.
475  unsigned EHSectionFlags = ELF::SHF_ALLOC;
476  if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
477  EHSectionFlags |= ELF::SHF_WRITE;
478 
479  // ELF
482 
485 
488 
491 
493  Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
495 
498 
499  DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
501 
503  Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
504  ELF::SHF_ALLOC | ELF::SHF_MERGE, 4, "");
505 
507  Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
508  ELF::SHF_ALLOC | ELF::SHF_MERGE, 8, "");
509 
511  Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
512  ELF::SHF_ALLOC | ELF::SHF_MERGE, 16, "");
513 
515  Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS,
516  ELF::SHF_ALLOC | ELF::SHF_MERGE, 32, "");
517 
518  // Exception Handling Sections.
519 
520  // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
521  // it contains relocatable pointers. In PIC mode, this is probably a big
522  // runtime hit for C++ apps. Either the contents of the LSDA need to be
523  // adjusted or this should be a data section.
524  LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
526 
527  COFFDebugSymbolsSection = nullptr;
528  COFFDebugTypesSection = nullptr;
529 
530  unsigned DebugSecType = ELF::SHT_PROGBITS;
531 
532  // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
533  // to distinguish among sections contain DWARF and ECOFF debug formats.
534  // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
535  if (T.isMIPS())
536  DebugSecType = ELF::SHT_MIPS_DWARF;
537 
538  // Debug Info Sections.
540  Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);
541  DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0);
542  DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0);
544  Ctx->getELFSection(".debug_line_str", DebugSecType,
546  DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0);
548  Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);
550  Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);
552  Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);
554  Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);
556  Ctx->getELFSection(".debug_str", DebugSecType,
558  DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0);
560  Ctx->getELFSection(".debug_aranges", DebugSecType, 0);
562  Ctx->getELFSection(".debug_ranges", DebugSecType, 0);
564  Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);
565 
566  // DWARF5 Experimental Debug Info
567 
568  // Accelerator Tables
570  Ctx->getELFSection(".debug_names", ELF::SHT_PROGBITS, 0);
572  Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);
574  Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);
576  Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);
578  Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);
579 
580  // String Offset and Address Sections
582  Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);
583  DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);
584  DwarfRnglistsSection = Ctx->getELFSection(".debug_rnglists", DebugSecType, 0);
585 
586  // Fission Sections
588  Ctx->getELFSection(".debug_info.dwo", DebugSecType, 0);
590  Ctx->getELFSection(".debug_types.dwo", DebugSecType, 0);
592  Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, 0);
594  Ctx->getELFSection(".debug_str.dwo", DebugSecType,
597  Ctx->getELFSection(".debug_line.dwo", DebugSecType, 0);
599  Ctx->getELFSection(".debug_loc.dwo", DebugSecType, 0);
601  Ctx->getELFSection(".debug_str_offsets.dwo", DebugSecType, 0);
603  Ctx->getELFSection(".debug_rnglists.dwo", DebugSecType, 0);
604 
605  // DWP Sections
607  Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);
609  Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);
610 
612  Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
613 
615  Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
616 
618  Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
619 
620  StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);
621 }
622 
623 void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
628 
629  // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
630  // used to indicate to the linker that the text segment contains thumb instructions
631  // and to set the ISA selection bit for calls accordingly.
632  const bool IsThumb = T.getArch() == Triple::thumb;
633 
635 
636  // COFF
637  BSSSection = Ctx->getCOFFSection(
642  ".text",
654 
655  // FIXME: We're emitting LSDA info into a readonly section on COFF, even
656  // though it contains relocatable pointers. In PIC mode, this is probably a
657  // big runtime hit for C++ apps. Either the contents of the LSDA need to be
658  // adjusted or this should be a data section.
659  if (T.getArch() == Triple::x86_64) {
660  // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
661  LSDASection = nullptr;
662  } else {
663  LSDASection = Ctx->getCOFFSection(".gcc_except_table",
667  }
668 
669  // Debug info.
681  ".debug$H",
685 
687  ".debug_abbrev",
690  SectionKind::getMetadata(), "section_abbrev");
692  ".debug_info",
695  SectionKind::getMetadata(), "section_info");
697  ".debug_line",
700  SectionKind::getMetadata(), "section_line");
702  ".debug_line_str",
705  SectionKind::getMetadata(), "section_line_str");
707  ".debug_frame",
712  ".debug_pubnames",
717  ".debug_pubtypes",
722  ".debug_gnu_pubnames",
727  ".debug_gnu_pubtypes",
732  ".debug_str",
735  SectionKind::getMetadata(), "info_string");
737  ".debug_str_offsets",
740  SectionKind::getMetadata(), "section_str_off");
742  ".debug_loc",
745  SectionKind::getMetadata(), "section_debug_loc");
747  ".debug_aranges",
752  ".debug_ranges",
755  SectionKind::getMetadata(), "debug_range");
757  ".debug_macinfo",
760  SectionKind::getMetadata(), "debug_macinfo");
762  ".debug_info.dwo",
765  SectionKind::getMetadata(), "section_info_dwo");
767  ".debug_types.dwo",
770  SectionKind::getMetadata(), "section_types_dwo");
772  ".debug_abbrev.dwo",
775  SectionKind::getMetadata(), "section_abbrev_dwo");
777  ".debug_str.dwo",
780  SectionKind::getMetadata(), "skel_string");
782  ".debug_line.dwo",
787  ".debug_loc.dwo",
790  SectionKind::getMetadata(), "skel_loc");
792  ".debug_str_offsets.dwo",
795  SectionKind::getMetadata(), "section_str_off_dwo");
797  ".debug_addr",
800  SectionKind::getMetadata(), "addr_sec");
802  ".debug_cu_index",
807  ".debug_tu_index",
812  ".debug_names",
815  SectionKind::getMetadata(), "debug_names_begin");
817  ".apple_names",
820  SectionKind::getMetadata(), "names_begin");
822  ".apple_namespaces",
825  SectionKind::getMetadata(), "namespac_begin");
827  ".apple_types",
830  SectionKind::getMetadata(), "types_begin");
832  ".apple_objc",
835  SectionKind::getMetadata(), "objc_begin");
836 
840 
844 
848 
851 
852  GFIDsSection = Ctx->getCOFFSection(".gfids$y",
856 
861 
862  StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
866 }
867 
868 void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
871 
873  Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());
875  Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata());
877  Ctx->getWasmSection(".debug_str", SectionKind::getMetadata());
879  Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());
881  Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata());
882  DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());
884  Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata());
886  Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata());
888  DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
889  DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
891  Ctx->getWasmSection(".debug_info", SectionKind::getMetadata());
893  DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
894  DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
895 
896  // TODO: Define more sections.
897 }
898 
899 void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
900  MCContext &ctx,
901  bool LargeCodeModel) {
902  PositionIndependent = PIC;
903  Ctx = &ctx;
904 
905  // Common.
910 
913 
915 
916  EHFrameSection = nullptr; // Created on demand.
917  CompactUnwindSection = nullptr; // Used only by selected targets.
918  DwarfAccelNamesSection = nullptr; // Used only by selected targets.
919  DwarfAccelObjCSection = nullptr; // Used only by selected targets.
920  DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
921  DwarfAccelTypesSection = nullptr; // Used only by selected targets.
922 
923  TT = TheTriple;
924 
925  switch (TT.getObjectFormat()) {
926  case Triple::MachO:
927  Env = IsMachO;
928  initMachOMCObjectFileInfo(TT);
929  break;
930  case Triple::COFF:
931  if (!TT.isOSWindows())
933  "Cannot initialize MC for non-Windows COFF object files.");
934 
935  Env = IsCOFF;
936  initCOFFMCObjectFileInfo(TT);
937  break;
938  case Triple::ELF:
939  Env = IsELF;
940  initELFMCObjectFileInfo(TT, LargeCodeModel);
941  break;
942  case Triple::Wasm:
943  Env = IsWasm;
944  initWasmMCObjectFileInfo(TT);
945  break;
947  report_fatal_error("Cannot initialize MC for unknown object file format.");
948  break;
949  }
950 }
951 
953  switch (TT.getObjectFormat()) {
954  case Triple::ELF:
955  return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
956  0, utostr(Hash));
957  case Triple::MachO:
958  case Triple::COFF:
959  case Triple::Wasm:
961  report_fatal_error("Cannot get DWARF types section for this object file "
962  "format: not implemented.");
963  break;
964  }
965  llvm_unreachable("Unknown ObjectFormatType");
966 }
967 
968 MCSection *
970  if (Env != IsELF)
971  return StackSizesSection;
972 
973  const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
974  unsigned Flags = ELF::SHF_LINK_ORDER;
975  StringRef GroupName;
976  if (const MCSymbol *Group = ElfSec.getGroup()) {
977  GroupName = Group->getName();
978  Flags |= ELF::SHF_GROUP;
979  }
980 
981  const MCSymbol *Link = TextSec.getBeginSymbol();
983  unsigned UniqueID = It.first->second;
984 
985  return Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, Flags, 0,
986  GroupName, UniqueID, cast<MCSymbolELF>(Link));
987 }
S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be in a ranlib table of contents...
Definition: MachO.h:185
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:293
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
Definition: Triple.h:470
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:202
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:132
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:119
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
bool isMacOSX() const
isMacOSX - Is this a Mac OS X triple.
Definition: Triple.h:442
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:42
MCSection * StackMapSection
StackMap section.
MCSection * SixteenByteConstantSection
MCSection * DwarfRnglistsSection
The DWARF v5 range list section.
unsigned PersonalityEncoding
PersonalityEncoding, LSDAEncoding, TTypeEncoding - Some encoding values for EH.
MCSection * TextSection
Section directive for standard text.
MCSection * ConstTextCoalSection
S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks.
Definition: MachO.h:192
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K)
Definition: MCContext.h:458
MCSection * LazySymbolPointerSection
static SectionKind getMergeableConst8()
Definition: SectionKind.h:193
static SectionKind getMergeableConst16()
Definition: SectionKind.h:194
static SectionKind getMergeable1ByteCString()
Definition: SectionKind.h:183
S_THREAD_LOCAL_VARIABLES - Section with thread local variable structure data.
Definition: MachO.h:165
setjmp/longjmp based exceptions
S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section in files with the MY_DYLDLINK f...
Definition: MachO.h:188
static SectionKind getMergeableConst4()
Definition: SectionKind.h:192
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:422
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:191
MCSection * MergeableConst32Section
MCSection * DwarfDebugNamesSection
Accelerator table sections.
S_4BYTE_LITERALS - Section with 4 byte literals.
Definition: MachO.h:126
static SectionKind getBSS()
Definition: SectionKind.h:198
MCSection * COFFDebugTypesSection
MCSection * MergeableConst16Section
MCSection * DwarfPubNamesSection
S_8BYTE_LITERALS - Section with 8 byte literals.
Definition: MachO.h:128
MCSection * EightByteConstantSection
MCSection * getStackSizesSection(const MCSection &TextSec) const
bool isOSSolaris() const
Definition: Triple.h:496
MCSection * TLSDataSection
Section directive for Thread Local data. ELF, MachO, COFF, and Wasm.
Context object for machine code objects.
Definition: MCContext.h:63
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:273
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:285
MCSection * ConstDataCoalSection
MCSection * DrectveSection
COFF specific sections.
bool isiOS() const
Is this an iOS triple.
Definition: Triple.h:451
MCSection * DwarfAccelNamesSection
MCSection * DataSection
Section directive for standard data.
SectionCharacteristics
Definition: COFF.h:284
bool isOSWindows() const
Tests whether the OS is Windows.
Definition: Triple.h:562
MCSection * ThreadLocalPointerSection
MCSection * DwarfLineStrSection
const MCSymbolELF * getGroup() const
Definition: MCSectionELF.h:78
MCSection * DwarfSwiftASTSection
MCSection * TLSTLVSection
Section for thread local structure information.
S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
Definition: MachO.h:162
bool isWatchABI() const
Definition: Triple.h:465
S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine instructions.
Definition: MachO.h:182
MCSection * DwarfAccelNamespaceSection
S_THREAD_LOCAL_REGULAR - Thread local data section.
Definition: MachO.h:160
unsigned size() const
Definition: DenseMap.h:96
MCSection * getDwarfTypesSection(uint64_t Hash) const
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:124
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:44
MCSection * COFFDebugSymbolsSection
MCSection * DwarfAbbrevSection
MCSection * EHFrameSection
EH frame section.
S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.
Definition: MachO.h:134
MCSection * DwarfTypesDWOSection
static SectionKind getThreadBSS()
Definition: SectionKind.h:196
MCSection * DwarfRangesSection
S_THREAD_LOCAL_VARIABLE_POINTERS - Section with pointers to thread local structures.
Definition: MachO.h:168
static SectionKind getMetadata()
Definition: SectionKind.h:179
static SectionKind getReadOnlyWithRel()
Definition: SectionKind.h:203
MCSymbol * getBeginSymbol()
Definition: MCSection.h:106
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:171
DenseMap< const MCSymbol *, unsigned > StackSizesUniquing
std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:223
MCSection * DwarfStrOffDWOSection
bool isOSFreeBSD() const
Definition: Triple.h:486
S_16BYTE_LITERALS - Section with only 16 byte literals.
Definition: MachO.h:153
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:674
MCSection * DwarfAbbrevDWOSection
MCSection * FaultMapSection
FaultMap section.
bool OmitDwarfIfHaveCompactUnwind
OmitDwarfIfHaveCompactUnwind - True if the target object file supports having some functions with com...
MCSection * FourByteConstantSection
static SectionKind getMergeable2ByteCString()
Definition: SectionKind.h:186
void InitMCObjectFileInfo(const Triple &TT, bool PIC, MCContext &ctx, bool LargeCodeModel=false)
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:315
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:28
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:427
S_ATTR_DEBUG - A debug section.
Definition: MachO.h:197
MCSection * DwarfAccelObjCSection
S_COALESCED - Section contains symbols that are to be coalesced.
Definition: MachO.h:145
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:393
const MCSection * TLSThreadInitSection
Section for thread local data initialization functions.
MCSection * DwarfRnglistsDWOSection
The DWARF v5 range list section for fission.
ExceptionHandling getExceptionHandlingType() const
Definition: MCAsmInfo.h:570
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.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:238
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
MCSection * ReadOnlySection
Section that is readonly and can contain arbitrary initialized data.
S_ZEROFILL - Zero fill on demand section.
Definition: MachO.h:122
MCSection * DwarfMacinfoSection
static SectionKind getReadOnly()
Definition: SectionKind.h:182
static SectionKind getText()
Definition: SectionKind.h:180
MCSection * MergeableConst8Section