1fcda31d2d194786601124dca4f34998f0039f03
[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   LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
146                                      SectionKind::getReadOnlyWithRel());
147
148   if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
149     CompactUnwindSection =
150       Ctx->getMachOSection("__LD", "__compact_unwind",
151                            MCSectionMachO::S_ATTR_DEBUG,
152                            SectionKind::getReadOnly());
153
154   // Debug Information.
155   DwarfAccelNamesSection =
156     Ctx->getMachOSection("__DWARF", "__apple_names",
157                          MCSectionMachO::S_ATTR_DEBUG,
158                          SectionKind::getMetadata());
159   DwarfAccelObjCSection =
160     Ctx->getMachOSection("__DWARF", "__apple_objc",
161                          MCSectionMachO::S_ATTR_DEBUG,
162                          SectionKind::getMetadata());
163   // 16 character section limit...
164   DwarfAccelNamespaceSection =
165     Ctx->getMachOSection("__DWARF", "__apple_namespac",
166                          MCSectionMachO::S_ATTR_DEBUG,
167                          SectionKind::getMetadata());
168   DwarfAccelTypesSection =
169     Ctx->getMachOSection("__DWARF", "__apple_types",
170                          MCSectionMachO::S_ATTR_DEBUG,
171                          SectionKind::getMetadata());
172     
173   DwarfAbbrevSection =
174     Ctx->getMachOSection("__DWARF", "__debug_abbrev",
175                          MCSectionMachO::S_ATTR_DEBUG,
176                          SectionKind::getMetadata());
177   DwarfInfoSection =
178     Ctx->getMachOSection("__DWARF", "__debug_info",
179                          MCSectionMachO::S_ATTR_DEBUG,
180                          SectionKind::getMetadata());
181   DwarfLineSection =
182     Ctx->getMachOSection("__DWARF", "__debug_line",
183                          MCSectionMachO::S_ATTR_DEBUG,
184                          SectionKind::getMetadata());
185   DwarfFrameSection =
186     Ctx->getMachOSection("__DWARF", "__debug_frame",
187                          MCSectionMachO::S_ATTR_DEBUG,
188                          SectionKind::getMetadata());
189   DwarfPubNamesSection =
190     Ctx->getMachOSection("__DWARF", "__debug_pubnames",
191                          MCSectionMachO::S_ATTR_DEBUG,
192                          SectionKind::getMetadata());
193   DwarfPubTypesSection =
194     Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
195                          MCSectionMachO::S_ATTR_DEBUG,
196                          SectionKind::getMetadata());
197   DwarfStrSection =
198     Ctx->getMachOSection("__DWARF", "__debug_str",
199                          MCSectionMachO::S_ATTR_DEBUG,
200                          SectionKind::getMetadata());
201   DwarfLocSection =
202     Ctx->getMachOSection("__DWARF", "__debug_loc",
203                          MCSectionMachO::S_ATTR_DEBUG,
204                          SectionKind::getMetadata());
205   DwarfARangesSection =
206     Ctx->getMachOSection("__DWARF", "__debug_aranges",
207                          MCSectionMachO::S_ATTR_DEBUG,
208                          SectionKind::getMetadata());
209   DwarfRangesSection =
210     Ctx->getMachOSection("__DWARF", "__debug_ranges",
211                          MCSectionMachO::S_ATTR_DEBUG,
212                          SectionKind::getMetadata());
213   DwarfMacroInfoSection =
214     Ctx->getMachOSection("__DWARF", "__debug_macinfo",
215                          MCSectionMachO::S_ATTR_DEBUG,
216                          SectionKind::getMetadata());
217   DwarfDebugInlineSection =
218     Ctx->getMachOSection("__DWARF", "__debug_inlined",
219                          MCSectionMachO::S_ATTR_DEBUG,
220                          SectionKind::getMetadata());
221
222   TLSExtraDataSection = TLSTLVSection;
223 }
224
225 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
226   if (T.getArch() == Triple::x86) {
227     PersonalityEncoding = (RelocM == Reloc::PIC_)
228       ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
229       : dwarf::DW_EH_PE_absptr;
230     LSDAEncoding = (RelocM == Reloc::PIC_)
231       ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
232       : dwarf::DW_EH_PE_absptr;
233     FDEEncoding = FDECFIEncoding = (RelocM == Reloc::PIC_)
234       ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
235       : dwarf::DW_EH_PE_absptr;
236     TTypeEncoding = (RelocM == Reloc::PIC_)
237       ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
238       : dwarf::DW_EH_PE_absptr;
239   } else if (T.getArch() == Triple::x86_64) {
240     FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
241
242     if (RelocM == Reloc::PIC_) {
243       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
244         ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
245          ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
246       LSDAEncoding = dwarf::DW_EH_PE_pcrel |
247         (CMModel == CodeModel::Small
248          ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
249       FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
250       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
251         ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
252          ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
253     } else {
254       PersonalityEncoding =
255         (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
256         ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
257       LSDAEncoding = (CMModel == CodeModel::Small)
258         ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
259       FDEEncoding = dwarf::DW_EH_PE_udata4;
260       TTypeEncoding = (CMModel == CodeModel::Small)
261         ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
262     }
263   }
264
265   // ELF
266   BSSSection =
267     Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
268                        ELF::SHF_WRITE |ELF::SHF_ALLOC,
269                        SectionKind::getBSS());
270
271   TextSection =
272     Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
273                        ELF::SHF_EXECINSTR |
274                        ELF::SHF_ALLOC,
275                        SectionKind::getText());
276
277   DataSection =
278     Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
279                        ELF::SHF_WRITE |ELF::SHF_ALLOC,
280                        SectionKind::getDataRel());
281
282   ReadOnlySection =
283     Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
284                        ELF::SHF_ALLOC,
285                        SectionKind::getReadOnly());
286
287   TLSDataSection =
288     Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
289                        ELF::SHF_ALLOC | ELF::SHF_TLS |
290                        ELF::SHF_WRITE,
291                        SectionKind::getThreadData());
292
293   TLSBSSSection =
294     Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
295                        ELF::SHF_ALLOC | ELF::SHF_TLS |
296                        ELF::SHF_WRITE,
297                        SectionKind::getThreadBSS());
298
299   DataRelSection =
300     Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
301                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
302                        SectionKind::getDataRel());
303
304   DataRelLocalSection =
305     Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
306                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
307                        SectionKind::getDataRelLocal());
308
309   DataRelROSection =
310     Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
311                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
312                        SectionKind::getReadOnlyWithRel());
313
314   DataRelROLocalSection =
315     Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
316                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
317                        SectionKind::getReadOnlyWithRelLocal());
318
319   MergeableConst4Section =
320     Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
321                        ELF::SHF_ALLOC |ELF::SHF_MERGE,
322                        SectionKind::getMergeableConst4());
323
324   MergeableConst8Section =
325     Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
326                        ELF::SHF_ALLOC |ELF::SHF_MERGE,
327                        SectionKind::getMergeableConst8());
328
329   MergeableConst16Section =
330     Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
331                        ELF::SHF_ALLOC |ELF::SHF_MERGE,
332                        SectionKind::getMergeableConst16());
333
334   StaticCtorSection =
335     Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
336                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
337                        SectionKind::getDataRel());
338
339   StaticDtorSection =
340     Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
341                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
342                        SectionKind::getDataRel());
343
344   // Exception Handling Sections.
345
346   // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
347   // it contains relocatable pointers.  In PIC mode, this is probably a big
348   // runtime hit for C++ apps.  Either the contents of the LSDA need to be
349   // adjusted or this should be a data section.
350   LSDASection =
351     Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
352                        ELF::SHF_ALLOC,
353                        SectionKind::getReadOnly());
354
355   // Debug Info Sections.
356   DwarfAbbrevSection =
357     Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
358                        SectionKind::getMetadata());
359   DwarfInfoSection =
360     Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
361                        SectionKind::getMetadata());
362   DwarfLineSection =
363     Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
364                        SectionKind::getMetadata());
365   DwarfFrameSection =
366     Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
367                        SectionKind::getMetadata());
368   DwarfPubNamesSection =
369     Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
370                        SectionKind::getMetadata());
371   DwarfPubTypesSection =
372     Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
373                        SectionKind::getMetadata());
374   DwarfStrSection =
375     Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
376                        ELF::SHF_MERGE | ELF::SHF_STRINGS,
377                        SectionKind::getMergeable1ByteCString());
378   DwarfLocSection =
379     Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
380                        SectionKind::getMetadata());
381   DwarfARangesSection =
382     Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
383                        SectionKind::getMetadata());
384   DwarfRangesSection =
385     Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
386                        SectionKind::getMetadata());
387   DwarfMacroInfoSection =
388     Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
389                        SectionKind::getMetadata());
390 }
391
392
393 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
394   // COFF
395   TextSection =
396     Ctx->getCOFFSection(".text",
397                         COFF::IMAGE_SCN_CNT_CODE |
398                         COFF::IMAGE_SCN_MEM_EXECUTE |
399                         COFF::IMAGE_SCN_MEM_READ,
400                         SectionKind::getText());
401   DataSection =
402     Ctx->getCOFFSection(".data",
403                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
404                         COFF::IMAGE_SCN_MEM_READ |
405                         COFF::IMAGE_SCN_MEM_WRITE,
406                         SectionKind::getDataRel());
407   ReadOnlySection =
408     Ctx->getCOFFSection(".rdata",
409                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
410                         COFF::IMAGE_SCN_MEM_READ,
411                         SectionKind::getReadOnly());
412   StaticCtorSection =
413     Ctx->getCOFFSection(".ctors",
414                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
415                         COFF::IMAGE_SCN_MEM_READ |
416                         COFF::IMAGE_SCN_MEM_WRITE,
417                         SectionKind::getDataRel());
418   StaticDtorSection =
419     Ctx->getCOFFSection(".dtors",
420                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
421                         COFF::IMAGE_SCN_MEM_READ |
422                         COFF::IMAGE_SCN_MEM_WRITE,
423                         SectionKind::getDataRel());
424
425   // FIXME: We're emitting LSDA info into a readonly section on COFF, even
426   // though it contains relocatable pointers.  In PIC mode, this is probably a
427   // big runtime hit for C++ apps.  Either the contents of the LSDA need to be
428   // adjusted or this should be a data section.
429   LSDASection =
430     Ctx->getCOFFSection(".gcc_except_table",
431                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
432                         COFF::IMAGE_SCN_MEM_READ,
433                         SectionKind::getReadOnly());
434
435   // Debug info.
436   DwarfAbbrevSection =
437     Ctx->getCOFFSection(".debug_abbrev",
438                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
439                         COFF::IMAGE_SCN_MEM_READ,
440                         SectionKind::getMetadata());
441   DwarfInfoSection =
442     Ctx->getCOFFSection(".debug_info",
443                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
444                         COFF::IMAGE_SCN_MEM_READ,
445                         SectionKind::getMetadata());
446   DwarfLineSection =
447     Ctx->getCOFFSection(".debug_line",
448                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
449                         COFF::IMAGE_SCN_MEM_READ,
450                         SectionKind::getMetadata());
451   DwarfFrameSection =
452     Ctx->getCOFFSection(".debug_frame",
453                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
454                         COFF::IMAGE_SCN_MEM_READ,
455                         SectionKind::getMetadata());
456   DwarfPubNamesSection =
457     Ctx->getCOFFSection(".debug_pubnames",
458                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
459                         COFF::IMAGE_SCN_MEM_READ,
460                         SectionKind::getMetadata());
461   DwarfPubTypesSection =
462     Ctx->getCOFFSection(".debug_pubtypes",
463                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
464                         COFF::IMAGE_SCN_MEM_READ,
465                         SectionKind::getMetadata());
466   DwarfStrSection =
467     Ctx->getCOFFSection(".debug_str",
468                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
469                         COFF::IMAGE_SCN_MEM_READ,
470                         SectionKind::getMetadata());
471   DwarfLocSection =
472     Ctx->getCOFFSection(".debug_loc",
473                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
474                         COFF::IMAGE_SCN_MEM_READ,
475                         SectionKind::getMetadata());
476   DwarfARangesSection =
477     Ctx->getCOFFSection(".debug_aranges",
478                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
479                         COFF::IMAGE_SCN_MEM_READ,
480                         SectionKind::getMetadata());
481   DwarfRangesSection =
482     Ctx->getCOFFSection(".debug_ranges",
483                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
484                         COFF::IMAGE_SCN_MEM_READ,
485                         SectionKind::getMetadata());
486   DwarfMacroInfoSection =
487     Ctx->getCOFFSection(".debug_macinfo",
488                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
489                         COFF::IMAGE_SCN_MEM_READ,
490                         SectionKind::getMetadata());
491
492   DrectveSection =
493     Ctx->getCOFFSection(".drectve",
494                         COFF::IMAGE_SCN_LNK_INFO,
495                         SectionKind::getMetadata());
496
497   PDataSection =
498     Ctx->getCOFFSection(".pdata",
499                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
500                         COFF::IMAGE_SCN_MEM_READ |
501                         COFF::IMAGE_SCN_MEM_WRITE,
502                         SectionKind::getDataRel());
503
504   XDataSection =
505     Ctx->getCOFFSection(".xdata",
506                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
507                         COFF::IMAGE_SCN_MEM_READ |
508                         COFF::IMAGE_SCN_MEM_WRITE,
509                         SectionKind::getDataRel());
510 }
511
512 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
513                                             CodeModel::Model cm,
514                                             MCContext &ctx) {
515   RelocM = relocm;
516   CMModel = cm;
517   Ctx = &ctx;
518
519   // Common.
520   CommDirectiveSupportsAlignment = true;
521   SupportsWeakOmittedEHFrame = true;
522   IsFunctionEHFrameSymbolPrivate = true;
523
524   PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
525     TTypeEncoding = dwarf::DW_EH_PE_absptr;
526
527   EHFrameSection = 0;             // Created on demand.
528   CompactUnwindSection = 0;       // Used only by selected targets.
529   DwarfAccelNamesSection = 0;     // Used only by selected targets.
530   DwarfAccelObjCSection = 0;      // Used only by selected targets.
531   DwarfAccelNamespaceSection = 0; // Used only by selected targets.
532   DwarfAccelTypesSection = 0;     // Used only by selected targets.
533
534   Triple T(TT);
535   Triple::ArchType Arch = T.getArch();
536   // FIXME: Checking for Arch here to filter out bogus triples such as
537   // cellspu-apple-darwin. Perhaps we should fix in Triple?
538   if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
539        Arch == Triple::arm || Arch == Triple::thumb ||
540        Arch == Triple::ppc || Arch == Triple::ppc64 ||
541        Arch == Triple::UnknownArch) &&
542       (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
543     Env = IsMachO;
544     InitMachOMCObjectFileInfo(T);
545   } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
546              (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
547               T.getOS() == Triple::Win32)) {
548     Env = IsCOFF;
549     InitCOFFMCObjectFileInfo(T);
550   } else {
551     Env = IsELF;
552     InitELFMCObjectFileInfo(T);
553   }
554 }
555
556 void MCObjectFileInfo::InitEHFrameSection() {
557   if (Env == IsMachO)
558     EHFrameSection =
559       Ctx->getMachOSection("__TEXT", "__eh_frame",
560                            MCSectionMachO::S_COALESCED |
561                            MCSectionMachO::S_ATTR_NO_TOC |
562                            MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
563                            MCSectionMachO::S_ATTR_LIVE_SUPPORT,
564                            SectionKind::getReadOnly());
565   else if (Env == IsELF)
566     EHFrameSection =
567       Ctx->getELFSection(".eh_frame", ELF::SHT_PROGBITS,
568                          ELF::SHF_ALLOC,
569                          SectionKind::getDataRel());
570   else
571     EHFrameSection =
572       Ctx->getCOFFSection(".eh_frame",
573                           COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
574                           COFF::IMAGE_SCN_MEM_READ |
575                           COFF::IMAGE_SCN_MEM_WRITE,
576                           SectionKind::getDataRel());
577 }