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 void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
23 IsFunctionEHFrameSymbolPrivate = false;
24 SupportsWeakOmittedEHFrame = false;
26 if (T.isOSDarwin() && T.getArch() == Triple::arm64)
27 SupportsCompactUnwindWithoutEHFrame = true;
29 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
30 | dwarf::DW_EH_PE_sdata4;
31 LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
32 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
33 dwarf::DW_EH_PE_sdata4;
35 // .comm doesn't support alignment before Leopard.
36 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
37 CommDirectiveSupportsAlignment = false;
40 = Ctx->getMachOSection("__TEXT", "__text",
41 MachO::S_ATTR_PURE_INSTRUCTIONS,
42 SectionKind::getText());
44 = Ctx->getMachOSection("__DATA", "__data", 0,
45 SectionKind::getDataRel());
47 // BSSSection might not be expected initialized on msvc.
50 TLSDataSection // .tdata
51 = Ctx->getMachOSection("__DATA", "__thread_data",
52 MachO::S_THREAD_LOCAL_REGULAR,
53 SectionKind::getDataRel());
54 TLSBSSSection // .tbss
55 = Ctx->getMachOSection("__DATA", "__thread_bss",
56 MachO::S_THREAD_LOCAL_ZEROFILL,
57 SectionKind::getThreadBSS());
59 // TODO: Verify datarel below.
61 = Ctx->getMachOSection("__DATA", "__thread_vars",
62 MachO::S_THREAD_LOCAL_VARIABLES,
63 SectionKind::getDataRel());
66 = Ctx->getMachOSection("__DATA", "__thread_init",
67 MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
68 SectionKind::getDataRel());
70 CStringSection // .cstring
71 = Ctx->getMachOSection("__TEXT", "__cstring",
72 MachO::S_CSTRING_LITERALS,
73 SectionKind::getMergeable1ByteCString());
75 = Ctx->getMachOSection("__TEXT","__ustring", 0,
76 SectionKind::getMergeable2ByteCString());
77 FourByteConstantSection // .literal4
78 = Ctx->getMachOSection("__TEXT", "__literal4",
79 MachO::S_4BYTE_LITERALS,
80 SectionKind::getMergeableConst4());
81 EightByteConstantSection // .literal8
82 = Ctx->getMachOSection("__TEXT", "__literal8",
83 MachO::S_8BYTE_LITERALS,
84 SectionKind::getMergeableConst8());
86 SixteenByteConstantSection // .literal16
87 = Ctx->getMachOSection("__TEXT", "__literal16",
88 MachO::S_16BYTE_LITERALS,
89 SectionKind::getMergeableConst16());
91 ReadOnlySection // .const
92 = Ctx->getMachOSection("__TEXT", "__const", 0,
93 SectionKind::getReadOnly());
96 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
98 MachO::S_ATTR_PURE_INSTRUCTIONS,
99 SectionKind::getText());
101 = Ctx->getMachOSection("__TEXT", "__const_coal",
103 SectionKind::getReadOnly());
104 ConstDataSection // .const_data
105 = Ctx->getMachOSection("__DATA", "__const", 0,
106 SectionKind::getReadOnlyWithRel());
108 = Ctx->getMachOSection("__DATA","__datacoal_nt",
110 SectionKind::getDataRel());
112 = Ctx->getMachOSection("__DATA","__common",
114 SectionKind::getBSS());
116 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
117 SectionKind::getBSS());
120 LazySymbolPointerSection
121 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
122 MachO::S_LAZY_SYMBOL_POINTERS,
123 SectionKind::getMetadata());
124 NonLazySymbolPointerSection
125 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
126 MachO::S_NON_LAZY_SYMBOL_POINTERS,
127 SectionKind::getMetadata());
129 if (RelocM == Reloc::Static) {
131 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
132 SectionKind::getDataRel());
134 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
135 SectionKind::getDataRel());
138 = Ctx->getMachOSection("__DATA", "__mod_init_func",
139 MachO::S_MOD_INIT_FUNC_POINTERS,
140 SectionKind::getDataRel());
142 = Ctx->getMachOSection("__DATA", "__mod_term_func",
143 MachO::S_MOD_TERM_FUNC_POINTERS,
144 SectionKind::getDataRel());
147 // Exception Handling.
148 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
149 SectionKind::getReadOnlyWithRel());
151 COFFDebugSymbolsSection = nullptr;
153 if ((T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) ||
154 (T.isOSDarwin() && T.getArch() == Triple::arm64)) {
155 CompactUnwindSection =
156 Ctx->getMachOSection("__LD", "__compact_unwind",
158 SectionKind::getReadOnly());
160 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
161 CompactUnwindDwarfEHFrameOnly = 0x04000000;
162 else if (T.getArch() == Triple::arm64)
163 CompactUnwindDwarfEHFrameOnly = 0x03000000;
166 // Debug Information.
167 DwarfAccelNamesSection =
168 Ctx->getMachOSection("__DWARF", "__apple_names",
170 SectionKind::getMetadata());
171 DwarfAccelObjCSection =
172 Ctx->getMachOSection("__DWARF", "__apple_objc",
174 SectionKind::getMetadata());
175 // 16 character section limit...
176 DwarfAccelNamespaceSection =
177 Ctx->getMachOSection("__DWARF", "__apple_namespac",
179 SectionKind::getMetadata());
180 DwarfAccelTypesSection =
181 Ctx->getMachOSection("__DWARF", "__apple_types",
183 SectionKind::getMetadata());
186 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
188 SectionKind::getMetadata());
190 Ctx->getMachOSection("__DWARF", "__debug_info",
192 SectionKind::getMetadata());
194 Ctx->getMachOSection("__DWARF", "__debug_line",
196 SectionKind::getMetadata());
198 Ctx->getMachOSection("__DWARF", "__debug_frame",
200 SectionKind::getMetadata());
201 DwarfPubNamesSection =
202 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
204 SectionKind::getMetadata());
205 DwarfPubTypesSection =
206 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
208 SectionKind::getMetadata());
209 DwarfGnuPubNamesSection =
210 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
212 SectionKind::getMetadata());
213 DwarfGnuPubTypesSection =
214 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
216 SectionKind::getMetadata());
218 Ctx->getMachOSection("__DWARF", "__debug_str",
220 SectionKind::getMetadata());
222 Ctx->getMachOSection("__DWARF", "__debug_loc",
224 SectionKind::getMetadata());
225 DwarfARangesSection =
226 Ctx->getMachOSection("__DWARF", "__debug_aranges",
228 SectionKind::getMetadata());
230 Ctx->getMachOSection("__DWARF", "__debug_ranges",
232 SectionKind::getMetadata());
233 DwarfMacroInfoSection =
234 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
236 SectionKind::getMetadata());
237 DwarfDebugInlineSection =
238 Ctx->getMachOSection("__DWARF", "__debug_inlined",
240 SectionKind::getMetadata());
242 Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
243 SectionKind::getMetadata());
245 TLSExtraDataSection = TLSTLVSection;
248 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
249 switch (T.getArch()) {
252 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
255 case Triple::mips64el:
256 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
259 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
263 switch (T.getArch()) {
267 case Triple::thumbeb:
268 if (Ctx->getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
270 // Fallthrough if not using EHABI
272 PersonalityEncoding = (RelocM == Reloc::PIC_)
273 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
274 : dwarf::DW_EH_PE_absptr;
275 LSDAEncoding = (RelocM == Reloc::PIC_)
276 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
277 : dwarf::DW_EH_PE_absptr;
278 TTypeEncoding = (RelocM == Reloc::PIC_)
279 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
280 : dwarf::DW_EH_PE_absptr;
283 if (RelocM == Reloc::PIC_) {
284 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
285 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
286 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
287 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
288 (CMModel == CodeModel::Small
289 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
290 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
291 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
292 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
294 PersonalityEncoding =
295 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
296 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
297 LSDAEncoding = (CMModel == CodeModel::Small)
298 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
299 TTypeEncoding = (CMModel == CodeModel::Small)
300 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
303 case Triple::aarch64:
304 case Triple::aarch64_be:
306 case Triple::arm64_be:
307 // The small model guarantees static code/data size < 4GB, but not where it
308 // will be in memory. Most of these could end up >2GB away so even a signed
309 // pc-relative 32-bit address is insufficient, theoretically.
310 if (RelocM == Reloc::PIC_) {
311 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
312 dwarf::DW_EH_PE_sdata8;
313 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
314 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
315 dwarf::DW_EH_PE_sdata8;
317 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
318 LSDAEncoding = dwarf::DW_EH_PE_absptr;
319 TTypeEncoding = dwarf::DW_EH_PE_absptr;
323 case Triple::ppc64le:
324 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
325 dwarf::DW_EH_PE_udata8;
326 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
327 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
328 dwarf::DW_EH_PE_udata8;
331 if (RelocM == Reloc::PIC_) {
332 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
333 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
334 dwarf::DW_EH_PE_sdata4;
335 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
336 dwarf::DW_EH_PE_sdata4;
338 LSDAEncoding = dwarf::DW_EH_PE_absptr;
339 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
340 TTypeEncoding = dwarf::DW_EH_PE_absptr;
343 case Triple::sparcv9:
344 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
345 if (RelocM == Reloc::PIC_) {
346 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
347 dwarf::DW_EH_PE_sdata4;
348 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
349 dwarf::DW_EH_PE_sdata4;
351 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
352 TTypeEncoding = dwarf::DW_EH_PE_absptr;
355 case Triple::systemz:
356 // All currently-defined code models guarantee that 4-byte PC-relative
357 // values will be in range.
358 if (RelocM == Reloc::PIC_) {
359 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
360 dwarf::DW_EH_PE_sdata4;
361 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
362 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
363 dwarf::DW_EH_PE_sdata4;
365 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
366 LSDAEncoding = dwarf::DW_EH_PE_absptr;
367 TTypeEncoding = dwarf::DW_EH_PE_absptr;
374 // Solaris requires different flags for .eh_frame to seemingly every other
376 EHSectionType = ELF::SHT_PROGBITS;
377 EHSectionFlags = ELF::SHF_ALLOC;
378 if (T.getOS() == Triple::Solaris) {
379 if (T.getArch() == Triple::x86_64)
380 EHSectionType = ELF::SHT_X86_64_UNWIND;
382 EHSectionFlags |= ELF::SHF_WRITE;
388 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
389 ELF::SHF_WRITE | ELF::SHF_ALLOC,
390 SectionKind::getBSS());
393 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
396 SectionKind::getText());
399 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
400 ELF::SHF_WRITE |ELF::SHF_ALLOC,
401 SectionKind::getDataRel());
404 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
406 SectionKind::getReadOnly());
409 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
410 ELF::SHF_ALLOC | ELF::SHF_TLS |
412 SectionKind::getThreadData());
415 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
416 ELF::SHF_ALLOC | ELF::SHF_TLS |
418 SectionKind::getThreadBSS());
421 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
422 ELF::SHF_ALLOC |ELF::SHF_WRITE,
423 SectionKind::getDataRel());
425 DataRelLocalSection =
426 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
427 ELF::SHF_ALLOC |ELF::SHF_WRITE,
428 SectionKind::getDataRelLocal());
431 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
432 ELF::SHF_ALLOC |ELF::SHF_WRITE,
433 SectionKind::getReadOnlyWithRel());
435 DataRelROLocalSection =
436 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
437 ELF::SHF_ALLOC |ELF::SHF_WRITE,
438 SectionKind::getReadOnlyWithRelLocal());
440 MergeableConst4Section =
441 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
442 ELF::SHF_ALLOC |ELF::SHF_MERGE,
443 SectionKind::getMergeableConst4());
445 MergeableConst8Section =
446 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
447 ELF::SHF_ALLOC |ELF::SHF_MERGE,
448 SectionKind::getMergeableConst8());
450 MergeableConst16Section =
451 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
452 ELF::SHF_ALLOC |ELF::SHF_MERGE,
453 SectionKind::getMergeableConst16());
456 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
457 ELF::SHF_ALLOC |ELF::SHF_WRITE,
458 SectionKind::getDataRel());
461 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
462 ELF::SHF_ALLOC |ELF::SHF_WRITE,
463 SectionKind::getDataRel());
465 // Exception Handling Sections.
467 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
468 // it contains relocatable pointers. In PIC mode, this is probably a big
469 // runtime hit for C++ apps. Either the contents of the LSDA need to be
470 // adjusted or this should be a data section.
472 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
474 SectionKind::getReadOnly());
476 COFFDebugSymbolsSection = nullptr;
478 // Debug Info Sections.
480 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
481 SectionKind::getMetadata());
483 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
484 SectionKind::getMetadata());
486 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
487 SectionKind::getMetadata());
489 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
490 SectionKind::getMetadata());
491 DwarfPubNamesSection =
492 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
493 SectionKind::getMetadata());
494 DwarfPubTypesSection =
495 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
496 SectionKind::getMetadata());
497 DwarfGnuPubNamesSection =
498 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
499 SectionKind::getMetadata());
500 DwarfGnuPubTypesSection =
501 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
502 SectionKind::getMetadata());
504 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
505 ELF::SHF_MERGE | ELF::SHF_STRINGS,
506 SectionKind::getMergeable1ByteCString());
508 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
509 SectionKind::getMetadata());
510 DwarfARangesSection =
511 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
512 SectionKind::getMetadata());
514 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
515 SectionKind::getMetadata());
516 DwarfMacroInfoSection =
517 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
518 SectionKind::getMetadata());
520 // DWARF5 Experimental Debug Info
522 // Accelerator Tables
523 DwarfAccelNamesSection =
524 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
525 SectionKind::getMetadata());
526 DwarfAccelObjCSection =
527 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
528 SectionKind::getMetadata());
529 DwarfAccelNamespaceSection =
530 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
531 SectionKind::getMetadata());
532 DwarfAccelTypesSection =
533 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
534 SectionKind::getMetadata());
537 DwarfInfoDWOSection =
538 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
539 SectionKind::getMetadata());
540 DwarfAbbrevDWOSection =
541 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
542 SectionKind::getMetadata());
544 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
545 ELF::SHF_MERGE | ELF::SHF_STRINGS,
546 SectionKind::getMergeable1ByteCString());
547 DwarfLineDWOSection =
548 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
549 SectionKind::getMetadata());
551 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
552 SectionKind::getMetadata());
553 DwarfStrOffDWOSection =
554 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
555 SectionKind::getMetadata());
557 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
558 SectionKind::getMetadata());
562 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
563 // The object file format cannot represent common symbols with explicit
565 CommDirectiveSupportsAlignment = false;
569 Ctx->getCOFFSection(".bss",
570 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
571 COFF::IMAGE_SCN_MEM_READ |
572 COFF::IMAGE_SCN_MEM_WRITE,
573 SectionKind::getBSS());
575 Ctx->getCOFFSection(".text",
576 COFF::IMAGE_SCN_CNT_CODE |
577 COFF::IMAGE_SCN_MEM_EXECUTE |
578 COFF::IMAGE_SCN_MEM_READ,
579 SectionKind::getText());
581 Ctx->getCOFFSection(".data",
582 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
583 COFF::IMAGE_SCN_MEM_READ |
584 COFF::IMAGE_SCN_MEM_WRITE,
585 SectionKind::getDataRel());
587 Ctx->getCOFFSection(".rdata",
588 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
589 COFF::IMAGE_SCN_MEM_READ,
590 SectionKind::getReadOnly());
591 if (T.isKnownWindowsMSVCEnvironment()) {
593 Ctx->getCOFFSection(".CRT$XCU",
594 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
595 COFF::IMAGE_SCN_MEM_READ,
596 SectionKind::getReadOnly());
599 Ctx->getCOFFSection(".ctors",
600 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
601 COFF::IMAGE_SCN_MEM_READ |
602 COFF::IMAGE_SCN_MEM_WRITE,
603 SectionKind::getDataRel());
607 if (T.isKnownWindowsMSVCEnvironment()) {
609 Ctx->getCOFFSection(".CRT$XTX",
610 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
611 COFF::IMAGE_SCN_MEM_READ,
612 SectionKind::getReadOnly());
615 Ctx->getCOFFSection(".dtors",
616 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
617 COFF::IMAGE_SCN_MEM_READ |
618 COFF::IMAGE_SCN_MEM_WRITE,
619 SectionKind::getDataRel());
622 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
623 // though it contains relocatable pointers. In PIC mode, this is probably a
624 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
625 // adjusted or this should be a data section.
627 Ctx->getCOFFSection(".gcc_except_table",
628 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
629 COFF::IMAGE_SCN_MEM_READ,
630 SectionKind::getReadOnly());
633 COFFDebugSymbolsSection =
634 Ctx->getCOFFSection(".debug$S",
635 COFF::IMAGE_SCN_MEM_DISCARDABLE |
636 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
637 COFF::IMAGE_SCN_MEM_READ,
638 SectionKind::getMetadata());
641 Ctx->getCOFFSection(".debug_abbrev",
642 COFF::IMAGE_SCN_MEM_DISCARDABLE |
643 COFF::IMAGE_SCN_MEM_READ,
644 SectionKind::getMetadata());
646 Ctx->getCOFFSection(".debug_info",
647 COFF::IMAGE_SCN_MEM_DISCARDABLE |
648 COFF::IMAGE_SCN_MEM_READ,
649 SectionKind::getMetadata());
651 Ctx->getCOFFSection(".debug_line",
652 COFF::IMAGE_SCN_MEM_DISCARDABLE |
653 COFF::IMAGE_SCN_MEM_READ,
654 SectionKind::getMetadata());
656 Ctx->getCOFFSection(".debug_frame",
657 COFF::IMAGE_SCN_MEM_DISCARDABLE |
658 COFF::IMAGE_SCN_MEM_READ,
659 SectionKind::getMetadata());
660 DwarfPubNamesSection =
661 Ctx->getCOFFSection(".debug_pubnames",
662 COFF::IMAGE_SCN_MEM_DISCARDABLE |
663 COFF::IMAGE_SCN_MEM_READ,
664 SectionKind::getMetadata());
665 DwarfPubTypesSection =
666 Ctx->getCOFFSection(".debug_pubtypes",
667 COFF::IMAGE_SCN_MEM_DISCARDABLE |
668 COFF::IMAGE_SCN_MEM_READ,
669 SectionKind::getMetadata());
670 DwarfGnuPubNamesSection =
671 Ctx->getCOFFSection(".debug_gnu_pubnames",
672 COFF::IMAGE_SCN_MEM_DISCARDABLE |
673 COFF::IMAGE_SCN_MEM_READ,
674 SectionKind::getMetadata());
675 DwarfGnuPubTypesSection =
676 Ctx->getCOFFSection(".debug_gnu_pubtypes",
677 COFF::IMAGE_SCN_MEM_DISCARDABLE |
678 COFF::IMAGE_SCN_MEM_READ,
679 SectionKind::getMetadata());
681 Ctx->getCOFFSection(".debug_str",
682 COFF::IMAGE_SCN_MEM_DISCARDABLE |
683 COFF::IMAGE_SCN_MEM_READ,
684 SectionKind::getMetadata());
686 Ctx->getCOFFSection(".debug_loc",
687 COFF::IMAGE_SCN_MEM_DISCARDABLE |
688 COFF::IMAGE_SCN_MEM_READ,
689 SectionKind::getMetadata());
690 DwarfARangesSection =
691 Ctx->getCOFFSection(".debug_aranges",
692 COFF::IMAGE_SCN_MEM_DISCARDABLE |
693 COFF::IMAGE_SCN_MEM_READ,
694 SectionKind::getMetadata());
696 Ctx->getCOFFSection(".debug_ranges",
697 COFF::IMAGE_SCN_MEM_DISCARDABLE |
698 COFF::IMAGE_SCN_MEM_READ,
699 SectionKind::getMetadata());
700 DwarfMacroInfoSection =
701 Ctx->getCOFFSection(".debug_macinfo",
702 COFF::IMAGE_SCN_MEM_DISCARDABLE |
703 COFF::IMAGE_SCN_MEM_READ,
704 SectionKind::getMetadata());
705 DwarfInfoDWOSection =
706 Ctx->getCOFFSection(".debug_info.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
707 COFF::IMAGE_SCN_MEM_READ,
708 SectionKind::getMetadata());
709 DwarfAbbrevDWOSection =
710 Ctx->getCOFFSection(".debug_abbrev.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
711 COFF::IMAGE_SCN_MEM_READ,
712 SectionKind::getMetadata());
714 Ctx->getCOFFSection(".debug_str.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
715 COFF::IMAGE_SCN_MEM_READ,
716 SectionKind::getMetadata());
717 DwarfLineDWOSection =
718 Ctx->getCOFFSection(".debug_line.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
719 COFF::IMAGE_SCN_MEM_READ,
720 SectionKind::getMetadata());
722 Ctx->getCOFFSection(".debug_loc.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
723 COFF::IMAGE_SCN_MEM_READ,
724 SectionKind::getMetadata());
725 DwarfStrOffDWOSection =
726 Ctx->getCOFFSection(".debug_str_offsets.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
727 COFF::IMAGE_SCN_MEM_READ,
728 SectionKind::getMetadata());
729 DwarfAddrSection = Ctx->getCOFFSection(
730 ".debug_addr", COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_MEM_READ,
731 SectionKind::getMetadata());
734 Ctx->getCOFFSection(".drectve",
735 COFF::IMAGE_SCN_LNK_INFO,
736 SectionKind::getMetadata());
739 Ctx->getCOFFSection(".pdata",
740 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
741 COFF::IMAGE_SCN_MEM_READ,
742 SectionKind::getDataRel());
745 Ctx->getCOFFSection(".xdata",
746 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
747 COFF::IMAGE_SCN_MEM_READ,
748 SectionKind::getDataRel());
750 Ctx->getCOFFSection(".tls$",
751 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
752 COFF::IMAGE_SCN_MEM_READ |
753 COFF::IMAGE_SCN_MEM_WRITE,
754 SectionKind::getDataRel());
757 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
765 CommDirectiveSupportsAlignment = true;
766 SupportsWeakOmittedEHFrame = true;
767 IsFunctionEHFrameSymbolPrivate = true;
768 SupportsCompactUnwindWithoutEHFrame = false;
770 PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
771 dwarf::DW_EH_PE_absptr;
773 CompactUnwindDwarfEHFrameOnly = 0;
775 EHFrameSection = nullptr; // Created on demand.
776 CompactUnwindSection = nullptr; // Used only by selected targets.
777 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
778 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
779 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
780 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
783 Triple::ArchType Arch = T.getArch();
784 // FIXME: Checking for Arch here to filter out bogus triples such as
785 // cellspu-apple-darwin. Perhaps we should fix in Triple?
786 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
787 Arch == Triple::arm || Arch == Triple::thumb ||
788 Arch == Triple::arm64 ||
789 Arch == Triple::ppc || Arch == Triple::ppc64 ||
790 Arch == Triple::UnknownArch) &&
791 (T.isOSDarwin() || T.isOSBinFormatMachO())) {
793 InitMachOMCObjectFileInfo(T);
794 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
795 Arch == Triple::arm || Arch == Triple::thumb) &&
796 (T.isOSWindows() && T.getObjectFormat() == Triple::COFF)) {
798 InitCOFFMCObjectFileInfo(T);
801 InitELFMCObjectFileInfo(T);
805 const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
806 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
807 SectionKind::getMetadata(), 0, utostr(Hash));
811 MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
812 return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS,
813 ELF::SHF_GROUP, SectionKind::getMetadata(), 0,
817 void MCObjectFileInfo::InitEHFrameSection() {
820 Ctx->getMachOSection("__TEXT", "__eh_frame",
822 MachO::S_ATTR_NO_TOC |
823 MachO::S_ATTR_STRIP_STATIC_SYMS |
824 MachO::S_ATTR_LIVE_SUPPORT,
825 SectionKind::getReadOnly());
826 else if (Env == IsELF)
828 Ctx->getELFSection(".eh_frame", EHSectionType,
830 SectionKind::getDataRel());
833 Ctx->getCOFFSection(".eh_frame",
834 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
835 COFF::IMAGE_SCN_MEM_READ |
836 COFF::IMAGE_SCN_MEM_WRITE,
837 SectionKind::getDataRel());