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;
27 (T.getArch() == Triple::arm64 || T.getArch() == Triple::aarch64))
28 SupportsCompactUnwindWithoutEHFrame = true;
30 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
31 | dwarf::DW_EH_PE_sdata4;
32 LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
33 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
34 dwarf::DW_EH_PE_sdata4;
36 // .comm doesn't support alignment before Leopard.
37 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
38 CommDirectiveSupportsAlignment = false;
41 = Ctx->getMachOSection("__TEXT", "__text",
42 MachO::S_ATTR_PURE_INSTRUCTIONS,
43 SectionKind::getText());
45 = Ctx->getMachOSection("__DATA", "__data", 0,
46 SectionKind::getDataRel());
48 // BSSSection might not be expected initialized on msvc.
51 TLSDataSection // .tdata
52 = Ctx->getMachOSection("__DATA", "__thread_data",
53 MachO::S_THREAD_LOCAL_REGULAR,
54 SectionKind::getDataRel());
55 TLSBSSSection // .tbss
56 = Ctx->getMachOSection("__DATA", "__thread_bss",
57 MachO::S_THREAD_LOCAL_ZEROFILL,
58 SectionKind::getThreadBSS());
60 // TODO: Verify datarel below.
62 = Ctx->getMachOSection("__DATA", "__thread_vars",
63 MachO::S_THREAD_LOCAL_VARIABLES,
64 SectionKind::getDataRel());
67 = Ctx->getMachOSection("__DATA", "__thread_init",
68 MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
69 SectionKind::getDataRel());
71 CStringSection // .cstring
72 = Ctx->getMachOSection("__TEXT", "__cstring",
73 MachO::S_CSTRING_LITERALS,
74 SectionKind::getMergeable1ByteCString());
76 = Ctx->getMachOSection("__TEXT","__ustring", 0,
77 SectionKind::getMergeable2ByteCString());
78 FourByteConstantSection // .literal4
79 = Ctx->getMachOSection("__TEXT", "__literal4",
80 MachO::S_4BYTE_LITERALS,
81 SectionKind::getMergeableConst4());
82 EightByteConstantSection // .literal8
83 = Ctx->getMachOSection("__TEXT", "__literal8",
84 MachO::S_8BYTE_LITERALS,
85 SectionKind::getMergeableConst8());
87 SixteenByteConstantSection // .literal16
88 = Ctx->getMachOSection("__TEXT", "__literal16",
89 MachO::S_16BYTE_LITERALS,
90 SectionKind::getMergeableConst16());
92 ReadOnlySection // .const
93 = Ctx->getMachOSection("__TEXT", "__const", 0,
94 SectionKind::getReadOnly());
97 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
99 MachO::S_ATTR_PURE_INSTRUCTIONS,
100 SectionKind::getText());
102 = Ctx->getMachOSection("__TEXT", "__const_coal",
104 SectionKind::getReadOnly());
105 ConstDataSection // .const_data
106 = Ctx->getMachOSection("__DATA", "__const", 0,
107 SectionKind::getReadOnlyWithRel());
109 = Ctx->getMachOSection("__DATA","__datacoal_nt",
111 SectionKind::getDataRel());
113 = Ctx->getMachOSection("__DATA","__common",
115 SectionKind::getBSS());
117 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
118 SectionKind::getBSS());
121 LazySymbolPointerSection
122 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
123 MachO::S_LAZY_SYMBOL_POINTERS,
124 SectionKind::getMetadata());
125 NonLazySymbolPointerSection
126 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
127 MachO::S_NON_LAZY_SYMBOL_POINTERS,
128 SectionKind::getMetadata());
130 if (RelocM == Reloc::Static) {
132 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
133 SectionKind::getDataRel());
135 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
136 SectionKind::getDataRel());
139 = Ctx->getMachOSection("__DATA", "__mod_init_func",
140 MachO::S_MOD_INIT_FUNC_POINTERS,
141 SectionKind::getDataRel());
143 = Ctx->getMachOSection("__DATA", "__mod_term_func",
144 MachO::S_MOD_TERM_FUNC_POINTERS,
145 SectionKind::getDataRel());
148 // Exception Handling.
149 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
150 SectionKind::getReadOnlyWithRel());
152 COFFDebugSymbolsSection = nullptr;
154 if ((T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) ||
156 (T.getArch() == Triple::arm64 || T.getArch() == Triple::aarch64))) {
157 CompactUnwindSection =
158 Ctx->getMachOSection("__LD", "__compact_unwind",
160 SectionKind::getReadOnly());
162 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
163 CompactUnwindDwarfEHFrameOnly = 0x04000000;
164 else if (T.getArch() == Triple::arm64 || T.getArch() == Triple::aarch64)
165 CompactUnwindDwarfEHFrameOnly = 0x03000000;
168 // Debug Information.
169 DwarfAccelNamesSection =
170 Ctx->getMachOSection("__DWARF", "__apple_names",
172 SectionKind::getMetadata());
173 DwarfAccelObjCSection =
174 Ctx->getMachOSection("__DWARF", "__apple_objc",
176 SectionKind::getMetadata());
177 // 16 character section limit...
178 DwarfAccelNamespaceSection =
179 Ctx->getMachOSection("__DWARF", "__apple_namespac",
181 SectionKind::getMetadata());
182 DwarfAccelTypesSection =
183 Ctx->getMachOSection("__DWARF", "__apple_types",
185 SectionKind::getMetadata());
188 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
190 SectionKind::getMetadata());
192 Ctx->getMachOSection("__DWARF", "__debug_info",
194 SectionKind::getMetadata());
196 Ctx->getMachOSection("__DWARF", "__debug_line",
198 SectionKind::getMetadata());
200 Ctx->getMachOSection("__DWARF", "__debug_frame",
202 SectionKind::getMetadata());
203 DwarfPubNamesSection =
204 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
206 SectionKind::getMetadata());
207 DwarfPubTypesSection =
208 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
210 SectionKind::getMetadata());
211 DwarfGnuPubNamesSection =
212 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
214 SectionKind::getMetadata());
215 DwarfGnuPubTypesSection =
216 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
218 SectionKind::getMetadata());
220 Ctx->getMachOSection("__DWARF", "__debug_str",
222 SectionKind::getMetadata());
224 Ctx->getMachOSection("__DWARF", "__debug_loc",
226 SectionKind::getMetadata());
227 DwarfARangesSection =
228 Ctx->getMachOSection("__DWARF", "__debug_aranges",
230 SectionKind::getMetadata());
232 Ctx->getMachOSection("__DWARF", "__debug_ranges",
234 SectionKind::getMetadata());
235 DwarfMacroInfoSection =
236 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
238 SectionKind::getMetadata());
239 DwarfDebugInlineSection =
240 Ctx->getMachOSection("__DWARF", "__debug_inlined",
242 SectionKind::getMetadata());
244 Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
245 SectionKind::getMetadata());
247 TLSExtraDataSection = TLSTLVSection;
250 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
251 switch (T.getArch()) {
254 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
257 case Triple::mips64el:
258 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
261 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
265 switch (T.getArch()) {
269 case Triple::thumbeb:
270 if (Ctx->getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
272 // Fallthrough if not using EHABI
274 PersonalityEncoding = (RelocM == Reloc::PIC_)
275 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
276 : dwarf::DW_EH_PE_absptr;
277 LSDAEncoding = (RelocM == Reloc::PIC_)
278 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
279 : dwarf::DW_EH_PE_absptr;
280 TTypeEncoding = (RelocM == Reloc::PIC_)
281 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
282 : dwarf::DW_EH_PE_absptr;
285 if (RelocM == Reloc::PIC_) {
286 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
287 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
288 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
289 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
290 (CMModel == CodeModel::Small
291 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
292 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
293 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
294 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
296 PersonalityEncoding =
297 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
298 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
299 LSDAEncoding = (CMModel == CodeModel::Small)
300 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
301 TTypeEncoding = (CMModel == CodeModel::Small)
302 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
305 case Triple::aarch64:
306 case Triple::aarch64_be:
308 case Triple::arm64_be:
309 // The small model guarantees static code/data size < 4GB, but not where it
310 // will be in memory. Most of these could end up >2GB away so even a signed
311 // pc-relative 32-bit address is insufficient, theoretically.
312 if (RelocM == Reloc::PIC_) {
313 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
314 dwarf::DW_EH_PE_sdata8;
315 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
316 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
317 dwarf::DW_EH_PE_sdata8;
319 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
320 LSDAEncoding = dwarf::DW_EH_PE_absptr;
321 TTypeEncoding = dwarf::DW_EH_PE_absptr;
326 // MIPS uses indirect pointer to refer personality functions, so that the
327 // eh_frame section can be read-only. DW.ref.personality will be generated
329 PersonalityEncoding = dwarf::DW_EH_PE_indirect;
332 case Triple::ppc64le:
333 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
334 dwarf::DW_EH_PE_udata8;
335 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
336 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
337 dwarf::DW_EH_PE_udata8;
340 if (RelocM == Reloc::PIC_) {
341 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
342 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
343 dwarf::DW_EH_PE_sdata4;
344 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
345 dwarf::DW_EH_PE_sdata4;
347 LSDAEncoding = dwarf::DW_EH_PE_absptr;
348 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
349 TTypeEncoding = dwarf::DW_EH_PE_absptr;
352 case Triple::sparcv9:
353 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
354 if (RelocM == Reloc::PIC_) {
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 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
361 TTypeEncoding = dwarf::DW_EH_PE_absptr;
364 case Triple::systemz:
365 // All currently-defined code models guarantee that 4-byte PC-relative
366 // values will be in range.
367 if (RelocM == Reloc::PIC_) {
368 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
369 dwarf::DW_EH_PE_sdata4;
370 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
371 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
372 dwarf::DW_EH_PE_sdata4;
374 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
375 LSDAEncoding = dwarf::DW_EH_PE_absptr;
376 TTypeEncoding = dwarf::DW_EH_PE_absptr;
383 // Solaris requires different flags for .eh_frame to seemingly every other
385 EHSectionType = ELF::SHT_PROGBITS;
386 EHSectionFlags = ELF::SHF_ALLOC;
387 if (T.getOS() == Triple::Solaris) {
388 if (T.getArch() == Triple::x86_64)
389 EHSectionType = ELF::SHT_X86_64_UNWIND;
391 EHSectionFlags |= ELF::SHF_WRITE;
397 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
398 ELF::SHF_WRITE | ELF::SHF_ALLOC,
399 SectionKind::getBSS());
402 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
405 SectionKind::getText());
408 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
409 ELF::SHF_WRITE |ELF::SHF_ALLOC,
410 SectionKind::getDataRel());
413 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
415 SectionKind::getReadOnly());
418 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
419 ELF::SHF_ALLOC | ELF::SHF_TLS |
421 SectionKind::getThreadData());
424 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
425 ELF::SHF_ALLOC | ELF::SHF_TLS |
427 SectionKind::getThreadBSS());
430 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
431 ELF::SHF_ALLOC |ELF::SHF_WRITE,
432 SectionKind::getDataRel());
434 DataRelLocalSection =
435 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
436 ELF::SHF_ALLOC |ELF::SHF_WRITE,
437 SectionKind::getDataRelLocal());
440 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
441 ELF::SHF_ALLOC |ELF::SHF_WRITE,
442 SectionKind::getReadOnlyWithRel());
444 DataRelROLocalSection =
445 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
446 ELF::SHF_ALLOC |ELF::SHF_WRITE,
447 SectionKind::getReadOnlyWithRelLocal());
449 MergeableConst4Section =
450 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
451 ELF::SHF_ALLOC |ELF::SHF_MERGE,
452 SectionKind::getMergeableConst4());
454 MergeableConst8Section =
455 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
456 ELF::SHF_ALLOC |ELF::SHF_MERGE,
457 SectionKind::getMergeableConst8());
459 MergeableConst16Section =
460 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
461 ELF::SHF_ALLOC |ELF::SHF_MERGE,
462 SectionKind::getMergeableConst16());
465 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
466 ELF::SHF_ALLOC |ELF::SHF_WRITE,
467 SectionKind::getDataRel());
470 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
471 ELF::SHF_ALLOC |ELF::SHF_WRITE,
472 SectionKind::getDataRel());
474 // Exception Handling Sections.
476 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
477 // it contains relocatable pointers. In PIC mode, this is probably a big
478 // runtime hit for C++ apps. Either the contents of the LSDA need to be
479 // adjusted or this should be a data section.
481 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
483 SectionKind::getReadOnly());
485 COFFDebugSymbolsSection = nullptr;
487 // Debug Info Sections.
489 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
490 SectionKind::getMetadata());
492 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
493 SectionKind::getMetadata());
495 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
496 SectionKind::getMetadata());
498 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
499 SectionKind::getMetadata());
500 DwarfPubNamesSection =
501 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
502 SectionKind::getMetadata());
503 DwarfPubTypesSection =
504 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
505 SectionKind::getMetadata());
506 DwarfGnuPubNamesSection =
507 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
508 SectionKind::getMetadata());
509 DwarfGnuPubTypesSection =
510 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
511 SectionKind::getMetadata());
513 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
514 ELF::SHF_MERGE | ELF::SHF_STRINGS,
515 SectionKind::getMergeable1ByteCString());
517 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
518 SectionKind::getMetadata());
519 DwarfARangesSection =
520 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
521 SectionKind::getMetadata());
523 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
524 SectionKind::getMetadata());
525 DwarfMacroInfoSection =
526 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
527 SectionKind::getMetadata());
529 // DWARF5 Experimental Debug Info
531 // Accelerator Tables
532 DwarfAccelNamesSection =
533 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
534 SectionKind::getMetadata());
535 DwarfAccelObjCSection =
536 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
537 SectionKind::getMetadata());
538 DwarfAccelNamespaceSection =
539 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
540 SectionKind::getMetadata());
541 DwarfAccelTypesSection =
542 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
543 SectionKind::getMetadata());
546 DwarfInfoDWOSection =
547 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
548 SectionKind::getMetadata());
549 DwarfAbbrevDWOSection =
550 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
551 SectionKind::getMetadata());
553 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
554 ELF::SHF_MERGE | ELF::SHF_STRINGS,
555 SectionKind::getMergeable1ByteCString());
556 DwarfLineDWOSection =
557 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
558 SectionKind::getMetadata());
560 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
561 SectionKind::getMetadata());
562 DwarfStrOffDWOSection =
563 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
564 SectionKind::getMetadata());
566 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
567 SectionKind::getMetadata());
571 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
572 // The object file format cannot represent common symbols with explicit
574 CommDirectiveSupportsAlignment = false;
578 Ctx->getCOFFSection(".bss",
579 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
580 COFF::IMAGE_SCN_MEM_READ |
581 COFF::IMAGE_SCN_MEM_WRITE,
582 SectionKind::getBSS());
584 Ctx->getCOFFSection(".text",
585 COFF::IMAGE_SCN_CNT_CODE |
586 COFF::IMAGE_SCN_MEM_EXECUTE |
587 COFF::IMAGE_SCN_MEM_READ,
588 SectionKind::getText());
590 Ctx->getCOFFSection(".data",
591 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
592 COFF::IMAGE_SCN_MEM_READ |
593 COFF::IMAGE_SCN_MEM_WRITE,
594 SectionKind::getDataRel());
596 Ctx->getCOFFSection(".rdata",
597 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
598 COFF::IMAGE_SCN_MEM_READ,
599 SectionKind::getReadOnly());
600 if (T.isKnownWindowsMSVCEnvironment()) {
602 Ctx->getCOFFSection(".CRT$XCU",
603 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
604 COFF::IMAGE_SCN_MEM_READ,
605 SectionKind::getReadOnly());
608 Ctx->getCOFFSection(".ctors",
609 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
610 COFF::IMAGE_SCN_MEM_READ |
611 COFF::IMAGE_SCN_MEM_WRITE,
612 SectionKind::getDataRel());
616 if (T.isKnownWindowsMSVCEnvironment()) {
618 Ctx->getCOFFSection(".CRT$XTX",
619 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
620 COFF::IMAGE_SCN_MEM_READ,
621 SectionKind::getReadOnly());
624 Ctx->getCOFFSection(".dtors",
625 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
626 COFF::IMAGE_SCN_MEM_READ |
627 COFF::IMAGE_SCN_MEM_WRITE,
628 SectionKind::getDataRel());
631 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
632 // though it contains relocatable pointers. In PIC mode, this is probably a
633 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
634 // adjusted or this should be a data section.
636 Ctx->getCOFFSection(".gcc_except_table",
637 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
638 COFF::IMAGE_SCN_MEM_READ,
639 SectionKind::getReadOnly());
642 COFFDebugSymbolsSection =
643 Ctx->getCOFFSection(".debug$S",
644 COFF::IMAGE_SCN_MEM_DISCARDABLE |
645 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
646 COFF::IMAGE_SCN_MEM_READ,
647 SectionKind::getMetadata());
650 Ctx->getCOFFSection(".debug_abbrev",
651 COFF::IMAGE_SCN_MEM_DISCARDABLE |
652 COFF::IMAGE_SCN_MEM_READ,
653 SectionKind::getMetadata());
655 Ctx->getCOFFSection(".debug_info",
656 COFF::IMAGE_SCN_MEM_DISCARDABLE |
657 COFF::IMAGE_SCN_MEM_READ,
658 SectionKind::getMetadata());
660 Ctx->getCOFFSection(".debug_line",
661 COFF::IMAGE_SCN_MEM_DISCARDABLE |
662 COFF::IMAGE_SCN_MEM_READ,
663 SectionKind::getMetadata());
665 Ctx->getCOFFSection(".debug_frame",
666 COFF::IMAGE_SCN_MEM_DISCARDABLE |
667 COFF::IMAGE_SCN_MEM_READ,
668 SectionKind::getMetadata());
669 DwarfPubNamesSection =
670 Ctx->getCOFFSection(".debug_pubnames",
671 COFF::IMAGE_SCN_MEM_DISCARDABLE |
672 COFF::IMAGE_SCN_MEM_READ,
673 SectionKind::getMetadata());
674 DwarfPubTypesSection =
675 Ctx->getCOFFSection(".debug_pubtypes",
676 COFF::IMAGE_SCN_MEM_DISCARDABLE |
677 COFF::IMAGE_SCN_MEM_READ,
678 SectionKind::getMetadata());
679 DwarfGnuPubNamesSection =
680 Ctx->getCOFFSection(".debug_gnu_pubnames",
681 COFF::IMAGE_SCN_MEM_DISCARDABLE |
682 COFF::IMAGE_SCN_MEM_READ,
683 SectionKind::getMetadata());
684 DwarfGnuPubTypesSection =
685 Ctx->getCOFFSection(".debug_gnu_pubtypes",
686 COFF::IMAGE_SCN_MEM_DISCARDABLE |
687 COFF::IMAGE_SCN_MEM_READ,
688 SectionKind::getMetadata());
690 Ctx->getCOFFSection(".debug_str",
691 COFF::IMAGE_SCN_MEM_DISCARDABLE |
692 COFF::IMAGE_SCN_MEM_READ,
693 SectionKind::getMetadata());
695 Ctx->getCOFFSection(".debug_loc",
696 COFF::IMAGE_SCN_MEM_DISCARDABLE |
697 COFF::IMAGE_SCN_MEM_READ,
698 SectionKind::getMetadata());
699 DwarfARangesSection =
700 Ctx->getCOFFSection(".debug_aranges",
701 COFF::IMAGE_SCN_MEM_DISCARDABLE |
702 COFF::IMAGE_SCN_MEM_READ,
703 SectionKind::getMetadata());
705 Ctx->getCOFFSection(".debug_ranges",
706 COFF::IMAGE_SCN_MEM_DISCARDABLE |
707 COFF::IMAGE_SCN_MEM_READ,
708 SectionKind::getMetadata());
709 DwarfMacroInfoSection =
710 Ctx->getCOFFSection(".debug_macinfo",
711 COFF::IMAGE_SCN_MEM_DISCARDABLE |
712 COFF::IMAGE_SCN_MEM_READ,
713 SectionKind::getMetadata());
714 DwarfInfoDWOSection =
715 Ctx->getCOFFSection(".debug_info.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
716 COFF::IMAGE_SCN_MEM_READ,
717 SectionKind::getMetadata());
718 DwarfAbbrevDWOSection =
719 Ctx->getCOFFSection(".debug_abbrev.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
720 COFF::IMAGE_SCN_MEM_READ,
721 SectionKind::getMetadata());
723 Ctx->getCOFFSection(".debug_str.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
724 COFF::IMAGE_SCN_MEM_READ,
725 SectionKind::getMetadata());
726 DwarfLineDWOSection =
727 Ctx->getCOFFSection(".debug_line.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
728 COFF::IMAGE_SCN_MEM_READ,
729 SectionKind::getMetadata());
731 Ctx->getCOFFSection(".debug_loc.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
732 COFF::IMAGE_SCN_MEM_READ,
733 SectionKind::getMetadata());
734 DwarfStrOffDWOSection =
735 Ctx->getCOFFSection(".debug_str_offsets.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
736 COFF::IMAGE_SCN_MEM_READ,
737 SectionKind::getMetadata());
738 DwarfAddrSection = Ctx->getCOFFSection(
739 ".debug_addr", COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_MEM_READ,
740 SectionKind::getMetadata());
743 Ctx->getCOFFSection(".drectve",
744 COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
745 SectionKind::getMetadata());
748 Ctx->getCOFFSection(".pdata",
749 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
750 COFF::IMAGE_SCN_MEM_READ,
751 SectionKind::getDataRel());
754 Ctx->getCOFFSection(".xdata",
755 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
756 COFF::IMAGE_SCN_MEM_READ,
757 SectionKind::getDataRel());
759 Ctx->getCOFFSection(".tls$",
760 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
761 COFF::IMAGE_SCN_MEM_READ |
762 COFF::IMAGE_SCN_MEM_WRITE,
763 SectionKind::getDataRel());
766 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
774 CommDirectiveSupportsAlignment = true;
775 SupportsWeakOmittedEHFrame = true;
776 IsFunctionEHFrameSymbolPrivate = true;
777 SupportsCompactUnwindWithoutEHFrame = false;
779 PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
780 dwarf::DW_EH_PE_absptr;
782 CompactUnwindDwarfEHFrameOnly = 0;
784 EHFrameSection = nullptr; // Created on demand.
785 CompactUnwindSection = nullptr; // Used only by selected targets.
786 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
787 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
788 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
789 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
792 Triple::ArchType Arch = T.getArch();
793 // FIXME: Checking for Arch here to filter out bogus triples such as
794 // cellspu-apple-darwin. Perhaps we should fix in Triple?
795 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
796 Arch == Triple::arm || Arch == Triple::thumb ||
797 Arch == Triple::arm64 || Arch == Triple::aarch64 ||
798 Arch == Triple::ppc || Arch == Triple::ppc64 ||
799 Arch == Triple::UnknownArch) &&
800 (T.isOSDarwin() || T.isOSBinFormatMachO())) {
802 InitMachOMCObjectFileInfo(T);
803 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
804 Arch == Triple::arm || Arch == Triple::thumb) &&
805 (T.isOSWindows() && T.getObjectFormat() == Triple::COFF)) {
807 InitCOFFMCObjectFileInfo(T);
810 InitELFMCObjectFileInfo(T);
814 const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
815 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
816 SectionKind::getMetadata(), 0, utostr(Hash));
820 MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
821 return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS,
822 ELF::SHF_GROUP, SectionKind::getMetadata(), 0,
826 void MCObjectFileInfo::InitEHFrameSection() {
829 Ctx->getMachOSection("__TEXT", "__eh_frame",
831 MachO::S_ATTR_NO_TOC |
832 MachO::S_ATTR_STRIP_STATIC_SYMS |
833 MachO::S_ATTR_LIVE_SUPPORT,
834 SectionKind::getReadOnly());
835 else if (Env == IsELF)
837 Ctx->getELFSection(".eh_frame", EHSectionType,
839 SectionKind::getDataRel());
842 Ctx->getCOFFSection(".eh_frame",
843 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
844 COFF::IMAGE_SCN_MEM_READ |
845 COFF::IMAGE_SCN_MEM_WRITE,
846 SectionKind::getDataRel());