3c3b50c134982da192bbe1299a2a751093e916c0
[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/MC/MCContext.h"
12 #include "llvm/MC/MCSection.h"
13 #include "llvm/MC/MCSectionCOFF.h"
14 #include "llvm/MC/MCSectionELF.h"
15 #include "llvm/MC/MCSectionMachO.h"
16 #include "llvm/ADT/Triple.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   TLSDataSection // .tdata
43     = Ctx->getMachOSection("__DATA", "__thread_data",
44                            MCSectionMachO::S_THREAD_LOCAL_REGULAR,
45                            SectionKind::getDataRel());
46   TLSBSSSection // .tbss
47     = Ctx->getMachOSection("__DATA", "__thread_bss",
48                            MCSectionMachO::S_THREAD_LOCAL_ZEROFILL,
49                            SectionKind::getThreadBSS());
50
51   // TODO: Verify datarel below.
52   TLSTLVSection // .tlv
53     = Ctx->getMachOSection("__DATA", "__thread_vars",
54                            MCSectionMachO::S_THREAD_LOCAL_VARIABLES,
55                            SectionKind::getDataRel());
56
57   TLSThreadInitSection
58     = Ctx->getMachOSection("__DATA", "__thread_init",
59                           MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
60                           SectionKind::getDataRel());
61
62   CStringSection // .cstring
63     = Ctx->getMachOSection("__TEXT", "__cstring",
64                            MCSectionMachO::S_CSTRING_LITERALS,
65                            SectionKind::getMergeable1ByteCString());
66   UStringSection
67     = Ctx->getMachOSection("__TEXT","__ustring", 0,
68                            SectionKind::getMergeable2ByteCString());
69   FourByteConstantSection // .literal4
70     = Ctx->getMachOSection("__TEXT", "__literal4",
71                            MCSectionMachO::S_4BYTE_LITERALS,
72                            SectionKind::getMergeableConst4());
73   EightByteConstantSection // .literal8
74     = Ctx->getMachOSection("__TEXT", "__literal8",
75                            MCSectionMachO::S_8BYTE_LITERALS,
76                            SectionKind::getMergeableConst8());
77
78   // ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back
79   // to using it in -static mode.
80   SixteenByteConstantSection = 0;
81   if (RelocM != Reloc::Static &&
82       T.getArch() != Triple::x86_64 && T.getArch() != Triple::ppc64)
83     SixteenByteConstantSection =   // .literal16
84       Ctx->getMachOSection("__TEXT", "__literal16",
85                            MCSectionMachO::S_16BYTE_LITERALS,
86                            SectionKind::getMergeableConst16());
87
88   ReadOnlySection  // .const
89     = Ctx->getMachOSection("__TEXT", "__const", 0,
90                            SectionKind::getReadOnly());
91
92   TextCoalSection
93     = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
94                            MCSectionMachO::S_COALESCED |
95                            MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
96                            SectionKind::getText());
97   ConstTextCoalSection
98     = Ctx->getMachOSection("__TEXT", "__const_coal",
99                            MCSectionMachO::S_COALESCED,
100                            SectionKind::getReadOnly());
101   ConstDataSection  // .const_data
102     = Ctx->getMachOSection("__DATA", "__const", 0,
103                            SectionKind::getReadOnlyWithRel());
104   DataCoalSection
105     = Ctx->getMachOSection("__DATA","__datacoal_nt",
106                            MCSectionMachO::S_COALESCED,
107                            SectionKind::getDataRel());
108   DataCommonSection
109     = Ctx->getMachOSection("__DATA","__common",
110                            MCSectionMachO::S_ZEROFILL,
111                            SectionKind::getBSS());
112   DataBSSSection
113     = Ctx->getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL,
114                            SectionKind::getBSS());
115
116
117   LazySymbolPointerSection
118     = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
119                            MCSectionMachO::S_LAZY_SYMBOL_POINTERS,
120                            SectionKind::getMetadata());
121   NonLazySymbolPointerSection
122     = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
123                            MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
124                            SectionKind::getMetadata());
125
126   if (RelocM == Reloc::Static) {
127     StaticCtorSection
128       = Ctx->getMachOSection("__TEXT", "__constructor", 0,
129                              SectionKind::getDataRel());
130     StaticDtorSection
131       = Ctx->getMachOSection("__TEXT", "__destructor", 0,
132                              SectionKind::getDataRel());
133   } else {
134     StaticCtorSection
135       = Ctx->getMachOSection("__DATA", "__mod_init_func",
136                              MCSectionMachO::S_MOD_INIT_FUNC_POINTERS,
137                              SectionKind::getDataRel());
138     StaticDtorSection
139       = Ctx->getMachOSection("__DATA", "__mod_term_func",
140                              MCSectionMachO::S_MOD_TERM_FUNC_POINTERS,
141                              SectionKind::getDataRel());
142   }
143
144   // Exception Handling.
145   EHFrameSection =
146     Ctx->getMachOSection("__TEXT", "__eh_frame",
147                          MCSectionMachO::S_COALESCED |
148                          MCSectionMachO::S_ATTR_NO_TOC |
149                          MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
150                          MCSectionMachO::S_ATTR_LIVE_SUPPORT,
151                          SectionKind::getReadOnly());
152
153   LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
154                                      SectionKind::getReadOnlyWithRel());
155
156   if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
157     CompactUnwindSection =
158       Ctx->getMachOSection("__LD", "__compact_unwind",
159                            MCSectionMachO::S_ATTR_DEBUG,
160                            SectionKind::getReadOnly());
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   DwarfPubTypesSection =
198     Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
199                          MCSectionMachO::S_ATTR_DEBUG,
200                          SectionKind::getMetadata());
201   DwarfStrSection =
202     Ctx->getMachOSection("__DWARF", "__debug_str",
203                          MCSectionMachO::S_ATTR_DEBUG,
204                          SectionKind::getMetadata());
205   DwarfLocSection =
206     Ctx->getMachOSection("__DWARF", "__debug_loc",
207                          MCSectionMachO::S_ATTR_DEBUG,
208                          SectionKind::getMetadata());
209   DwarfARangesSection =
210     Ctx->getMachOSection("__DWARF", "__debug_aranges",
211                          MCSectionMachO::S_ATTR_DEBUG,
212                          SectionKind::getMetadata());
213   DwarfRangesSection =
214     Ctx->getMachOSection("__DWARF", "__debug_ranges",
215                          MCSectionMachO::S_ATTR_DEBUG,
216                          SectionKind::getMetadata());
217   DwarfMacroInfoSection =
218     Ctx->getMachOSection("__DWARF", "__debug_macinfo",
219                          MCSectionMachO::S_ATTR_DEBUG,
220                          SectionKind::getMetadata());
221   DwarfDebugInlineSection =
222     Ctx->getMachOSection("__DWARF", "__debug_inlined",
223                          MCSectionMachO::S_ATTR_DEBUG,
224                          SectionKind::getMetadata());
225
226   TLSExtraDataSection = TLSTLVSection;
227 }
228
229 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
230   if (T.getArch() == Triple::x86) {
231     PersonalityEncoding = (RelocM == Reloc::PIC_)
232      ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
233      : dwarf::DW_EH_PE_absptr;
234     LSDAEncoding = (RelocM == Reloc::PIC_)
235       ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
236       : dwarf::DW_EH_PE_absptr;
237     FDEEncoding = FDECFIEncoding = (RelocM == Reloc::PIC_)
238       ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
239       : dwarf::DW_EH_PE_absptr;
240     TTypeEncoding = (RelocM == Reloc::PIC_)
241      ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
242      : dwarf::DW_EH_PE_absptr;
243   } else if (T.getArch() == Triple::x86_64) {
244     FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
245
246     if (RelocM == Reloc::PIC_) {
247       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
248         ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
249          ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
250       LSDAEncoding = dwarf::DW_EH_PE_pcrel |
251         (CMModel == CodeModel::Small
252          ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
253       FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
254       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
255         ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
256          ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
257     } else {
258       PersonalityEncoding =
259         (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
260         ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
261       LSDAEncoding = (CMModel == CodeModel::Small)
262         ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
263       FDEEncoding = dwarf::DW_EH_PE_udata4;
264       TTypeEncoding = (CMModel == CodeModel::Small)
265         ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
266     }
267   }
268
269   // ELF
270   BSSSection =
271     Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
272                        ELF::SHF_WRITE | ELF::SHF_ALLOC,
273                        SectionKind::getBSS());
274
275   TextSection =
276     Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
277                        ELF::SHF_EXECINSTR |
278                        ELF::SHF_ALLOC,
279                        SectionKind::getText());
280
281   DataSection =
282     Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
283                        ELF::SHF_WRITE |ELF::SHF_ALLOC,
284                        SectionKind::getDataRel());
285
286   ReadOnlySection =
287     Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
288                        ELF::SHF_ALLOC,
289                        SectionKind::getReadOnly());
290
291   TLSDataSection =
292     Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
293                        ELF::SHF_ALLOC | ELF::SHF_TLS |
294                        ELF::SHF_WRITE,
295                        SectionKind::getThreadData());
296
297   TLSBSSSection =
298     Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
299                        ELF::SHF_ALLOC | ELF::SHF_TLS |
300                        ELF::SHF_WRITE,
301                        SectionKind::getThreadBSS());
302
303   DataRelSection =
304     Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
305                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
306                        SectionKind::getDataRel());
307
308   DataRelLocalSection =
309     Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
310                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
311                        SectionKind::getDataRelLocal());
312
313   DataRelROSection =
314     Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
315                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
316                        SectionKind::getReadOnlyWithRel());
317
318   DataRelROLocalSection =
319     Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
320                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
321                        SectionKind::getReadOnlyWithRelLocal());
322
323   MergeableConst4Section =
324     Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
325                        ELF::SHF_ALLOC |ELF::SHF_MERGE,
326                        SectionKind::getMergeableConst4());
327
328   MergeableConst8Section =
329     Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
330                        ELF::SHF_ALLOC |ELF::SHF_MERGE,
331                        SectionKind::getMergeableConst8());
332
333   MergeableConst16Section =
334     Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
335                        ELF::SHF_ALLOC |ELF::SHF_MERGE,
336                        SectionKind::getMergeableConst16());
337
338   StaticCtorSection =
339     Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
340                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
341                        SectionKind::getDataRel());
342
343   StaticDtorSection =
344     Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
345                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
346                        SectionKind::getDataRel());
347
348   // Exception Handling Sections.
349
350   // Solaris requires different flags for .eh_frame to seemingly every other
351   // platform.
352   unsigned EHSectionFlags = ELF::SHF_ALLOC;
353   if (T.getOS() == Triple::Solaris)
354     EHSectionFlags |= ELF::SHF_WRITE;
355
356   EHFrameSection =
357     Ctx->getELFSection(".eh_frame", ELF::SHT_PROGBITS, 
358                        EHSectionFlags,
359                        SectionKind::getDataRel());
360
361   // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
362   // it contains relocatable pointers.  In PIC mode, this is probably a big
363   // runtime hit for C++ apps.  Either the contents of the LSDA need to be
364   // adjusted or this should be a data section.
365   LSDASection =
366     Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
367                        ELF::SHF_ALLOC,
368                        SectionKind::getReadOnly());
369
370   // Debug Info Sections.
371   DwarfAbbrevSection =
372     Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
373                        SectionKind::getMetadata());
374   DwarfInfoSection =
375     Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
376                        SectionKind::getMetadata());
377   DwarfLineSection =
378     Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
379                        SectionKind::getMetadata());
380   DwarfFrameSection =
381     Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
382                        SectionKind::getMetadata());
383   DwarfPubTypesSection =
384     Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
385                        SectionKind::getMetadata());
386   DwarfStrSection =
387     Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
388                        ELF::SHF_MERGE | ELF::SHF_STRINGS,
389                        SectionKind::getMergeable1ByteCString());
390   DwarfLocSection =
391     Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
392                        SectionKind::getMetadata());
393   DwarfARangesSection =
394     Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
395                        SectionKind::getMetadata());
396   DwarfRangesSection =
397     Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
398                        SectionKind::getMetadata());
399   DwarfMacroInfoSection =
400     Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
401                        SectionKind::getMetadata());
402 }
403
404
405 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
406   // COFF
407   TextSection =
408     Ctx->getCOFFSection(".text",
409                         COFF::IMAGE_SCN_CNT_CODE |
410                         COFF::IMAGE_SCN_MEM_EXECUTE |
411                         COFF::IMAGE_SCN_MEM_READ,
412                         SectionKind::getText());
413   DataSection =
414     Ctx->getCOFFSection(".data",
415                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
416                         COFF::IMAGE_SCN_MEM_READ |
417                         COFF::IMAGE_SCN_MEM_WRITE,
418                         SectionKind::getDataRel());
419   ReadOnlySection =
420     Ctx->getCOFFSection(".rdata",
421                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
422                         COFF::IMAGE_SCN_MEM_READ,
423                         SectionKind::getReadOnly());
424   StaticCtorSection =
425     Ctx->getCOFFSection(".ctors",
426                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
427                         COFF::IMAGE_SCN_MEM_READ |
428                         COFF::IMAGE_SCN_MEM_WRITE,
429                         SectionKind::getDataRel());
430   StaticDtorSection =
431     Ctx->getCOFFSection(".dtors",
432                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
433                         COFF::IMAGE_SCN_MEM_READ |
434                         COFF::IMAGE_SCN_MEM_WRITE,
435                         SectionKind::getDataRel());
436
437   EHFrameSection =
438     Ctx->getCOFFSection(".eh_frame",
439                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
440                         COFF::IMAGE_SCN_MEM_READ |
441                         COFF::IMAGE_SCN_MEM_WRITE,
442                         SectionKind::getDataRel());
443
444   // FIXME: We're emitting LSDA info into a readonly section on COFF, even
445   // though it contains relocatable pointers.  In PIC mode, this is probably a
446   // big runtime hit for C++ apps.  Either the contents of the LSDA need to be
447   // adjusted or this should be a data section.
448   LSDASection =
449     Ctx->getCOFFSection(".gcc_except_table",
450                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
451                         COFF::IMAGE_SCN_MEM_READ,
452                         SectionKind::getReadOnly());
453
454   // Debug info.
455   DwarfAbbrevSection =
456     Ctx->getCOFFSection(".debug_abbrev",
457                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
458                         COFF::IMAGE_SCN_MEM_READ,
459                         SectionKind::getMetadata());
460   DwarfInfoSection =
461     Ctx->getCOFFSection(".debug_info",
462                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
463                         COFF::IMAGE_SCN_MEM_READ,
464                         SectionKind::getMetadata());
465   DwarfLineSection =
466     Ctx->getCOFFSection(".debug_line",
467                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
468                         COFF::IMAGE_SCN_MEM_READ,
469                         SectionKind::getMetadata());
470   DwarfFrameSection =
471     Ctx->getCOFFSection(".debug_frame",
472                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
473                         COFF::IMAGE_SCN_MEM_READ,
474                         SectionKind::getMetadata());
475   DwarfPubTypesSection =
476     Ctx->getCOFFSection(".debug_pubtypes",
477                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
478                         COFF::IMAGE_SCN_MEM_READ,
479                         SectionKind::getMetadata());
480   DwarfStrSection =
481     Ctx->getCOFFSection(".debug_str",
482                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
483                         COFF::IMAGE_SCN_MEM_READ,
484                         SectionKind::getMetadata());
485   DwarfLocSection =
486     Ctx->getCOFFSection(".debug_loc",
487                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
488                         COFF::IMAGE_SCN_MEM_READ,
489                         SectionKind::getMetadata());
490   DwarfARangesSection =
491     Ctx->getCOFFSection(".debug_aranges",
492                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
493                         COFF::IMAGE_SCN_MEM_READ,
494                         SectionKind::getMetadata());
495   DwarfRangesSection =
496     Ctx->getCOFFSection(".debug_ranges",
497                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
498                         COFF::IMAGE_SCN_MEM_READ,
499                         SectionKind::getMetadata());
500   DwarfMacroInfoSection =
501     Ctx->getCOFFSection(".debug_macinfo",
502                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
503                         COFF::IMAGE_SCN_MEM_READ,
504                         SectionKind::getMetadata());
505
506   DrectveSection =
507     Ctx->getCOFFSection(".drectve",
508                         COFF::IMAGE_SCN_LNK_INFO,
509                         SectionKind::getMetadata());
510
511   PDataSection =
512     Ctx->getCOFFSection(".pdata",
513                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
514                         COFF::IMAGE_SCN_MEM_READ |
515                         COFF::IMAGE_SCN_MEM_WRITE,
516                         SectionKind::getDataRel());
517
518   XDataSection =
519     Ctx->getCOFFSection(".xdata",
520                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
521                         COFF::IMAGE_SCN_MEM_READ |
522                         COFF::IMAGE_SCN_MEM_WRITE,
523                         SectionKind::getDataRel());
524   TLSDataSection =
525     Ctx->getCOFFSection(".tls$",
526                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
527                         COFF::IMAGE_SCN_MEM_READ |
528                         COFF::IMAGE_SCN_MEM_WRITE,
529                         SectionKind::getDataRel());
530 }
531
532 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
533                                             CodeModel::Model cm,
534                                             MCContext &ctx) {
535   RelocM = relocm;
536   CMModel = cm;
537   Ctx = &ctx;
538
539   // Common.
540   CommDirectiveSupportsAlignment = true;
541   SupportsWeakOmittedEHFrame = true;
542   IsFunctionEHFrameSymbolPrivate = true;
543
544   PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
545     TTypeEncoding = dwarf::DW_EH_PE_absptr;
546
547   EHFrameSection = 0;             // Created on demand.
548   CompactUnwindSection = 0;       // Used only by selected targets.
549   DwarfAccelNamesSection = 0;     // Used only by selected targets.
550   DwarfAccelObjCSection = 0;      // Used only by selected targets.
551   DwarfAccelNamespaceSection = 0; // Used only by selected targets.
552   DwarfAccelTypesSection = 0;     // Used only by selected targets.
553
554   Triple T(TT);
555   Triple::ArchType Arch = T.getArch();
556   // FIXME: Checking for Arch here to filter out bogus triples such as
557   // cellspu-apple-darwin. Perhaps we should fix in Triple?
558   if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
559        Arch == Triple::arm || Arch == Triple::thumb ||
560        Arch == Triple::ppc || Arch == Triple::ppc64 ||
561        Arch == Triple::UnknownArch) &&
562       (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
563     Env = IsMachO;
564     InitMachOMCObjectFileInfo(T);
565   } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
566              (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
567               T.getOS() == Triple::Win32)) {
568     Env = IsCOFF;
569     InitCOFFMCObjectFileInfo(T);
570   } else {
571     Env = IsELF;
572     InitELFMCObjectFileInfo(T);
573   }
574 }
575