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