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 IsFunctionEHFrameSymbolPrivate = false;
45 SupportsWeakOmittedEHFrame = false;
48 (T.getArch() == Triple::arm64 || T.getArch() == Triple::aarch64))
49 SupportsCompactUnwindWithoutEHFrame = true;
51 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
52 | dwarf::DW_EH_PE_sdata4;
53 LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
54 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
55 dwarf::DW_EH_PE_sdata4;
57 // .comm doesn't support alignment before Leopard.
58 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
59 CommDirectiveSupportsAlignment = false;
62 = Ctx->getMachOSection("__TEXT", "__text",
63 MachO::S_ATTR_PURE_INSTRUCTIONS,
64 SectionKind::getText());
66 = Ctx->getMachOSection("__DATA", "__data", 0,
67 SectionKind::getDataRel());
69 // BSSSection might not be expected initialized on msvc.
72 TLSDataSection // .tdata
73 = Ctx->getMachOSection("__DATA", "__thread_data",
74 MachO::S_THREAD_LOCAL_REGULAR,
75 SectionKind::getDataRel());
76 TLSBSSSection // .tbss
77 = Ctx->getMachOSection("__DATA", "__thread_bss",
78 MachO::S_THREAD_LOCAL_ZEROFILL,
79 SectionKind::getThreadBSS());
81 // TODO: Verify datarel below.
83 = Ctx->getMachOSection("__DATA", "__thread_vars",
84 MachO::S_THREAD_LOCAL_VARIABLES,
85 SectionKind::getDataRel());
88 = Ctx->getMachOSection("__DATA", "__thread_init",
89 MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
90 SectionKind::getDataRel());
92 CStringSection // .cstring
93 = Ctx->getMachOSection("__TEXT", "__cstring",
94 MachO::S_CSTRING_LITERALS,
95 SectionKind::getMergeable1ByteCString());
97 = Ctx->getMachOSection("__TEXT","__ustring", 0,
98 SectionKind::getMergeable2ByteCString());
99 FourByteConstantSection // .literal4
100 = Ctx->getMachOSection("__TEXT", "__literal4",
101 MachO::S_4BYTE_LITERALS,
102 SectionKind::getMergeableConst4());
103 EightByteConstantSection // .literal8
104 = Ctx->getMachOSection("__TEXT", "__literal8",
105 MachO::S_8BYTE_LITERALS,
106 SectionKind::getMergeableConst8());
108 SixteenByteConstantSection // .literal16
109 = Ctx->getMachOSection("__TEXT", "__literal16",
110 MachO::S_16BYTE_LITERALS,
111 SectionKind::getMergeableConst16());
113 ReadOnlySection // .const
114 = Ctx->getMachOSection("__TEXT", "__const", 0,
115 SectionKind::getReadOnly());
118 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
120 MachO::S_ATTR_PURE_INSTRUCTIONS,
121 SectionKind::getText());
123 = Ctx->getMachOSection("__TEXT", "__const_coal",
125 SectionKind::getReadOnly());
126 ConstDataSection // .const_data
127 = Ctx->getMachOSection("__DATA", "__const", 0,
128 SectionKind::getReadOnlyWithRel());
130 = Ctx->getMachOSection("__DATA","__datacoal_nt",
132 SectionKind::getDataRel());
134 = Ctx->getMachOSection("__DATA","__common",
136 SectionKind::getBSS());
138 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
139 SectionKind::getBSS());
142 LazySymbolPointerSection
143 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
144 MachO::S_LAZY_SYMBOL_POINTERS,
145 SectionKind::getMetadata());
146 NonLazySymbolPointerSection
147 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
148 MachO::S_NON_LAZY_SYMBOL_POINTERS,
149 SectionKind::getMetadata());
151 if (RelocM == Reloc::Static) {
153 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
154 SectionKind::getDataRel());
156 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
157 SectionKind::getDataRel());
160 = Ctx->getMachOSection("__DATA", "__mod_init_func",
161 MachO::S_MOD_INIT_FUNC_POINTERS,
162 SectionKind::getDataRel());
164 = Ctx->getMachOSection("__DATA", "__mod_term_func",
165 MachO::S_MOD_TERM_FUNC_POINTERS,
166 SectionKind::getDataRel());
169 // Exception Handling.
170 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
171 SectionKind::getReadOnlyWithRel());
173 COFFDebugSymbolsSection = nullptr;
175 if (useCompactUnwind(T)) {
176 CompactUnwindSection =
177 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
178 SectionKind::getReadOnly());
180 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
181 CompactUnwindDwarfEHFrameOnly = 0x04000000;
182 else if (T.getArch() == Triple::arm64 || T.getArch() == Triple::aarch64)
183 CompactUnwindDwarfEHFrameOnly = 0x03000000;
186 // Debug Information.
187 DwarfAccelNamesSection =
188 Ctx->getMachOSection("__DWARF", "__apple_names",
190 SectionKind::getMetadata());
191 DwarfAccelObjCSection =
192 Ctx->getMachOSection("__DWARF", "__apple_objc",
194 SectionKind::getMetadata());
195 // 16 character section limit...
196 DwarfAccelNamespaceSection =
197 Ctx->getMachOSection("__DWARF", "__apple_namespac",
199 SectionKind::getMetadata());
200 DwarfAccelTypesSection =
201 Ctx->getMachOSection("__DWARF", "__apple_types",
203 SectionKind::getMetadata());
206 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
208 SectionKind::getMetadata());
210 Ctx->getMachOSection("__DWARF", "__debug_info",
212 SectionKind::getMetadata());
214 Ctx->getMachOSection("__DWARF", "__debug_line",
216 SectionKind::getMetadata());
218 Ctx->getMachOSection("__DWARF", "__debug_frame",
220 SectionKind::getMetadata());
221 DwarfPubNamesSection =
222 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
224 SectionKind::getMetadata());
225 DwarfPubTypesSection =
226 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
228 SectionKind::getMetadata());
229 DwarfGnuPubNamesSection =
230 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
232 SectionKind::getMetadata());
233 DwarfGnuPubTypesSection =
234 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
236 SectionKind::getMetadata());
238 Ctx->getMachOSection("__DWARF", "__debug_str",
240 SectionKind::getMetadata());
242 Ctx->getMachOSection("__DWARF", "__debug_loc",
244 SectionKind::getMetadata());
245 DwarfARangesSection =
246 Ctx->getMachOSection("__DWARF", "__debug_aranges",
248 SectionKind::getMetadata());
250 Ctx->getMachOSection("__DWARF", "__debug_ranges",
252 SectionKind::getMetadata());
253 DwarfMacroInfoSection =
254 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
256 SectionKind::getMetadata());
257 DwarfDebugInlineSection =
258 Ctx->getMachOSection("__DWARF", "__debug_inlined",
260 SectionKind::getMetadata());
262 Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
263 SectionKind::getMetadata());
265 TLSExtraDataSection = TLSTLVSection;
268 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
269 switch (T.getArch()) {
272 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
275 case Triple::mips64el:
276 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
279 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
283 switch (T.getArch()) {
287 case Triple::thumbeb:
288 if (Ctx->getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
290 // 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;
344 // MIPS uses indirect pointer to refer personality functions, so that the
345 // eh_frame section can be read-only. DW.ref.personality will be generated
347 PersonalityEncoding = dwarf::DW_EH_PE_indirect;
350 case Triple::ppc64le:
351 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
352 dwarf::DW_EH_PE_udata8;
353 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
354 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
355 dwarf::DW_EH_PE_udata8;
358 if (RelocM == Reloc::PIC_) {
359 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
360 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
361 dwarf::DW_EH_PE_sdata4;
362 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
363 dwarf::DW_EH_PE_sdata4;
365 LSDAEncoding = dwarf::DW_EH_PE_absptr;
366 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
367 TTypeEncoding = dwarf::DW_EH_PE_absptr;
370 case Triple::sparcv9:
371 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
372 if (RelocM == Reloc::PIC_) {
373 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
374 dwarf::DW_EH_PE_sdata4;
375 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
376 dwarf::DW_EH_PE_sdata4;
378 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
379 TTypeEncoding = dwarf::DW_EH_PE_absptr;
382 case Triple::systemz:
383 // All currently-defined code models guarantee that 4-byte PC-relative
384 // values will be in range.
385 if (RelocM == Reloc::PIC_) {
386 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
387 dwarf::DW_EH_PE_sdata4;
388 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
389 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
390 dwarf::DW_EH_PE_sdata4;
392 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
393 LSDAEncoding = dwarf::DW_EH_PE_absptr;
394 TTypeEncoding = dwarf::DW_EH_PE_absptr;
401 // Solaris requires different flags for .eh_frame to seemingly every other
403 EHSectionType = ELF::SHT_PROGBITS;
404 EHSectionFlags = ELF::SHF_ALLOC;
405 if (T.getOS() == Triple::Solaris) {
406 if (T.getArch() == Triple::x86_64)
407 EHSectionType = ELF::SHT_X86_64_UNWIND;
409 EHSectionFlags |= ELF::SHF_WRITE;
415 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
416 ELF::SHF_WRITE | ELF::SHF_ALLOC,
417 SectionKind::getBSS());
420 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
423 SectionKind::getText());
426 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
427 ELF::SHF_WRITE |ELF::SHF_ALLOC,
428 SectionKind::getDataRel());
431 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
433 SectionKind::getReadOnly());
436 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
437 ELF::SHF_ALLOC | ELF::SHF_TLS |
439 SectionKind::getThreadData());
442 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
443 ELF::SHF_ALLOC | ELF::SHF_TLS |
445 SectionKind::getThreadBSS());
448 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
449 ELF::SHF_ALLOC |ELF::SHF_WRITE,
450 SectionKind::getDataRel());
452 DataRelLocalSection =
453 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
454 ELF::SHF_ALLOC |ELF::SHF_WRITE,
455 SectionKind::getDataRelLocal());
458 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
459 ELF::SHF_ALLOC |ELF::SHF_WRITE,
460 SectionKind::getReadOnlyWithRel());
462 DataRelROLocalSection =
463 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
464 ELF::SHF_ALLOC |ELF::SHF_WRITE,
465 SectionKind::getReadOnlyWithRelLocal());
467 MergeableConst4Section =
468 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
469 ELF::SHF_ALLOC |ELF::SHF_MERGE,
470 SectionKind::getMergeableConst4());
472 MergeableConst8Section =
473 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
474 ELF::SHF_ALLOC |ELF::SHF_MERGE,
475 SectionKind::getMergeableConst8());
477 MergeableConst16Section =
478 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
479 ELF::SHF_ALLOC |ELF::SHF_MERGE,
480 SectionKind::getMergeableConst16());
483 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
484 ELF::SHF_ALLOC |ELF::SHF_WRITE,
485 SectionKind::getDataRel());
488 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
489 ELF::SHF_ALLOC |ELF::SHF_WRITE,
490 SectionKind::getDataRel());
492 // Exception Handling Sections.
494 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
495 // it contains relocatable pointers. In PIC mode, this is probably a big
496 // runtime hit for C++ apps. Either the contents of the LSDA need to be
497 // adjusted or this should be a data section.
499 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
501 SectionKind::getReadOnly());
503 COFFDebugSymbolsSection = nullptr;
505 // Debug Info Sections.
507 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
508 SectionKind::getMetadata());
510 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
511 SectionKind::getMetadata());
513 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
514 SectionKind::getMetadata());
516 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
517 SectionKind::getMetadata());
518 DwarfPubNamesSection =
519 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
520 SectionKind::getMetadata());
521 DwarfPubTypesSection =
522 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
523 SectionKind::getMetadata());
524 DwarfGnuPubNamesSection =
525 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
526 SectionKind::getMetadata());
527 DwarfGnuPubTypesSection =
528 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
529 SectionKind::getMetadata());
531 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
532 ELF::SHF_MERGE | ELF::SHF_STRINGS,
533 SectionKind::getMergeable1ByteCString());
535 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
536 SectionKind::getMetadata());
537 DwarfARangesSection =
538 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
539 SectionKind::getMetadata());
541 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
542 SectionKind::getMetadata());
543 DwarfMacroInfoSection =
544 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
545 SectionKind::getMetadata());
547 // DWARF5 Experimental Debug Info
549 // Accelerator Tables
550 DwarfAccelNamesSection =
551 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
552 SectionKind::getMetadata());
553 DwarfAccelObjCSection =
554 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
555 SectionKind::getMetadata());
556 DwarfAccelNamespaceSection =
557 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
558 SectionKind::getMetadata());
559 DwarfAccelTypesSection =
560 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
561 SectionKind::getMetadata());
564 DwarfInfoDWOSection =
565 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
566 SectionKind::getMetadata());
567 DwarfAbbrevDWOSection =
568 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
569 SectionKind::getMetadata());
571 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
572 ELF::SHF_MERGE | ELF::SHF_STRINGS,
573 SectionKind::getMergeable1ByteCString());
574 DwarfLineDWOSection =
575 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
576 SectionKind::getMetadata());
578 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
579 SectionKind::getMetadata());
580 DwarfStrOffDWOSection =
581 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
582 SectionKind::getMetadata());
584 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
585 SectionKind::getMetadata());
589 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
590 bool IsWoA = T.getArch() == Triple::arm || T.getArch() == Triple::thumb;
592 // The object file format cannot represent common symbols with explicit
594 CommDirectiveSupportsAlignment = false;
598 Ctx->getCOFFSection(".bss",
599 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
600 COFF::IMAGE_SCN_MEM_READ |
601 COFF::IMAGE_SCN_MEM_WRITE,
602 SectionKind::getBSS());
604 Ctx->getCOFFSection(".text",
605 (IsWoA ? COFF::IMAGE_SCN_MEM_16BIT
606 : (COFF::SectionCharacteristics)0) |
607 COFF::IMAGE_SCN_CNT_CODE |
608 COFF::IMAGE_SCN_MEM_EXECUTE |
609 COFF::IMAGE_SCN_MEM_READ,
610 SectionKind::getText());
612 Ctx->getCOFFSection(".data",
613 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
614 COFF::IMAGE_SCN_MEM_READ |
615 COFF::IMAGE_SCN_MEM_WRITE,
616 SectionKind::getDataRel());
618 Ctx->getCOFFSection(".rdata",
619 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
620 COFF::IMAGE_SCN_MEM_READ,
621 SectionKind::getReadOnly());
623 if (T.isKnownWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
625 Ctx->getCOFFSection(".CRT$XCU",
626 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
627 COFF::IMAGE_SCN_MEM_READ,
628 SectionKind::getReadOnly());
630 Ctx->getCOFFSection(".CRT$XTX",
631 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
632 COFF::IMAGE_SCN_MEM_READ,
633 SectionKind::getReadOnly());
636 Ctx->getCOFFSection(".ctors",
637 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
638 COFF::IMAGE_SCN_MEM_READ |
639 COFF::IMAGE_SCN_MEM_WRITE,
640 SectionKind::getDataRel());
642 Ctx->getCOFFSection(".dtors",
643 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
644 COFF::IMAGE_SCN_MEM_READ |
645 COFF::IMAGE_SCN_MEM_WRITE,
646 SectionKind::getDataRel());
649 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
650 // though it contains relocatable pointers. In PIC mode, this is probably a
651 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
652 // adjusted or this should be a data section.
654 Ctx->getCOFFSection(".gcc_except_table",
655 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
656 COFF::IMAGE_SCN_MEM_READ,
657 SectionKind::getReadOnly());
660 COFFDebugSymbolsSection =
661 Ctx->getCOFFSection(".debug$S",
662 COFF::IMAGE_SCN_MEM_DISCARDABLE |
663 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
664 COFF::IMAGE_SCN_MEM_READ,
665 SectionKind::getMetadata());
668 Ctx->getCOFFSection(".debug_abbrev",
669 COFF::IMAGE_SCN_MEM_DISCARDABLE |
670 COFF::IMAGE_SCN_MEM_READ,
671 SectionKind::getMetadata());
673 Ctx->getCOFFSection(".debug_info",
674 COFF::IMAGE_SCN_MEM_DISCARDABLE |
675 COFF::IMAGE_SCN_MEM_READ,
676 SectionKind::getMetadata());
678 Ctx->getCOFFSection(".debug_line",
679 COFF::IMAGE_SCN_MEM_DISCARDABLE |
680 COFF::IMAGE_SCN_MEM_READ,
681 SectionKind::getMetadata());
683 Ctx->getCOFFSection(".debug_frame",
684 COFF::IMAGE_SCN_MEM_DISCARDABLE |
685 COFF::IMAGE_SCN_MEM_READ,
686 SectionKind::getMetadata());
687 DwarfPubNamesSection =
688 Ctx->getCOFFSection(".debug_pubnames",
689 COFF::IMAGE_SCN_MEM_DISCARDABLE |
690 COFF::IMAGE_SCN_MEM_READ,
691 SectionKind::getMetadata());
692 DwarfPubTypesSection =
693 Ctx->getCOFFSection(".debug_pubtypes",
694 COFF::IMAGE_SCN_MEM_DISCARDABLE |
695 COFF::IMAGE_SCN_MEM_READ,
696 SectionKind::getMetadata());
697 DwarfGnuPubNamesSection =
698 Ctx->getCOFFSection(".debug_gnu_pubnames",
699 COFF::IMAGE_SCN_MEM_DISCARDABLE |
700 COFF::IMAGE_SCN_MEM_READ,
701 SectionKind::getMetadata());
702 DwarfGnuPubTypesSection =
703 Ctx->getCOFFSection(".debug_gnu_pubtypes",
704 COFF::IMAGE_SCN_MEM_DISCARDABLE |
705 COFF::IMAGE_SCN_MEM_READ,
706 SectionKind::getMetadata());
708 Ctx->getCOFFSection(".debug_str",
709 COFF::IMAGE_SCN_MEM_DISCARDABLE |
710 COFF::IMAGE_SCN_MEM_READ,
711 SectionKind::getMetadata());
713 Ctx->getCOFFSection(".debug_loc",
714 COFF::IMAGE_SCN_MEM_DISCARDABLE |
715 COFF::IMAGE_SCN_MEM_READ,
716 SectionKind::getMetadata());
717 DwarfARangesSection =
718 Ctx->getCOFFSection(".debug_aranges",
719 COFF::IMAGE_SCN_MEM_DISCARDABLE |
720 COFF::IMAGE_SCN_MEM_READ,
721 SectionKind::getMetadata());
723 Ctx->getCOFFSection(".debug_ranges",
724 COFF::IMAGE_SCN_MEM_DISCARDABLE |
725 COFF::IMAGE_SCN_MEM_READ,
726 SectionKind::getMetadata());
727 DwarfMacroInfoSection =
728 Ctx->getCOFFSection(".debug_macinfo",
729 COFF::IMAGE_SCN_MEM_DISCARDABLE |
730 COFF::IMAGE_SCN_MEM_READ,
731 SectionKind::getMetadata());
732 DwarfInfoDWOSection =
733 Ctx->getCOFFSection(".debug_info.dwo",
734 COFF::IMAGE_SCN_MEM_DISCARDABLE |
735 COFF::IMAGE_SCN_MEM_READ,
736 SectionKind::getMetadata());
737 DwarfAbbrevDWOSection =
738 Ctx->getCOFFSection(".debug_abbrev.dwo",
739 COFF::IMAGE_SCN_MEM_DISCARDABLE |
740 COFF::IMAGE_SCN_MEM_READ,
741 SectionKind::getMetadata());
743 Ctx->getCOFFSection(".debug_str.dwo",
744 COFF::IMAGE_SCN_MEM_DISCARDABLE |
745 COFF::IMAGE_SCN_MEM_READ,
746 SectionKind::getMetadata());
747 DwarfLineDWOSection =
748 Ctx->getCOFFSection(".debug_line.dwo",
749 COFF::IMAGE_SCN_MEM_DISCARDABLE |
750 COFF::IMAGE_SCN_MEM_READ,
751 SectionKind::getMetadata());
753 Ctx->getCOFFSection(".debug_loc.dwo",
754 COFF::IMAGE_SCN_MEM_DISCARDABLE |
755 COFF::IMAGE_SCN_MEM_READ,
756 SectionKind::getMetadata());
757 DwarfStrOffDWOSection =
758 Ctx->getCOFFSection(".debug_str_offsets.dwo",
759 COFF::IMAGE_SCN_MEM_DISCARDABLE |
760 COFF::IMAGE_SCN_MEM_READ,
761 SectionKind::getMetadata());
764 Ctx->getCOFFSection(".debug_addr",
765 COFF::IMAGE_SCN_MEM_DISCARDABLE |
766 COFF::IMAGE_SCN_MEM_READ,
767 SectionKind::getMetadata());
770 Ctx->getCOFFSection(".drectve",
771 COFF::IMAGE_SCN_LNK_INFO |
772 COFF::IMAGE_SCN_LNK_REMOVE,
773 SectionKind::getMetadata());
776 Ctx->getCOFFSection(".pdata",
777 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
778 COFF::IMAGE_SCN_MEM_READ,
779 SectionKind::getDataRel());
782 Ctx->getCOFFSection(".xdata",
783 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
784 COFF::IMAGE_SCN_MEM_READ,
785 SectionKind::getDataRel());
788 Ctx->getCOFFSection(".tls$",
789 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
790 COFF::IMAGE_SCN_MEM_READ |
791 COFF::IMAGE_SCN_MEM_WRITE,
792 SectionKind::getDataRel());
795 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef T, Reloc::Model relocm,
803 CommDirectiveSupportsAlignment = true;
804 SupportsWeakOmittedEHFrame = true;
805 IsFunctionEHFrameSymbolPrivate = true;
806 SupportsCompactUnwindWithoutEHFrame = false;
808 PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
809 dwarf::DW_EH_PE_absptr;
811 CompactUnwindDwarfEHFrameOnly = 0;
813 EHFrameSection = nullptr; // Created on demand.
814 CompactUnwindSection = nullptr; // Used only by selected targets.
815 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
816 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
817 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
818 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
822 Triple::ArchType Arch = TT.getArch();
823 // FIXME: Checking for Arch here to filter out bogus triples such as
824 // cellspu-apple-darwin. Perhaps we should fix in Triple?
825 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
826 Arch == Triple::arm || Arch == Triple::thumb ||
827 Arch == Triple::arm64 || Arch == Triple::aarch64 ||
828 Arch == Triple::ppc || Arch == Triple::ppc64 ||
829 Arch == Triple::UnknownArch) &&
830 (TT.isOSDarwin() || TT.isOSBinFormatMachO())) {
832 InitMachOMCObjectFileInfo(TT);
833 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
834 Arch == Triple::arm || Arch == Triple::thumb) &&
835 (TT.isOSWindows() && TT.getObjectFormat() == Triple::COFF)) {
837 InitCOFFMCObjectFileInfo(TT);
840 InitELFMCObjectFileInfo(TT);
844 const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
845 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
846 SectionKind::getMetadata(), 0, utostr(Hash));
850 MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
851 return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS,
852 ELF::SHF_GROUP, SectionKind::getMetadata(), 0,
856 void MCObjectFileInfo::InitEHFrameSection() {
859 Ctx->getMachOSection("__TEXT", "__eh_frame",
861 MachO::S_ATTR_NO_TOC |
862 MachO::S_ATTR_STRIP_STATIC_SYMS |
863 MachO::S_ATTR_LIVE_SUPPORT,
864 SectionKind::getReadOnly());
865 else if (Env == IsELF)
867 Ctx->getELFSection(".eh_frame", EHSectionType,
869 SectionKind::getDataRel());
872 Ctx->getCOFFSection(".eh_frame",
873 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
874 COFF::IMAGE_SCN_MEM_READ |
875 COFF::IMAGE_SCN_MEM_WRITE,
876 SectionKind::getDataRel());