1 //===-- MObjectFileInfo.cpp - Object File Information ---------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/MC/MCObjectFileInfo.h"
11 #include "llvm/ADT/Triple.h"
12 #include "llvm/MC/MCContext.h"
13 #include "llvm/MC/MCSection.h"
14 #include "llvm/MC/MCSectionCOFF.h"
15 #include "llvm/MC/MCSectionELF.h"
16 #include "llvm/MC/MCSectionMachO.h"
19 void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
21 IsFunctionEHFrameSymbolPrivate = false;
22 SupportsWeakOmittedEHFrame = false;
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;
30 // .comm doesn't support alignment before Leopard.
31 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
32 CommDirectiveSupportsAlignment = false;
35 = Ctx->getMachOSection("__TEXT", "__text",
36 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
37 SectionKind::getText());
39 = Ctx->getMachOSection("__DATA", "__data", 0,
40 SectionKind::getDataRel());
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());
51 // TODO: Verify datarel below.
53 = Ctx->getMachOSection("__DATA", "__thread_vars",
54 MCSectionMachO::S_THREAD_LOCAL_VARIABLES,
55 SectionKind::getDataRel());
58 = Ctx->getMachOSection("__DATA", "__thread_init",
59 MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
60 SectionKind::getDataRel());
62 CStringSection // .cstring
63 = Ctx->getMachOSection("__TEXT", "__cstring",
64 MCSectionMachO::S_CSTRING_LITERALS,
65 SectionKind::getMergeable1ByteCString());
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());
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());
88 ReadOnlySection // .const
89 = Ctx->getMachOSection("__TEXT", "__const", 0,
90 SectionKind::getReadOnly());
93 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
94 MCSectionMachO::S_COALESCED |
95 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
96 SectionKind::getText());
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());
105 = Ctx->getMachOSection("__DATA","__datacoal_nt",
106 MCSectionMachO::S_COALESCED,
107 SectionKind::getDataRel());
109 = Ctx->getMachOSection("__DATA","__common",
110 MCSectionMachO::S_ZEROFILL,
111 SectionKind::getBSS());
113 = Ctx->getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL,
114 SectionKind::getBSS());
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());
126 if (RelocM == Reloc::Static) {
128 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
129 SectionKind::getDataRel());
131 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
132 SectionKind::getDataRel());
135 = Ctx->getMachOSection("__DATA", "__mod_init_func",
136 MCSectionMachO::S_MOD_INIT_FUNC_POINTERS,
137 SectionKind::getDataRel());
139 = Ctx->getMachOSection("__DATA", "__mod_term_func",
140 MCSectionMachO::S_MOD_TERM_FUNC_POINTERS,
141 SectionKind::getDataRel());
144 // Exception Handling.
145 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
146 SectionKind::getReadOnlyWithRel());
148 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) {
149 CompactUnwindSection =
150 Ctx->getMachOSection("__LD", "__compact_unwind",
151 MCSectionMachO::S_ATTR_DEBUG,
152 SectionKind::getReadOnly());
154 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
155 CompactUnwindDwarfEHFrameOnly = 0x04000000;
158 // Debug Information.
159 DwarfAccelNamesSection =
160 Ctx->getMachOSection("__DWARF", "__apple_names",
161 MCSectionMachO::S_ATTR_DEBUG,
162 SectionKind::getMetadata());
163 DwarfAccelObjCSection =
164 Ctx->getMachOSection("__DWARF", "__apple_objc",
165 MCSectionMachO::S_ATTR_DEBUG,
166 SectionKind::getMetadata());
167 // 16 character section limit...
168 DwarfAccelNamespaceSection =
169 Ctx->getMachOSection("__DWARF", "__apple_namespac",
170 MCSectionMachO::S_ATTR_DEBUG,
171 SectionKind::getMetadata());
172 DwarfAccelTypesSection =
173 Ctx->getMachOSection("__DWARF", "__apple_types",
174 MCSectionMachO::S_ATTR_DEBUG,
175 SectionKind::getMetadata());
178 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
179 MCSectionMachO::S_ATTR_DEBUG,
180 SectionKind::getMetadata());
182 Ctx->getMachOSection("__DWARF", "__debug_info",
183 MCSectionMachO::S_ATTR_DEBUG,
184 SectionKind::getMetadata());
186 Ctx->getMachOSection("__DWARF", "__debug_line",
187 MCSectionMachO::S_ATTR_DEBUG,
188 SectionKind::getMetadata());
190 Ctx->getMachOSection("__DWARF", "__debug_frame",
191 MCSectionMachO::S_ATTR_DEBUG,
192 SectionKind::getMetadata());
193 DwarfPubNamesSection =
194 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
195 MCSectionMachO::S_ATTR_DEBUG,
196 SectionKind::getMetadata());
197 DwarfPubTypesSection =
198 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
199 MCSectionMachO::S_ATTR_DEBUG,
200 SectionKind::getMetadata());
202 Ctx->getMachOSection("__DWARF", "__debug_str",
203 MCSectionMachO::S_ATTR_DEBUG,
204 SectionKind::getMetadata());
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());
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());
226 TLSExtraDataSection = TLSTLVSection;
229 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
230 if (T.getArch() == Triple::mips ||
231 T.getArch() == Triple::mipsel)
232 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
233 else if (T.getArch() == Triple::mips64 ||
234 T.getArch() == Triple::mips64el)
235 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
237 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
239 if (T.getArch() == Triple::x86) {
240 PersonalityEncoding = (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 LSDAEncoding = (RelocM == Reloc::PIC_)
244 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
245 : dwarf::DW_EH_PE_absptr;
246 FDEEncoding = (RelocM == Reloc::PIC_)
247 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
248 : dwarf::DW_EH_PE_absptr;
249 TTypeEncoding = (RelocM == Reloc::PIC_)
250 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
251 : dwarf::DW_EH_PE_absptr;
252 } else if (T.getArch() == Triple::x86_64) {
253 if (RelocM == Reloc::PIC_) {
254 PersonalityEncoding = 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 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
258 (CMModel == CodeModel::Small
259 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
260 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
261 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
262 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
263 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
265 PersonalityEncoding =
266 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
267 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
268 LSDAEncoding = (CMModel == CodeModel::Small)
269 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
270 FDEEncoding = dwarf::DW_EH_PE_udata4;
271 TTypeEncoding = (CMModel == CodeModel::Small)
272 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
274 } else if (T.getArch() == Triple::aarch64) {
275 // The small model guarantees static code/data size < 4GB, but not where it
276 // will be in memory. Most of these could end up >2GB away so even a signed
277 // pc-relative 32-bit address is insufficient, theoretically.
278 if (RelocM == Reloc::PIC_) {
279 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
280 dwarf::DW_EH_PE_sdata8;
281 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
282 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
283 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
284 dwarf::DW_EH_PE_sdata8;
286 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
287 LSDAEncoding = dwarf::DW_EH_PE_absptr;
288 FDEEncoding = dwarf::DW_EH_PE_udata4;
289 TTypeEncoding = dwarf::DW_EH_PE_absptr;
291 } else if (T.getArch() == Triple::ppc64) {
292 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
293 dwarf::DW_EH_PE_udata8;
294 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
295 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
296 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
297 dwarf::DW_EH_PE_udata8;
298 } else if (T.getArch() == Triple::systemz) {
299 // All currently-defined code models guarantee that 4-byte PC-relative
300 // values will be in range.
301 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
302 dwarf::DW_EH_PE_sdata4;
303 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
304 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
305 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
306 dwarf::DW_EH_PE_sdata4;
309 // Solaris requires different flags for .eh_frame to seemingly every other
311 EHSectionType = ELF::SHT_PROGBITS;
312 EHSectionFlags = ELF::SHF_ALLOC;
313 if (T.getOS() == Triple::Solaris) {
314 if (T.getArch() == Triple::x86_64)
315 EHSectionType = ELF::SHT_X86_64_UNWIND;
317 EHSectionFlags |= ELF::SHF_WRITE;
323 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
324 ELF::SHF_WRITE | ELF::SHF_ALLOC,
325 SectionKind::getBSS());
328 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
331 SectionKind::getText());
334 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
335 ELF::SHF_WRITE |ELF::SHF_ALLOC,
336 SectionKind::getDataRel());
339 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
341 SectionKind::getReadOnly());
344 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
345 ELF::SHF_ALLOC | ELF::SHF_TLS |
347 SectionKind::getThreadData());
350 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
351 ELF::SHF_ALLOC | ELF::SHF_TLS |
353 SectionKind::getThreadBSS());
356 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
357 ELF::SHF_ALLOC |ELF::SHF_WRITE,
358 SectionKind::getDataRel());
360 DataRelLocalSection =
361 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
362 ELF::SHF_ALLOC |ELF::SHF_WRITE,
363 SectionKind::getDataRelLocal());
366 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
367 ELF::SHF_ALLOC |ELF::SHF_WRITE,
368 SectionKind::getReadOnlyWithRel());
370 DataRelROLocalSection =
371 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
372 ELF::SHF_ALLOC |ELF::SHF_WRITE,
373 SectionKind::getReadOnlyWithRelLocal());
375 MergeableConst4Section =
376 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
377 ELF::SHF_ALLOC |ELF::SHF_MERGE,
378 SectionKind::getMergeableConst4());
380 MergeableConst8Section =
381 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
382 ELF::SHF_ALLOC |ELF::SHF_MERGE,
383 SectionKind::getMergeableConst8());
385 MergeableConst16Section =
386 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
387 ELF::SHF_ALLOC |ELF::SHF_MERGE,
388 SectionKind::getMergeableConst16());
391 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
392 ELF::SHF_ALLOC |ELF::SHF_WRITE,
393 SectionKind::getDataRel());
396 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
397 ELF::SHF_ALLOC |ELF::SHF_WRITE,
398 SectionKind::getDataRel());
400 // Exception Handling Sections.
402 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
403 // it contains relocatable pointers. In PIC mode, this is probably a big
404 // runtime hit for C++ apps. Either the contents of the LSDA need to be
405 // adjusted or this should be a data section.
407 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
409 SectionKind::getReadOnly());
411 // Debug Info Sections.
413 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
414 SectionKind::getMetadata());
416 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
417 SectionKind::getMetadata());
419 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
420 SectionKind::getMetadata());
422 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
423 SectionKind::getMetadata());
424 DwarfPubNamesSection =
425 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
426 SectionKind::getMetadata());
427 DwarfPubTypesSection =
428 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
429 SectionKind::getMetadata());
431 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
432 ELF::SHF_MERGE | ELF::SHF_STRINGS,
433 SectionKind::getMergeable1ByteCString());
435 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
436 SectionKind::getMetadata());
437 DwarfARangesSection =
438 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
439 SectionKind::getMetadata());
441 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
442 SectionKind::getMetadata());
443 DwarfMacroInfoSection =
444 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
445 SectionKind::getMetadata());
447 // DWARF5 Experimental Debug Info
449 // Accelerator Tables
450 DwarfAccelNamesSection =
451 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
452 SectionKind::getMetadata());
453 DwarfAccelObjCSection =
454 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
455 SectionKind::getMetadata());
456 DwarfAccelNamespaceSection =
457 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
458 SectionKind::getMetadata());
459 DwarfAccelTypesSection =
460 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
461 SectionKind::getMetadata());
464 DwarfInfoDWOSection =
465 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
466 SectionKind::getMetadata());
467 DwarfAbbrevDWOSection =
468 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
469 SectionKind::getMetadata());
471 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
472 ELF::SHF_MERGE | ELF::SHF_STRINGS,
473 SectionKind::getMergeable1ByteCString());
474 DwarfLineDWOSection =
475 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
476 SectionKind::getMetadata());
478 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
479 SectionKind::getMetadata());
480 DwarfStrOffDWOSection =
481 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
482 SectionKind::getMetadata());
484 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
485 SectionKind::getMetadata());
489 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
492 Ctx->getCOFFSection(".text",
493 COFF::IMAGE_SCN_CNT_CODE |
494 COFF::IMAGE_SCN_MEM_EXECUTE |
495 COFF::IMAGE_SCN_MEM_READ,
496 SectionKind::getText());
498 Ctx->getCOFFSection(".data",
499 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
500 COFF::IMAGE_SCN_MEM_READ |
501 COFF::IMAGE_SCN_MEM_WRITE,
502 SectionKind::getDataRel());
504 Ctx->getCOFFSection(".rdata",
505 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
506 COFF::IMAGE_SCN_MEM_READ,
507 SectionKind::getReadOnly());
508 if (T.getOS() == Triple::Win32) {
510 Ctx->getCOFFSection(".CRT$XCU",
511 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
512 COFF::IMAGE_SCN_MEM_READ,
513 SectionKind::getReadOnly());
516 Ctx->getCOFFSection(".ctors",
517 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
518 COFF::IMAGE_SCN_MEM_READ |
519 COFF::IMAGE_SCN_MEM_WRITE,
520 SectionKind::getDataRel());
524 if (T.getOS() == Triple::Win32) {
526 Ctx->getCOFFSection(".CRT$XTX",
527 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
528 COFF::IMAGE_SCN_MEM_READ,
529 SectionKind::getReadOnly());
532 Ctx->getCOFFSection(".dtors",
533 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
534 COFF::IMAGE_SCN_MEM_READ |
535 COFF::IMAGE_SCN_MEM_WRITE,
536 SectionKind::getDataRel());
539 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
540 // though it contains relocatable pointers. In PIC mode, this is probably a
541 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
542 // adjusted or this should be a data section.
544 Ctx->getCOFFSection(".gcc_except_table",
545 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
546 COFF::IMAGE_SCN_MEM_READ,
547 SectionKind::getReadOnly());
551 Ctx->getCOFFSection(".debug_abbrev",
552 COFF::IMAGE_SCN_MEM_DISCARDABLE |
553 COFF::IMAGE_SCN_MEM_READ,
554 SectionKind::getMetadata());
556 Ctx->getCOFFSection(".debug_info",
557 COFF::IMAGE_SCN_MEM_DISCARDABLE |
558 COFF::IMAGE_SCN_MEM_READ,
559 SectionKind::getMetadata());
561 Ctx->getCOFFSection(".debug_line",
562 COFF::IMAGE_SCN_MEM_DISCARDABLE |
563 COFF::IMAGE_SCN_MEM_READ,
564 SectionKind::getMetadata());
566 Ctx->getCOFFSection(".debug_frame",
567 COFF::IMAGE_SCN_MEM_DISCARDABLE |
568 COFF::IMAGE_SCN_MEM_READ,
569 SectionKind::getMetadata());
570 DwarfPubNamesSection =
571 Ctx->getCOFFSection(".debug_pubnames",
572 COFF::IMAGE_SCN_MEM_DISCARDABLE |
573 COFF::IMAGE_SCN_MEM_READ,
574 SectionKind::getMetadata());
575 DwarfPubTypesSection =
576 Ctx->getCOFFSection(".debug_pubtypes",
577 COFF::IMAGE_SCN_MEM_DISCARDABLE |
578 COFF::IMAGE_SCN_MEM_READ,
579 SectionKind::getMetadata());
581 Ctx->getCOFFSection(".debug_str",
582 COFF::IMAGE_SCN_MEM_DISCARDABLE |
583 COFF::IMAGE_SCN_MEM_READ,
584 SectionKind::getMetadata());
586 Ctx->getCOFFSection(".debug_loc",
587 COFF::IMAGE_SCN_MEM_DISCARDABLE |
588 COFF::IMAGE_SCN_MEM_READ,
589 SectionKind::getMetadata());
590 DwarfARangesSection =
591 Ctx->getCOFFSection(".debug_aranges",
592 COFF::IMAGE_SCN_MEM_DISCARDABLE |
593 COFF::IMAGE_SCN_MEM_READ,
594 SectionKind::getMetadata());
596 Ctx->getCOFFSection(".debug_ranges",
597 COFF::IMAGE_SCN_MEM_DISCARDABLE |
598 COFF::IMAGE_SCN_MEM_READ,
599 SectionKind::getMetadata());
600 DwarfMacroInfoSection =
601 Ctx->getCOFFSection(".debug_macinfo",
602 COFF::IMAGE_SCN_MEM_DISCARDABLE |
603 COFF::IMAGE_SCN_MEM_READ,
604 SectionKind::getMetadata());
607 Ctx->getCOFFSection(".drectve",
608 COFF::IMAGE_SCN_LNK_INFO,
609 SectionKind::getMetadata());
612 Ctx->getCOFFSection(".pdata",
613 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
614 COFF::IMAGE_SCN_MEM_READ,
615 SectionKind::getDataRel());
618 Ctx->getCOFFSection(".xdata",
619 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
620 COFF::IMAGE_SCN_MEM_READ,
621 SectionKind::getDataRel());
623 Ctx->getCOFFSection(".tls$",
624 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
625 COFF::IMAGE_SCN_MEM_READ |
626 COFF::IMAGE_SCN_MEM_WRITE,
627 SectionKind::getDataRel());
630 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
638 CommDirectiveSupportsAlignment = true;
639 SupportsWeakOmittedEHFrame = true;
640 IsFunctionEHFrameSymbolPrivate = true;
642 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
643 TTypeEncoding = dwarf::DW_EH_PE_absptr;
645 CompactUnwindDwarfEHFrameOnly = 0;
647 EHFrameSection = 0; // Created on demand.
648 CompactUnwindSection = 0; // Used only by selected targets.
649 DwarfAccelNamesSection = 0; // Used only by selected targets.
650 DwarfAccelObjCSection = 0; // Used only by selected targets.
651 DwarfAccelNamespaceSection = 0; // Used only by selected targets.
652 DwarfAccelTypesSection = 0; // Used only by selected targets.
655 Triple::ArchType Arch = T.getArch();
656 // FIXME: Checking for Arch here to filter out bogus triples such as
657 // cellspu-apple-darwin. Perhaps we should fix in Triple?
658 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
659 Arch == Triple::arm || Arch == Triple::thumb ||
660 Arch == Triple::ppc || Arch == Triple::ppc64 ||
661 Arch == Triple::UnknownArch) &&
662 (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
664 InitMachOMCObjectFileInfo(T);
665 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
666 (T.getEnvironment() != Triple::ELF) &&
667 (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
668 T.getOS() == Triple::Win32)) {
670 InitCOFFMCObjectFileInfo(T);
673 InitELFMCObjectFileInfo(T);
677 void MCObjectFileInfo::InitEHFrameSection() {
680 Ctx->getMachOSection("__TEXT", "__eh_frame",
681 MCSectionMachO::S_COALESCED |
682 MCSectionMachO::S_ATTR_NO_TOC |
683 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
684 MCSectionMachO::S_ATTR_LIVE_SUPPORT,
685 SectionKind::getReadOnly());
686 else if (Env == IsELF)
688 Ctx->getELFSection(".eh_frame", EHSectionType,
690 SectionKind::getDataRel());
693 Ctx->getCOFFSection(".eh_frame",
694 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
695 COFF::IMAGE_SCN_MEM_READ |
696 COFF::IMAGE_SCN_MEM_WRITE,
697 SectionKind::getDataRel());