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