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
291 PersonalityEncoding = (RelocM == Reloc::PIC_)
292 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
293 : dwarf::DW_EH_PE_absptr;
294 LSDAEncoding = (RelocM == Reloc::PIC_)
295 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
296 : dwarf::DW_EH_PE_absptr;
297 TTypeEncoding = (RelocM == Reloc::PIC_)
298 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
299 : dwarf::DW_EH_PE_absptr;
302 if (RelocM == Reloc::PIC_) {
303 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
304 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
305 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
306 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
307 (CMModel == CodeModel::Small
308 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
309 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
310 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
311 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
313 PersonalityEncoding =
314 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
315 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
316 LSDAEncoding = (CMModel == CodeModel::Small)
317 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
318 TTypeEncoding = (CMModel == CodeModel::Small)
319 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
322 case Triple::aarch64:
323 case Triple::aarch64_be:
325 case Triple::arm64_be:
326 // The small model guarantees static code/data size < 4GB, but not where it
327 // will be in memory. Most of these could end up >2GB away so even a signed
328 // pc-relative 32-bit address is insufficient, theoretically.
329 if (RelocM == Reloc::PIC_) {
330 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
331 dwarf::DW_EH_PE_sdata8;
332 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
333 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
334 dwarf::DW_EH_PE_sdata8;
336 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
337 LSDAEncoding = dwarf::DW_EH_PE_absptr;
338 TTypeEncoding = dwarf::DW_EH_PE_absptr;
343 // MIPS uses indirect pointer to refer personality functions, so that the
344 // eh_frame section can be read-only. DW.ref.personality will be generated
346 PersonalityEncoding = dwarf::DW_EH_PE_indirect;
349 case Triple::ppc64le:
350 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
351 dwarf::DW_EH_PE_udata8;
352 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
353 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
354 dwarf::DW_EH_PE_udata8;
357 if (RelocM == Reloc::PIC_) {
358 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
359 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
360 dwarf::DW_EH_PE_sdata4;
361 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
362 dwarf::DW_EH_PE_sdata4;
364 LSDAEncoding = dwarf::DW_EH_PE_absptr;
365 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
366 TTypeEncoding = dwarf::DW_EH_PE_absptr;
369 case Triple::sparcv9:
370 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
371 if (RelocM == Reloc::PIC_) {
372 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
373 dwarf::DW_EH_PE_sdata4;
374 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
375 dwarf::DW_EH_PE_sdata4;
377 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
378 TTypeEncoding = dwarf::DW_EH_PE_absptr;
381 case Triple::systemz:
382 // All currently-defined code models guarantee that 4-byte PC-relative
383 // values will be in range.
384 if (RelocM == Reloc::PIC_) {
385 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
386 dwarf::DW_EH_PE_sdata4;
387 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
388 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
389 dwarf::DW_EH_PE_sdata4;
391 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
392 LSDAEncoding = dwarf::DW_EH_PE_absptr;
393 TTypeEncoding = dwarf::DW_EH_PE_absptr;
400 // Solaris requires different flags for .eh_frame to seemingly every other
402 EHSectionType = ELF::SHT_PROGBITS;
403 EHSectionFlags = ELF::SHF_ALLOC;
404 if (T.getOS() == Triple::Solaris) {
405 if (T.getArch() == Triple::x86_64)
406 EHSectionType = ELF::SHT_X86_64_UNWIND;
408 EHSectionFlags |= ELF::SHF_WRITE;
414 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
415 ELF::SHF_WRITE | ELF::SHF_ALLOC,
416 SectionKind::getBSS());
419 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
422 SectionKind::getText());
425 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
426 ELF::SHF_WRITE |ELF::SHF_ALLOC,
427 SectionKind::getDataRel());
430 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
432 SectionKind::getReadOnly());
435 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
436 ELF::SHF_ALLOC | ELF::SHF_TLS |
438 SectionKind::getThreadData());
441 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
442 ELF::SHF_ALLOC | ELF::SHF_TLS |
444 SectionKind::getThreadBSS());
447 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
448 ELF::SHF_ALLOC |ELF::SHF_WRITE,
449 SectionKind::getDataRel());
451 DataRelLocalSection =
452 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
453 ELF::SHF_ALLOC |ELF::SHF_WRITE,
454 SectionKind::getDataRelLocal());
457 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
458 ELF::SHF_ALLOC |ELF::SHF_WRITE,
459 SectionKind::getReadOnlyWithRel());
461 DataRelROLocalSection =
462 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
463 ELF::SHF_ALLOC |ELF::SHF_WRITE,
464 SectionKind::getReadOnlyWithRelLocal());
466 MergeableConst4Section =
467 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
468 ELF::SHF_ALLOC |ELF::SHF_MERGE,
469 SectionKind::getMergeableConst4());
471 MergeableConst8Section =
472 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
473 ELF::SHF_ALLOC |ELF::SHF_MERGE,
474 SectionKind::getMergeableConst8());
476 MergeableConst16Section =
477 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
478 ELF::SHF_ALLOC |ELF::SHF_MERGE,
479 SectionKind::getMergeableConst16());
482 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
483 ELF::SHF_ALLOC |ELF::SHF_WRITE,
484 SectionKind::getDataRel());
487 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
488 ELF::SHF_ALLOC |ELF::SHF_WRITE,
489 SectionKind::getDataRel());
491 // Exception Handling Sections.
493 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
494 // it contains relocatable pointers. In PIC mode, this is probably a big
495 // runtime hit for C++ apps. Either the contents of the LSDA need to be
496 // adjusted or this should be a data section.
498 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
500 SectionKind::getReadOnly());
502 COFFDebugSymbolsSection = nullptr;
504 // Debug Info Sections.
506 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
507 SectionKind::getMetadata());
509 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
510 SectionKind::getMetadata());
512 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
513 SectionKind::getMetadata());
515 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
516 SectionKind::getMetadata());
517 DwarfPubNamesSection =
518 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
519 SectionKind::getMetadata());
520 DwarfPubTypesSection =
521 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
522 SectionKind::getMetadata());
523 DwarfGnuPubNamesSection =
524 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
525 SectionKind::getMetadata());
526 DwarfGnuPubTypesSection =
527 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
528 SectionKind::getMetadata());
530 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
531 ELF::SHF_MERGE | ELF::SHF_STRINGS,
532 SectionKind::getMergeable1ByteCString());
534 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
535 SectionKind::getMetadata());
536 DwarfARangesSection =
537 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
538 SectionKind::getMetadata());
540 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
541 SectionKind::getMetadata());
542 DwarfMacroInfoSection =
543 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
544 SectionKind::getMetadata());
546 // DWARF5 Experimental Debug Info
548 // Accelerator Tables
549 DwarfAccelNamesSection =
550 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
551 SectionKind::getMetadata());
552 DwarfAccelObjCSection =
553 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
554 SectionKind::getMetadata());
555 DwarfAccelNamespaceSection =
556 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
557 SectionKind::getMetadata());
558 DwarfAccelTypesSection =
559 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
560 SectionKind::getMetadata());
563 DwarfInfoDWOSection =
564 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
565 SectionKind::getMetadata());
566 DwarfAbbrevDWOSection =
567 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
568 SectionKind::getMetadata());
570 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
571 ELF::SHF_MERGE | ELF::SHF_STRINGS,
572 SectionKind::getMergeable1ByteCString());
573 DwarfLineDWOSection =
574 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
575 SectionKind::getMetadata());
577 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
578 SectionKind::getMetadata());
579 DwarfStrOffDWOSection =
580 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
581 SectionKind::getMetadata());
583 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
584 SectionKind::getMetadata());
588 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
589 bool IsWoA = T.getArch() == Triple::arm || T.getArch() == Triple::thumb;
591 // The object file format cannot represent common symbols with explicit
593 CommDirectiveSupportsAlignment = false;
597 Ctx->getCOFFSection(".bss",
598 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
599 COFF::IMAGE_SCN_MEM_READ |
600 COFF::IMAGE_SCN_MEM_WRITE,
601 SectionKind::getBSS());
603 Ctx->getCOFFSection(".text",
604 (IsWoA ? COFF::IMAGE_SCN_MEM_16BIT
605 : (COFF::SectionCharacteristics)0) |
606 COFF::IMAGE_SCN_CNT_CODE |
607 COFF::IMAGE_SCN_MEM_EXECUTE |
608 COFF::IMAGE_SCN_MEM_READ,
609 SectionKind::getText());
611 Ctx->getCOFFSection(".data",
612 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
613 COFF::IMAGE_SCN_MEM_READ |
614 COFF::IMAGE_SCN_MEM_WRITE,
615 SectionKind::getDataRel());
617 Ctx->getCOFFSection(".rdata",
618 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
619 COFF::IMAGE_SCN_MEM_READ,
620 SectionKind::getReadOnly());
622 if (T.isKnownWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
624 Ctx->getCOFFSection(".CRT$XCU",
625 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
626 COFF::IMAGE_SCN_MEM_READ,
627 SectionKind::getReadOnly());
629 Ctx->getCOFFSection(".CRT$XTX",
630 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
631 COFF::IMAGE_SCN_MEM_READ,
632 SectionKind::getReadOnly());
635 Ctx->getCOFFSection(".ctors",
636 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
637 COFF::IMAGE_SCN_MEM_READ |
638 COFF::IMAGE_SCN_MEM_WRITE,
639 SectionKind::getDataRel());
641 Ctx->getCOFFSection(".dtors",
642 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
643 COFF::IMAGE_SCN_MEM_READ |
644 COFF::IMAGE_SCN_MEM_WRITE,
645 SectionKind::getDataRel());
648 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
649 // though it contains relocatable pointers. In PIC mode, this is probably a
650 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
651 // adjusted or this should be a data section.
653 Ctx->getCOFFSection(".gcc_except_table",
654 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
655 COFF::IMAGE_SCN_MEM_READ,
656 SectionKind::getReadOnly());
659 COFFDebugSymbolsSection =
660 Ctx->getCOFFSection(".debug$S",
661 COFF::IMAGE_SCN_MEM_DISCARDABLE |
662 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
663 COFF::IMAGE_SCN_MEM_READ,
664 SectionKind::getMetadata());
667 Ctx->getCOFFSection(".debug_abbrev",
668 COFF::IMAGE_SCN_MEM_DISCARDABLE |
669 COFF::IMAGE_SCN_MEM_READ,
670 SectionKind::getMetadata());
672 Ctx->getCOFFSection(".debug_info",
673 COFF::IMAGE_SCN_MEM_DISCARDABLE |
674 COFF::IMAGE_SCN_MEM_READ,
675 SectionKind::getMetadata());
677 Ctx->getCOFFSection(".debug_line",
678 COFF::IMAGE_SCN_MEM_DISCARDABLE |
679 COFF::IMAGE_SCN_MEM_READ,
680 SectionKind::getMetadata());
682 Ctx->getCOFFSection(".debug_frame",
683 COFF::IMAGE_SCN_MEM_DISCARDABLE |
684 COFF::IMAGE_SCN_MEM_READ,
685 SectionKind::getMetadata());
686 DwarfPubNamesSection =
687 Ctx->getCOFFSection(".debug_pubnames",
688 COFF::IMAGE_SCN_MEM_DISCARDABLE |
689 COFF::IMAGE_SCN_MEM_READ,
690 SectionKind::getMetadata());
691 DwarfPubTypesSection =
692 Ctx->getCOFFSection(".debug_pubtypes",
693 COFF::IMAGE_SCN_MEM_DISCARDABLE |
694 COFF::IMAGE_SCN_MEM_READ,
695 SectionKind::getMetadata());
696 DwarfGnuPubNamesSection =
697 Ctx->getCOFFSection(".debug_gnu_pubnames",
698 COFF::IMAGE_SCN_MEM_DISCARDABLE |
699 COFF::IMAGE_SCN_MEM_READ,
700 SectionKind::getMetadata());
701 DwarfGnuPubTypesSection =
702 Ctx->getCOFFSection(".debug_gnu_pubtypes",
703 COFF::IMAGE_SCN_MEM_DISCARDABLE |
704 COFF::IMAGE_SCN_MEM_READ,
705 SectionKind::getMetadata());
707 Ctx->getCOFFSection(".debug_str",
708 COFF::IMAGE_SCN_MEM_DISCARDABLE |
709 COFF::IMAGE_SCN_MEM_READ,
710 SectionKind::getMetadata());
712 Ctx->getCOFFSection(".debug_loc",
713 COFF::IMAGE_SCN_MEM_DISCARDABLE |
714 COFF::IMAGE_SCN_MEM_READ,
715 SectionKind::getMetadata());
716 DwarfARangesSection =
717 Ctx->getCOFFSection(".debug_aranges",
718 COFF::IMAGE_SCN_MEM_DISCARDABLE |
719 COFF::IMAGE_SCN_MEM_READ,
720 SectionKind::getMetadata());
722 Ctx->getCOFFSection(".debug_ranges",
723 COFF::IMAGE_SCN_MEM_DISCARDABLE |
724 COFF::IMAGE_SCN_MEM_READ,
725 SectionKind::getMetadata());
726 DwarfMacroInfoSection =
727 Ctx->getCOFFSection(".debug_macinfo",
728 COFF::IMAGE_SCN_MEM_DISCARDABLE |
729 COFF::IMAGE_SCN_MEM_READ,
730 SectionKind::getMetadata());
731 DwarfInfoDWOSection =
732 Ctx->getCOFFSection(".debug_info.dwo",
733 COFF::IMAGE_SCN_MEM_DISCARDABLE |
734 COFF::IMAGE_SCN_MEM_READ,
735 SectionKind::getMetadata());
736 DwarfAbbrevDWOSection =
737 Ctx->getCOFFSection(".debug_abbrev.dwo",
738 COFF::IMAGE_SCN_MEM_DISCARDABLE |
739 COFF::IMAGE_SCN_MEM_READ,
740 SectionKind::getMetadata());
742 Ctx->getCOFFSection(".debug_str.dwo",
743 COFF::IMAGE_SCN_MEM_DISCARDABLE |
744 COFF::IMAGE_SCN_MEM_READ,
745 SectionKind::getMetadata());
746 DwarfLineDWOSection =
747 Ctx->getCOFFSection(".debug_line.dwo",
748 COFF::IMAGE_SCN_MEM_DISCARDABLE |
749 COFF::IMAGE_SCN_MEM_READ,
750 SectionKind::getMetadata());
752 Ctx->getCOFFSection(".debug_loc.dwo",
753 COFF::IMAGE_SCN_MEM_DISCARDABLE |
754 COFF::IMAGE_SCN_MEM_READ,
755 SectionKind::getMetadata());
756 DwarfStrOffDWOSection =
757 Ctx->getCOFFSection(".debug_str_offsets.dwo",
758 COFF::IMAGE_SCN_MEM_DISCARDABLE |
759 COFF::IMAGE_SCN_MEM_READ,
760 SectionKind::getMetadata());
763 Ctx->getCOFFSection(".debug_addr",
764 COFF::IMAGE_SCN_MEM_DISCARDABLE |
765 COFF::IMAGE_SCN_MEM_READ,
766 SectionKind::getMetadata());
769 Ctx->getCOFFSection(".drectve",
770 COFF::IMAGE_SCN_LNK_INFO |
771 COFF::IMAGE_SCN_LNK_REMOVE,
772 SectionKind::getMetadata());
775 Ctx->getCOFFSection(".pdata",
776 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
777 COFF::IMAGE_SCN_MEM_READ,
778 SectionKind::getDataRel());
781 Ctx->getCOFFSection(".xdata",
782 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
783 COFF::IMAGE_SCN_MEM_READ,
784 SectionKind::getDataRel());
787 Ctx->getCOFFSection(".tls$",
788 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
789 COFF::IMAGE_SCN_MEM_READ |
790 COFF::IMAGE_SCN_MEM_WRITE,
791 SectionKind::getDataRel());
794 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef T, Reloc::Model relocm,
802 CommDirectiveSupportsAlignment = true;
803 SupportsWeakOmittedEHFrame = true;
804 SupportsCompactUnwindWithoutEHFrame = false;
806 PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
807 dwarf::DW_EH_PE_absptr;
809 CompactUnwindDwarfEHFrameOnly = 0;
811 EHFrameSection = nullptr; // Created on demand.
812 CompactUnwindSection = nullptr; // Used only by selected targets.
813 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
814 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
815 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
816 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
820 Triple::ArchType Arch = TT.getArch();
821 // FIXME: Checking for Arch here to filter out bogus triples such as
822 // cellspu-apple-darwin. Perhaps we should fix in Triple?
823 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
824 Arch == Triple::arm || Arch == Triple::thumb ||
825 Arch == Triple::arm64 || Arch == Triple::aarch64 ||
826 Arch == Triple::ppc || Arch == Triple::ppc64 ||
827 Arch == Triple::UnknownArch) &&
828 (TT.isOSDarwin() || TT.isOSBinFormatMachO())) {
830 InitMachOMCObjectFileInfo(TT);
831 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
832 Arch == Triple::arm || Arch == Triple::thumb) &&
833 (TT.isOSWindows() && TT.getObjectFormat() == Triple::COFF)) {
835 InitCOFFMCObjectFileInfo(TT);
838 InitELFMCObjectFileInfo(TT);
842 const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
843 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
844 SectionKind::getMetadata(), 0, utostr(Hash));
848 MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
849 return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS,
850 ELF::SHF_GROUP, SectionKind::getMetadata(), 0,
854 void MCObjectFileInfo::InitEHFrameSection() {
857 Ctx->getMachOSection("__TEXT", "__eh_frame",
859 MachO::S_ATTR_NO_TOC |
860 MachO::S_ATTR_STRIP_STATIC_SYMS |
861 MachO::S_ATTR_LIVE_SUPPORT,
862 SectionKind::getReadOnly());
863 else if (Env == IsELF)
865 Ctx->getELFSection(".eh_frame", EHSectionType,
867 SectionKind::getDataRel());
870 Ctx->getCOFFSection(".eh_frame",
871 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
872 COFF::IMAGE_SCN_MEM_READ |
873 COFF::IMAGE_SCN_MEM_WRITE,
874 SectionKind::getDataRel());