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 T.getArch() != Triple::ppc64le)
84 SixteenByteConstantSection = // .literal16
85 Ctx->getMachOSection("__TEXT", "__literal16",
86 MCSectionMachO::S_16BYTE_LITERALS,
87 SectionKind::getMergeableConst16());
89 ReadOnlySection // .const
90 = Ctx->getMachOSection("__TEXT", "__const", 0,
91 SectionKind::getReadOnly());
94 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
95 MCSectionMachO::S_COALESCED |
96 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
97 SectionKind::getText());
99 = Ctx->getMachOSection("__TEXT", "__const_coal",
100 MCSectionMachO::S_COALESCED,
101 SectionKind::getReadOnly());
102 ConstDataSection // .const_data
103 = Ctx->getMachOSection("__DATA", "__const", 0,
104 SectionKind::getReadOnlyWithRel());
106 = Ctx->getMachOSection("__DATA","__datacoal_nt",
107 MCSectionMachO::S_COALESCED,
108 SectionKind::getDataRel());
110 = Ctx->getMachOSection("__DATA","__common",
111 MCSectionMachO::S_ZEROFILL,
112 SectionKind::getBSS());
114 = Ctx->getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL,
115 SectionKind::getBSS());
118 LazySymbolPointerSection
119 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
120 MCSectionMachO::S_LAZY_SYMBOL_POINTERS,
121 SectionKind::getMetadata());
122 NonLazySymbolPointerSection
123 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
124 MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
125 SectionKind::getMetadata());
127 if (RelocM == Reloc::Static) {
129 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
130 SectionKind::getDataRel());
132 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
133 SectionKind::getDataRel());
136 = Ctx->getMachOSection("__DATA", "__mod_init_func",
137 MCSectionMachO::S_MOD_INIT_FUNC_POINTERS,
138 SectionKind::getDataRel());
140 = Ctx->getMachOSection("__DATA", "__mod_term_func",
141 MCSectionMachO::S_MOD_TERM_FUNC_POINTERS,
142 SectionKind::getDataRel());
145 // Exception Handling.
146 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
147 SectionKind::getReadOnlyWithRel());
149 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) {
150 CompactUnwindSection =
151 Ctx->getMachOSection("__LD", "__compact_unwind",
152 MCSectionMachO::S_ATTR_DEBUG,
153 SectionKind::getReadOnly());
155 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
156 CompactUnwindDwarfEHFrameOnly = 0x04000000;
159 // Debug Information.
160 DwarfAccelNamesSection =
161 Ctx->getMachOSection("__DWARF", "__apple_names",
162 MCSectionMachO::S_ATTR_DEBUG,
163 SectionKind::getMetadata());
164 DwarfAccelObjCSection =
165 Ctx->getMachOSection("__DWARF", "__apple_objc",
166 MCSectionMachO::S_ATTR_DEBUG,
167 SectionKind::getMetadata());
168 // 16 character section limit...
169 DwarfAccelNamespaceSection =
170 Ctx->getMachOSection("__DWARF", "__apple_namespac",
171 MCSectionMachO::S_ATTR_DEBUG,
172 SectionKind::getMetadata());
173 DwarfAccelTypesSection =
174 Ctx->getMachOSection("__DWARF", "__apple_types",
175 MCSectionMachO::S_ATTR_DEBUG,
176 SectionKind::getMetadata());
179 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
180 MCSectionMachO::S_ATTR_DEBUG,
181 SectionKind::getMetadata());
183 Ctx->getMachOSection("__DWARF", "__debug_info",
184 MCSectionMachO::S_ATTR_DEBUG,
185 SectionKind::getMetadata());
187 Ctx->getMachOSection("__DWARF", "__debug_line",
188 MCSectionMachO::S_ATTR_DEBUG,
189 SectionKind::getMetadata());
191 Ctx->getMachOSection("__DWARF", "__debug_frame",
192 MCSectionMachO::S_ATTR_DEBUG,
193 SectionKind::getMetadata());
194 DwarfPubNamesSection =
195 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
196 MCSectionMachO::S_ATTR_DEBUG,
197 SectionKind::getMetadata());
198 DwarfPubTypesSection =
199 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
200 MCSectionMachO::S_ATTR_DEBUG,
201 SectionKind::getMetadata());
203 Ctx->getMachOSection("__DWARF", "__debug_str",
204 MCSectionMachO::S_ATTR_DEBUG,
205 SectionKind::getMetadata());
207 Ctx->getMachOSection("__DWARF", "__debug_loc",
208 MCSectionMachO::S_ATTR_DEBUG,
209 SectionKind::getMetadata());
210 DwarfARangesSection =
211 Ctx->getMachOSection("__DWARF", "__debug_aranges",
212 MCSectionMachO::S_ATTR_DEBUG,
213 SectionKind::getMetadata());
215 Ctx->getMachOSection("__DWARF", "__debug_ranges",
216 MCSectionMachO::S_ATTR_DEBUG,
217 SectionKind::getMetadata());
218 DwarfMacroInfoSection =
219 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
220 MCSectionMachO::S_ATTR_DEBUG,
221 SectionKind::getMetadata());
222 DwarfDebugInlineSection =
223 Ctx->getMachOSection("__DWARF", "__debug_inlined",
224 MCSectionMachO::S_ATTR_DEBUG,
225 SectionKind::getMetadata());
227 TLSExtraDataSection = TLSTLVSection;
230 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
231 if (T.getArch() == Triple::mips ||
232 T.getArch() == Triple::mipsel)
233 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
234 else if (T.getArch() == Triple::mips64 ||
235 T.getArch() == Triple::mips64el)
236 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
238 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
240 if (T.getArch() == Triple::x86) {
241 PersonalityEncoding = (RelocM == Reloc::PIC_)
242 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
243 : dwarf::DW_EH_PE_absptr;
244 LSDAEncoding = (RelocM == Reloc::PIC_)
245 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
246 : dwarf::DW_EH_PE_absptr;
247 FDEEncoding = (RelocM == Reloc::PIC_)
248 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
249 : dwarf::DW_EH_PE_absptr;
250 TTypeEncoding = (RelocM == Reloc::PIC_)
251 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
252 : dwarf::DW_EH_PE_absptr;
253 } else if (T.getArch() == Triple::x86_64) {
254 if (RelocM == Reloc::PIC_) {
255 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
256 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
257 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
258 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
259 (CMModel == CodeModel::Small
260 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
261 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
262 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
263 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
264 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
266 PersonalityEncoding =
267 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
268 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
269 LSDAEncoding = (CMModel == CodeModel::Small)
270 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
271 FDEEncoding = dwarf::DW_EH_PE_udata4;
272 TTypeEncoding = (CMModel == CodeModel::Small)
273 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
275 } else if (T.getArch() == Triple::aarch64) {
276 // The small model guarantees static code/data size < 4GB, but not where it
277 // will be in memory. Most of these could end up >2GB away so even a signed
278 // pc-relative 32-bit address is insufficient, theoretically.
279 if (RelocM == Reloc::PIC_) {
280 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
281 dwarf::DW_EH_PE_sdata8;
282 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
283 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
284 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
285 dwarf::DW_EH_PE_sdata8;
287 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
288 LSDAEncoding = dwarf::DW_EH_PE_absptr;
289 FDEEncoding = dwarf::DW_EH_PE_udata4;
290 TTypeEncoding = dwarf::DW_EH_PE_absptr;
292 } else if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le) {
293 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
294 dwarf::DW_EH_PE_udata8;
295 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
296 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
297 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
298 dwarf::DW_EH_PE_udata8;
299 } else if (T.getArch() == Triple::systemz) {
300 // All currently-defined code models guarantee that 4-byte PC-relative
301 // values will be in range.
302 if (RelocM == Reloc::PIC_) {
303 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
304 dwarf::DW_EH_PE_sdata4;
305 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
306 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
307 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
308 dwarf::DW_EH_PE_sdata4;
310 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
311 LSDAEncoding = dwarf::DW_EH_PE_absptr;
312 FDEEncoding = dwarf::DW_EH_PE_absptr;
313 TTypeEncoding = dwarf::DW_EH_PE_absptr;
317 // Solaris requires different flags for .eh_frame to seemingly every other
319 EHSectionType = ELF::SHT_PROGBITS;
320 EHSectionFlags = ELF::SHF_ALLOC;
321 if (T.getOS() == Triple::Solaris) {
322 if (T.getArch() == Triple::x86_64)
323 EHSectionType = ELF::SHT_X86_64_UNWIND;
325 EHSectionFlags |= ELF::SHF_WRITE;
331 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
332 ELF::SHF_WRITE | ELF::SHF_ALLOC,
333 SectionKind::getBSS());
336 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
339 SectionKind::getText());
342 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
343 ELF::SHF_WRITE |ELF::SHF_ALLOC,
344 SectionKind::getDataRel());
347 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
349 SectionKind::getReadOnly());
352 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
353 ELF::SHF_ALLOC | ELF::SHF_TLS |
355 SectionKind::getThreadData());
358 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
359 ELF::SHF_ALLOC | ELF::SHF_TLS |
361 SectionKind::getThreadBSS());
364 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
365 ELF::SHF_ALLOC |ELF::SHF_WRITE,
366 SectionKind::getDataRel());
368 DataRelLocalSection =
369 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
370 ELF::SHF_ALLOC |ELF::SHF_WRITE,
371 SectionKind::getDataRelLocal());
374 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
375 ELF::SHF_ALLOC |ELF::SHF_WRITE,
376 SectionKind::getReadOnlyWithRel());
378 DataRelROLocalSection =
379 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
380 ELF::SHF_ALLOC |ELF::SHF_WRITE,
381 SectionKind::getReadOnlyWithRelLocal());
383 MergeableConst4Section =
384 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
385 ELF::SHF_ALLOC |ELF::SHF_MERGE,
386 SectionKind::getMergeableConst4());
388 MergeableConst8Section =
389 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
390 ELF::SHF_ALLOC |ELF::SHF_MERGE,
391 SectionKind::getMergeableConst8());
393 MergeableConst16Section =
394 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
395 ELF::SHF_ALLOC |ELF::SHF_MERGE,
396 SectionKind::getMergeableConst16());
399 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
400 ELF::SHF_ALLOC |ELF::SHF_WRITE,
401 SectionKind::getDataRel());
404 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
405 ELF::SHF_ALLOC |ELF::SHF_WRITE,
406 SectionKind::getDataRel());
408 // Exception Handling Sections.
410 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
411 // it contains relocatable pointers. In PIC mode, this is probably a big
412 // runtime hit for C++ apps. Either the contents of the LSDA need to be
413 // adjusted or this should be a data section.
415 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
417 SectionKind::getReadOnly());
419 // Debug Info Sections.
421 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
422 SectionKind::getMetadata());
424 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
425 SectionKind::getMetadata());
427 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
428 SectionKind::getMetadata());
430 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
431 SectionKind::getMetadata());
432 DwarfPubNamesSection =
433 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
434 SectionKind::getMetadata());
435 DwarfPubTypesSection =
436 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
437 SectionKind::getMetadata());
439 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
440 ELF::SHF_MERGE | ELF::SHF_STRINGS,
441 SectionKind::getMergeable1ByteCString());
443 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
444 SectionKind::getMetadata());
445 DwarfARangesSection =
446 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
447 SectionKind::getMetadata());
449 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
450 SectionKind::getMetadata());
451 DwarfMacroInfoSection =
452 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
453 SectionKind::getMetadata());
455 // DWARF5 Experimental Debug Info
457 // Accelerator Tables
458 DwarfAccelNamesSection =
459 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
460 SectionKind::getMetadata());
461 DwarfAccelObjCSection =
462 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
463 SectionKind::getMetadata());
464 DwarfAccelNamespaceSection =
465 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
466 SectionKind::getMetadata());
467 DwarfAccelTypesSection =
468 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
469 SectionKind::getMetadata());
472 DwarfInfoDWOSection =
473 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
474 SectionKind::getMetadata());
475 DwarfAbbrevDWOSection =
476 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
477 SectionKind::getMetadata());
479 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
480 ELF::SHF_MERGE | ELF::SHF_STRINGS,
481 SectionKind::getMergeable1ByteCString());
482 DwarfLineDWOSection =
483 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
484 SectionKind::getMetadata());
486 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
487 SectionKind::getMetadata());
488 DwarfStrOffDWOSection =
489 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
490 SectionKind::getMetadata());
492 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
493 SectionKind::getMetadata());
497 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
500 Ctx->getCOFFSection(".text",
501 COFF::IMAGE_SCN_CNT_CODE |
502 COFF::IMAGE_SCN_MEM_EXECUTE |
503 COFF::IMAGE_SCN_MEM_READ,
504 SectionKind::getText());
506 Ctx->getCOFFSection(".data",
507 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
508 COFF::IMAGE_SCN_MEM_READ |
509 COFF::IMAGE_SCN_MEM_WRITE,
510 SectionKind::getDataRel());
512 Ctx->getCOFFSection(".rdata",
513 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
514 COFF::IMAGE_SCN_MEM_READ,
515 SectionKind::getReadOnly());
516 if (T.getOS() == Triple::Win32) {
518 Ctx->getCOFFSection(".CRT$XCU",
519 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
520 COFF::IMAGE_SCN_MEM_READ,
521 SectionKind::getReadOnly());
524 Ctx->getCOFFSection(".ctors",
525 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
526 COFF::IMAGE_SCN_MEM_READ |
527 COFF::IMAGE_SCN_MEM_WRITE,
528 SectionKind::getDataRel());
532 if (T.getOS() == Triple::Win32) {
534 Ctx->getCOFFSection(".CRT$XTX",
535 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
536 COFF::IMAGE_SCN_MEM_READ,
537 SectionKind::getReadOnly());
540 Ctx->getCOFFSection(".dtors",
541 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
542 COFF::IMAGE_SCN_MEM_READ |
543 COFF::IMAGE_SCN_MEM_WRITE,
544 SectionKind::getDataRel());
547 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
548 // though it contains relocatable pointers. In PIC mode, this is probably a
549 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
550 // adjusted or this should be a data section.
552 Ctx->getCOFFSection(".gcc_except_table",
553 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
554 COFF::IMAGE_SCN_MEM_READ,
555 SectionKind::getReadOnly());
559 Ctx->getCOFFSection(".debug_abbrev",
560 COFF::IMAGE_SCN_MEM_DISCARDABLE |
561 COFF::IMAGE_SCN_MEM_READ,
562 SectionKind::getMetadata());
564 Ctx->getCOFFSection(".debug_info",
565 COFF::IMAGE_SCN_MEM_DISCARDABLE |
566 COFF::IMAGE_SCN_MEM_READ,
567 SectionKind::getMetadata());
569 Ctx->getCOFFSection(".debug_line",
570 COFF::IMAGE_SCN_MEM_DISCARDABLE |
571 COFF::IMAGE_SCN_MEM_READ,
572 SectionKind::getMetadata());
574 Ctx->getCOFFSection(".debug_frame",
575 COFF::IMAGE_SCN_MEM_DISCARDABLE |
576 COFF::IMAGE_SCN_MEM_READ,
577 SectionKind::getMetadata());
578 DwarfPubNamesSection =
579 Ctx->getCOFFSection(".debug_pubnames",
580 COFF::IMAGE_SCN_MEM_DISCARDABLE |
581 COFF::IMAGE_SCN_MEM_READ,
582 SectionKind::getMetadata());
583 DwarfPubTypesSection =
584 Ctx->getCOFFSection(".debug_pubtypes",
585 COFF::IMAGE_SCN_MEM_DISCARDABLE |
586 COFF::IMAGE_SCN_MEM_READ,
587 SectionKind::getMetadata());
589 Ctx->getCOFFSection(".debug_str",
590 COFF::IMAGE_SCN_MEM_DISCARDABLE |
591 COFF::IMAGE_SCN_MEM_READ,
592 SectionKind::getMetadata());
594 Ctx->getCOFFSection(".debug_loc",
595 COFF::IMAGE_SCN_MEM_DISCARDABLE |
596 COFF::IMAGE_SCN_MEM_READ,
597 SectionKind::getMetadata());
598 DwarfARangesSection =
599 Ctx->getCOFFSection(".debug_aranges",
600 COFF::IMAGE_SCN_MEM_DISCARDABLE |
601 COFF::IMAGE_SCN_MEM_READ,
602 SectionKind::getMetadata());
604 Ctx->getCOFFSection(".debug_ranges",
605 COFF::IMAGE_SCN_MEM_DISCARDABLE |
606 COFF::IMAGE_SCN_MEM_READ,
607 SectionKind::getMetadata());
608 DwarfMacroInfoSection =
609 Ctx->getCOFFSection(".debug_macinfo",
610 COFF::IMAGE_SCN_MEM_DISCARDABLE |
611 COFF::IMAGE_SCN_MEM_READ,
612 SectionKind::getMetadata());
615 Ctx->getCOFFSection(".drectve",
616 COFF::IMAGE_SCN_LNK_INFO,
617 SectionKind::getMetadata());
620 Ctx->getCOFFSection(".pdata",
621 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
622 COFF::IMAGE_SCN_MEM_READ,
623 SectionKind::getDataRel());
626 Ctx->getCOFFSection(".xdata",
627 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
628 COFF::IMAGE_SCN_MEM_READ,
629 SectionKind::getDataRel());
631 Ctx->getCOFFSection(".tls$",
632 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
633 COFF::IMAGE_SCN_MEM_READ |
634 COFF::IMAGE_SCN_MEM_WRITE,
635 SectionKind::getDataRel());
638 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
646 CommDirectiveSupportsAlignment = true;
647 SupportsWeakOmittedEHFrame = true;
648 IsFunctionEHFrameSymbolPrivate = true;
650 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
651 TTypeEncoding = dwarf::DW_EH_PE_absptr;
653 CompactUnwindDwarfEHFrameOnly = 0;
655 EHFrameSection = 0; // Created on demand.
656 CompactUnwindSection = 0; // Used only by selected targets.
657 DwarfAccelNamesSection = 0; // Used only by selected targets.
658 DwarfAccelObjCSection = 0; // Used only by selected targets.
659 DwarfAccelNamespaceSection = 0; // Used only by selected targets.
660 DwarfAccelTypesSection = 0; // Used only by selected targets.
663 Triple::ArchType Arch = T.getArch();
664 // FIXME: Checking for Arch here to filter out bogus triples such as
665 // cellspu-apple-darwin. Perhaps we should fix in Triple?
666 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
667 Arch == Triple::arm || Arch == Triple::thumb ||
668 Arch == Triple::ppc || Arch == Triple::ppc64 ||
669 Arch == Triple::UnknownArch) &&
670 (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
672 InitMachOMCObjectFileInfo(T);
673 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
674 (T.getEnvironment() != Triple::ELF) &&
675 (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
676 T.getOS() == Triple::Win32)) {
678 InitCOFFMCObjectFileInfo(T);
681 InitELFMCObjectFileInfo(T);
685 void MCObjectFileInfo::InitEHFrameSection() {
688 Ctx->getMachOSection("__TEXT", "__eh_frame",
689 MCSectionMachO::S_COALESCED |
690 MCSectionMachO::S_ATTR_NO_TOC |
691 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
692 MCSectionMachO::S_ATTR_LIVE_SUPPORT,
693 SectionKind::getReadOnly());
694 else if (Env == IsELF)
696 Ctx->getELFSection(".eh_frame", EHSectionType,
698 SectionKind::getDataRel());
701 Ctx->getCOFFSection(".eh_frame",
702 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
703 COFF::IMAGE_SCN_MEM_READ |
704 COFF::IMAGE_SCN_MEM_WRITE,
705 SectionKind::getDataRel());