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))
37 void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
39 IsFunctionEHFrameSymbolPrivate = false;
40 SupportsWeakOmittedEHFrame = false;
43 (T.getArch() == Triple::arm64 || T.getArch() == Triple::aarch64))
44 SupportsCompactUnwindWithoutEHFrame = true;
46 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
47 | dwarf::DW_EH_PE_sdata4;
48 LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
49 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
50 dwarf::DW_EH_PE_sdata4;
52 // .comm doesn't support alignment before Leopard.
53 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
54 CommDirectiveSupportsAlignment = false;
57 = Ctx->getMachOSection("__TEXT", "__text",
58 MachO::S_ATTR_PURE_INSTRUCTIONS,
59 SectionKind::getText());
61 = Ctx->getMachOSection("__DATA", "__data", 0,
62 SectionKind::getDataRel());
64 // BSSSection might not be expected initialized on msvc.
67 TLSDataSection // .tdata
68 = Ctx->getMachOSection("__DATA", "__thread_data",
69 MachO::S_THREAD_LOCAL_REGULAR,
70 SectionKind::getDataRel());
71 TLSBSSSection // .tbss
72 = Ctx->getMachOSection("__DATA", "__thread_bss",
73 MachO::S_THREAD_LOCAL_ZEROFILL,
74 SectionKind::getThreadBSS());
76 // TODO: Verify datarel below.
78 = Ctx->getMachOSection("__DATA", "__thread_vars",
79 MachO::S_THREAD_LOCAL_VARIABLES,
80 SectionKind::getDataRel());
83 = Ctx->getMachOSection("__DATA", "__thread_init",
84 MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
85 SectionKind::getDataRel());
87 CStringSection // .cstring
88 = Ctx->getMachOSection("__TEXT", "__cstring",
89 MachO::S_CSTRING_LITERALS,
90 SectionKind::getMergeable1ByteCString());
92 = Ctx->getMachOSection("__TEXT","__ustring", 0,
93 SectionKind::getMergeable2ByteCString());
94 FourByteConstantSection // .literal4
95 = Ctx->getMachOSection("__TEXT", "__literal4",
96 MachO::S_4BYTE_LITERALS,
97 SectionKind::getMergeableConst4());
98 EightByteConstantSection // .literal8
99 = Ctx->getMachOSection("__TEXT", "__literal8",
100 MachO::S_8BYTE_LITERALS,
101 SectionKind::getMergeableConst8());
103 SixteenByteConstantSection // .literal16
104 = Ctx->getMachOSection("__TEXT", "__literal16",
105 MachO::S_16BYTE_LITERALS,
106 SectionKind::getMergeableConst16());
108 ReadOnlySection // .const
109 = Ctx->getMachOSection("__TEXT", "__const", 0,
110 SectionKind::getReadOnly());
113 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
115 MachO::S_ATTR_PURE_INSTRUCTIONS,
116 SectionKind::getText());
118 = Ctx->getMachOSection("__TEXT", "__const_coal",
120 SectionKind::getReadOnly());
121 ConstDataSection // .const_data
122 = Ctx->getMachOSection("__DATA", "__const", 0,
123 SectionKind::getReadOnlyWithRel());
125 = Ctx->getMachOSection("__DATA","__datacoal_nt",
127 SectionKind::getDataRel());
129 = Ctx->getMachOSection("__DATA","__common",
131 SectionKind::getBSS());
133 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
134 SectionKind::getBSS());
137 LazySymbolPointerSection
138 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
139 MachO::S_LAZY_SYMBOL_POINTERS,
140 SectionKind::getMetadata());
141 NonLazySymbolPointerSection
142 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
143 MachO::S_NON_LAZY_SYMBOL_POINTERS,
144 SectionKind::getMetadata());
146 if (RelocM == Reloc::Static) {
148 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
149 SectionKind::getDataRel());
151 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
152 SectionKind::getDataRel());
155 = Ctx->getMachOSection("__DATA", "__mod_init_func",
156 MachO::S_MOD_INIT_FUNC_POINTERS,
157 SectionKind::getDataRel());
159 = Ctx->getMachOSection("__DATA", "__mod_term_func",
160 MachO::S_MOD_TERM_FUNC_POINTERS,
161 SectionKind::getDataRel());
164 // Exception Handling.
165 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
166 SectionKind::getReadOnlyWithRel());
168 COFFDebugSymbolsSection = nullptr;
170 if (useCompactUnwind(T)) {
171 CompactUnwindSection =
172 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
173 SectionKind::getReadOnly());
175 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
176 CompactUnwindDwarfEHFrameOnly = 0x04000000;
177 else if (T.getArch() == Triple::arm64 || T.getArch() == Triple::aarch64)
178 CompactUnwindDwarfEHFrameOnly = 0x03000000;
181 // Debug Information.
182 DwarfAccelNamesSection =
183 Ctx->getMachOSection("__DWARF", "__apple_names",
185 SectionKind::getMetadata());
186 DwarfAccelObjCSection =
187 Ctx->getMachOSection("__DWARF", "__apple_objc",
189 SectionKind::getMetadata());
190 // 16 character section limit...
191 DwarfAccelNamespaceSection =
192 Ctx->getMachOSection("__DWARF", "__apple_namespac",
194 SectionKind::getMetadata());
195 DwarfAccelTypesSection =
196 Ctx->getMachOSection("__DWARF", "__apple_types",
198 SectionKind::getMetadata());
201 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
203 SectionKind::getMetadata());
205 Ctx->getMachOSection("__DWARF", "__debug_info",
207 SectionKind::getMetadata());
209 Ctx->getMachOSection("__DWARF", "__debug_line",
211 SectionKind::getMetadata());
213 Ctx->getMachOSection("__DWARF", "__debug_frame",
215 SectionKind::getMetadata());
216 DwarfPubNamesSection =
217 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
219 SectionKind::getMetadata());
220 DwarfPubTypesSection =
221 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
223 SectionKind::getMetadata());
224 DwarfGnuPubNamesSection =
225 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
227 SectionKind::getMetadata());
228 DwarfGnuPubTypesSection =
229 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
231 SectionKind::getMetadata());
233 Ctx->getMachOSection("__DWARF", "__debug_str",
235 SectionKind::getMetadata());
237 Ctx->getMachOSection("__DWARF", "__debug_loc",
239 SectionKind::getMetadata());
240 DwarfARangesSection =
241 Ctx->getMachOSection("__DWARF", "__debug_aranges",
243 SectionKind::getMetadata());
245 Ctx->getMachOSection("__DWARF", "__debug_ranges",
247 SectionKind::getMetadata());
248 DwarfMacroInfoSection =
249 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
251 SectionKind::getMetadata());
252 DwarfDebugInlineSection =
253 Ctx->getMachOSection("__DWARF", "__debug_inlined",
255 SectionKind::getMetadata());
257 Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
258 SectionKind::getMetadata());
260 TLSExtraDataSection = TLSTLVSection;
263 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
264 switch (T.getArch()) {
267 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
270 case Triple::mips64el:
271 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
274 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
278 switch (T.getArch()) {
282 case Triple::thumbeb:
283 if (Ctx->getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
285 // Fallthrough if not using EHABI
287 PersonalityEncoding = (RelocM == Reloc::PIC_)
288 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
289 : dwarf::DW_EH_PE_absptr;
290 LSDAEncoding = (RelocM == Reloc::PIC_)
291 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
292 : dwarf::DW_EH_PE_absptr;
293 TTypeEncoding = (RelocM == Reloc::PIC_)
294 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
295 : dwarf::DW_EH_PE_absptr;
298 if (RelocM == Reloc::PIC_) {
299 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
300 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
301 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
302 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
303 (CMModel == CodeModel::Small
304 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
305 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
306 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
307 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
309 PersonalityEncoding =
310 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
311 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
312 LSDAEncoding = (CMModel == CodeModel::Small)
313 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
314 TTypeEncoding = (CMModel == CodeModel::Small)
315 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
318 case Triple::aarch64:
319 case Triple::aarch64_be:
321 case Triple::arm64_be:
322 // The small model guarantees static code/data size < 4GB, but not where it
323 // will be in memory. Most of these could end up >2GB away so even a signed
324 // pc-relative 32-bit address is insufficient, theoretically.
325 if (RelocM == Reloc::PIC_) {
326 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
327 dwarf::DW_EH_PE_sdata8;
328 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
329 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
330 dwarf::DW_EH_PE_sdata8;
332 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
333 LSDAEncoding = dwarf::DW_EH_PE_absptr;
334 TTypeEncoding = dwarf::DW_EH_PE_absptr;
339 // MIPS uses indirect pointer to refer personality functions, so that the
340 // eh_frame section can be read-only. DW.ref.personality will be generated
342 PersonalityEncoding = dwarf::DW_EH_PE_indirect;
345 case Triple::ppc64le:
346 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
347 dwarf::DW_EH_PE_udata8;
348 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
349 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
350 dwarf::DW_EH_PE_udata8;
353 if (RelocM == Reloc::PIC_) {
354 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
355 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
356 dwarf::DW_EH_PE_sdata4;
357 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
358 dwarf::DW_EH_PE_sdata4;
360 LSDAEncoding = dwarf::DW_EH_PE_absptr;
361 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
362 TTypeEncoding = dwarf::DW_EH_PE_absptr;
365 case Triple::sparcv9:
366 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
367 if (RelocM == Reloc::PIC_) {
368 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
369 dwarf::DW_EH_PE_sdata4;
370 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
371 dwarf::DW_EH_PE_sdata4;
373 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
374 TTypeEncoding = dwarf::DW_EH_PE_absptr;
377 case Triple::systemz:
378 // All currently-defined code models guarantee that 4-byte PC-relative
379 // values will be in range.
380 if (RelocM == Reloc::PIC_) {
381 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
382 dwarf::DW_EH_PE_sdata4;
383 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
384 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
385 dwarf::DW_EH_PE_sdata4;
387 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
388 LSDAEncoding = dwarf::DW_EH_PE_absptr;
389 TTypeEncoding = dwarf::DW_EH_PE_absptr;
396 // Solaris requires different flags for .eh_frame to seemingly every other
398 EHSectionType = ELF::SHT_PROGBITS;
399 EHSectionFlags = ELF::SHF_ALLOC;
400 if (T.getOS() == Triple::Solaris) {
401 if (T.getArch() == Triple::x86_64)
402 EHSectionType = ELF::SHT_X86_64_UNWIND;
404 EHSectionFlags |= ELF::SHF_WRITE;
410 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
411 ELF::SHF_WRITE | ELF::SHF_ALLOC,
412 SectionKind::getBSS());
415 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
418 SectionKind::getText());
421 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
422 ELF::SHF_WRITE |ELF::SHF_ALLOC,
423 SectionKind::getDataRel());
426 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
428 SectionKind::getReadOnly());
431 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
432 ELF::SHF_ALLOC | ELF::SHF_TLS |
434 SectionKind::getThreadData());
437 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
438 ELF::SHF_ALLOC | ELF::SHF_TLS |
440 SectionKind::getThreadBSS());
443 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
444 ELF::SHF_ALLOC |ELF::SHF_WRITE,
445 SectionKind::getDataRel());
447 DataRelLocalSection =
448 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
449 ELF::SHF_ALLOC |ELF::SHF_WRITE,
450 SectionKind::getDataRelLocal());
453 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
454 ELF::SHF_ALLOC |ELF::SHF_WRITE,
455 SectionKind::getReadOnlyWithRel());
457 DataRelROLocalSection =
458 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
459 ELF::SHF_ALLOC |ELF::SHF_WRITE,
460 SectionKind::getReadOnlyWithRelLocal());
462 MergeableConst4Section =
463 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
464 ELF::SHF_ALLOC |ELF::SHF_MERGE,
465 SectionKind::getMergeableConst4());
467 MergeableConst8Section =
468 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
469 ELF::SHF_ALLOC |ELF::SHF_MERGE,
470 SectionKind::getMergeableConst8());
472 MergeableConst16Section =
473 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
474 ELF::SHF_ALLOC |ELF::SHF_MERGE,
475 SectionKind::getMergeableConst16());
478 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
479 ELF::SHF_ALLOC |ELF::SHF_WRITE,
480 SectionKind::getDataRel());
483 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
484 ELF::SHF_ALLOC |ELF::SHF_WRITE,
485 SectionKind::getDataRel());
487 // Exception Handling Sections.
489 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
490 // it contains relocatable pointers. In PIC mode, this is probably a big
491 // runtime hit for C++ apps. Either the contents of the LSDA need to be
492 // adjusted or this should be a data section.
494 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
496 SectionKind::getReadOnly());
498 COFFDebugSymbolsSection = nullptr;
500 // Debug Info Sections.
502 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
503 SectionKind::getMetadata());
505 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
506 SectionKind::getMetadata());
508 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
509 SectionKind::getMetadata());
511 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
512 SectionKind::getMetadata());
513 DwarfPubNamesSection =
514 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
515 SectionKind::getMetadata());
516 DwarfPubTypesSection =
517 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
518 SectionKind::getMetadata());
519 DwarfGnuPubNamesSection =
520 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
521 SectionKind::getMetadata());
522 DwarfGnuPubTypesSection =
523 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
524 SectionKind::getMetadata());
526 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
527 ELF::SHF_MERGE | ELF::SHF_STRINGS,
528 SectionKind::getMergeable1ByteCString());
530 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
531 SectionKind::getMetadata());
532 DwarfARangesSection =
533 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
534 SectionKind::getMetadata());
536 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
537 SectionKind::getMetadata());
538 DwarfMacroInfoSection =
539 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
540 SectionKind::getMetadata());
542 // DWARF5 Experimental Debug Info
544 // Accelerator Tables
545 DwarfAccelNamesSection =
546 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
547 SectionKind::getMetadata());
548 DwarfAccelObjCSection =
549 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
550 SectionKind::getMetadata());
551 DwarfAccelNamespaceSection =
552 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
553 SectionKind::getMetadata());
554 DwarfAccelTypesSection =
555 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
556 SectionKind::getMetadata());
559 DwarfInfoDWOSection =
560 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
561 SectionKind::getMetadata());
562 DwarfAbbrevDWOSection =
563 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
564 SectionKind::getMetadata());
566 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
567 ELF::SHF_MERGE | ELF::SHF_STRINGS,
568 SectionKind::getMergeable1ByteCString());
569 DwarfLineDWOSection =
570 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
571 SectionKind::getMetadata());
573 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
574 SectionKind::getMetadata());
575 DwarfStrOffDWOSection =
576 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
577 SectionKind::getMetadata());
579 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
580 SectionKind::getMetadata());
584 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
585 bool IsWoA = T.getArch() == Triple::arm || T.getArch() == Triple::thumb;
587 // The object file format cannot represent common symbols with explicit
589 CommDirectiveSupportsAlignment = false;
593 Ctx->getCOFFSection(".bss",
594 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
595 COFF::IMAGE_SCN_MEM_READ |
596 COFF::IMAGE_SCN_MEM_WRITE,
597 SectionKind::getBSS());
599 Ctx->getCOFFSection(".text",
600 (IsWoA ? COFF::IMAGE_SCN_MEM_16BIT
601 : (COFF::SectionCharacteristics)0) |
602 COFF::IMAGE_SCN_CNT_CODE |
603 COFF::IMAGE_SCN_MEM_EXECUTE |
604 COFF::IMAGE_SCN_MEM_READ,
605 SectionKind::getText());
607 Ctx->getCOFFSection(".data",
608 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
609 COFF::IMAGE_SCN_MEM_READ |
610 COFF::IMAGE_SCN_MEM_WRITE,
611 SectionKind::getDataRel());
613 Ctx->getCOFFSection(".rdata",
614 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
615 COFF::IMAGE_SCN_MEM_READ,
616 SectionKind::getReadOnly());
618 if (T.isKnownWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
620 Ctx->getCOFFSection(".CRT$XCU",
621 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
622 COFF::IMAGE_SCN_MEM_READ,
623 SectionKind::getReadOnly());
625 Ctx->getCOFFSection(".CRT$XTX",
626 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
627 COFF::IMAGE_SCN_MEM_READ,
628 SectionKind::getReadOnly());
631 Ctx->getCOFFSection(".ctors",
632 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
633 COFF::IMAGE_SCN_MEM_READ |
634 COFF::IMAGE_SCN_MEM_WRITE,
635 SectionKind::getDataRel());
637 Ctx->getCOFFSection(".dtors",
638 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
639 COFF::IMAGE_SCN_MEM_READ |
640 COFF::IMAGE_SCN_MEM_WRITE,
641 SectionKind::getDataRel());
644 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
645 // though it contains relocatable pointers. In PIC mode, this is probably a
646 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
647 // adjusted or this should be a data section.
648 assert(T.isOSWindows() && "Windows is the only supported COFF target");
649 if (T.getArch() == Triple::x86_64) {
650 // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
653 LSDASection = Ctx->getCOFFSection(".gcc_except_table",
654 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
655 COFF::IMAGE_SCN_MEM_READ,
656 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 TT, 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.
821 Triple::ArchType Arch = T.getArch();
822 // FIXME: Checking for Arch here to filter out bogus triples such as
823 // cellspu-apple-darwin. Perhaps we should fix in Triple?
824 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
825 Arch == Triple::arm || Arch == Triple::thumb ||
826 Arch == Triple::arm64 || Arch == Triple::aarch64 ||
827 Arch == Triple::ppc || Arch == Triple::ppc64 ||
828 Arch == Triple::UnknownArch) &&
829 (T.isOSDarwin() || T.isOSBinFormatMachO())) {
831 InitMachOMCObjectFileInfo(T);
832 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
833 Arch == Triple::arm || Arch == Triple::thumb) &&
834 (T.isOSWindows() && T.getObjectFormat() == Triple::COFF)) {
836 InitCOFFMCObjectFileInfo(T);
839 InitELFMCObjectFileInfo(T);
843 const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
844 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
845 SectionKind::getMetadata(), 0, utostr(Hash));
849 MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
850 return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS,
851 ELF::SHF_GROUP, SectionKind::getMetadata(), 0,
855 void MCObjectFileInfo::InitEHFrameSection() {
858 Ctx->getMachOSection("__TEXT", "__eh_frame",
860 MachO::S_ATTR_NO_TOC |
861 MachO::S_ATTR_STRIP_STATIC_SYMS |
862 MachO::S_ATTR_LIVE_SUPPORT,
863 SectionKind::getReadOnly());
864 else if (Env == IsELF)
866 Ctx->getELFSection(".eh_frame", EHSectionType,
868 SectionKind::getDataRel());
871 Ctx->getCOFFSection(".eh_frame",
872 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
873 COFF::IMAGE_SCN_MEM_READ |
874 COFF::IMAGE_SCN_MEM_WRITE,
875 SectionKind::getDataRel());