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 // BSSSection might not be expected initialized on msvc.
45 TLSDataSection // .tdata
46 = Ctx->getMachOSection("__DATA", "__thread_data",
47 MCSectionMachO::S_THREAD_LOCAL_REGULAR,
48 SectionKind::getDataRel());
49 TLSBSSSection // .tbss
50 = Ctx->getMachOSection("__DATA", "__thread_bss",
51 MCSectionMachO::S_THREAD_LOCAL_ZEROFILL,
52 SectionKind::getThreadBSS());
54 // TODO: Verify datarel below.
56 = Ctx->getMachOSection("__DATA", "__thread_vars",
57 MCSectionMachO::S_THREAD_LOCAL_VARIABLES,
58 SectionKind::getDataRel());
61 = Ctx->getMachOSection("__DATA", "__thread_init",
62 MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
63 SectionKind::getDataRel());
65 CStringSection // .cstring
66 = Ctx->getMachOSection("__TEXT", "__cstring",
67 MCSectionMachO::S_CSTRING_LITERALS,
68 SectionKind::getMergeable1ByteCString());
70 = Ctx->getMachOSection("__TEXT","__ustring", 0,
71 SectionKind::getMergeable2ByteCString());
72 FourByteConstantSection // .literal4
73 = Ctx->getMachOSection("__TEXT", "__literal4",
74 MCSectionMachO::S_4BYTE_LITERALS,
75 SectionKind::getMergeableConst4());
76 EightByteConstantSection // .literal8
77 = Ctx->getMachOSection("__TEXT", "__literal8",
78 MCSectionMachO::S_8BYTE_LITERALS,
79 SectionKind::getMergeableConst8());
81 // ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back
82 // to using it in -static mode.
83 SixteenByteConstantSection = 0;
84 if (RelocM != Reloc::Static &&
85 T.getArch() != Triple::x86_64 && T.getArch() != Triple::ppc64 &&
86 T.getArch() != Triple::ppc64le)
87 SixteenByteConstantSection = // .literal16
88 Ctx->getMachOSection("__TEXT", "__literal16",
89 MCSectionMachO::S_16BYTE_LITERALS,
90 SectionKind::getMergeableConst16());
92 ReadOnlySection // .const
93 = Ctx->getMachOSection("__TEXT", "__const", 0,
94 SectionKind::getReadOnly());
97 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
98 MCSectionMachO::S_COALESCED |
99 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
100 SectionKind::getText());
102 = Ctx->getMachOSection("__TEXT", "__const_coal",
103 MCSectionMachO::S_COALESCED,
104 SectionKind::getReadOnly());
105 ConstDataSection // .const_data
106 = Ctx->getMachOSection("__DATA", "__const", 0,
107 SectionKind::getReadOnlyWithRel());
109 = Ctx->getMachOSection("__DATA","__datacoal_nt",
110 MCSectionMachO::S_COALESCED,
111 SectionKind::getDataRel());
113 = Ctx->getMachOSection("__DATA","__common",
114 MCSectionMachO::S_ZEROFILL,
115 SectionKind::getBSS());
117 = Ctx->getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL,
118 SectionKind::getBSS());
121 LazySymbolPointerSection
122 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
123 MCSectionMachO::S_LAZY_SYMBOL_POINTERS,
124 SectionKind::getMetadata());
125 NonLazySymbolPointerSection
126 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
127 MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
128 SectionKind::getMetadata());
130 if (RelocM == Reloc::Static) {
132 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
133 SectionKind::getDataRel());
135 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
136 SectionKind::getDataRel());
139 = Ctx->getMachOSection("__DATA", "__mod_init_func",
140 MCSectionMachO::S_MOD_INIT_FUNC_POINTERS,
141 SectionKind::getDataRel());
143 = Ctx->getMachOSection("__DATA", "__mod_term_func",
144 MCSectionMachO::S_MOD_TERM_FUNC_POINTERS,
145 SectionKind::getDataRel());
148 // Exception Handling.
149 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
150 SectionKind::getReadOnlyWithRel());
152 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) {
153 CompactUnwindSection =
154 Ctx->getMachOSection("__LD", "__compact_unwind",
155 MCSectionMachO::S_ATTR_DEBUG,
156 SectionKind::getReadOnly());
158 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
159 CompactUnwindDwarfEHFrameOnly = 0x04000000;
162 // Debug Information.
163 DwarfAccelNamesSection =
164 Ctx->getMachOSection("__DWARF", "__apple_names",
165 MCSectionMachO::S_ATTR_DEBUG,
166 SectionKind::getMetadata());
167 DwarfAccelObjCSection =
168 Ctx->getMachOSection("__DWARF", "__apple_objc",
169 MCSectionMachO::S_ATTR_DEBUG,
170 SectionKind::getMetadata());
171 // 16 character section limit...
172 DwarfAccelNamespaceSection =
173 Ctx->getMachOSection("__DWARF", "__apple_namespac",
174 MCSectionMachO::S_ATTR_DEBUG,
175 SectionKind::getMetadata());
176 DwarfAccelTypesSection =
177 Ctx->getMachOSection("__DWARF", "__apple_types",
178 MCSectionMachO::S_ATTR_DEBUG,
179 SectionKind::getMetadata());
182 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
183 MCSectionMachO::S_ATTR_DEBUG,
184 SectionKind::getMetadata());
186 Ctx->getMachOSection("__DWARF", "__debug_info",
187 MCSectionMachO::S_ATTR_DEBUG,
188 SectionKind::getMetadata());
190 Ctx->getMachOSection("__DWARF", "__debug_line",
191 MCSectionMachO::S_ATTR_DEBUG,
192 SectionKind::getMetadata());
194 Ctx->getMachOSection("__DWARF", "__debug_frame",
195 MCSectionMachO::S_ATTR_DEBUG,
196 SectionKind::getMetadata());
197 DwarfPubNamesSection =
198 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
199 MCSectionMachO::S_ATTR_DEBUG,
200 SectionKind::getMetadata());
201 DwarfPubTypesSection =
202 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
203 MCSectionMachO::S_ATTR_DEBUG,
204 SectionKind::getMetadata());
205 DwarfGnuPubNamesSection =
206 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
207 MCSectionMachO::S_ATTR_DEBUG,
208 SectionKind::getMetadata());
209 DwarfGnuPubTypesSection =
210 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
211 MCSectionMachO::S_ATTR_DEBUG,
212 SectionKind::getMetadata());
214 Ctx->getMachOSection("__DWARF", "__debug_str",
215 MCSectionMachO::S_ATTR_DEBUG,
216 SectionKind::getMetadata());
218 Ctx->getMachOSection("__DWARF", "__debug_loc",
219 MCSectionMachO::S_ATTR_DEBUG,
220 SectionKind::getMetadata());
221 DwarfARangesSection =
222 Ctx->getMachOSection("__DWARF", "__debug_aranges",
223 MCSectionMachO::S_ATTR_DEBUG,
224 SectionKind::getMetadata());
226 Ctx->getMachOSection("__DWARF", "__debug_ranges",
227 MCSectionMachO::S_ATTR_DEBUG,
228 SectionKind::getMetadata());
229 DwarfMacroInfoSection =
230 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
231 MCSectionMachO::S_ATTR_DEBUG,
232 SectionKind::getMetadata());
233 DwarfDebugInlineSection =
234 Ctx->getMachOSection("__DWARF", "__debug_inlined",
235 MCSectionMachO::S_ATTR_DEBUG,
236 SectionKind::getMetadata());
238 TLSExtraDataSection = TLSTLVSection;
241 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
242 if (T.getArch() == Triple::mips ||
243 T.getArch() == Triple::mipsel)
244 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
245 else if (T.getArch() == Triple::mips64 ||
246 T.getArch() == Triple::mips64el)
247 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
249 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
251 if (T.getArch() == Triple::x86) {
252 PersonalityEncoding = (RelocM == Reloc::PIC_)
253 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
254 : dwarf::DW_EH_PE_absptr;
255 LSDAEncoding = (RelocM == Reloc::PIC_)
256 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
257 : dwarf::DW_EH_PE_absptr;
258 FDEEncoding = (RelocM == Reloc::PIC_)
259 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
260 : dwarf::DW_EH_PE_absptr;
261 TTypeEncoding = (RelocM == Reloc::PIC_)
262 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
263 : dwarf::DW_EH_PE_absptr;
264 } else if (T.getArch() == Triple::x86_64) {
265 if (RelocM == Reloc::PIC_) {
266 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
267 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
268 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
269 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
270 (CMModel == CodeModel::Small
271 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
272 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
273 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
274 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
275 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
277 PersonalityEncoding =
278 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
279 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
280 LSDAEncoding = (CMModel == CodeModel::Small)
281 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
282 FDEEncoding = dwarf::DW_EH_PE_udata4;
283 TTypeEncoding = (CMModel == CodeModel::Small)
284 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
286 } else if (T.getArch() == Triple::aarch64) {
287 // The small model guarantees static code/data size < 4GB, but not where it
288 // will be in memory. Most of these could end up >2GB away so even a signed
289 // pc-relative 32-bit address is insufficient, theoretically.
290 if (RelocM == Reloc::PIC_) {
291 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
292 dwarf::DW_EH_PE_sdata8;
293 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
294 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
295 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
296 dwarf::DW_EH_PE_sdata8;
298 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
299 LSDAEncoding = dwarf::DW_EH_PE_absptr;
300 FDEEncoding = dwarf::DW_EH_PE_udata4;
301 TTypeEncoding = dwarf::DW_EH_PE_absptr;
303 } else if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le) {
304 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
305 dwarf::DW_EH_PE_udata8;
306 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
307 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
308 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
309 dwarf::DW_EH_PE_udata8;
310 } else if (T.getArch() == Triple::systemz) {
311 // All currently-defined code models guarantee that 4-byte PC-relative
312 // values will be in range.
313 if (RelocM == Reloc::PIC_) {
314 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
315 dwarf::DW_EH_PE_sdata4;
316 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
317 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
318 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
319 dwarf::DW_EH_PE_sdata4;
321 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
322 LSDAEncoding = dwarf::DW_EH_PE_absptr;
323 FDEEncoding = dwarf::DW_EH_PE_absptr;
324 TTypeEncoding = dwarf::DW_EH_PE_absptr;
328 // Solaris requires different flags for .eh_frame to seemingly every other
330 EHSectionType = ELF::SHT_PROGBITS;
331 EHSectionFlags = ELF::SHF_ALLOC;
332 if (T.getOS() == Triple::Solaris) {
333 if (T.getArch() == Triple::x86_64)
334 EHSectionType = ELF::SHT_X86_64_UNWIND;
336 EHSectionFlags |= ELF::SHF_WRITE;
342 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
343 ELF::SHF_WRITE | ELF::SHF_ALLOC,
344 SectionKind::getBSS());
347 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
350 SectionKind::getText());
353 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
354 ELF::SHF_WRITE |ELF::SHF_ALLOC,
355 SectionKind::getDataRel());
358 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
360 SectionKind::getReadOnly());
363 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
364 ELF::SHF_ALLOC | ELF::SHF_TLS |
366 SectionKind::getThreadData());
369 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
370 ELF::SHF_ALLOC | ELF::SHF_TLS |
372 SectionKind::getThreadBSS());
375 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
376 ELF::SHF_ALLOC |ELF::SHF_WRITE,
377 SectionKind::getDataRel());
379 DataRelLocalSection =
380 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
381 ELF::SHF_ALLOC |ELF::SHF_WRITE,
382 SectionKind::getDataRelLocal());
385 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
386 ELF::SHF_ALLOC |ELF::SHF_WRITE,
387 SectionKind::getReadOnlyWithRel());
389 DataRelROLocalSection =
390 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
391 ELF::SHF_ALLOC |ELF::SHF_WRITE,
392 SectionKind::getReadOnlyWithRelLocal());
394 MergeableConst4Section =
395 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
396 ELF::SHF_ALLOC |ELF::SHF_MERGE,
397 SectionKind::getMergeableConst4());
399 MergeableConst8Section =
400 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
401 ELF::SHF_ALLOC |ELF::SHF_MERGE,
402 SectionKind::getMergeableConst8());
404 MergeableConst16Section =
405 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
406 ELF::SHF_ALLOC |ELF::SHF_MERGE,
407 SectionKind::getMergeableConst16());
410 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
411 ELF::SHF_ALLOC |ELF::SHF_WRITE,
412 SectionKind::getDataRel());
415 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
416 ELF::SHF_ALLOC |ELF::SHF_WRITE,
417 SectionKind::getDataRel());
419 // Exception Handling Sections.
421 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
422 // it contains relocatable pointers. In PIC mode, this is probably a big
423 // runtime hit for C++ apps. Either the contents of the LSDA need to be
424 // adjusted or this should be a data section.
426 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
428 SectionKind::getReadOnly());
430 // Debug Info Sections.
432 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
433 SectionKind::getMetadata());
435 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
436 SectionKind::getMetadata());
438 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
439 SectionKind::getMetadata());
441 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
442 SectionKind::getMetadata());
443 DwarfPubNamesSection =
444 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
445 SectionKind::getMetadata());
446 DwarfPubTypesSection =
447 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
448 SectionKind::getMetadata());
449 DwarfGnuPubNamesSection =
450 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
451 SectionKind::getMetadata());
452 DwarfGnuPubTypesSection =
453 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
454 SectionKind::getMetadata());
456 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
457 ELF::SHF_MERGE | ELF::SHF_STRINGS,
458 SectionKind::getMergeable1ByteCString());
460 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
461 SectionKind::getMetadata());
462 DwarfARangesSection =
463 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
464 SectionKind::getMetadata());
466 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
467 SectionKind::getMetadata());
468 DwarfMacroInfoSection =
469 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
470 SectionKind::getMetadata());
472 // DWARF5 Experimental Debug Info
474 // Accelerator Tables
475 DwarfAccelNamesSection =
476 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
477 SectionKind::getMetadata());
478 DwarfAccelObjCSection =
479 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
480 SectionKind::getMetadata());
481 DwarfAccelNamespaceSection =
482 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
483 SectionKind::getMetadata());
484 DwarfAccelTypesSection =
485 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
486 SectionKind::getMetadata());
489 DwarfInfoDWOSection =
490 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
491 SectionKind::getMetadata());
492 DwarfAbbrevDWOSection =
493 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
494 SectionKind::getMetadata());
496 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
497 ELF::SHF_MERGE | ELF::SHF_STRINGS,
498 SectionKind::getMergeable1ByteCString());
499 DwarfLineDWOSection =
500 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
501 SectionKind::getMetadata());
503 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
504 SectionKind::getMetadata());
505 DwarfStrOffDWOSection =
506 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
507 SectionKind::getMetadata());
509 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
510 SectionKind::getMetadata());
514 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
517 Ctx->getCOFFSection(".bss",
518 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
519 COFF::IMAGE_SCN_MEM_READ |
520 COFF::IMAGE_SCN_MEM_WRITE,
521 SectionKind::getBSS());
523 Ctx->getCOFFSection(".text",
524 COFF::IMAGE_SCN_CNT_CODE |
525 COFF::IMAGE_SCN_MEM_EXECUTE |
526 COFF::IMAGE_SCN_MEM_READ,
527 SectionKind::getText());
529 Ctx->getCOFFSection(".data",
530 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
531 COFF::IMAGE_SCN_MEM_READ |
532 COFF::IMAGE_SCN_MEM_WRITE,
533 SectionKind::getDataRel());
535 Ctx->getCOFFSection(".rdata",
536 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
537 COFF::IMAGE_SCN_MEM_READ,
538 SectionKind::getReadOnly());
539 if (T.getOS() == Triple::Win32) {
541 Ctx->getCOFFSection(".CRT$XCU",
542 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
543 COFF::IMAGE_SCN_MEM_READ,
544 SectionKind::getReadOnly());
547 Ctx->getCOFFSection(".ctors",
548 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
549 COFF::IMAGE_SCN_MEM_READ |
550 COFF::IMAGE_SCN_MEM_WRITE,
551 SectionKind::getDataRel());
555 if (T.getOS() == Triple::Win32) {
557 Ctx->getCOFFSection(".CRT$XTX",
558 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
559 COFF::IMAGE_SCN_MEM_READ,
560 SectionKind::getReadOnly());
563 Ctx->getCOFFSection(".dtors",
564 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
565 COFF::IMAGE_SCN_MEM_READ |
566 COFF::IMAGE_SCN_MEM_WRITE,
567 SectionKind::getDataRel());
570 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
571 // though it contains relocatable pointers. In PIC mode, this is probably a
572 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
573 // adjusted or this should be a data section.
575 Ctx->getCOFFSection(".gcc_except_table",
576 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
577 COFF::IMAGE_SCN_MEM_READ,
578 SectionKind::getReadOnly());
582 Ctx->getCOFFSection(".debug_abbrev",
583 COFF::IMAGE_SCN_MEM_DISCARDABLE |
584 COFF::IMAGE_SCN_MEM_READ,
585 SectionKind::getMetadata());
587 Ctx->getCOFFSection(".debug_info",
588 COFF::IMAGE_SCN_MEM_DISCARDABLE |
589 COFF::IMAGE_SCN_MEM_READ,
590 SectionKind::getMetadata());
592 Ctx->getCOFFSection(".debug_line",
593 COFF::IMAGE_SCN_MEM_DISCARDABLE |
594 COFF::IMAGE_SCN_MEM_READ,
595 SectionKind::getMetadata());
597 Ctx->getCOFFSection(".debug_frame",
598 COFF::IMAGE_SCN_MEM_DISCARDABLE |
599 COFF::IMAGE_SCN_MEM_READ,
600 SectionKind::getMetadata());
601 DwarfPubNamesSection =
602 Ctx->getCOFFSection(".debug_pubnames",
603 COFF::IMAGE_SCN_MEM_DISCARDABLE |
604 COFF::IMAGE_SCN_MEM_READ,
605 SectionKind::getMetadata());
606 DwarfPubTypesSection =
607 Ctx->getCOFFSection(".debug_pubtypes",
608 COFF::IMAGE_SCN_MEM_DISCARDABLE |
609 COFF::IMAGE_SCN_MEM_READ,
610 SectionKind::getMetadata());
611 DwarfGnuPubNamesSection =
612 Ctx->getCOFFSection(".debug_gnu_pubnames",
613 COFF::IMAGE_SCN_MEM_DISCARDABLE |
614 COFF::IMAGE_SCN_MEM_READ,
615 SectionKind::getMetadata());
616 DwarfGnuPubTypesSection =
617 Ctx->getCOFFSection(".debug_gnu_pubtypes",
618 COFF::IMAGE_SCN_MEM_DISCARDABLE |
619 COFF::IMAGE_SCN_MEM_READ,
620 SectionKind::getMetadata());
622 Ctx->getCOFFSection(".debug_str",
623 COFF::IMAGE_SCN_MEM_DISCARDABLE |
624 COFF::IMAGE_SCN_MEM_READ,
625 SectionKind::getMetadata());
627 Ctx->getCOFFSection(".debug_loc",
628 COFF::IMAGE_SCN_MEM_DISCARDABLE |
629 COFF::IMAGE_SCN_MEM_READ,
630 SectionKind::getMetadata());
631 DwarfARangesSection =
632 Ctx->getCOFFSection(".debug_aranges",
633 COFF::IMAGE_SCN_MEM_DISCARDABLE |
634 COFF::IMAGE_SCN_MEM_READ,
635 SectionKind::getMetadata());
637 Ctx->getCOFFSection(".debug_ranges",
638 COFF::IMAGE_SCN_MEM_DISCARDABLE |
639 COFF::IMAGE_SCN_MEM_READ,
640 SectionKind::getMetadata());
641 DwarfMacroInfoSection =
642 Ctx->getCOFFSection(".debug_macinfo",
643 COFF::IMAGE_SCN_MEM_DISCARDABLE |
644 COFF::IMAGE_SCN_MEM_READ,
645 SectionKind::getMetadata());
648 Ctx->getCOFFSection(".drectve",
649 COFF::IMAGE_SCN_LNK_INFO,
650 SectionKind::getMetadata());
653 Ctx->getCOFFSection(".pdata",
654 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
655 COFF::IMAGE_SCN_MEM_READ,
656 SectionKind::getDataRel());
659 Ctx->getCOFFSection(".xdata",
660 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
661 COFF::IMAGE_SCN_MEM_READ,
662 SectionKind::getDataRel());
664 Ctx->getCOFFSection(".tls$",
665 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
666 COFF::IMAGE_SCN_MEM_READ |
667 COFF::IMAGE_SCN_MEM_WRITE,
668 SectionKind::getDataRel());
671 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
679 CommDirectiveSupportsAlignment = true;
680 SupportsWeakOmittedEHFrame = true;
681 IsFunctionEHFrameSymbolPrivate = true;
683 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
684 TTypeEncoding = dwarf::DW_EH_PE_absptr;
686 CompactUnwindDwarfEHFrameOnly = 0;
688 EHFrameSection = 0; // Created on demand.
689 CompactUnwindSection = 0; // Used only by selected targets.
690 DwarfAccelNamesSection = 0; // Used only by selected targets.
691 DwarfAccelObjCSection = 0; // Used only by selected targets.
692 DwarfAccelNamespaceSection = 0; // Used only by selected targets.
693 DwarfAccelTypesSection = 0; // Used only by selected targets.
696 Triple::ArchType Arch = T.getArch();
697 // FIXME: Checking for Arch here to filter out bogus triples such as
698 // cellspu-apple-darwin. Perhaps we should fix in Triple?
699 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
700 Arch == Triple::arm || Arch == Triple::thumb ||
701 Arch == Triple::ppc || Arch == Triple::ppc64 ||
702 Arch == Triple::UnknownArch) &&
703 (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
705 InitMachOMCObjectFileInfo(T);
706 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
707 (T.getEnvironment() != Triple::ELF) &&
708 (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
709 T.getOS() == Triple::Win32)) {
711 InitCOFFMCObjectFileInfo(T);
714 InitELFMCObjectFileInfo(T);
718 void MCObjectFileInfo::InitEHFrameSection() {
721 Ctx->getMachOSection("__TEXT", "__eh_frame",
722 MCSectionMachO::S_COALESCED |
723 MCSectionMachO::S_ATTR_NO_TOC |
724 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
725 MCSectionMachO::S_ATTR_LIVE_SUPPORT,
726 SectionKind::getReadOnly());
727 else if (Env == IsELF)
729 Ctx->getELFSection(".eh_frame", EHSectionType,
731 SectionKind::getDataRel());
734 Ctx->getCOFFSection(".eh_frame",
735 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
736 COFF::IMAGE_SCN_MEM_READ |
737 COFF::IMAGE_SCN_MEM_WRITE,
738 SectionKind::getDataRel());