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