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