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/StringExtras.h"
12 #include "llvm/ADT/Triple.h"
13 #include "llvm/MC/MCContext.h"
14 #include "llvm/MC/MCSection.h"
15 #include "llvm/MC/MCSectionCOFF.h"
16 #include "llvm/MC/MCSectionELF.h"
17 #include "llvm/MC/MCSectionMachO.h"
20 void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
22 IsFunctionEHFrameSymbolPrivate = false;
23 SupportsWeakOmittedEHFrame = false;
25 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
26 | dwarf::DW_EH_PE_sdata4;
27 LSDAEncoding = FDEEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
28 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
29 dwarf::DW_EH_PE_sdata4;
31 // .comm doesn't support alignment before Leopard.
32 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
33 CommDirectiveSupportsAlignment = false;
36 = Ctx->getMachOSection("__TEXT", "__text",
37 MachO::S_ATTR_PURE_INSTRUCTIONS,
38 SectionKind::getText());
40 = Ctx->getMachOSection("__DATA", "__data", 0,
41 SectionKind::getDataRel());
43 // BSSSection might not be expected initialized on msvc.
46 TLSDataSection // .tdata
47 = Ctx->getMachOSection("__DATA", "__thread_data",
48 MachO::S_THREAD_LOCAL_REGULAR,
49 SectionKind::getDataRel());
50 TLSBSSSection // .tbss
51 = Ctx->getMachOSection("__DATA", "__thread_bss",
52 MachO::S_THREAD_LOCAL_ZEROFILL,
53 SectionKind::getThreadBSS());
55 // TODO: Verify datarel below.
57 = Ctx->getMachOSection("__DATA", "__thread_vars",
58 MachO::S_THREAD_LOCAL_VARIABLES,
59 SectionKind::getDataRel());
62 = Ctx->getMachOSection("__DATA", "__thread_init",
63 MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
64 SectionKind::getDataRel());
66 CStringSection // .cstring
67 = Ctx->getMachOSection("__TEXT", "__cstring",
68 MachO::S_CSTRING_LITERALS,
69 SectionKind::getMergeable1ByteCString());
71 = Ctx->getMachOSection("__TEXT","__ustring", 0,
72 SectionKind::getMergeable2ByteCString());
73 FourByteConstantSection // .literal4
74 = Ctx->getMachOSection("__TEXT", "__literal4",
75 MachO::S_4BYTE_LITERALS,
76 SectionKind::getMergeableConst4());
77 EightByteConstantSection // .literal8
78 = Ctx->getMachOSection("__TEXT", "__literal8",
79 MachO::S_8BYTE_LITERALS,
80 SectionKind::getMergeableConst8());
82 SixteenByteConstantSection // .literal16
83 = Ctx->getMachOSection("__TEXT", "__literal16",
84 MachO::S_16BYTE_LITERALS,
85 SectionKind::getMergeableConst16());
87 ReadOnlySection // .const
88 = Ctx->getMachOSection("__TEXT", "__const", 0,
89 SectionKind::getReadOnly());
92 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
94 MachO::S_ATTR_PURE_INSTRUCTIONS,
95 SectionKind::getText());
97 = Ctx->getMachOSection("__TEXT", "__const_coal",
99 SectionKind::getReadOnly());
100 ConstDataSection // .const_data
101 = Ctx->getMachOSection("__DATA", "__const", 0,
102 SectionKind::getReadOnlyWithRel());
104 = Ctx->getMachOSection("__DATA","__datacoal_nt",
106 SectionKind::getDataRel());
108 = Ctx->getMachOSection("__DATA","__common",
110 SectionKind::getBSS());
112 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
113 SectionKind::getBSS());
116 LazySymbolPointerSection
117 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
118 MachO::S_LAZY_SYMBOL_POINTERS,
119 SectionKind::getMetadata());
120 NonLazySymbolPointerSection
121 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
122 MachO::S_NON_LAZY_SYMBOL_POINTERS,
123 SectionKind::getMetadata());
125 if (RelocM == Reloc::Static) {
127 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
128 SectionKind::getDataRel());
130 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
131 SectionKind::getDataRel());
134 = Ctx->getMachOSection("__DATA", "__mod_init_func",
135 MachO::S_MOD_INIT_FUNC_POINTERS,
136 SectionKind::getDataRel());
138 = Ctx->getMachOSection("__DATA", "__mod_term_func",
139 MachO::S_MOD_TERM_FUNC_POINTERS,
140 SectionKind::getDataRel());
143 // Exception Handling.
144 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
145 SectionKind::getReadOnlyWithRel());
147 COFFDebugSymbolsSection = 0;
149 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) {
150 CompactUnwindSection =
151 Ctx->getMachOSection("__LD", "__compact_unwind",
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",
163 SectionKind::getMetadata());
164 DwarfAccelObjCSection =
165 Ctx->getMachOSection("__DWARF", "__apple_objc",
167 SectionKind::getMetadata());
168 // 16 character section limit...
169 DwarfAccelNamespaceSection =
170 Ctx->getMachOSection("__DWARF", "__apple_namespac",
172 SectionKind::getMetadata());
173 DwarfAccelTypesSection =
174 Ctx->getMachOSection("__DWARF", "__apple_types",
176 SectionKind::getMetadata());
179 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
181 SectionKind::getMetadata());
183 Ctx->getMachOSection("__DWARF", "__debug_info",
185 SectionKind::getMetadata());
187 Ctx->getMachOSection("__DWARF", "__debug_line",
189 SectionKind::getMetadata());
191 Ctx->getMachOSection("__DWARF", "__debug_frame",
193 SectionKind::getMetadata());
194 DwarfPubNamesSection =
195 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
197 SectionKind::getMetadata());
198 DwarfPubTypesSection =
199 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
201 SectionKind::getMetadata());
202 DwarfGnuPubNamesSection =
203 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
205 SectionKind::getMetadata());
206 DwarfGnuPubTypesSection =
207 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
209 SectionKind::getMetadata());
211 Ctx->getMachOSection("__DWARF", "__debug_str",
213 SectionKind::getMetadata());
215 Ctx->getMachOSection("__DWARF", "__debug_loc",
217 SectionKind::getMetadata());
218 DwarfARangesSection =
219 Ctx->getMachOSection("__DWARF", "__debug_aranges",
221 SectionKind::getMetadata());
223 Ctx->getMachOSection("__DWARF", "__debug_ranges",
225 SectionKind::getMetadata());
226 DwarfMacroInfoSection =
227 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
229 SectionKind::getMetadata());
230 DwarfDebugInlineSection =
231 Ctx->getMachOSection("__DWARF", "__debug_inlined",
233 SectionKind::getMetadata());
235 Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
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 T.getArch() == Triple::aarch64_be ) {
288 // The small model guarantees static code/data size < 4GB, but not where it
289 // will be in memory. Most of these could end up >2GB away so even a signed
290 // pc-relative 32-bit address is insufficient, theoretically.
291 if (RelocM == Reloc::PIC_) {
292 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
293 dwarf::DW_EH_PE_sdata8;
294 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
295 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
296 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
297 dwarf::DW_EH_PE_sdata8;
299 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
300 LSDAEncoding = dwarf::DW_EH_PE_absptr;
301 FDEEncoding = dwarf::DW_EH_PE_udata4;
302 TTypeEncoding = dwarf::DW_EH_PE_absptr;
304 } else if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le) {
305 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
306 dwarf::DW_EH_PE_udata8;
307 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
308 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
309 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
310 dwarf::DW_EH_PE_udata8;
311 } else if (T.getArch() == Triple::sparc) {
312 if (RelocM == Reloc::PIC_) {
313 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
314 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
315 dwarf::DW_EH_PE_sdata4;
316 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
317 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
318 dwarf::DW_EH_PE_sdata4;
320 LSDAEncoding = dwarf::DW_EH_PE_absptr;
321 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
322 FDEEncoding = dwarf::DW_EH_PE_udata4;
323 TTypeEncoding = dwarf::DW_EH_PE_absptr;
325 } else if (T.getArch() == Triple::sparcv9) {
326 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
327 if (RelocM == Reloc::PIC_) {
328 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
329 dwarf::DW_EH_PE_sdata4;
330 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
331 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
332 dwarf::DW_EH_PE_sdata4;
334 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
335 FDEEncoding = dwarf::DW_EH_PE_udata4;
336 TTypeEncoding = dwarf::DW_EH_PE_absptr;
338 } else if (T.getArch() == Triple::systemz) {
339 // All currently-defined code models guarantee that 4-byte PC-relative
340 // values will be in range.
341 if (RelocM == Reloc::PIC_) {
342 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
343 dwarf::DW_EH_PE_sdata4;
344 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
345 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
346 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
347 dwarf::DW_EH_PE_sdata4;
349 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
350 LSDAEncoding = dwarf::DW_EH_PE_absptr;
351 FDEEncoding = dwarf::DW_EH_PE_absptr;
352 TTypeEncoding = dwarf::DW_EH_PE_absptr;
356 // Solaris requires different flags for .eh_frame to seemingly every other
358 EHSectionType = ELF::SHT_PROGBITS;
359 EHSectionFlags = ELF::SHF_ALLOC;
360 if (T.getOS() == Triple::Solaris) {
361 if (T.getArch() == Triple::x86_64)
362 EHSectionType = ELF::SHT_X86_64_UNWIND;
364 EHSectionFlags |= ELF::SHF_WRITE;
370 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
371 ELF::SHF_WRITE | ELF::SHF_ALLOC,
372 SectionKind::getBSS());
375 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
378 SectionKind::getText());
381 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
382 ELF::SHF_WRITE |ELF::SHF_ALLOC,
383 SectionKind::getDataRel());
386 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
388 SectionKind::getReadOnly());
391 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
392 ELF::SHF_ALLOC | ELF::SHF_TLS |
394 SectionKind::getThreadData());
397 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
398 ELF::SHF_ALLOC | ELF::SHF_TLS |
400 SectionKind::getThreadBSS());
403 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
404 ELF::SHF_ALLOC |ELF::SHF_WRITE,
405 SectionKind::getDataRel());
407 DataRelLocalSection =
408 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
409 ELF::SHF_ALLOC |ELF::SHF_WRITE,
410 SectionKind::getDataRelLocal());
413 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
414 ELF::SHF_ALLOC |ELF::SHF_WRITE,
415 SectionKind::getReadOnlyWithRel());
417 DataRelROLocalSection =
418 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
419 ELF::SHF_ALLOC |ELF::SHF_WRITE,
420 SectionKind::getReadOnlyWithRelLocal());
422 MergeableConst4Section =
423 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
424 ELF::SHF_ALLOC |ELF::SHF_MERGE,
425 SectionKind::getMergeableConst4());
427 MergeableConst8Section =
428 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
429 ELF::SHF_ALLOC |ELF::SHF_MERGE,
430 SectionKind::getMergeableConst8());
432 MergeableConst16Section =
433 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
434 ELF::SHF_ALLOC |ELF::SHF_MERGE,
435 SectionKind::getMergeableConst16());
438 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
439 ELF::SHF_ALLOC |ELF::SHF_WRITE,
440 SectionKind::getDataRel());
443 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
444 ELF::SHF_ALLOC |ELF::SHF_WRITE,
445 SectionKind::getDataRel());
447 // Exception Handling Sections.
449 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
450 // it contains relocatable pointers. In PIC mode, this is probably a big
451 // runtime hit for C++ apps. Either the contents of the LSDA need to be
452 // adjusted or this should be a data section.
454 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
456 SectionKind::getReadOnly());
458 COFFDebugSymbolsSection = 0;
460 // Debug Info Sections.
462 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
463 SectionKind::getMetadata());
465 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
466 SectionKind::getMetadata());
468 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
469 SectionKind::getMetadata());
471 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
472 SectionKind::getMetadata());
473 DwarfPubNamesSection =
474 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
475 SectionKind::getMetadata());
476 DwarfPubTypesSection =
477 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
478 SectionKind::getMetadata());
479 DwarfGnuPubNamesSection =
480 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
481 SectionKind::getMetadata());
482 DwarfGnuPubTypesSection =
483 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
484 SectionKind::getMetadata());
486 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
487 ELF::SHF_MERGE | ELF::SHF_STRINGS,
488 SectionKind::getMergeable1ByteCString());
490 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
491 SectionKind::getMetadata());
492 DwarfARangesSection =
493 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
494 SectionKind::getMetadata());
496 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
497 SectionKind::getMetadata());
498 DwarfMacroInfoSection =
499 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
500 SectionKind::getMetadata());
502 // DWARF5 Experimental Debug Info
504 // Accelerator Tables
505 DwarfAccelNamesSection =
506 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
507 SectionKind::getMetadata());
508 DwarfAccelObjCSection =
509 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
510 SectionKind::getMetadata());
511 DwarfAccelNamespaceSection =
512 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
513 SectionKind::getMetadata());
514 DwarfAccelTypesSection =
515 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
516 SectionKind::getMetadata());
519 DwarfInfoDWOSection =
520 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
521 SectionKind::getMetadata());
522 DwarfAbbrevDWOSection =
523 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
524 SectionKind::getMetadata());
526 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
527 ELF::SHF_MERGE | ELF::SHF_STRINGS,
528 SectionKind::getMergeable1ByteCString());
529 DwarfLineDWOSection =
530 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
531 SectionKind::getMetadata());
533 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
534 SectionKind::getMetadata());
535 DwarfStrOffDWOSection =
536 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
537 SectionKind::getMetadata());
539 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
540 SectionKind::getMetadata());
544 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
547 Ctx->getCOFFSection(".bss",
548 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
549 COFF::IMAGE_SCN_MEM_READ |
550 COFF::IMAGE_SCN_MEM_WRITE,
551 SectionKind::getBSS());
553 Ctx->getCOFFSection(".text",
554 COFF::IMAGE_SCN_CNT_CODE |
555 COFF::IMAGE_SCN_MEM_EXECUTE |
556 COFF::IMAGE_SCN_MEM_READ,
557 SectionKind::getText());
559 Ctx->getCOFFSection(".data",
560 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
561 COFF::IMAGE_SCN_MEM_READ |
562 COFF::IMAGE_SCN_MEM_WRITE,
563 SectionKind::getDataRel());
565 Ctx->getCOFFSection(".rdata",
566 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
567 COFF::IMAGE_SCN_MEM_READ,
568 SectionKind::getReadOnly());
569 if (T.isKnownWindowsMSVCEnvironment()) {
571 Ctx->getCOFFSection(".CRT$XCU",
572 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
573 COFF::IMAGE_SCN_MEM_READ,
574 SectionKind::getReadOnly());
577 Ctx->getCOFFSection(".ctors",
578 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
579 COFF::IMAGE_SCN_MEM_READ |
580 COFF::IMAGE_SCN_MEM_WRITE,
581 SectionKind::getDataRel());
585 if (T.isKnownWindowsMSVCEnvironment()) {
587 Ctx->getCOFFSection(".CRT$XTX",
588 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
589 COFF::IMAGE_SCN_MEM_READ,
590 SectionKind::getReadOnly());
593 Ctx->getCOFFSection(".dtors",
594 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
595 COFF::IMAGE_SCN_MEM_READ |
596 COFF::IMAGE_SCN_MEM_WRITE,
597 SectionKind::getDataRel());
600 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
601 // though it contains relocatable pointers. In PIC mode, this is probably a
602 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
603 // adjusted or this should be a data section.
605 Ctx->getCOFFSection(".gcc_except_table",
606 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
607 COFF::IMAGE_SCN_MEM_READ,
608 SectionKind::getReadOnly());
611 COFFDebugSymbolsSection =
612 Ctx->getCOFFSection(".debug$S",
613 COFF::IMAGE_SCN_MEM_DISCARDABLE |
614 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
615 COFF::IMAGE_SCN_MEM_READ,
616 SectionKind::getMetadata());
619 Ctx->getCOFFSection(".debug_abbrev",
620 COFF::IMAGE_SCN_MEM_DISCARDABLE |
621 COFF::IMAGE_SCN_MEM_READ,
622 SectionKind::getMetadata());
624 Ctx->getCOFFSection(".debug_info",
625 COFF::IMAGE_SCN_MEM_DISCARDABLE |
626 COFF::IMAGE_SCN_MEM_READ,
627 SectionKind::getMetadata());
629 Ctx->getCOFFSection(".debug_line",
630 COFF::IMAGE_SCN_MEM_DISCARDABLE |
631 COFF::IMAGE_SCN_MEM_READ,
632 SectionKind::getMetadata());
634 Ctx->getCOFFSection(".debug_frame",
635 COFF::IMAGE_SCN_MEM_DISCARDABLE |
636 COFF::IMAGE_SCN_MEM_READ,
637 SectionKind::getMetadata());
638 DwarfPubNamesSection =
639 Ctx->getCOFFSection(".debug_pubnames",
640 COFF::IMAGE_SCN_MEM_DISCARDABLE |
641 COFF::IMAGE_SCN_MEM_READ,
642 SectionKind::getMetadata());
643 DwarfPubTypesSection =
644 Ctx->getCOFFSection(".debug_pubtypes",
645 COFF::IMAGE_SCN_MEM_DISCARDABLE |
646 COFF::IMAGE_SCN_MEM_READ,
647 SectionKind::getMetadata());
648 DwarfGnuPubNamesSection =
649 Ctx->getCOFFSection(".debug_gnu_pubnames",
650 COFF::IMAGE_SCN_MEM_DISCARDABLE |
651 COFF::IMAGE_SCN_MEM_READ,
652 SectionKind::getMetadata());
653 DwarfGnuPubTypesSection =
654 Ctx->getCOFFSection(".debug_gnu_pubtypes",
655 COFF::IMAGE_SCN_MEM_DISCARDABLE |
656 COFF::IMAGE_SCN_MEM_READ,
657 SectionKind::getMetadata());
659 Ctx->getCOFFSection(".debug_str",
660 COFF::IMAGE_SCN_MEM_DISCARDABLE |
661 COFF::IMAGE_SCN_MEM_READ,
662 SectionKind::getMetadata());
664 Ctx->getCOFFSection(".debug_loc",
665 COFF::IMAGE_SCN_MEM_DISCARDABLE |
666 COFF::IMAGE_SCN_MEM_READ,
667 SectionKind::getMetadata());
668 DwarfARangesSection =
669 Ctx->getCOFFSection(".debug_aranges",
670 COFF::IMAGE_SCN_MEM_DISCARDABLE |
671 COFF::IMAGE_SCN_MEM_READ,
672 SectionKind::getMetadata());
674 Ctx->getCOFFSection(".debug_ranges",
675 COFF::IMAGE_SCN_MEM_DISCARDABLE |
676 COFF::IMAGE_SCN_MEM_READ,
677 SectionKind::getMetadata());
678 DwarfMacroInfoSection =
679 Ctx->getCOFFSection(".debug_macinfo",
680 COFF::IMAGE_SCN_MEM_DISCARDABLE |
681 COFF::IMAGE_SCN_MEM_READ,
682 SectionKind::getMetadata());
683 DwarfInfoDWOSection =
684 Ctx->getCOFFSection(".debug_info.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
685 COFF::IMAGE_SCN_MEM_READ,
686 SectionKind::getMetadata());
687 DwarfAbbrevDWOSection =
688 Ctx->getCOFFSection(".debug_abbrev.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
689 COFF::IMAGE_SCN_MEM_READ,
690 SectionKind::getMetadata());
692 Ctx->getCOFFSection(".debug_str.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
693 COFF::IMAGE_SCN_MEM_READ,
694 SectionKind::getMetadata());
695 DwarfLineDWOSection =
696 Ctx->getCOFFSection(".debug_line.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
697 COFF::IMAGE_SCN_MEM_READ,
698 SectionKind::getMetadata());
700 Ctx->getCOFFSection(".debug_loc.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
701 COFF::IMAGE_SCN_MEM_READ,
702 SectionKind::getMetadata());
703 DwarfStrOffDWOSection =
704 Ctx->getCOFFSection(".debug_str_offsets.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
705 COFF::IMAGE_SCN_MEM_READ,
706 SectionKind::getMetadata());
707 DwarfAddrSection = Ctx->getCOFFSection(
708 ".debug_addr", COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_MEM_READ,
709 SectionKind::getMetadata());
712 Ctx->getCOFFSection(".drectve",
713 COFF::IMAGE_SCN_LNK_INFO,
714 SectionKind::getMetadata());
717 Ctx->getCOFFSection(".pdata",
718 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
719 COFF::IMAGE_SCN_MEM_READ,
720 SectionKind::getDataRel());
723 Ctx->getCOFFSection(".xdata",
724 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
725 COFF::IMAGE_SCN_MEM_READ,
726 SectionKind::getDataRel());
728 Ctx->getCOFFSection(".tls$",
729 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
730 COFF::IMAGE_SCN_MEM_READ |
731 COFF::IMAGE_SCN_MEM_WRITE,
732 SectionKind::getDataRel());
735 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
743 CommDirectiveSupportsAlignment = true;
744 SupportsWeakOmittedEHFrame = true;
745 IsFunctionEHFrameSymbolPrivate = true;
747 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
748 TTypeEncoding = dwarf::DW_EH_PE_absptr;
750 CompactUnwindDwarfEHFrameOnly = 0;
752 EHFrameSection = 0; // Created on demand.
753 CompactUnwindSection = 0; // Used only by selected targets.
754 DwarfAccelNamesSection = 0; // Used only by selected targets.
755 DwarfAccelObjCSection = 0; // Used only by selected targets.
756 DwarfAccelNamespaceSection = 0; // Used only by selected targets.
757 DwarfAccelTypesSection = 0; // Used only by selected targets.
760 Triple::ArchType Arch = T.getArch();
761 // FIXME: Checking for Arch here to filter out bogus triples such as
762 // cellspu-apple-darwin. Perhaps we should fix in Triple?
763 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
764 Arch == Triple::arm || Arch == Triple::thumb ||
765 Arch == Triple::ppc || Arch == Triple::ppc64 ||
766 Arch == Triple::UnknownArch) &&
767 (T.isOSDarwin() || T.isOSBinFormatMachO())) {
769 InitMachOMCObjectFileInfo(T);
770 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
771 T.getObjectFormat() != Triple::ELF && T.isOSWindows()) {
773 InitCOFFMCObjectFileInfo(T);
776 InitELFMCObjectFileInfo(T);
780 const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
781 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
782 SectionKind::getMetadata(), 0, utostr(Hash));
786 MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
787 return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS,
788 ELF::SHF_GROUP, SectionKind::getMetadata(), 0,
792 void MCObjectFileInfo::InitEHFrameSection() {
795 Ctx->getMachOSection("__TEXT", "__eh_frame",
797 MachO::S_ATTR_NO_TOC |
798 MachO::S_ATTR_STRIP_STATIC_SYMS |
799 MachO::S_ATTR_LIVE_SUPPORT,
800 SectionKind::getReadOnly());
801 else if (Env == IsELF)
803 Ctx->getELFSection(".eh_frame", EHSectionType,
805 SectionKind::getDataRel());
808 Ctx->getCOFFSection(".eh_frame",
809 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
810 COFF::IMAGE_SCN_MEM_READ |
811 COFF::IMAGE_SCN_MEM_WRITE,
812 SectionKind::getDataRel());