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::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;
46 if (T.isOSDarwin() && T.getArch() == Triple::aarch64)
47 SupportsCompactUnwindWithoutEHFrame = true;
49 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
50 | dwarf::DW_EH_PE_sdata4;
51 LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
52 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
53 dwarf::DW_EH_PE_sdata4;
55 // .comm doesn't support alignment before Leopard.
56 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
57 CommDirectiveSupportsAlignment = false;
60 = Ctx->getMachOSection("__TEXT", "__text",
61 MachO::S_ATTR_PURE_INSTRUCTIONS,
62 SectionKind::getText());
64 = Ctx->getMachOSection("__DATA", "__data", 0,
65 SectionKind::getDataRel());
67 // BSSSection might not be expected initialized on msvc.
70 TLSDataSection // .tdata
71 = Ctx->getMachOSection("__DATA", "__thread_data",
72 MachO::S_THREAD_LOCAL_REGULAR,
73 SectionKind::getDataRel());
74 TLSBSSSection // .tbss
75 = Ctx->getMachOSection("__DATA", "__thread_bss",
76 MachO::S_THREAD_LOCAL_ZEROFILL,
77 SectionKind::getThreadBSS());
79 // TODO: Verify datarel below.
81 = Ctx->getMachOSection("__DATA", "__thread_vars",
82 MachO::S_THREAD_LOCAL_VARIABLES,
83 SectionKind::getDataRel());
86 = Ctx->getMachOSection("__DATA", "__thread_init",
87 MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
88 SectionKind::getDataRel());
90 CStringSection // .cstring
91 = Ctx->getMachOSection("__TEXT", "__cstring",
92 MachO::S_CSTRING_LITERALS,
93 SectionKind::getMergeable1ByteCString());
95 = Ctx->getMachOSection("__TEXT","__ustring", 0,
96 SectionKind::getMergeable2ByteCString());
97 FourByteConstantSection // .literal4
98 = Ctx->getMachOSection("__TEXT", "__literal4",
99 MachO::S_4BYTE_LITERALS,
100 SectionKind::getMergeableConst4());
101 EightByteConstantSection // .literal8
102 = Ctx->getMachOSection("__TEXT", "__literal8",
103 MachO::S_8BYTE_LITERALS,
104 SectionKind::getMergeableConst8());
106 SixteenByteConstantSection // .literal16
107 = Ctx->getMachOSection("__TEXT", "__literal16",
108 MachO::S_16BYTE_LITERALS,
109 SectionKind::getMergeableConst16());
111 ReadOnlySection // .const
112 = Ctx->getMachOSection("__TEXT", "__const", 0,
113 SectionKind::getReadOnly());
116 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
118 MachO::S_ATTR_PURE_INSTRUCTIONS,
119 SectionKind::getText());
121 = Ctx->getMachOSection("__TEXT", "__const_coal",
123 SectionKind::getReadOnly());
124 ConstDataSection // .const_data
125 = Ctx->getMachOSection("__DATA", "__const", 0,
126 SectionKind::getReadOnlyWithRel());
128 = Ctx->getMachOSection("__DATA","__datacoal_nt",
130 SectionKind::getDataRel());
132 = Ctx->getMachOSection("__DATA","__common",
134 SectionKind::getBSS());
136 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
137 SectionKind::getBSS());
140 LazySymbolPointerSection
141 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
142 MachO::S_LAZY_SYMBOL_POINTERS,
143 SectionKind::getMetadata());
144 NonLazySymbolPointerSection
145 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
146 MachO::S_NON_LAZY_SYMBOL_POINTERS,
147 SectionKind::getMetadata());
149 if (RelocM == Reloc::Static) {
151 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
152 SectionKind::getDataRel());
154 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
155 SectionKind::getDataRel());
158 = Ctx->getMachOSection("__DATA", "__mod_init_func",
159 MachO::S_MOD_INIT_FUNC_POINTERS,
160 SectionKind::getDataRel());
162 = Ctx->getMachOSection("__DATA", "__mod_term_func",
163 MachO::S_MOD_TERM_FUNC_POINTERS,
164 SectionKind::getDataRel());
167 // Exception Handling.
168 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
169 SectionKind::getReadOnlyWithRel());
171 COFFDebugSymbolsSection = nullptr;
173 if (useCompactUnwind(T)) {
174 CompactUnwindSection =
175 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
176 SectionKind::getReadOnly());
178 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
179 CompactUnwindDwarfEHFrameOnly = 0x04000000;
180 else if (T.getArch() == Triple::aarch64)
181 CompactUnwindDwarfEHFrameOnly = 0x03000000;
184 // Debug Information.
185 DwarfAccelNamesSection =
186 Ctx->getMachOSection("__DWARF", "__apple_names",
188 SectionKind::getMetadata());
189 DwarfAccelObjCSection =
190 Ctx->getMachOSection("__DWARF", "__apple_objc",
192 SectionKind::getMetadata());
193 // 16 character section limit...
194 DwarfAccelNamespaceSection =
195 Ctx->getMachOSection("__DWARF", "__apple_namespac",
197 SectionKind::getMetadata());
198 DwarfAccelTypesSection =
199 Ctx->getMachOSection("__DWARF", "__apple_types",
201 SectionKind::getMetadata());
204 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
206 SectionKind::getMetadata());
208 Ctx->getMachOSection("__DWARF", "__debug_info",
210 SectionKind::getMetadata());
212 Ctx->getMachOSection("__DWARF", "__debug_line",
214 SectionKind::getMetadata());
216 Ctx->getMachOSection("__DWARF", "__debug_frame",
218 SectionKind::getMetadata());
219 DwarfPubNamesSection =
220 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
222 SectionKind::getMetadata());
223 DwarfPubTypesSection =
224 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
226 SectionKind::getMetadata());
227 DwarfGnuPubNamesSection =
228 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
230 SectionKind::getMetadata());
231 DwarfGnuPubTypesSection =
232 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
234 SectionKind::getMetadata());
236 Ctx->getMachOSection("__DWARF", "__debug_str",
238 SectionKind::getMetadata());
240 Ctx->getMachOSection("__DWARF", "__debug_loc",
242 SectionKind::getMetadata());
243 DwarfARangesSection =
244 Ctx->getMachOSection("__DWARF", "__debug_aranges",
246 SectionKind::getMetadata());
248 Ctx->getMachOSection("__DWARF", "__debug_ranges",
250 SectionKind::getMetadata());
251 DwarfMacroInfoSection =
252 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
254 SectionKind::getMetadata());
255 DwarfDebugInlineSection =
256 Ctx->getMachOSection("__DWARF", "__debug_inlined",
258 SectionKind::getMetadata());
260 Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
261 SectionKind::getMetadata());
263 TLSExtraDataSection = TLSTLVSection;
266 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
267 switch (T.getArch()) {
270 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
273 case Triple::mips64el:
274 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
277 if (RelocM == Reloc::PIC_) {
278 FDECFIEncoding = dwarf::DW_EH_PE_pcrel |
279 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
280 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
283 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
284 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
288 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
292 switch (T.getArch()) {
296 case Triple::thumbeb:
297 if (Ctx->getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
299 // Fallthrough if not using EHABI
302 PersonalityEncoding = (RelocM == Reloc::PIC_)
303 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
304 : dwarf::DW_EH_PE_absptr;
305 LSDAEncoding = (RelocM == Reloc::PIC_)
306 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
307 : dwarf::DW_EH_PE_absptr;
308 TTypeEncoding = (RelocM == Reloc::PIC_)
309 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
310 : dwarf::DW_EH_PE_absptr;
313 if (RelocM == Reloc::PIC_) {
314 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
315 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
316 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
317 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
318 (CMModel == CodeModel::Small
319 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
320 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
321 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
322 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
324 PersonalityEncoding =
325 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
326 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
327 LSDAEncoding = (CMModel == CodeModel::Small)
328 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
329 TTypeEncoding = (CMModel == CodeModel::Small)
330 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
333 case Triple::aarch64:
334 case Triple::aarch64_be:
335 // The small model guarantees static code/data size < 4GB, but not where it
336 // will be in memory. Most of these could end up >2GB away so even a signed
337 // pc-relative 32-bit address is insufficient, theoretically.
338 if (RelocM == Reloc::PIC_) {
339 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
340 dwarf::DW_EH_PE_sdata8;
341 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
342 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
343 dwarf::DW_EH_PE_sdata8;
345 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
346 LSDAEncoding = dwarf::DW_EH_PE_absptr;
347 TTypeEncoding = dwarf::DW_EH_PE_absptr;
353 case Triple::mips64el:
354 // MIPS uses indirect pointer to refer personality functions, so that the
355 // eh_frame section can be read-only. DW.ref.personality will be generated
357 PersonalityEncoding = dwarf::DW_EH_PE_indirect;
360 case Triple::ppc64le:
361 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
362 dwarf::DW_EH_PE_udata8;
363 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
364 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
365 dwarf::DW_EH_PE_udata8;
368 if (RelocM == Reloc::PIC_) {
369 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
370 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
371 dwarf::DW_EH_PE_sdata4;
372 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
373 dwarf::DW_EH_PE_sdata4;
375 LSDAEncoding = dwarf::DW_EH_PE_absptr;
376 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
377 TTypeEncoding = dwarf::DW_EH_PE_absptr;
380 case Triple::sparcv9:
381 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
382 if (RelocM == Reloc::PIC_) {
383 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
384 dwarf::DW_EH_PE_sdata4;
385 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
386 dwarf::DW_EH_PE_sdata4;
388 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
389 TTypeEncoding = dwarf::DW_EH_PE_absptr;
392 case Triple::systemz:
393 // All currently-defined code models guarantee that 4-byte PC-relative
394 // values will be in range.
395 if (RelocM == Reloc::PIC_) {
396 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
397 dwarf::DW_EH_PE_sdata4;
398 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
399 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
400 dwarf::DW_EH_PE_sdata4;
402 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
403 LSDAEncoding = dwarf::DW_EH_PE_absptr;
404 TTypeEncoding = dwarf::DW_EH_PE_absptr;
411 // Solaris requires different flags for .eh_frame to seemingly every other
413 EHSectionType = ELF::SHT_PROGBITS;
414 EHSectionFlags = ELF::SHF_ALLOC;
415 if (T.isOSSolaris()) {
416 if (T.getArch() == Triple::x86_64)
417 EHSectionType = ELF::SHT_X86_64_UNWIND;
419 EHSectionFlags |= ELF::SHF_WRITE;
425 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
426 ELF::SHF_WRITE | ELF::SHF_ALLOC,
427 SectionKind::getBSS());
430 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
433 SectionKind::getText());
436 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
437 ELF::SHF_WRITE |ELF::SHF_ALLOC,
438 SectionKind::getDataRel());
441 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
443 SectionKind::getReadOnly());
446 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
447 ELF::SHF_ALLOC | ELF::SHF_TLS |
449 SectionKind::getThreadData());
452 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
453 ELF::SHF_ALLOC | ELF::SHF_TLS |
455 SectionKind::getThreadBSS());
458 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
459 ELF::SHF_ALLOC |ELF::SHF_WRITE,
460 SectionKind::getDataRel());
462 DataRelLocalSection =
463 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
464 ELF::SHF_ALLOC |ELF::SHF_WRITE,
465 SectionKind::getDataRelLocal());
468 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
469 ELF::SHF_ALLOC |ELF::SHF_WRITE,
470 SectionKind::getReadOnlyWithRel());
472 DataRelROLocalSection =
473 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
474 ELF::SHF_ALLOC |ELF::SHF_WRITE,
475 SectionKind::getReadOnlyWithRelLocal());
477 MergeableConst4Section =
478 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
479 ELF::SHF_ALLOC |ELF::SHF_MERGE,
480 SectionKind::getMergeableConst4());
482 MergeableConst8Section =
483 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
484 ELF::SHF_ALLOC |ELF::SHF_MERGE,
485 SectionKind::getMergeableConst8());
487 MergeableConst16Section =
488 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
489 ELF::SHF_ALLOC |ELF::SHF_MERGE,
490 SectionKind::getMergeableConst16());
493 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
494 ELF::SHF_ALLOC |ELF::SHF_WRITE,
495 SectionKind::getDataRel());
498 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
499 ELF::SHF_ALLOC |ELF::SHF_WRITE,
500 SectionKind::getDataRel());
502 // Exception Handling Sections.
504 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
505 // it contains relocatable pointers. In PIC mode, this is probably a big
506 // runtime hit for C++ apps. Either the contents of the LSDA need to be
507 // adjusted or this should be a data section.
509 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
511 SectionKind::getReadOnly());
513 COFFDebugSymbolsSection = nullptr;
515 // Debug Info Sections.
517 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
518 SectionKind::getMetadata());
520 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
521 SectionKind::getMetadata());
523 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
524 SectionKind::getMetadata());
526 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
527 SectionKind::getMetadata());
528 DwarfPubNamesSection =
529 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
530 SectionKind::getMetadata());
531 DwarfPubTypesSection =
532 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
533 SectionKind::getMetadata());
534 DwarfGnuPubNamesSection =
535 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
536 SectionKind::getMetadata());
537 DwarfGnuPubTypesSection =
538 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
539 SectionKind::getMetadata());
541 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
542 ELF::SHF_MERGE | ELF::SHF_STRINGS,
543 SectionKind::getMergeable1ByteCString());
545 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
546 SectionKind::getMetadata());
547 DwarfARangesSection =
548 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
549 SectionKind::getMetadata());
551 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
552 SectionKind::getMetadata());
553 DwarfMacroInfoSection =
554 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
555 SectionKind::getMetadata());
557 // DWARF5 Experimental Debug Info
559 // Accelerator Tables
560 DwarfAccelNamesSection =
561 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
562 SectionKind::getMetadata());
563 DwarfAccelObjCSection =
564 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
565 SectionKind::getMetadata());
566 DwarfAccelNamespaceSection =
567 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
568 SectionKind::getMetadata());
569 DwarfAccelTypesSection =
570 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
571 SectionKind::getMetadata());
574 DwarfInfoDWOSection =
575 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
576 SectionKind::getMetadata());
577 DwarfTypesDWOSection =
578 Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS, 0,
579 SectionKind::getMetadata());
580 DwarfAbbrevDWOSection =
581 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
582 SectionKind::getMetadata());
584 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
585 ELF::SHF_MERGE | ELF::SHF_STRINGS,
586 SectionKind::getMergeable1ByteCString());
587 DwarfLineDWOSection =
588 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
589 SectionKind::getMetadata());
591 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
592 SectionKind::getMetadata());
593 DwarfStrOffDWOSection =
594 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
595 SectionKind::getMetadata());
597 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
598 SectionKind::getMetadata());
601 Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS,
603 SectionKind::getMetadata());
608 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
609 bool IsWoA = T.getArch() == Triple::arm || T.getArch() == Triple::thumb;
611 CommDirectiveSupportsAlignment = true;
615 Ctx->getCOFFSection(".bss",
616 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
617 COFF::IMAGE_SCN_MEM_READ |
618 COFF::IMAGE_SCN_MEM_WRITE,
619 SectionKind::getBSS());
621 Ctx->getCOFFSection(".text",
622 (IsWoA ? COFF::IMAGE_SCN_MEM_16BIT
623 : (COFF::SectionCharacteristics)0) |
624 COFF::IMAGE_SCN_CNT_CODE |
625 COFF::IMAGE_SCN_MEM_EXECUTE |
626 COFF::IMAGE_SCN_MEM_READ,
627 SectionKind::getText());
629 Ctx->getCOFFSection(".data",
630 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
631 COFF::IMAGE_SCN_MEM_READ |
632 COFF::IMAGE_SCN_MEM_WRITE,
633 SectionKind::getDataRel());
635 Ctx->getCOFFSection(".rdata",
636 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
637 COFF::IMAGE_SCN_MEM_READ,
638 SectionKind::getReadOnly());
640 if (T.isKnownWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
642 Ctx->getCOFFSection(".CRT$XCU",
643 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
644 COFF::IMAGE_SCN_MEM_READ,
645 SectionKind::getReadOnly());
647 Ctx->getCOFFSection(".CRT$XTX",
648 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
649 COFF::IMAGE_SCN_MEM_READ,
650 SectionKind::getReadOnly());
653 Ctx->getCOFFSection(".ctors",
654 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
655 COFF::IMAGE_SCN_MEM_READ |
656 COFF::IMAGE_SCN_MEM_WRITE,
657 SectionKind::getDataRel());
659 Ctx->getCOFFSection(".dtors",
660 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
661 COFF::IMAGE_SCN_MEM_READ |
662 COFF::IMAGE_SCN_MEM_WRITE,
663 SectionKind::getDataRel());
666 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
667 // though it contains relocatable pointers. In PIC mode, this is probably a
668 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
669 // adjusted or this should be a data section.
670 assert(T.isOSWindows() && "Windows is the only supported COFF target");
671 if (T.getArch() == Triple::x86_64) {
672 // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
675 LSDASection = Ctx->getCOFFSection(".gcc_except_table",
676 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
677 COFF::IMAGE_SCN_MEM_READ,
678 SectionKind::getReadOnly());
682 COFFDebugSymbolsSection =
683 Ctx->getCOFFSection(".debug$S",
684 COFF::IMAGE_SCN_MEM_DISCARDABLE |
685 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
686 COFF::IMAGE_SCN_MEM_READ,
687 SectionKind::getMetadata());
690 Ctx->getCOFFSection(".debug_abbrev",
691 COFF::IMAGE_SCN_MEM_DISCARDABLE |
692 COFF::IMAGE_SCN_MEM_READ,
693 SectionKind::getMetadata());
695 Ctx->getCOFFSection(".debug_info",
696 COFF::IMAGE_SCN_MEM_DISCARDABLE |
697 COFF::IMAGE_SCN_MEM_READ,
698 SectionKind::getMetadata());
700 Ctx->getCOFFSection(".debug_line",
701 COFF::IMAGE_SCN_MEM_DISCARDABLE |
702 COFF::IMAGE_SCN_MEM_READ,
703 SectionKind::getMetadata());
705 Ctx->getCOFFSection(".debug_frame",
706 COFF::IMAGE_SCN_MEM_DISCARDABLE |
707 COFF::IMAGE_SCN_MEM_READ,
708 SectionKind::getMetadata());
709 DwarfPubNamesSection =
710 Ctx->getCOFFSection(".debug_pubnames",
711 COFF::IMAGE_SCN_MEM_DISCARDABLE |
712 COFF::IMAGE_SCN_MEM_READ,
713 SectionKind::getMetadata());
714 DwarfPubTypesSection =
715 Ctx->getCOFFSection(".debug_pubtypes",
716 COFF::IMAGE_SCN_MEM_DISCARDABLE |
717 COFF::IMAGE_SCN_MEM_READ,
718 SectionKind::getMetadata());
719 DwarfGnuPubNamesSection =
720 Ctx->getCOFFSection(".debug_gnu_pubnames",
721 COFF::IMAGE_SCN_MEM_DISCARDABLE |
722 COFF::IMAGE_SCN_MEM_READ,
723 SectionKind::getMetadata());
724 DwarfGnuPubTypesSection =
725 Ctx->getCOFFSection(".debug_gnu_pubtypes",
726 COFF::IMAGE_SCN_MEM_DISCARDABLE |
727 COFF::IMAGE_SCN_MEM_READ,
728 SectionKind::getMetadata());
730 Ctx->getCOFFSection(".debug_str",
731 COFF::IMAGE_SCN_MEM_DISCARDABLE |
732 COFF::IMAGE_SCN_MEM_READ,
733 SectionKind::getMetadata());
735 Ctx->getCOFFSection(".debug_loc",
736 COFF::IMAGE_SCN_MEM_DISCARDABLE |
737 COFF::IMAGE_SCN_MEM_READ,
738 SectionKind::getMetadata());
739 DwarfARangesSection =
740 Ctx->getCOFFSection(".debug_aranges",
741 COFF::IMAGE_SCN_MEM_DISCARDABLE |
742 COFF::IMAGE_SCN_MEM_READ,
743 SectionKind::getMetadata());
745 Ctx->getCOFFSection(".debug_ranges",
746 COFF::IMAGE_SCN_MEM_DISCARDABLE |
747 COFF::IMAGE_SCN_MEM_READ,
748 SectionKind::getMetadata());
749 DwarfMacroInfoSection =
750 Ctx->getCOFFSection(".debug_macinfo",
751 COFF::IMAGE_SCN_MEM_DISCARDABLE |
752 COFF::IMAGE_SCN_MEM_READ,
753 SectionKind::getMetadata());
754 DwarfInfoDWOSection =
755 Ctx->getCOFFSection(".debug_info.dwo",
756 COFF::IMAGE_SCN_MEM_DISCARDABLE |
757 COFF::IMAGE_SCN_MEM_READ,
758 SectionKind::getMetadata());
759 DwarfTypesDWOSection =
760 Ctx->getCOFFSection(".debug_types.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
761 COFF::IMAGE_SCN_MEM_READ,
762 SectionKind::getMetadata());
763 DwarfAbbrevDWOSection =
764 Ctx->getCOFFSection(".debug_abbrev.dwo",
765 COFF::IMAGE_SCN_MEM_DISCARDABLE |
766 COFF::IMAGE_SCN_MEM_READ,
767 SectionKind::getMetadata());
769 Ctx->getCOFFSection(".debug_str.dwo",
770 COFF::IMAGE_SCN_MEM_DISCARDABLE |
771 COFF::IMAGE_SCN_MEM_READ,
772 SectionKind::getMetadata());
773 DwarfLineDWOSection =
774 Ctx->getCOFFSection(".debug_line.dwo",
775 COFF::IMAGE_SCN_MEM_DISCARDABLE |
776 COFF::IMAGE_SCN_MEM_READ,
777 SectionKind::getMetadata());
779 Ctx->getCOFFSection(".debug_loc.dwo",
780 COFF::IMAGE_SCN_MEM_DISCARDABLE |
781 COFF::IMAGE_SCN_MEM_READ,
782 SectionKind::getMetadata());
783 DwarfStrOffDWOSection =
784 Ctx->getCOFFSection(".debug_str_offsets.dwo",
785 COFF::IMAGE_SCN_MEM_DISCARDABLE |
786 COFF::IMAGE_SCN_MEM_READ,
787 SectionKind::getMetadata());
790 Ctx->getCOFFSection(".debug_addr",
791 COFF::IMAGE_SCN_MEM_DISCARDABLE |
792 COFF::IMAGE_SCN_MEM_READ,
793 SectionKind::getMetadata());
795 DwarfAccelNamesSection =
796 Ctx->getCOFFSection(".apple_names",
797 COFF::IMAGE_SCN_MEM_DISCARDABLE |
798 COFF::IMAGE_SCN_MEM_READ,
799 SectionKind::getMetadata());
800 DwarfAccelNamespaceSection =
801 Ctx->getCOFFSection(".apple_namespaces",
802 COFF::IMAGE_SCN_MEM_DISCARDABLE |
803 COFF::IMAGE_SCN_MEM_READ,
804 SectionKind::getMetadata());
805 DwarfAccelTypesSection =
806 Ctx->getCOFFSection(".apple_types",
807 COFF::IMAGE_SCN_MEM_DISCARDABLE |
808 COFF::IMAGE_SCN_MEM_READ,
809 SectionKind::getMetadata());
810 DwarfAccelObjCSection =
811 Ctx->getCOFFSection(".apple_objc",
812 COFF::IMAGE_SCN_MEM_DISCARDABLE |
813 COFF::IMAGE_SCN_MEM_READ,
814 SectionKind::getMetadata());
817 Ctx->getCOFFSection(".drectve",
818 COFF::IMAGE_SCN_LNK_INFO |
819 COFF::IMAGE_SCN_LNK_REMOVE,
820 SectionKind::getMetadata());
823 Ctx->getCOFFSection(".pdata",
824 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
825 COFF::IMAGE_SCN_MEM_READ,
826 SectionKind::getDataRel());
829 Ctx->getCOFFSection(".xdata",
830 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
831 COFF::IMAGE_SCN_MEM_READ,
832 SectionKind::getDataRel());
835 Ctx->getCOFFSection(".tls$",
836 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
837 COFF::IMAGE_SCN_MEM_READ |
838 COFF::IMAGE_SCN_MEM_WRITE,
839 SectionKind::getDataRel());
842 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef T, Reloc::Model relocm,
850 CommDirectiveSupportsAlignment = true;
851 SupportsWeakOmittedEHFrame = true;
852 SupportsCompactUnwindWithoutEHFrame = false;
854 PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
855 dwarf::DW_EH_PE_absptr;
857 CompactUnwindDwarfEHFrameOnly = 0;
859 EHFrameSection = nullptr; // Created on demand.
860 CompactUnwindSection = nullptr; // Used only by selected targets.
861 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
862 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
863 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
864 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
868 Triple::ArchType Arch = TT.getArch();
869 // FIXME: Checking for Arch here to filter out bogus triples such as
870 // cellspu-apple-darwin. Perhaps we should fix in Triple?
871 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
872 Arch == Triple::arm || Arch == Triple::thumb ||
873 Arch == Triple::aarch64 ||
874 Arch == Triple::ppc || Arch == Triple::ppc64 ||
875 Arch == Triple::UnknownArch) &&
876 (TT.isOSDarwin() || TT.isOSBinFormatMachO())) {
878 InitMachOMCObjectFileInfo(TT);
879 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
880 Arch == Triple::arm || Arch == Triple::thumb) &&
881 (TT.isOSWindows() && TT.getObjectFormat() == Triple::COFF)) {
883 InitCOFFMCObjectFileInfo(TT);
886 InitELFMCObjectFileInfo(TT);
890 const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
891 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
892 SectionKind::getMetadata(), 0, utostr(Hash));
895 void MCObjectFileInfo::InitEHFrameSection() {
898 Ctx->getMachOSection("__TEXT", "__eh_frame",
900 MachO::S_ATTR_NO_TOC |
901 MachO::S_ATTR_STRIP_STATIC_SYMS |
902 MachO::S_ATTR_LIVE_SUPPORT,
903 SectionKind::getReadOnly());
904 else if (Env == IsELF)
906 Ctx->getELFSection(".eh_frame", EHSectionType,
908 SectionKind::getDataRel());
911 Ctx->getCOFFSection(".eh_frame",
912 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
913 COFF::IMAGE_SCN_MEM_READ |
914 COFF::IMAGE_SCN_MEM_WRITE,
915 SectionKind::getDataRel());