]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/MC/MCObjectFileInfo.cpp
MFC r335799:
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / MC / MCObjectFileInfo.cpp
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
10 #include "llvm/MC/MCObjectFileInfo.h"
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
52   SupportsWeakOmittedEHFrame = false;
53
54   EHFrameSection = Ctx->getMachOSection(
55       "__TEXT", "__eh_frame",
56       MachO::S_COALESCED | MachO::S_ATTR_NO_TOC |
57           MachO::S_ATTR_STRIP_STATIC_SYMS | MachO::S_ATTR_LIVE_SUPPORT,
58       SectionKind::getReadOnly());
59
60   if (T.isOSDarwin() && T.getArch() == Triple::aarch64)
61     SupportsCompactUnwindWithoutEHFrame = true;
62
63   if (T.isWatchABI())
64     OmitDwarfIfHaveCompactUnwind = true;
65
66   PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
67     | dwarf::DW_EH_PE_sdata4;
68   LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
69   TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
70     dwarf::DW_EH_PE_sdata4;
71
72   // .comm doesn't support alignment before Leopard.
73   if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
74     CommDirectiveSupportsAlignment = false;
75
76   TextSection // .text
77     = Ctx->getMachOSection("__TEXT", "__text",
78                            MachO::S_ATTR_PURE_INSTRUCTIONS,
79                            SectionKind::getText());
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",
88                              MachO::S_THREAD_LOCAL_REGULAR,
89                              SectionKind::getData());
90   TLSBSSSection // .tbss
91     = Ctx->getMachOSection("__DATA", "__thread_bss",
92                            MachO::S_THREAD_LOCAL_ZEROFILL,
93                            SectionKind::getThreadBSS());
94
95   // TODO: Verify datarel below.
96   TLSTLVSection // .tlv
97       = Ctx->getMachOSection("__DATA", "__thread_vars",
98                              MachO::S_THREAD_LOCAL_VARIABLES,
99                              SectionKind::getData());
100
101   TLSThreadInitSection = Ctx->getMachOSection(
102       "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
103       SectionKind::getData());
104
105   CStringSection // .cstring
106     = Ctx->getMachOSection("__TEXT", "__cstring",
107                            MachO::S_CSTRING_LITERALS,
108                            SectionKind::getMergeable1ByteCString());
109   UStringSection
110     = Ctx->getMachOSection("__TEXT","__ustring", 0,
111                            SectionKind::getMergeable2ByteCString());
112   FourByteConstantSection // .literal4
113     = Ctx->getMachOSection("__TEXT", "__literal4",
114                            MachO::S_4BYTE_LITERALS,
115                            SectionKind::getMergeableConst4());
116   EightByteConstantSection // .literal8
117     = Ctx->getMachOSection("__TEXT", "__literal8",
118                            MachO::S_8BYTE_LITERALS,
119                            SectionKind::getMergeableConst8());
120
121   SixteenByteConstantSection // .literal16
122       = Ctx->getMachOSection("__TEXT", "__literal16",
123                              MachO::S_16BYTE_LITERALS,
124                              SectionKind::getMergeableConst16());
125
126   ReadOnlySection  // .const
127     = Ctx->getMachOSection("__TEXT", "__const", 0,
128                            SectionKind::getReadOnly());
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   if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
139     TextCoalSection
140       = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
141                              MachO::S_COALESCED |
142                              MachO::S_ATTR_PURE_INSTRUCTIONS,
143                              SectionKind::getText());
144     ConstTextCoalSection
145       = Ctx->getMachOSection("__TEXT", "__const_coal",
146                              MachO::S_COALESCED,
147                              SectionKind::getReadOnly());
148     DataCoalSection = Ctx->getMachOSection(
149         "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());
150   } else {
151     TextCoalSection = TextSection;
152     ConstTextCoalSection = ReadOnlySection;
153     DataCoalSection = DataSection;
154   }
155
156   ConstDataSection  // .const_data
157     = Ctx->getMachOSection("__DATA", "__const", 0,
158                            SectionKind::getReadOnlyWithRel());
159   DataCommonSection
160     = Ctx->getMachOSection("__DATA","__common",
161                            MachO::S_ZEROFILL,
162                            SectionKind::getBSS());
163   DataBSSSection
164     = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
165                            SectionKind::getBSS());
166
167
168   LazySymbolPointerSection
169     = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
170                            MachO::S_LAZY_SYMBOL_POINTERS,
171                            SectionKind::getMetadata());
172   NonLazySymbolPointerSection
173     = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
174                            MachO::S_NON_LAZY_SYMBOL_POINTERS,
175                            SectionKind::getMetadata());
176
177   ThreadLocalPointerSection
178     = Ctx->getMachOSection("__DATA", "__thread_ptr",
179                            MachO::S_THREAD_LOCAL_VARIABLE_POINTERS,
180                            SectionKind::getMetadata());
181
182   // Exception Handling.
183   LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
184                                      SectionKind::getReadOnlyWithRel());
185
186   COFFDebugSymbolsSection = nullptr;
187   COFFDebugTypesSection = nullptr;
188   COFFGlobalTypeHashesSection = nullptr;
189
190   if (useCompactUnwind(T)) {
191     CompactUnwindSection =
192         Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
193                              SectionKind::getReadOnly());
194
195     if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
196       CompactUnwindDwarfEHFrameOnly = 0x04000000;  // UNWIND_X86_64_MODE_DWARF
197     else if (T.getArch() == Triple::aarch64)
198       CompactUnwindDwarfEHFrameOnly = 0x03000000;  // UNWIND_ARM64_MODE_DWARF
199     else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
200       CompactUnwindDwarfEHFrameOnly = 0x04000000;  // UNWIND_ARM_MODE_DWARF
201   }
202
203   // Debug Information.
204   DwarfAccelNamesSection =
205       Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
206                            SectionKind::getMetadata(), "names_begin");
207   DwarfAccelObjCSection =
208       Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
209                            SectionKind::getMetadata(), "objc_begin");
210   // 16 character section limit...
211   DwarfAccelNamespaceSection =
212       Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
213                            SectionKind::getMetadata(), "namespac_begin");
214   DwarfAccelTypesSection =
215       Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
216                            SectionKind::getMetadata(), "types_begin");
217
218   DwarfSwiftASTSection =
219       Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG,
220                            SectionKind::getMetadata());
221
222   DwarfAbbrevSection =
223       Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
224                            SectionKind::getMetadata(), "section_abbrev");
225   DwarfInfoSection =
226       Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
227                            SectionKind::getMetadata(), "section_info");
228   DwarfLineSection =
229       Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
230                            SectionKind::getMetadata(), "section_line");
231   DwarfFrameSection =
232       Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
233                            SectionKind::getMetadata());
234   DwarfPubNamesSection =
235       Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
236                            SectionKind::getMetadata());
237   DwarfPubTypesSection =
238       Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
239                            SectionKind::getMetadata());
240   DwarfGnuPubNamesSection =
241       Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
242                            SectionKind::getMetadata());
243   DwarfGnuPubTypesSection =
244       Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
245                            SectionKind::getMetadata());
246   DwarfStrSection =
247       Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
248                            SectionKind::getMetadata(), "info_string");
249   DwarfStrOffSection =
250       Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG,
251                            SectionKind::getMetadata(), "section_str_off");
252   DwarfLocSection =
253       Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
254                            SectionKind::getMetadata(), "section_debug_loc");
255   DwarfARangesSection =
256       Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
257                            SectionKind::getMetadata());
258   DwarfRangesSection =
259       Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
260                            SectionKind::getMetadata(), "debug_range");
261   DwarfMacinfoSection =
262       Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG,
263                            SectionKind::getMetadata(), "debug_macinfo");
264   DwarfDebugInlineSection =
265       Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
266                            SectionKind::getMetadata());
267   DwarfCUIndexSection =
268       Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,
269                            SectionKind::getMetadata());
270   DwarfTUIndexSection =
271       Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG,
272                            SectionKind::getMetadata());
273   StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
274                                          0, SectionKind::getMetadata());
275
276   FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
277                                          0, SectionKind::getMetadata());
278
279   TLSExtraDataSection = TLSTLVSection;
280 }
281
282 void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
283   switch (T.getArch()) {
284   case Triple::mips:
285   case Triple::mipsel:
286     FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
287     break;
288   case Triple::mips64:
289   case Triple::mips64el:
290     FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
291     break;
292   case Triple::ppc64:
293   case Triple::ppc64le:
294   case Triple::x86_64:
295     FDECFIEncoding = dwarf::DW_EH_PE_pcrel |
296                      (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
297     break;
298   case Triple::bpfel:
299   case Triple::bpfeb:
300     FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
301     break;
302   default:
303     FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
304     break;
305   }
306
307   switch (T.getArch()) {
308   case Triple::arm:
309   case Triple::armeb:
310   case Triple::thumb:
311   case Triple::thumbeb:
312     if (Ctx->getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
313       break;
314     // Fallthrough if not using EHABI
315     LLVM_FALLTHROUGH;
316   case Triple::ppc:
317   case Triple::x86:
318     PersonalityEncoding = PositionIndependent
319                               ? dwarf::DW_EH_PE_indirect |
320                                     dwarf::DW_EH_PE_pcrel |
321                                     dwarf::DW_EH_PE_sdata4
322                               : dwarf::DW_EH_PE_absptr;
323     LSDAEncoding = PositionIndependent
324                        ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
325                        : dwarf::DW_EH_PE_absptr;
326     TTypeEncoding = PositionIndependent
327                         ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
328                               dwarf::DW_EH_PE_sdata4
329                         : dwarf::DW_EH_PE_absptr;
330     break;
331   case Triple::x86_64:
332     if (PositionIndependent) {
333       PersonalityEncoding =
334           dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
335           (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
336       LSDAEncoding = dwarf::DW_EH_PE_pcrel |
337                      (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
338       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
339                       (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
340     } else {
341       PersonalityEncoding =
342           Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
343       LSDAEncoding = Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
344       TTypeEncoding = Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
345     }
346     break;
347   case Triple::hexagon:
348     PersonalityEncoding = dwarf::DW_EH_PE_absptr;
349     LSDAEncoding = dwarf::DW_EH_PE_absptr;
350     FDECFIEncoding = dwarf::DW_EH_PE_absptr;
351     TTypeEncoding = dwarf::DW_EH_PE_absptr;
352     if (PositionIndependent) {
353       PersonalityEncoding |= dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel;
354       LSDAEncoding |= dwarf::DW_EH_PE_pcrel;
355       FDECFIEncoding |= dwarf::DW_EH_PE_pcrel;
356       TTypeEncoding |= dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel;
357     }
358     break;
359   case Triple::aarch64:
360   case Triple::aarch64_be:
361     // The small model guarantees static code/data size < 4GB, but not where it
362     // will be in memory. Most of these could end up >2GB away so even a signed
363     // pc-relative 32-bit address is insufficient, theoretically.
364     if (PositionIndependent) {
365       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
366         dwarf::DW_EH_PE_sdata8;
367       LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
368       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
369         dwarf::DW_EH_PE_sdata8;
370     } else {
371       PersonalityEncoding = dwarf::DW_EH_PE_absptr;
372       LSDAEncoding = dwarf::DW_EH_PE_absptr;
373       TTypeEncoding = dwarf::DW_EH_PE_absptr;
374     }
375     break;
376   case Triple::lanai:
377     LSDAEncoding = dwarf::DW_EH_PE_absptr;
378     PersonalityEncoding = dwarf::DW_EH_PE_absptr;
379     TTypeEncoding = dwarf::DW_EH_PE_absptr;
380     break;
381   case Triple::mips:
382   case Triple::mipsel:
383   case Triple::mips64:
384   case Triple::mips64el:
385     // MIPS uses indirect pointer to refer personality functions and types, so
386     // that the eh_frame section can be read-only. DW.ref.personality will be
387     // generated for relocation.
388     PersonalityEncoding = dwarf::DW_EH_PE_indirect;
389     // FIXME: The N64 ABI probably ought to use DW_EH_PE_sdata8 but we can't
390     //        identify N64 from just a triple.
391     TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
392                     dwarf::DW_EH_PE_sdata4;
393     // We don't support PC-relative LSDA references in GAS so we use the default
394     // DW_EH_PE_absptr for those.
395
396     // FreeBSD must be explicit about the data size and using pcrel since it's
397     // assembler/linker won't do the automatic conversion that the Linux tools
398     // do.
399     if (T.isOSFreeBSD()) {
400       PersonalityEncoding |= dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
401       LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
402     }
403     break;
404   case Triple::ppc64:
405   case Triple::ppc64le:
406     PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
407       dwarf::DW_EH_PE_udata8;
408     LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
409     TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
410       dwarf::DW_EH_PE_udata8;
411     break;
412   case Triple::sparcel:
413   case Triple::sparc:
414     if (PositionIndependent) {
415       LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
416       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
417         dwarf::DW_EH_PE_sdata4;
418       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
419         dwarf::DW_EH_PE_sdata4;
420     } else {
421       LSDAEncoding = dwarf::DW_EH_PE_absptr;
422       PersonalityEncoding = dwarf::DW_EH_PE_absptr;
423       TTypeEncoding = dwarf::DW_EH_PE_absptr;
424     }
425     break;
426   case Triple::sparcv9:
427     LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
428     if (PositionIndependent) {
429       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
430         dwarf::DW_EH_PE_sdata4;
431       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
432         dwarf::DW_EH_PE_sdata4;
433     } else {
434       PersonalityEncoding = dwarf::DW_EH_PE_absptr;
435       TTypeEncoding = dwarf::DW_EH_PE_absptr;
436     }
437     break;
438   case Triple::systemz:
439     // All currently-defined code models guarantee that 4-byte PC-relative
440     // values will be in range.
441     if (PositionIndependent) {
442       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
443         dwarf::DW_EH_PE_sdata4;
444       LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
445       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
446         dwarf::DW_EH_PE_sdata4;
447     } else {
448       PersonalityEncoding = dwarf::DW_EH_PE_absptr;
449       LSDAEncoding = dwarf::DW_EH_PE_absptr;
450       TTypeEncoding = dwarf::DW_EH_PE_absptr;
451     }
452     break;
453   default:
454     break;
455   }
456
457   unsigned EHSectionType = T.getArch() == Triple::x86_64
458                                ? ELF::SHT_X86_64_UNWIND
459                                : ELF::SHT_PROGBITS;
460
461   // Solaris requires different flags for .eh_frame to seemingly every other
462   // platform.
463   unsigned EHSectionFlags = ELF::SHF_ALLOC;
464   if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
465     EHSectionFlags |= ELF::SHF_WRITE;
466
467   // ELF
468   BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
469                                   ELF::SHF_WRITE | ELF::SHF_ALLOC);
470
471   TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
472                                    ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
473
474   DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
475                                    ELF::SHF_WRITE | ELF::SHF_ALLOC);
476
477   ReadOnlySection =
478       Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
479
480   TLSDataSection =
481       Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
482                          ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
483
484   TLSBSSSection = Ctx->getELFSection(
485       ".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
486
487   DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
488                                         ELF::SHF_ALLOC | ELF::SHF_WRITE);
489
490   MergeableConst4Section =
491       Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
492                          ELF::SHF_ALLOC | ELF::SHF_MERGE, 4, "");
493
494   MergeableConst8Section =
495       Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
496                          ELF::SHF_ALLOC | ELF::SHF_MERGE, 8, "");
497
498   MergeableConst16Section =
499       Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
500                          ELF::SHF_ALLOC | ELF::SHF_MERGE, 16, "");
501
502   MergeableConst32Section =
503       Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS,
504                          ELF::SHF_ALLOC | ELF::SHF_MERGE, 32, "");
505
506   // Exception Handling Sections.
507
508   // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
509   // it contains relocatable pointers.  In PIC mode, this is probably a big
510   // runtime hit for C++ apps.  Either the contents of the LSDA need to be
511   // adjusted or this should be a data section.
512   LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
513                                    ELF::SHF_ALLOC);
514
515   COFFDebugSymbolsSection = nullptr;
516   COFFDebugTypesSection = nullptr;
517
518   unsigned DebugSecType = ELF::SHT_PROGBITS;
519
520   // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
521   // to distinguish among sections contain DWARF and ECOFF debug formats.
522   // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
523   if (T.getArch() == Triple::mips || T.getArch() == Triple::mipsel ||
524       T.getArch() == Triple::mips64 || T.getArch() == Triple::mips64el)
525     DebugSecType = ELF::SHT_MIPS_DWARF;
526
527   // Debug Info Sections.
528   DwarfAbbrevSection =
529       Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);
530   DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0);
531   DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0);
532   DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0);
533   DwarfPubNamesSection =
534       Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);
535   DwarfPubTypesSection =
536       Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);
537   DwarfGnuPubNamesSection =
538       Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);
539   DwarfGnuPubTypesSection =
540       Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);
541   DwarfStrSection =
542       Ctx->getELFSection(".debug_str", DebugSecType,
543                          ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
544   DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0);
545   DwarfARangesSection =
546       Ctx->getELFSection(".debug_aranges", DebugSecType, 0);
547   DwarfRangesSection =
548       Ctx->getELFSection(".debug_ranges", DebugSecType, 0);
549   DwarfMacinfoSection =
550       Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);
551
552   // DWARF5 Experimental Debug Info
553
554   // Accelerator Tables
555   DwarfAccelNamesSection =
556       Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);
557   DwarfAccelObjCSection =
558       Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);
559   DwarfAccelNamespaceSection =
560       Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);
561   DwarfAccelTypesSection =
562       Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);
563
564   // String Offset and Address Sections
565   DwarfStrOffSection =
566       Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);
567   DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);
568
569   // Fission Sections
570   DwarfInfoDWOSection =
571       Ctx->getELFSection(".debug_info.dwo", DebugSecType, 0);
572   DwarfTypesDWOSection =
573       Ctx->getELFSection(".debug_types.dwo", DebugSecType, 0);
574   DwarfAbbrevDWOSection =
575       Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, 0);
576   DwarfStrDWOSection =
577       Ctx->getELFSection(".debug_str.dwo", DebugSecType,
578                          ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
579   DwarfLineDWOSection =
580       Ctx->getELFSection(".debug_line.dwo", DebugSecType, 0);
581   DwarfLocDWOSection =
582       Ctx->getELFSection(".debug_loc.dwo", DebugSecType, 0);
583   DwarfStrOffDWOSection =
584       Ctx->getELFSection(".debug_str_offsets.dwo", DebugSecType, 0);
585
586   // DWP Sections
587   DwarfCUIndexSection =
588       Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);
589   DwarfTUIndexSection =
590       Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);
591
592   StackMapSection =
593       Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
594
595   FaultMapSection =
596       Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
597
598   EHFrameSection =
599       Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
600
601   StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);
602 }
603
604 void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
605   EHFrameSection = Ctx->getCOFFSection(
606       ".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
607                        COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
608       SectionKind::getData());
609
610   // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode.  This is
611   // used to indicate to the linker that the text segment contains thumb instructions
612   // and to set the ISA selection bit for calls accordingly.
613   const bool IsThumb = T.getArch() == Triple::thumb;
614
615   CommDirectiveSupportsAlignment = true;
616
617   // COFF
618   BSSSection = Ctx->getCOFFSection(
619       ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
620                   COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
621       SectionKind::getBSS());
622   TextSection = Ctx->getCOFFSection(
623       ".text",
624       (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |
625           COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
626           COFF::IMAGE_SCN_MEM_READ,
627       SectionKind::getText());
628   DataSection = Ctx->getCOFFSection(
629       ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
630                    COFF::IMAGE_SCN_MEM_WRITE,
631       SectionKind::getData());
632   ReadOnlySection = Ctx->getCOFFSection(
633       ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
634       SectionKind::getReadOnly());
635
636   // FIXME: We're emitting LSDA info into a readonly section on COFF, even
637   // though it contains relocatable pointers.  In PIC mode, this is probably a
638   // big runtime hit for C++ apps.  Either the contents of the LSDA need to be
639   // adjusted or this should be a data section.
640   if (T.getArch() == Triple::x86_64) {
641     // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
642     LSDASection = nullptr;
643   } else {
644     LSDASection = Ctx->getCOFFSection(".gcc_except_table",
645                                       COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
646                                           COFF::IMAGE_SCN_MEM_READ,
647                                       SectionKind::getReadOnly());
648   }
649
650   // Debug info.
651   COFFDebugSymbolsSection =
652       Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
653                                        COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
654                                        COFF::IMAGE_SCN_MEM_READ),
655                           SectionKind::getMetadata());
656   COFFDebugTypesSection =
657       Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
658                                        COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
659                                        COFF::IMAGE_SCN_MEM_READ),
660                           SectionKind::getMetadata());
661   COFFGlobalTypeHashesSection = Ctx->getCOFFSection(
662       ".debug$H",
663       (COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
664        COFF::IMAGE_SCN_MEM_READ),
665       SectionKind::getMetadata());
666
667   DwarfAbbrevSection = Ctx->getCOFFSection(
668       ".debug_abbrev",
669       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
670           COFF::IMAGE_SCN_MEM_READ,
671       SectionKind::getMetadata(), "section_abbrev");
672   DwarfInfoSection = Ctx->getCOFFSection(
673       ".debug_info",
674       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
675           COFF::IMAGE_SCN_MEM_READ,
676       SectionKind::getMetadata(), "section_info");
677   DwarfLineSection = Ctx->getCOFFSection(
678       ".debug_line",
679       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
680           COFF::IMAGE_SCN_MEM_READ,
681       SectionKind::getMetadata(), "section_line");
682
683   DwarfFrameSection = Ctx->getCOFFSection(
684       ".debug_frame",
685       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
686           COFF::IMAGE_SCN_MEM_READ,
687       SectionKind::getMetadata());
688   DwarfPubNamesSection = Ctx->getCOFFSection(
689       ".debug_pubnames",
690       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
691           COFF::IMAGE_SCN_MEM_READ,
692       SectionKind::getMetadata());
693   DwarfPubTypesSection = Ctx->getCOFFSection(
694       ".debug_pubtypes",
695       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
696           COFF::IMAGE_SCN_MEM_READ,
697       SectionKind::getMetadata());
698   DwarfGnuPubNamesSection = Ctx->getCOFFSection(
699       ".debug_gnu_pubnames",
700       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
701           COFF::IMAGE_SCN_MEM_READ,
702       SectionKind::getMetadata());
703   DwarfGnuPubTypesSection = Ctx->getCOFFSection(
704       ".debug_gnu_pubtypes",
705       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
706           COFF::IMAGE_SCN_MEM_READ,
707       SectionKind::getMetadata());
708   DwarfStrSection = Ctx->getCOFFSection(
709       ".debug_str",
710       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
711           COFF::IMAGE_SCN_MEM_READ,
712       SectionKind::getMetadata(), "info_string");
713   DwarfStrOffSection = Ctx->getCOFFSection(
714       ".debug_str_offsets",
715       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
716           COFF::IMAGE_SCN_MEM_READ,
717       SectionKind::getMetadata(), "section_str_off");
718   DwarfLocSection = Ctx->getCOFFSection(
719       ".debug_loc",
720       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
721           COFF::IMAGE_SCN_MEM_READ,
722       SectionKind::getMetadata(), "section_debug_loc");
723   DwarfARangesSection = Ctx->getCOFFSection(
724       ".debug_aranges",
725       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
726           COFF::IMAGE_SCN_MEM_READ,
727       SectionKind::getMetadata());
728   DwarfRangesSection = Ctx->getCOFFSection(
729       ".debug_ranges",
730       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
731           COFF::IMAGE_SCN_MEM_READ,
732       SectionKind::getMetadata(), "debug_range");
733   DwarfMacinfoSection = Ctx->getCOFFSection(
734       ".debug_macinfo",
735       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
736           COFF::IMAGE_SCN_MEM_READ,
737       SectionKind::getMetadata(), "debug_macinfo");
738   DwarfInfoDWOSection = Ctx->getCOFFSection(
739       ".debug_info.dwo",
740       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
741           COFF::IMAGE_SCN_MEM_READ,
742       SectionKind::getMetadata(), "section_info_dwo");
743   DwarfTypesDWOSection = Ctx->getCOFFSection(
744       ".debug_types.dwo",
745       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
746           COFF::IMAGE_SCN_MEM_READ,
747       SectionKind::getMetadata(), "section_types_dwo");
748   DwarfAbbrevDWOSection = Ctx->getCOFFSection(
749       ".debug_abbrev.dwo",
750       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
751           COFF::IMAGE_SCN_MEM_READ,
752       SectionKind::getMetadata(), "section_abbrev_dwo");
753   DwarfStrDWOSection = Ctx->getCOFFSection(
754       ".debug_str.dwo",
755       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
756           COFF::IMAGE_SCN_MEM_READ,
757       SectionKind::getMetadata(), "skel_string");
758   DwarfLineDWOSection = Ctx->getCOFFSection(
759       ".debug_line.dwo",
760       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
761           COFF::IMAGE_SCN_MEM_READ,
762       SectionKind::getMetadata());
763   DwarfLocDWOSection = Ctx->getCOFFSection(
764       ".debug_loc.dwo",
765       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
766           COFF::IMAGE_SCN_MEM_READ,
767       SectionKind::getMetadata(), "skel_loc");
768   DwarfStrOffDWOSection = Ctx->getCOFFSection(
769       ".debug_str_offsets.dwo",
770       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
771           COFF::IMAGE_SCN_MEM_READ,
772       SectionKind::getMetadata(), "section_str_off_dwo");
773   DwarfAddrSection = Ctx->getCOFFSection(
774       ".debug_addr",
775       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
776           COFF::IMAGE_SCN_MEM_READ,
777       SectionKind::getMetadata(), "addr_sec");
778   DwarfCUIndexSection = Ctx->getCOFFSection(
779       ".debug_cu_index",
780       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
781           COFF::IMAGE_SCN_MEM_READ,
782       SectionKind::getMetadata());
783   DwarfTUIndexSection = Ctx->getCOFFSection(
784       ".debug_tu_index",
785       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
786           COFF::IMAGE_SCN_MEM_READ,
787       SectionKind::getMetadata());
788   DwarfAccelNamesSection = Ctx->getCOFFSection(
789       ".apple_names",
790       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
791           COFF::IMAGE_SCN_MEM_READ,
792       SectionKind::getMetadata(), "names_begin");
793   DwarfAccelNamespaceSection = Ctx->getCOFFSection(
794       ".apple_namespaces",
795       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
796           COFF::IMAGE_SCN_MEM_READ,
797       SectionKind::getMetadata(), "namespac_begin");
798   DwarfAccelTypesSection = Ctx->getCOFFSection(
799       ".apple_types",
800       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
801           COFF::IMAGE_SCN_MEM_READ,
802       SectionKind::getMetadata(), "types_begin");
803   DwarfAccelObjCSection = Ctx->getCOFFSection(
804       ".apple_objc",
805       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
806           COFF::IMAGE_SCN_MEM_READ,
807       SectionKind::getMetadata(), "objc_begin");
808
809   DrectveSection = Ctx->getCOFFSection(
810       ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
811       SectionKind::getMetadata());
812
813   PDataSection = Ctx->getCOFFSection(
814       ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
815       SectionKind::getData());
816
817   XDataSection = Ctx->getCOFFSection(
818       ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
819       SectionKind::getData());
820
821   SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO,
822                                       SectionKind::getMetadata());
823
824   TLSDataSection = Ctx->getCOFFSection(
825       ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
826                    COFF::IMAGE_SCN_MEM_WRITE,
827       SectionKind::getData());
828
829   StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
830                                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
831                                             COFF::IMAGE_SCN_MEM_READ,
832                                         SectionKind::getReadOnly());
833 }
834
835 void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
836   // TODO: Set the section types and flags.
837   TextSection = Ctx->getWasmSection(".text", SectionKind::getText());
838   DataSection = Ctx->getWasmSection(".data", SectionKind::getData());
839
840   // TODO: Set the section types and flags.
841   DwarfLineSection = Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());
842   DwarfStrSection = Ctx->getWasmSection(".debug_str", SectionKind::getMetadata());
843   DwarfLocSection = Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());
844   DwarfAbbrevSection = Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata(), "section_abbrev");
845   DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());
846   DwarfRangesSection = Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata(), "debug_range");
847   DwarfMacinfoSection = Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata(), "debug_macinfo");
848   DwarfAddrSection = Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata());
849   DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
850   DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
851   DwarfInfoSection = Ctx->getWasmSection(".debug_info", SectionKind::getMetadata(), "section_info");
852   DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());
853   DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
854   DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
855
856   // TODO: Define more sections.
857 }
858
859 void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
860                                             MCContext &ctx,
861                                             bool LargeCodeModel) {
862   PositionIndependent = PIC;
863   Ctx = &ctx;
864
865   // Common.
866   CommDirectiveSupportsAlignment = true;
867   SupportsWeakOmittedEHFrame = true;
868   SupportsCompactUnwindWithoutEHFrame = false;
869   OmitDwarfIfHaveCompactUnwind = false;
870
871   PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
872       dwarf::DW_EH_PE_absptr;
873
874   CompactUnwindDwarfEHFrameOnly = 0;
875
876   EHFrameSection = nullptr;             // Created on demand.
877   CompactUnwindSection = nullptr;       // Used only by selected targets.
878   DwarfAccelNamesSection = nullptr;     // Used only by selected targets.
879   DwarfAccelObjCSection = nullptr;      // Used only by selected targets.
880   DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
881   DwarfAccelTypesSection = nullptr;     // Used only by selected targets.
882
883   TT = TheTriple;
884
885   switch (TT.getObjectFormat()) {
886   case Triple::MachO:
887     Env = IsMachO;
888     initMachOMCObjectFileInfo(TT);
889     break;
890   case Triple::COFF:
891     if (!TT.isOSWindows())
892       report_fatal_error(
893           "Cannot initialize MC for non-Windows COFF object files.");
894
895     Env = IsCOFF;
896     initCOFFMCObjectFileInfo(TT);
897     break;
898   case Triple::ELF:
899     Env = IsELF;
900     initELFMCObjectFileInfo(TT, LargeCodeModel);
901     break;
902   case Triple::Wasm:
903     Env = IsWasm;
904     initWasmMCObjectFileInfo(TT);
905     break;
906   case Triple::UnknownObjectFormat:
907     report_fatal_error("Cannot initialize MC for unknown object file format.");
908     break;
909   }
910 }
911
912 MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
913   return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
914                             0, utostr(Hash));
915 }