Initialize BSSSection explicitly in InitMachOMCObjectFileInfo() to appease msvc.
[oota-llvm.git] / lib / MC / MCObjectFileInfo.cpp
1 //===-- MObjectFileInfo.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/Triple.h"
12 #include "llvm/MC/MCContext.h"
13 #include "llvm/MC/MCSection.h"
14 #include "llvm/MC/MCSectionCOFF.h"
15 #include "llvm/MC/MCSectionELF.h"
16 #include "llvm/MC/MCSectionMachO.h"
17 using namespace llvm;
18
19 void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
20   // MachO
21   IsFunctionEHFrameSymbolPrivate = false;
22   SupportsWeakOmittedEHFrame = false;
23
24   PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
25     | dwarf::DW_EH_PE_sdata4;
26   LSDAEncoding = FDEEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
27   TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
28     dwarf::DW_EH_PE_sdata4;
29
30   // .comm doesn't support alignment before Leopard.
31   if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
32     CommDirectiveSupportsAlignment = false;
33
34   TextSection // .text
35     = Ctx->getMachOSection("__TEXT", "__text",
36                            MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
37                            SectionKind::getText());
38   DataSection // .data
39     = Ctx->getMachOSection("__DATA", "__data", 0,
40                            SectionKind::getDataRel());
41
42   // BSSSection might not be expected initialized on msvc.
43   BSSSection = 0;
44
45   TLSDataSection // .tdata
46     = Ctx->getMachOSection("__DATA", "__thread_data",
47                            MCSectionMachO::S_THREAD_LOCAL_REGULAR,
48                            SectionKind::getDataRel());
49   TLSBSSSection // .tbss
50     = Ctx->getMachOSection("__DATA", "__thread_bss",
51                            MCSectionMachO::S_THREAD_LOCAL_ZEROFILL,
52                            SectionKind::getThreadBSS());
53
54   // TODO: Verify datarel below.
55   TLSTLVSection // .tlv
56     = Ctx->getMachOSection("__DATA", "__thread_vars",
57                            MCSectionMachO::S_THREAD_LOCAL_VARIABLES,
58                            SectionKind::getDataRel());
59
60   TLSThreadInitSection
61     = Ctx->getMachOSection("__DATA", "__thread_init",
62                           MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
63                           SectionKind::getDataRel());
64
65   CStringSection // .cstring
66     = Ctx->getMachOSection("__TEXT", "__cstring",
67                            MCSectionMachO::S_CSTRING_LITERALS,
68                            SectionKind::getMergeable1ByteCString());
69   UStringSection
70     = Ctx->getMachOSection("__TEXT","__ustring", 0,
71                            SectionKind::getMergeable2ByteCString());
72   FourByteConstantSection // .literal4
73     = Ctx->getMachOSection("__TEXT", "__literal4",
74                            MCSectionMachO::S_4BYTE_LITERALS,
75                            SectionKind::getMergeableConst4());
76   EightByteConstantSection // .literal8
77     = Ctx->getMachOSection("__TEXT", "__literal8",
78                            MCSectionMachO::S_8BYTE_LITERALS,
79                            SectionKind::getMergeableConst8());
80
81   // ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back
82   // to using it in -static mode.
83   SixteenByteConstantSection = 0;
84   if (RelocM != Reloc::Static &&
85       T.getArch() != Triple::x86_64 && T.getArch() != Triple::ppc64 &&
86       T.getArch() != Triple::ppc64le)
87     SixteenByteConstantSection =   // .literal16
88       Ctx->getMachOSection("__TEXT", "__literal16",
89                            MCSectionMachO::S_16BYTE_LITERALS,
90                            SectionKind::getMergeableConst16());
91
92   ReadOnlySection  // .const
93     = Ctx->getMachOSection("__TEXT", "__const", 0,
94                            SectionKind::getReadOnly());
95
96   TextCoalSection
97     = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
98                            MCSectionMachO::S_COALESCED |
99                            MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
100                            SectionKind::getText());
101   ConstTextCoalSection
102     = Ctx->getMachOSection("__TEXT", "__const_coal",
103                            MCSectionMachO::S_COALESCED,
104                            SectionKind::getReadOnly());
105   ConstDataSection  // .const_data
106     = Ctx->getMachOSection("__DATA", "__const", 0,
107                            SectionKind::getReadOnlyWithRel());
108   DataCoalSection
109     = Ctx->getMachOSection("__DATA","__datacoal_nt",
110                            MCSectionMachO::S_COALESCED,
111                            SectionKind::getDataRel());
112   DataCommonSection
113     = Ctx->getMachOSection("__DATA","__common",
114                            MCSectionMachO::S_ZEROFILL,
115                            SectionKind::getBSS());
116   DataBSSSection
117     = Ctx->getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL,
118                            SectionKind::getBSS());
119
120
121   LazySymbolPointerSection
122     = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
123                            MCSectionMachO::S_LAZY_SYMBOL_POINTERS,
124                            SectionKind::getMetadata());
125   NonLazySymbolPointerSection
126     = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
127                            MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
128                            SectionKind::getMetadata());
129
130   if (RelocM == Reloc::Static) {
131     StaticCtorSection
132       = Ctx->getMachOSection("__TEXT", "__constructor", 0,
133                              SectionKind::getDataRel());
134     StaticDtorSection
135       = Ctx->getMachOSection("__TEXT", "__destructor", 0,
136                              SectionKind::getDataRel());
137   } else {
138     StaticCtorSection
139       = Ctx->getMachOSection("__DATA", "__mod_init_func",
140                              MCSectionMachO::S_MOD_INIT_FUNC_POINTERS,
141                              SectionKind::getDataRel());
142     StaticDtorSection
143       = Ctx->getMachOSection("__DATA", "__mod_term_func",
144                              MCSectionMachO::S_MOD_TERM_FUNC_POINTERS,
145                              SectionKind::getDataRel());
146   }
147
148   // Exception Handling.
149   LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
150                                      SectionKind::getReadOnlyWithRel());
151
152   if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) {
153     CompactUnwindSection =
154       Ctx->getMachOSection("__LD", "__compact_unwind",
155                            MCSectionMachO::S_ATTR_DEBUG,
156                            SectionKind::getReadOnly());
157
158     if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
159       CompactUnwindDwarfEHFrameOnly = 0x04000000;
160   }
161
162   // Debug Information.
163   DwarfAccelNamesSection =
164     Ctx->getMachOSection("__DWARF", "__apple_names",
165                          MCSectionMachO::S_ATTR_DEBUG,
166                          SectionKind::getMetadata());
167   DwarfAccelObjCSection =
168     Ctx->getMachOSection("__DWARF", "__apple_objc",
169                          MCSectionMachO::S_ATTR_DEBUG,
170                          SectionKind::getMetadata());
171   // 16 character section limit...
172   DwarfAccelNamespaceSection =
173     Ctx->getMachOSection("__DWARF", "__apple_namespac",
174                          MCSectionMachO::S_ATTR_DEBUG,
175                          SectionKind::getMetadata());
176   DwarfAccelTypesSection =
177     Ctx->getMachOSection("__DWARF", "__apple_types",
178                          MCSectionMachO::S_ATTR_DEBUG,
179                          SectionKind::getMetadata());
180
181   DwarfAbbrevSection =
182     Ctx->getMachOSection("__DWARF", "__debug_abbrev",
183                          MCSectionMachO::S_ATTR_DEBUG,
184                          SectionKind::getMetadata());
185   DwarfInfoSection =
186     Ctx->getMachOSection("__DWARF", "__debug_info",
187                          MCSectionMachO::S_ATTR_DEBUG,
188                          SectionKind::getMetadata());
189   DwarfLineSection =
190     Ctx->getMachOSection("__DWARF", "__debug_line",
191                          MCSectionMachO::S_ATTR_DEBUG,
192                          SectionKind::getMetadata());
193   DwarfFrameSection =
194     Ctx->getMachOSection("__DWARF", "__debug_frame",
195                          MCSectionMachO::S_ATTR_DEBUG,
196                          SectionKind::getMetadata());
197   DwarfPubNamesSection =
198     Ctx->getMachOSection("__DWARF", "__debug_pubnames",
199                          MCSectionMachO::S_ATTR_DEBUG,
200                          SectionKind::getMetadata());
201   DwarfPubTypesSection =
202     Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
203                          MCSectionMachO::S_ATTR_DEBUG,
204                          SectionKind::getMetadata());
205   DwarfGnuPubNamesSection =
206     Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
207                          MCSectionMachO::S_ATTR_DEBUG,
208                          SectionKind::getMetadata());
209   DwarfGnuPubTypesSection =
210     Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
211                          MCSectionMachO::S_ATTR_DEBUG,
212                          SectionKind::getMetadata());
213   DwarfStrSection =
214     Ctx->getMachOSection("__DWARF", "__debug_str",
215                          MCSectionMachO::S_ATTR_DEBUG,
216                          SectionKind::getMetadata());
217   DwarfLocSection =
218     Ctx->getMachOSection("__DWARF", "__debug_loc",
219                          MCSectionMachO::S_ATTR_DEBUG,
220                          SectionKind::getMetadata());
221   DwarfARangesSection =
222     Ctx->getMachOSection("__DWARF", "__debug_aranges",
223                          MCSectionMachO::S_ATTR_DEBUG,
224                          SectionKind::getMetadata());
225   DwarfRangesSection =
226     Ctx->getMachOSection("__DWARF", "__debug_ranges",
227                          MCSectionMachO::S_ATTR_DEBUG,
228                          SectionKind::getMetadata());
229   DwarfMacroInfoSection =
230     Ctx->getMachOSection("__DWARF", "__debug_macinfo",
231                          MCSectionMachO::S_ATTR_DEBUG,
232                          SectionKind::getMetadata());
233   DwarfDebugInlineSection =
234     Ctx->getMachOSection("__DWARF", "__debug_inlined",
235                          MCSectionMachO::S_ATTR_DEBUG,
236                          SectionKind::getMetadata());
237
238   TLSExtraDataSection = TLSTLVSection;
239 }
240
241 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
242   if (T.getArch() == Triple::mips ||
243       T.getArch() == Triple::mipsel)
244     FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
245   else if (T.getArch() == Triple::mips64 ||
246            T.getArch() == Triple::mips64el)
247     FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
248   else
249     FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
250
251   if (T.getArch() == Triple::x86) {
252     PersonalityEncoding = (RelocM == Reloc::PIC_)
253      ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
254      : dwarf::DW_EH_PE_absptr;
255     LSDAEncoding = (RelocM == Reloc::PIC_)
256       ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
257       : dwarf::DW_EH_PE_absptr;
258     FDEEncoding = (RelocM == Reloc::PIC_)
259       ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
260       : dwarf::DW_EH_PE_absptr;
261     TTypeEncoding = (RelocM == Reloc::PIC_)
262      ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
263      : dwarf::DW_EH_PE_absptr;
264   } else if (T.getArch() == Triple::x86_64) {
265     if (RelocM == Reloc::PIC_) {
266       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
267         ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
268          ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
269       LSDAEncoding = dwarf::DW_EH_PE_pcrel |
270         (CMModel == CodeModel::Small
271          ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
272       FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
273       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
274         ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
275          ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
276     } else {
277       PersonalityEncoding =
278         (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
279         ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
280       LSDAEncoding = (CMModel == CodeModel::Small)
281         ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
282       FDEEncoding = dwarf::DW_EH_PE_udata4;
283       TTypeEncoding = (CMModel == CodeModel::Small)
284         ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
285     }
286   }  else if (T.getArch() ==  Triple::aarch64) {
287     // The small model guarantees static code/data size < 4GB, but not where it
288     // will be in memory. Most of these could end up >2GB away so even a signed
289     // pc-relative 32-bit address is insufficient, theoretically.
290     if (RelocM == Reloc::PIC_) {
291       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
292         dwarf::DW_EH_PE_sdata8;
293       LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
294       FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
295       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
296         dwarf::DW_EH_PE_sdata8;
297     } else {
298       PersonalityEncoding = dwarf::DW_EH_PE_absptr;
299       LSDAEncoding = dwarf::DW_EH_PE_absptr;
300       FDEEncoding = dwarf::DW_EH_PE_udata4;
301       TTypeEncoding = dwarf::DW_EH_PE_absptr;
302     }
303   } else if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le) {
304     PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
305       dwarf::DW_EH_PE_udata8;
306     LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
307     FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
308     TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
309       dwarf::DW_EH_PE_udata8;
310   } else if (T.getArch() == Triple::systemz) {
311     // All currently-defined code models guarantee that 4-byte PC-relative
312     // values will be in range.
313     if (RelocM == Reloc::PIC_) {
314       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
315         dwarf::DW_EH_PE_sdata4;
316       LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
317       FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
318       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
319         dwarf::DW_EH_PE_sdata4;
320     } else {
321       PersonalityEncoding = dwarf::DW_EH_PE_absptr;
322       LSDAEncoding = dwarf::DW_EH_PE_absptr;
323       FDEEncoding = dwarf::DW_EH_PE_absptr;
324       TTypeEncoding = dwarf::DW_EH_PE_absptr;
325     }
326   }
327
328   // Solaris requires different flags for .eh_frame to seemingly every other
329   // platform.
330   EHSectionType = ELF::SHT_PROGBITS;
331   EHSectionFlags = ELF::SHF_ALLOC;
332   if (T.getOS() == Triple::Solaris) {
333     if (T.getArch() == Triple::x86_64)
334       EHSectionType = ELF::SHT_X86_64_UNWIND;
335     else
336       EHSectionFlags |= ELF::SHF_WRITE;
337   }
338
339
340   // ELF
341   BSSSection =
342     Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
343                        ELF::SHF_WRITE | ELF::SHF_ALLOC,
344                        SectionKind::getBSS());
345
346   TextSection =
347     Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
348                        ELF::SHF_EXECINSTR |
349                        ELF::SHF_ALLOC,
350                        SectionKind::getText());
351
352   DataSection =
353     Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
354                        ELF::SHF_WRITE |ELF::SHF_ALLOC,
355                        SectionKind::getDataRel());
356
357   ReadOnlySection =
358     Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
359                        ELF::SHF_ALLOC,
360                        SectionKind::getReadOnly());
361
362   TLSDataSection =
363     Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
364                        ELF::SHF_ALLOC | ELF::SHF_TLS |
365                        ELF::SHF_WRITE,
366                        SectionKind::getThreadData());
367
368   TLSBSSSection =
369     Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
370                        ELF::SHF_ALLOC | ELF::SHF_TLS |
371                        ELF::SHF_WRITE,
372                        SectionKind::getThreadBSS());
373
374   DataRelSection =
375     Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
376                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
377                        SectionKind::getDataRel());
378
379   DataRelLocalSection =
380     Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
381                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
382                        SectionKind::getDataRelLocal());
383
384   DataRelROSection =
385     Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
386                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
387                        SectionKind::getReadOnlyWithRel());
388
389   DataRelROLocalSection =
390     Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
391                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
392                        SectionKind::getReadOnlyWithRelLocal());
393
394   MergeableConst4Section =
395     Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
396                        ELF::SHF_ALLOC |ELF::SHF_MERGE,
397                        SectionKind::getMergeableConst4());
398
399   MergeableConst8Section =
400     Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
401                        ELF::SHF_ALLOC |ELF::SHF_MERGE,
402                        SectionKind::getMergeableConst8());
403
404   MergeableConst16Section =
405     Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
406                        ELF::SHF_ALLOC |ELF::SHF_MERGE,
407                        SectionKind::getMergeableConst16());
408
409   StaticCtorSection =
410     Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
411                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
412                        SectionKind::getDataRel());
413
414   StaticDtorSection =
415     Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
416                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
417                        SectionKind::getDataRel());
418
419   // Exception Handling Sections.
420
421   // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
422   // it contains relocatable pointers.  In PIC mode, this is probably a big
423   // runtime hit for C++ apps.  Either the contents of the LSDA need to be
424   // adjusted or this should be a data section.
425   LSDASection =
426     Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
427                        ELF::SHF_ALLOC,
428                        SectionKind::getReadOnly());
429
430   // Debug Info Sections.
431   DwarfAbbrevSection =
432     Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
433                        SectionKind::getMetadata());
434   DwarfInfoSection =
435     Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
436                        SectionKind::getMetadata());
437   DwarfLineSection =
438     Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
439                        SectionKind::getMetadata());
440   DwarfFrameSection =
441     Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
442                        SectionKind::getMetadata());
443   DwarfPubNamesSection =
444     Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
445                        SectionKind::getMetadata());
446   DwarfPubTypesSection =
447     Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
448                        SectionKind::getMetadata());
449   DwarfGnuPubNamesSection =
450     Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
451                        SectionKind::getMetadata());
452   DwarfGnuPubTypesSection =
453     Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
454                        SectionKind::getMetadata());
455   DwarfStrSection =
456     Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
457                        ELF::SHF_MERGE | ELF::SHF_STRINGS,
458                        SectionKind::getMergeable1ByteCString());
459   DwarfLocSection =
460     Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
461                        SectionKind::getMetadata());
462   DwarfARangesSection =
463     Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
464                        SectionKind::getMetadata());
465   DwarfRangesSection =
466     Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
467                        SectionKind::getMetadata());
468   DwarfMacroInfoSection =
469     Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
470                        SectionKind::getMetadata());
471
472   // DWARF5 Experimental Debug Info
473
474   // Accelerator Tables
475   DwarfAccelNamesSection =
476     Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
477                        SectionKind::getMetadata());
478   DwarfAccelObjCSection =
479     Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
480                        SectionKind::getMetadata());
481   DwarfAccelNamespaceSection =
482     Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
483                        SectionKind::getMetadata());
484   DwarfAccelTypesSection =
485     Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
486                        SectionKind::getMetadata());
487
488   // Fission Sections
489   DwarfInfoDWOSection =
490     Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
491                        SectionKind::getMetadata());
492   DwarfAbbrevDWOSection =
493     Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
494                        SectionKind::getMetadata());
495   DwarfStrDWOSection =
496     Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
497                        ELF::SHF_MERGE | ELF::SHF_STRINGS,
498                        SectionKind::getMergeable1ByteCString());
499   DwarfLineDWOSection =
500     Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
501                        SectionKind::getMetadata());
502   DwarfLocDWOSection =
503     Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
504                        SectionKind::getMetadata());
505   DwarfStrOffDWOSection =
506     Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
507                        SectionKind::getMetadata());
508   DwarfAddrSection =
509     Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
510                        SectionKind::getMetadata());
511 }
512
513
514 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
515   // COFF
516   BSSSection =
517     Ctx->getCOFFSection(".bss",
518                         COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
519                         COFF::IMAGE_SCN_MEM_READ |
520                         COFF::IMAGE_SCN_MEM_WRITE,
521                         SectionKind::getBSS());
522   TextSection =
523     Ctx->getCOFFSection(".text",
524                         COFF::IMAGE_SCN_CNT_CODE |
525                         COFF::IMAGE_SCN_MEM_EXECUTE |
526                         COFF::IMAGE_SCN_MEM_READ,
527                         SectionKind::getText());
528   DataSection =
529     Ctx->getCOFFSection(".data",
530                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
531                         COFF::IMAGE_SCN_MEM_READ |
532                         COFF::IMAGE_SCN_MEM_WRITE,
533                         SectionKind::getDataRel());
534   ReadOnlySection =
535     Ctx->getCOFFSection(".rdata",
536                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
537                         COFF::IMAGE_SCN_MEM_READ,
538                         SectionKind::getReadOnly());
539   if (T.getOS() == Triple::Win32) {
540     StaticCtorSection =
541       Ctx->getCOFFSection(".CRT$XCU",
542                           COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
543                           COFF::IMAGE_SCN_MEM_READ,
544                           SectionKind::getReadOnly());
545   } else {
546     StaticCtorSection =
547       Ctx->getCOFFSection(".ctors",
548                           COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
549                           COFF::IMAGE_SCN_MEM_READ |
550                           COFF::IMAGE_SCN_MEM_WRITE,
551                           SectionKind::getDataRel());
552   }
553
554
555   if (T.getOS() == Triple::Win32) {
556     StaticDtorSection =
557       Ctx->getCOFFSection(".CRT$XTX",
558                           COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
559                           COFF::IMAGE_SCN_MEM_READ,
560                           SectionKind::getReadOnly());
561   } else {
562     StaticDtorSection =
563       Ctx->getCOFFSection(".dtors",
564                           COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
565                           COFF::IMAGE_SCN_MEM_READ |
566                           COFF::IMAGE_SCN_MEM_WRITE,
567                           SectionKind::getDataRel());
568   }
569
570   // FIXME: We're emitting LSDA info into a readonly section on COFF, even
571   // though it contains relocatable pointers.  In PIC mode, this is probably a
572   // big runtime hit for C++ apps.  Either the contents of the LSDA need to be
573   // adjusted or this should be a data section.
574   LSDASection =
575     Ctx->getCOFFSection(".gcc_except_table",
576                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
577                         COFF::IMAGE_SCN_MEM_READ,
578                         SectionKind::getReadOnly());
579
580   // Debug info.
581   DwarfAbbrevSection =
582     Ctx->getCOFFSection(".debug_abbrev",
583                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
584                         COFF::IMAGE_SCN_MEM_READ,
585                         SectionKind::getMetadata());
586   DwarfInfoSection =
587     Ctx->getCOFFSection(".debug_info",
588                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
589                         COFF::IMAGE_SCN_MEM_READ,
590                         SectionKind::getMetadata());
591   DwarfLineSection =
592     Ctx->getCOFFSection(".debug_line",
593                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
594                         COFF::IMAGE_SCN_MEM_READ,
595                         SectionKind::getMetadata());
596   DwarfFrameSection =
597     Ctx->getCOFFSection(".debug_frame",
598                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
599                         COFF::IMAGE_SCN_MEM_READ,
600                         SectionKind::getMetadata());
601   DwarfPubNamesSection =
602     Ctx->getCOFFSection(".debug_pubnames",
603                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
604                         COFF::IMAGE_SCN_MEM_READ,
605                         SectionKind::getMetadata());
606   DwarfPubTypesSection =
607     Ctx->getCOFFSection(".debug_pubtypes",
608                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
609                         COFF::IMAGE_SCN_MEM_READ,
610                         SectionKind::getMetadata());
611   DwarfGnuPubNamesSection =
612     Ctx->getCOFFSection(".debug_gnu_pubnames",
613                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
614                         COFF::IMAGE_SCN_MEM_READ,
615                         SectionKind::getMetadata());
616   DwarfGnuPubTypesSection =
617     Ctx->getCOFFSection(".debug_gnu_pubtypes",
618                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
619                         COFF::IMAGE_SCN_MEM_READ,
620                         SectionKind::getMetadata());
621   DwarfStrSection =
622     Ctx->getCOFFSection(".debug_str",
623                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
624                         COFF::IMAGE_SCN_MEM_READ,
625                         SectionKind::getMetadata());
626   DwarfLocSection =
627     Ctx->getCOFFSection(".debug_loc",
628                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
629                         COFF::IMAGE_SCN_MEM_READ,
630                         SectionKind::getMetadata());
631   DwarfARangesSection =
632     Ctx->getCOFFSection(".debug_aranges",
633                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
634                         COFF::IMAGE_SCN_MEM_READ,
635                         SectionKind::getMetadata());
636   DwarfRangesSection =
637     Ctx->getCOFFSection(".debug_ranges",
638                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
639                         COFF::IMAGE_SCN_MEM_READ,
640                         SectionKind::getMetadata());
641   DwarfMacroInfoSection =
642     Ctx->getCOFFSection(".debug_macinfo",
643                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
644                         COFF::IMAGE_SCN_MEM_READ,
645                         SectionKind::getMetadata());
646
647   DrectveSection =
648     Ctx->getCOFFSection(".drectve",
649                         COFF::IMAGE_SCN_LNK_INFO,
650                         SectionKind::getMetadata());
651
652   PDataSection =
653     Ctx->getCOFFSection(".pdata",
654                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
655                         COFF::IMAGE_SCN_MEM_READ,
656                         SectionKind::getDataRel());
657
658   XDataSection =
659     Ctx->getCOFFSection(".xdata",
660                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
661                         COFF::IMAGE_SCN_MEM_READ,
662                         SectionKind::getDataRel());
663   TLSDataSection =
664     Ctx->getCOFFSection(".tls$",
665                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
666                         COFF::IMAGE_SCN_MEM_READ |
667                         COFF::IMAGE_SCN_MEM_WRITE,
668                         SectionKind::getDataRel());
669 }
670
671 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
672                                             CodeModel::Model cm,
673                                             MCContext &ctx) {
674   RelocM = relocm;
675   CMModel = cm;
676   Ctx = &ctx;
677
678   // Common.
679   CommDirectiveSupportsAlignment = true;
680   SupportsWeakOmittedEHFrame = true;
681   IsFunctionEHFrameSymbolPrivate = true;
682
683   PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
684     TTypeEncoding = dwarf::DW_EH_PE_absptr;
685
686   CompactUnwindDwarfEHFrameOnly = 0;
687
688   EHFrameSection = 0;             // Created on demand.
689   CompactUnwindSection = 0;       // Used only by selected targets.
690   DwarfAccelNamesSection = 0;     // Used only by selected targets.
691   DwarfAccelObjCSection = 0;      // Used only by selected targets.
692   DwarfAccelNamespaceSection = 0; // Used only by selected targets.
693   DwarfAccelTypesSection = 0;     // Used only by selected targets.
694
695   Triple T(TT);
696   Triple::ArchType Arch = T.getArch();
697   // FIXME: Checking for Arch here to filter out bogus triples such as
698   // cellspu-apple-darwin. Perhaps we should fix in Triple?
699   if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
700        Arch == Triple::arm || Arch == Triple::thumb ||
701        Arch == Triple::ppc || Arch == Triple::ppc64 ||
702        Arch == Triple::UnknownArch) &&
703       (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
704     Env = IsMachO;
705     InitMachOMCObjectFileInfo(T);
706   } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
707              (T.getEnvironment() != Triple::ELF) &&
708              (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
709               T.getOS() == Triple::Win32)) {
710     Env = IsCOFF;
711     InitCOFFMCObjectFileInfo(T);
712   } else {
713     Env = IsELF;
714     InitELFMCObjectFileInfo(T);
715   }
716 }
717
718 void MCObjectFileInfo::InitEHFrameSection() {
719   if (Env == IsMachO)
720     EHFrameSection =
721       Ctx->getMachOSection("__TEXT", "__eh_frame",
722                            MCSectionMachO::S_COALESCED |
723                            MCSectionMachO::S_ATTR_NO_TOC |
724                            MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
725                            MCSectionMachO::S_ATTR_LIVE_SUPPORT,
726                            SectionKind::getReadOnly());
727   else if (Env == IsELF)
728     EHFrameSection =
729       Ctx->getELFSection(".eh_frame", EHSectionType,
730                          EHSectionFlags,
731                          SectionKind::getDataRel());
732   else
733     EHFrameSection =
734       Ctx->getCOFFSection(".eh_frame",
735                           COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
736                           COFF::IMAGE_SCN_MEM_READ |
737                           COFF::IMAGE_SCN_MEM_WRITE,
738                           SectionKind::getDataRel());
739 }