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/MCAsmInfo.h"
14 #include "llvm/MC/MCContext.h"
15 #include "llvm/MC/MCSection.h"
16 #include "llvm/MC/MCSectionCOFF.h"
17 #include "llvm/MC/MCSectionELF.h"
18 #include "llvm/MC/MCSectionMachO.h"
21 static bool useCompactUnwind(const Triple &T) {
26 // aarch64 always has it.
27 if (T.getArch() == Triple::arm64 || T.getArch() == Triple::aarch64)
30 // Use it on newer version of OS X.
31 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
34 // And the iOS simulator.
36 (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86))
42 void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
44 SupportsWeakOmittedEHFrame = false;
47 (T.getArch() == Triple::arm64 || T.getArch() == Triple::aarch64))
48 SupportsCompactUnwindWithoutEHFrame = true;
50 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
51 | dwarf::DW_EH_PE_sdata4;
52 LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
53 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
54 dwarf::DW_EH_PE_sdata4;
56 // .comm doesn't support alignment before Leopard.
57 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
58 CommDirectiveSupportsAlignment = false;
61 = Ctx->getMachOSection("__TEXT", "__text",
62 MachO::S_ATTR_PURE_INSTRUCTIONS,
63 SectionKind::getText());
65 = Ctx->getMachOSection("__DATA", "__data", 0,
66 SectionKind::getDataRel());
68 // BSSSection might not be expected initialized on msvc.
71 TLSDataSection // .tdata
72 = Ctx->getMachOSection("__DATA", "__thread_data",
73 MachO::S_THREAD_LOCAL_REGULAR,
74 SectionKind::getDataRel());
75 TLSBSSSection // .tbss
76 = Ctx->getMachOSection("__DATA", "__thread_bss",
77 MachO::S_THREAD_LOCAL_ZEROFILL,
78 SectionKind::getThreadBSS());
80 // TODO: Verify datarel below.
82 = Ctx->getMachOSection("__DATA", "__thread_vars",
83 MachO::S_THREAD_LOCAL_VARIABLES,
84 SectionKind::getDataRel());
87 = Ctx->getMachOSection("__DATA", "__thread_init",
88 MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
89 SectionKind::getDataRel());
91 CStringSection // .cstring
92 = Ctx->getMachOSection("__TEXT", "__cstring",
93 MachO::S_CSTRING_LITERALS,
94 SectionKind::getMergeable1ByteCString());
96 = Ctx->getMachOSection("__TEXT","__ustring", 0,
97 SectionKind::getMergeable2ByteCString());
98 FourByteConstantSection // .literal4
99 = Ctx->getMachOSection("__TEXT", "__literal4",
100 MachO::S_4BYTE_LITERALS,
101 SectionKind::getMergeableConst4());
102 EightByteConstantSection // .literal8
103 = Ctx->getMachOSection("__TEXT", "__literal8",
104 MachO::S_8BYTE_LITERALS,
105 SectionKind::getMergeableConst8());
107 SixteenByteConstantSection // .literal16
108 = Ctx->getMachOSection("__TEXT", "__literal16",
109 MachO::S_16BYTE_LITERALS,
110 SectionKind::getMergeableConst16());
112 ReadOnlySection // .const
113 = Ctx->getMachOSection("__TEXT", "__const", 0,
114 SectionKind::getReadOnly());
117 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
119 MachO::S_ATTR_PURE_INSTRUCTIONS,
120 SectionKind::getText());
122 = Ctx->getMachOSection("__TEXT", "__const_coal",
124 SectionKind::getReadOnly());
125 ConstDataSection // .const_data
126 = Ctx->getMachOSection("__DATA", "__const", 0,
127 SectionKind::getReadOnlyWithRel());
129 = Ctx->getMachOSection("__DATA","__datacoal_nt",
131 SectionKind::getDataRel());
133 = Ctx->getMachOSection("__DATA","__common",
135 SectionKind::getBSS());
137 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
138 SectionKind::getBSS());
141 LazySymbolPointerSection
142 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
143 MachO::S_LAZY_SYMBOL_POINTERS,
144 SectionKind::getMetadata());
145 NonLazySymbolPointerSection
146 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
147 MachO::S_NON_LAZY_SYMBOL_POINTERS,
148 SectionKind::getMetadata());
150 if (RelocM == Reloc::Static) {
152 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
153 SectionKind::getDataRel());
155 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
156 SectionKind::getDataRel());
159 = Ctx->getMachOSection("__DATA", "__mod_init_func",
160 MachO::S_MOD_INIT_FUNC_POINTERS,
161 SectionKind::getDataRel());
163 = Ctx->getMachOSection("__DATA", "__mod_term_func",
164 MachO::S_MOD_TERM_FUNC_POINTERS,
165 SectionKind::getDataRel());
168 // Exception Handling.
169 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
170 SectionKind::getReadOnlyWithRel());
172 COFFDebugSymbolsSection = nullptr;
174 if (useCompactUnwind(T)) {
175 CompactUnwindSection =
176 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
177 SectionKind::getReadOnly());
179 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
180 CompactUnwindDwarfEHFrameOnly = 0x04000000;
181 else if (T.getArch() == Triple::arm64 || T.getArch() == Triple::aarch64)
182 CompactUnwindDwarfEHFrameOnly = 0x03000000;
185 // Debug Information.
186 DwarfAccelNamesSection =
187 Ctx->getMachOSection("__DWARF", "__apple_names",
189 SectionKind::getMetadata());
190 DwarfAccelObjCSection =
191 Ctx->getMachOSection("__DWARF", "__apple_objc",
193 SectionKind::getMetadata());
194 // 16 character section limit...
195 DwarfAccelNamespaceSection =
196 Ctx->getMachOSection("__DWARF", "__apple_namespac",
198 SectionKind::getMetadata());
199 DwarfAccelTypesSection =
200 Ctx->getMachOSection("__DWARF", "__apple_types",
202 SectionKind::getMetadata());
205 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
207 SectionKind::getMetadata());
209 Ctx->getMachOSection("__DWARF", "__debug_info",
211 SectionKind::getMetadata());
213 Ctx->getMachOSection("__DWARF", "__debug_line",
215 SectionKind::getMetadata());
217 Ctx->getMachOSection("__DWARF", "__debug_frame",
219 SectionKind::getMetadata());
220 DwarfPubNamesSection =
221 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
223 SectionKind::getMetadata());
224 DwarfPubTypesSection =
225 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
227 SectionKind::getMetadata());
228 DwarfGnuPubNamesSection =
229 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
231 SectionKind::getMetadata());
232 DwarfGnuPubTypesSection =
233 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
235 SectionKind::getMetadata());
237 Ctx->getMachOSection("__DWARF", "__debug_str",
239 SectionKind::getMetadata());
241 Ctx->getMachOSection("__DWARF", "__debug_loc",
243 SectionKind::getMetadata());
244 DwarfARangesSection =
245 Ctx->getMachOSection("__DWARF", "__debug_aranges",
247 SectionKind::getMetadata());
249 Ctx->getMachOSection("__DWARF", "__debug_ranges",
251 SectionKind::getMetadata());
252 DwarfMacroInfoSection =
253 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
255 SectionKind::getMetadata());
256 DwarfDebugInlineSection =
257 Ctx->getMachOSection("__DWARF", "__debug_inlined",
259 SectionKind::getMetadata());
261 Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
262 SectionKind::getMetadata());
264 TLSExtraDataSection = TLSTLVSection;
267 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
268 switch (T.getArch()) {
271 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
274 case Triple::mips64el:
275 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
278 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
282 switch (T.getArch()) {
286 case Triple::thumbeb:
287 if (Ctx->getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
289 // Fallthrough if not using EHABI
292 PersonalityEncoding = (RelocM == Reloc::PIC_)
293 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
294 : dwarf::DW_EH_PE_absptr;
295 LSDAEncoding = (RelocM == Reloc::PIC_)
296 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
297 : dwarf::DW_EH_PE_absptr;
298 TTypeEncoding = (RelocM == Reloc::PIC_)
299 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
300 : dwarf::DW_EH_PE_absptr;
303 if (RelocM == Reloc::PIC_) {
304 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
305 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
306 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
307 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
308 (CMModel == CodeModel::Small
309 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
310 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
311 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
312 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
314 PersonalityEncoding =
315 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
316 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
317 LSDAEncoding = (CMModel == CodeModel::Small)
318 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
319 TTypeEncoding = (CMModel == CodeModel::Small)
320 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
323 case Triple::aarch64:
324 case Triple::aarch64_be:
326 case Triple::arm64_be:
327 // The small model guarantees static code/data size < 4GB, but not where it
328 // will be in memory. Most of these could end up >2GB away so even a signed
329 // pc-relative 32-bit address is insufficient, theoretically.
330 if (RelocM == Reloc::PIC_) {
331 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
332 dwarf::DW_EH_PE_sdata8;
333 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
334 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
335 dwarf::DW_EH_PE_sdata8;
337 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
338 LSDAEncoding = dwarf::DW_EH_PE_absptr;
339 TTypeEncoding = dwarf::DW_EH_PE_absptr;
345 case Triple::mips64el:
346 // MIPS uses indirect pointer to refer personality functions, so that the
347 // eh_frame section can be read-only. DW.ref.personality will be generated
349 PersonalityEncoding = dwarf::DW_EH_PE_indirect;
352 case Triple::ppc64le:
353 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
354 dwarf::DW_EH_PE_udata8;
355 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
356 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
357 dwarf::DW_EH_PE_udata8;
360 if (RelocM == Reloc::PIC_) {
361 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
362 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
363 dwarf::DW_EH_PE_sdata4;
364 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
365 dwarf::DW_EH_PE_sdata4;
367 LSDAEncoding = dwarf::DW_EH_PE_absptr;
368 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
369 TTypeEncoding = dwarf::DW_EH_PE_absptr;
372 case Triple::sparcv9:
373 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
374 if (RelocM == Reloc::PIC_) {
375 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
376 dwarf::DW_EH_PE_sdata4;
377 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
378 dwarf::DW_EH_PE_sdata4;
380 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
381 TTypeEncoding = dwarf::DW_EH_PE_absptr;
384 case Triple::systemz:
385 // All currently-defined code models guarantee that 4-byte PC-relative
386 // values will be in range.
387 if (RelocM == Reloc::PIC_) {
388 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
389 dwarf::DW_EH_PE_sdata4;
390 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
391 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
392 dwarf::DW_EH_PE_sdata4;
394 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
395 LSDAEncoding = dwarf::DW_EH_PE_absptr;
396 TTypeEncoding = dwarf::DW_EH_PE_absptr;
403 // Solaris requires different flags for .eh_frame to seemingly every other
405 EHSectionType = ELF::SHT_PROGBITS;
406 EHSectionFlags = ELF::SHF_ALLOC;
407 if (T.getOS() == Triple::Solaris) {
408 if (T.getArch() == Triple::x86_64)
409 EHSectionType = ELF::SHT_X86_64_UNWIND;
411 EHSectionFlags |= ELF::SHF_WRITE;
417 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
418 ELF::SHF_WRITE | ELF::SHF_ALLOC,
419 SectionKind::getBSS());
422 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
425 SectionKind::getText());
428 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
429 ELF::SHF_WRITE |ELF::SHF_ALLOC,
430 SectionKind::getDataRel());
433 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
435 SectionKind::getReadOnly());
438 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
439 ELF::SHF_ALLOC | ELF::SHF_TLS |
441 SectionKind::getThreadData());
444 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
445 ELF::SHF_ALLOC | ELF::SHF_TLS |
447 SectionKind::getThreadBSS());
450 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
451 ELF::SHF_ALLOC |ELF::SHF_WRITE,
452 SectionKind::getDataRel());
454 DataRelLocalSection =
455 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
456 ELF::SHF_ALLOC |ELF::SHF_WRITE,
457 SectionKind::getDataRelLocal());
460 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
461 ELF::SHF_ALLOC |ELF::SHF_WRITE,
462 SectionKind::getReadOnlyWithRel());
464 DataRelROLocalSection =
465 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
466 ELF::SHF_ALLOC |ELF::SHF_WRITE,
467 SectionKind::getReadOnlyWithRelLocal());
469 MergeableConst4Section =
470 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
471 ELF::SHF_ALLOC |ELF::SHF_MERGE,
472 SectionKind::getMergeableConst4());
474 MergeableConst8Section =
475 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
476 ELF::SHF_ALLOC |ELF::SHF_MERGE,
477 SectionKind::getMergeableConst8());
479 MergeableConst16Section =
480 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
481 ELF::SHF_ALLOC |ELF::SHF_MERGE,
482 SectionKind::getMergeableConst16());
485 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
486 ELF::SHF_ALLOC |ELF::SHF_WRITE,
487 SectionKind::getDataRel());
490 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
491 ELF::SHF_ALLOC |ELF::SHF_WRITE,
492 SectionKind::getDataRel());
494 // Exception Handling Sections.
496 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
497 // it contains relocatable pointers. In PIC mode, this is probably a big
498 // runtime hit for C++ apps. Either the contents of the LSDA need to be
499 // adjusted or this should be a data section.
501 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
503 SectionKind::getReadOnly());
505 COFFDebugSymbolsSection = nullptr;
507 // Debug Info Sections.
509 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
510 SectionKind::getMetadata());
512 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
513 SectionKind::getMetadata());
515 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
516 SectionKind::getMetadata());
518 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
519 SectionKind::getMetadata());
520 DwarfPubNamesSection =
521 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
522 SectionKind::getMetadata());
523 DwarfPubTypesSection =
524 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
525 SectionKind::getMetadata());
526 DwarfGnuPubNamesSection =
527 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
528 SectionKind::getMetadata());
529 DwarfGnuPubTypesSection =
530 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
531 SectionKind::getMetadata());
533 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
534 ELF::SHF_MERGE | ELF::SHF_STRINGS,
535 SectionKind::getMergeable1ByteCString());
537 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
538 SectionKind::getMetadata());
539 DwarfARangesSection =
540 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
541 SectionKind::getMetadata());
543 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
544 SectionKind::getMetadata());
545 DwarfMacroInfoSection =
546 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
547 SectionKind::getMetadata());
549 // DWARF5 Experimental Debug Info
551 // Accelerator Tables
552 DwarfAccelNamesSection =
553 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
554 SectionKind::getMetadata());
555 DwarfAccelObjCSection =
556 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
557 SectionKind::getMetadata());
558 DwarfAccelNamespaceSection =
559 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
560 SectionKind::getMetadata());
561 DwarfAccelTypesSection =
562 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
563 SectionKind::getMetadata());
566 DwarfInfoDWOSection =
567 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
568 SectionKind::getMetadata());
569 DwarfAbbrevDWOSection =
570 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
571 SectionKind::getMetadata());
573 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
574 ELF::SHF_MERGE | ELF::SHF_STRINGS,
575 SectionKind::getMergeable1ByteCString());
576 DwarfLineDWOSection =
577 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
578 SectionKind::getMetadata());
580 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
581 SectionKind::getMetadata());
582 DwarfStrOffDWOSection =
583 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
584 SectionKind::getMetadata());
586 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
587 SectionKind::getMetadata());
591 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
592 bool IsWoA = T.getArch() == Triple::arm || T.getArch() == Triple::thumb;
594 // The object file format cannot represent common symbols with explicit
596 CommDirectiveSupportsAlignment = false;
600 Ctx->getCOFFSection(".bss",
601 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
602 COFF::IMAGE_SCN_MEM_READ |
603 COFF::IMAGE_SCN_MEM_WRITE,
604 SectionKind::getBSS());
606 Ctx->getCOFFSection(".text",
607 (IsWoA ? COFF::IMAGE_SCN_MEM_16BIT
608 : (COFF::SectionCharacteristics)0) |
609 COFF::IMAGE_SCN_CNT_CODE |
610 COFF::IMAGE_SCN_MEM_EXECUTE |
611 COFF::IMAGE_SCN_MEM_READ,
612 SectionKind::getText());
614 Ctx->getCOFFSection(".data",
615 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
616 COFF::IMAGE_SCN_MEM_READ |
617 COFF::IMAGE_SCN_MEM_WRITE,
618 SectionKind::getDataRel());
620 Ctx->getCOFFSection(".rdata",
621 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
622 COFF::IMAGE_SCN_MEM_READ,
623 SectionKind::getReadOnly());
625 if (T.isKnownWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
627 Ctx->getCOFFSection(".CRT$XCU",
628 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
629 COFF::IMAGE_SCN_MEM_READ,
630 SectionKind::getReadOnly());
632 Ctx->getCOFFSection(".CRT$XTX",
633 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
634 COFF::IMAGE_SCN_MEM_READ,
635 SectionKind::getReadOnly());
638 Ctx->getCOFFSection(".ctors",
639 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
640 COFF::IMAGE_SCN_MEM_READ |
641 COFF::IMAGE_SCN_MEM_WRITE,
642 SectionKind::getDataRel());
644 Ctx->getCOFFSection(".dtors",
645 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
646 COFF::IMAGE_SCN_MEM_READ |
647 COFF::IMAGE_SCN_MEM_WRITE,
648 SectionKind::getDataRel());
651 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
652 // though it contains relocatable pointers. In PIC mode, this is probably a
653 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
654 // adjusted or this should be a data section.
655 assert(T.isOSWindows() && "Windows is the only supported COFF target");
656 if (T.getArch() == Triple::x86_64) {
657 // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
660 LSDASection = Ctx->getCOFFSection(".gcc_except_table",
661 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
662 COFF::IMAGE_SCN_MEM_READ,
663 SectionKind::getReadOnly());
667 COFFDebugSymbolsSection =
668 Ctx->getCOFFSection(".debug$S",
669 COFF::IMAGE_SCN_MEM_DISCARDABLE |
670 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
671 COFF::IMAGE_SCN_MEM_READ,
672 SectionKind::getMetadata());
675 Ctx->getCOFFSection(".debug_abbrev",
676 COFF::IMAGE_SCN_MEM_DISCARDABLE |
677 COFF::IMAGE_SCN_MEM_READ,
678 SectionKind::getMetadata());
680 Ctx->getCOFFSection(".debug_info",
681 COFF::IMAGE_SCN_MEM_DISCARDABLE |
682 COFF::IMAGE_SCN_MEM_READ,
683 SectionKind::getMetadata());
685 Ctx->getCOFFSection(".debug_line",
686 COFF::IMAGE_SCN_MEM_DISCARDABLE |
687 COFF::IMAGE_SCN_MEM_READ,
688 SectionKind::getMetadata());
690 Ctx->getCOFFSection(".debug_frame",
691 COFF::IMAGE_SCN_MEM_DISCARDABLE |
692 COFF::IMAGE_SCN_MEM_READ,
693 SectionKind::getMetadata());
694 DwarfPubNamesSection =
695 Ctx->getCOFFSection(".debug_pubnames",
696 COFF::IMAGE_SCN_MEM_DISCARDABLE |
697 COFF::IMAGE_SCN_MEM_READ,
698 SectionKind::getMetadata());
699 DwarfPubTypesSection =
700 Ctx->getCOFFSection(".debug_pubtypes",
701 COFF::IMAGE_SCN_MEM_DISCARDABLE |
702 COFF::IMAGE_SCN_MEM_READ,
703 SectionKind::getMetadata());
704 DwarfGnuPubNamesSection =
705 Ctx->getCOFFSection(".debug_gnu_pubnames",
706 COFF::IMAGE_SCN_MEM_DISCARDABLE |
707 COFF::IMAGE_SCN_MEM_READ,
708 SectionKind::getMetadata());
709 DwarfGnuPubTypesSection =
710 Ctx->getCOFFSection(".debug_gnu_pubtypes",
711 COFF::IMAGE_SCN_MEM_DISCARDABLE |
712 COFF::IMAGE_SCN_MEM_READ,
713 SectionKind::getMetadata());
715 Ctx->getCOFFSection(".debug_str",
716 COFF::IMAGE_SCN_MEM_DISCARDABLE |
717 COFF::IMAGE_SCN_MEM_READ,
718 SectionKind::getMetadata());
720 Ctx->getCOFFSection(".debug_loc",
721 COFF::IMAGE_SCN_MEM_DISCARDABLE |
722 COFF::IMAGE_SCN_MEM_READ,
723 SectionKind::getMetadata());
724 DwarfARangesSection =
725 Ctx->getCOFFSection(".debug_aranges",
726 COFF::IMAGE_SCN_MEM_DISCARDABLE |
727 COFF::IMAGE_SCN_MEM_READ,
728 SectionKind::getMetadata());
730 Ctx->getCOFFSection(".debug_ranges",
731 COFF::IMAGE_SCN_MEM_DISCARDABLE |
732 COFF::IMAGE_SCN_MEM_READ,
733 SectionKind::getMetadata());
734 DwarfMacroInfoSection =
735 Ctx->getCOFFSection(".debug_macinfo",
736 COFF::IMAGE_SCN_MEM_DISCARDABLE |
737 COFF::IMAGE_SCN_MEM_READ,
738 SectionKind::getMetadata());
739 DwarfInfoDWOSection =
740 Ctx->getCOFFSection(".debug_info.dwo",
741 COFF::IMAGE_SCN_MEM_DISCARDABLE |
742 COFF::IMAGE_SCN_MEM_READ,
743 SectionKind::getMetadata());
744 DwarfAbbrevDWOSection =
745 Ctx->getCOFFSection(".debug_abbrev.dwo",
746 COFF::IMAGE_SCN_MEM_DISCARDABLE |
747 COFF::IMAGE_SCN_MEM_READ,
748 SectionKind::getMetadata());
750 Ctx->getCOFFSection(".debug_str.dwo",
751 COFF::IMAGE_SCN_MEM_DISCARDABLE |
752 COFF::IMAGE_SCN_MEM_READ,
753 SectionKind::getMetadata());
754 DwarfLineDWOSection =
755 Ctx->getCOFFSection(".debug_line.dwo",
756 COFF::IMAGE_SCN_MEM_DISCARDABLE |
757 COFF::IMAGE_SCN_MEM_READ,
758 SectionKind::getMetadata());
760 Ctx->getCOFFSection(".debug_loc.dwo",
761 COFF::IMAGE_SCN_MEM_DISCARDABLE |
762 COFF::IMAGE_SCN_MEM_READ,
763 SectionKind::getMetadata());
764 DwarfStrOffDWOSection =
765 Ctx->getCOFFSection(".debug_str_offsets.dwo",
766 COFF::IMAGE_SCN_MEM_DISCARDABLE |
767 COFF::IMAGE_SCN_MEM_READ,
768 SectionKind::getMetadata());
771 Ctx->getCOFFSection(".debug_addr",
772 COFF::IMAGE_SCN_MEM_DISCARDABLE |
773 COFF::IMAGE_SCN_MEM_READ,
774 SectionKind::getMetadata());
777 Ctx->getCOFFSection(".drectve",
778 COFF::IMAGE_SCN_LNK_INFO |
779 COFF::IMAGE_SCN_LNK_REMOVE,
780 SectionKind::getMetadata());
783 Ctx->getCOFFSection(".pdata",
784 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
785 COFF::IMAGE_SCN_MEM_READ,
786 SectionKind::getDataRel());
789 Ctx->getCOFFSection(".xdata",
790 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
791 COFF::IMAGE_SCN_MEM_READ,
792 SectionKind::getDataRel());
795 Ctx->getCOFFSection(".tls$",
796 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
797 COFF::IMAGE_SCN_MEM_READ |
798 COFF::IMAGE_SCN_MEM_WRITE,
799 SectionKind::getDataRel());
802 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef T, Reloc::Model relocm,
810 CommDirectiveSupportsAlignment = true;
811 SupportsWeakOmittedEHFrame = true;
812 SupportsCompactUnwindWithoutEHFrame = false;
814 PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
815 dwarf::DW_EH_PE_absptr;
817 CompactUnwindDwarfEHFrameOnly = 0;
819 EHFrameSection = nullptr; // Created on demand.
820 CompactUnwindSection = nullptr; // Used only by selected targets.
821 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
822 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
823 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
824 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
828 Triple::ArchType Arch = TT.getArch();
829 // FIXME: Checking for Arch here to filter out bogus triples such as
830 // cellspu-apple-darwin. Perhaps we should fix in Triple?
831 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
832 Arch == Triple::arm || Arch == Triple::thumb ||
833 Arch == Triple::arm64 || Arch == Triple::aarch64 ||
834 Arch == Triple::ppc || Arch == Triple::ppc64 ||
835 Arch == Triple::UnknownArch) &&
836 (TT.isOSDarwin() || TT.isOSBinFormatMachO())) {
838 InitMachOMCObjectFileInfo(TT);
839 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
840 Arch == Triple::arm || Arch == Triple::thumb) &&
841 (TT.isOSWindows() && TT.getObjectFormat() == Triple::COFF)) {
843 InitCOFFMCObjectFileInfo(TT);
846 InitELFMCObjectFileInfo(TT);
850 const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
851 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
852 SectionKind::getMetadata(), 0, utostr(Hash));
856 MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
857 return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS,
858 ELF::SHF_GROUP, SectionKind::getMetadata(), 0,
862 void MCObjectFileInfo::InitEHFrameSection() {
865 Ctx->getMachOSection("__TEXT", "__eh_frame",
867 MachO::S_ATTR_NO_TOC |
868 MachO::S_ATTR_STRIP_STATIC_SYMS |
869 MachO::S_ATTR_LIVE_SUPPORT,
870 SectionKind::getReadOnly());
871 else if (Env == IsELF)
873 Ctx->getELFSection(".eh_frame", EHSectionType,
875 SectionKind::getDataRel());
878 Ctx->getCOFFSection(".eh_frame",
879 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
880 COFF::IMAGE_SCN_MEM_READ |
881 COFF::IMAGE_SCN_MEM_WRITE,
882 SectionKind::getDataRel());