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;
325 case Triple::ppc64le:
326 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
327 dwarf::DW_EH_PE_udata8;
328 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
329 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
330 dwarf::DW_EH_PE_udata8;
333 if (RelocM == Reloc::PIC_) {
334 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
335 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
336 dwarf::DW_EH_PE_sdata4;
337 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
338 dwarf::DW_EH_PE_sdata4;
340 LSDAEncoding = dwarf::DW_EH_PE_absptr;
341 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
342 TTypeEncoding = dwarf::DW_EH_PE_absptr;
345 case Triple::sparcv9:
346 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
347 if (RelocM == Reloc::PIC_) {
348 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
349 dwarf::DW_EH_PE_sdata4;
350 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
351 dwarf::DW_EH_PE_sdata4;
353 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
354 TTypeEncoding = dwarf::DW_EH_PE_absptr;
357 case Triple::systemz:
358 // All currently-defined code models guarantee that 4-byte PC-relative
359 // values will be in range.
360 if (RelocM == Reloc::PIC_) {
361 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
362 dwarf::DW_EH_PE_sdata4;
363 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
364 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
365 dwarf::DW_EH_PE_sdata4;
367 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
368 LSDAEncoding = dwarf::DW_EH_PE_absptr;
369 TTypeEncoding = dwarf::DW_EH_PE_absptr;
376 // Solaris requires different flags for .eh_frame to seemingly every other
378 EHSectionType = ELF::SHT_PROGBITS;
379 EHSectionFlags = ELF::SHF_ALLOC;
380 if (T.getOS() == Triple::Solaris) {
381 if (T.getArch() == Triple::x86_64)
382 EHSectionType = ELF::SHT_X86_64_UNWIND;
384 EHSectionFlags |= ELF::SHF_WRITE;
390 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
391 ELF::SHF_WRITE | ELF::SHF_ALLOC,
392 SectionKind::getBSS());
395 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
398 SectionKind::getText());
401 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
402 ELF::SHF_WRITE |ELF::SHF_ALLOC,
403 SectionKind::getDataRel());
406 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
408 SectionKind::getReadOnly());
411 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
412 ELF::SHF_ALLOC | ELF::SHF_TLS |
414 SectionKind::getThreadData());
417 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
418 ELF::SHF_ALLOC | ELF::SHF_TLS |
420 SectionKind::getThreadBSS());
423 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
424 ELF::SHF_ALLOC |ELF::SHF_WRITE,
425 SectionKind::getDataRel());
427 DataRelLocalSection =
428 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
429 ELF::SHF_ALLOC |ELF::SHF_WRITE,
430 SectionKind::getDataRelLocal());
433 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
434 ELF::SHF_ALLOC |ELF::SHF_WRITE,
435 SectionKind::getReadOnlyWithRel());
437 DataRelROLocalSection =
438 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
439 ELF::SHF_ALLOC |ELF::SHF_WRITE,
440 SectionKind::getReadOnlyWithRelLocal());
442 MergeableConst4Section =
443 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
444 ELF::SHF_ALLOC |ELF::SHF_MERGE,
445 SectionKind::getMergeableConst4());
447 MergeableConst8Section =
448 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
449 ELF::SHF_ALLOC |ELF::SHF_MERGE,
450 SectionKind::getMergeableConst8());
452 MergeableConst16Section =
453 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
454 ELF::SHF_ALLOC |ELF::SHF_MERGE,
455 SectionKind::getMergeableConst16());
458 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
459 ELF::SHF_ALLOC |ELF::SHF_WRITE,
460 SectionKind::getDataRel());
463 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
464 ELF::SHF_ALLOC |ELF::SHF_WRITE,
465 SectionKind::getDataRel());
467 // Exception Handling Sections.
469 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
470 // it contains relocatable pointers. In PIC mode, this is probably a big
471 // runtime hit for C++ apps. Either the contents of the LSDA need to be
472 // adjusted or this should be a data section.
474 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
476 SectionKind::getReadOnly());
478 COFFDebugSymbolsSection = nullptr;
480 // Debug Info Sections.
482 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
483 SectionKind::getMetadata());
485 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
486 SectionKind::getMetadata());
488 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
489 SectionKind::getMetadata());
491 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
492 SectionKind::getMetadata());
493 DwarfPubNamesSection =
494 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
495 SectionKind::getMetadata());
496 DwarfPubTypesSection =
497 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
498 SectionKind::getMetadata());
499 DwarfGnuPubNamesSection =
500 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
501 SectionKind::getMetadata());
502 DwarfGnuPubTypesSection =
503 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
504 SectionKind::getMetadata());
506 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
507 ELF::SHF_MERGE | ELF::SHF_STRINGS,
508 SectionKind::getMergeable1ByteCString());
510 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
511 SectionKind::getMetadata());
512 DwarfARangesSection =
513 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
514 SectionKind::getMetadata());
516 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
517 SectionKind::getMetadata());
518 DwarfMacroInfoSection =
519 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
520 SectionKind::getMetadata());
522 // DWARF5 Experimental Debug Info
524 // Accelerator Tables
525 DwarfAccelNamesSection =
526 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
527 SectionKind::getMetadata());
528 DwarfAccelObjCSection =
529 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
530 SectionKind::getMetadata());
531 DwarfAccelNamespaceSection =
532 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
533 SectionKind::getMetadata());
534 DwarfAccelTypesSection =
535 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
536 SectionKind::getMetadata());
539 DwarfInfoDWOSection =
540 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
541 SectionKind::getMetadata());
542 DwarfAbbrevDWOSection =
543 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
544 SectionKind::getMetadata());
546 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
547 ELF::SHF_MERGE | ELF::SHF_STRINGS,
548 SectionKind::getMergeable1ByteCString());
549 DwarfLineDWOSection =
550 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
551 SectionKind::getMetadata());
553 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
554 SectionKind::getMetadata());
555 DwarfStrOffDWOSection =
556 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
557 SectionKind::getMetadata());
559 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
560 SectionKind::getMetadata());
564 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
565 // The object file format cannot represent common symbols with explicit
567 CommDirectiveSupportsAlignment = false;
571 Ctx->getCOFFSection(".bss",
572 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
573 COFF::IMAGE_SCN_MEM_READ |
574 COFF::IMAGE_SCN_MEM_WRITE,
575 SectionKind::getBSS());
577 Ctx->getCOFFSection(".text",
578 COFF::IMAGE_SCN_CNT_CODE |
579 COFF::IMAGE_SCN_MEM_EXECUTE |
580 COFF::IMAGE_SCN_MEM_READ,
581 SectionKind::getText());
583 Ctx->getCOFFSection(".data",
584 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
585 COFF::IMAGE_SCN_MEM_READ |
586 COFF::IMAGE_SCN_MEM_WRITE,
587 SectionKind::getDataRel());
589 Ctx->getCOFFSection(".rdata",
590 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
591 COFF::IMAGE_SCN_MEM_READ,
592 SectionKind::getReadOnly());
593 if (T.isKnownWindowsMSVCEnvironment()) {
595 Ctx->getCOFFSection(".CRT$XCU",
596 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
597 COFF::IMAGE_SCN_MEM_READ,
598 SectionKind::getReadOnly());
601 Ctx->getCOFFSection(".ctors",
602 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
603 COFF::IMAGE_SCN_MEM_READ |
604 COFF::IMAGE_SCN_MEM_WRITE,
605 SectionKind::getDataRel());
609 if (T.isKnownWindowsMSVCEnvironment()) {
611 Ctx->getCOFFSection(".CRT$XTX",
612 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
613 COFF::IMAGE_SCN_MEM_READ,
614 SectionKind::getReadOnly());
617 Ctx->getCOFFSection(".dtors",
618 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
619 COFF::IMAGE_SCN_MEM_READ |
620 COFF::IMAGE_SCN_MEM_WRITE,
621 SectionKind::getDataRel());
624 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
625 // though it contains relocatable pointers. In PIC mode, this is probably a
626 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
627 // adjusted or this should be a data section.
629 Ctx->getCOFFSection(".gcc_except_table",
630 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
631 COFF::IMAGE_SCN_MEM_READ,
632 SectionKind::getReadOnly());
635 COFFDebugSymbolsSection =
636 Ctx->getCOFFSection(".debug$S",
637 COFF::IMAGE_SCN_MEM_DISCARDABLE |
638 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
639 COFF::IMAGE_SCN_MEM_READ,
640 SectionKind::getMetadata());
643 Ctx->getCOFFSection(".debug_abbrev",
644 COFF::IMAGE_SCN_MEM_DISCARDABLE |
645 COFF::IMAGE_SCN_MEM_READ,
646 SectionKind::getMetadata());
648 Ctx->getCOFFSection(".debug_info",
649 COFF::IMAGE_SCN_MEM_DISCARDABLE |
650 COFF::IMAGE_SCN_MEM_READ,
651 SectionKind::getMetadata());
653 Ctx->getCOFFSection(".debug_line",
654 COFF::IMAGE_SCN_MEM_DISCARDABLE |
655 COFF::IMAGE_SCN_MEM_READ,
656 SectionKind::getMetadata());
658 Ctx->getCOFFSection(".debug_frame",
659 COFF::IMAGE_SCN_MEM_DISCARDABLE |
660 COFF::IMAGE_SCN_MEM_READ,
661 SectionKind::getMetadata());
662 DwarfPubNamesSection =
663 Ctx->getCOFFSection(".debug_pubnames",
664 COFF::IMAGE_SCN_MEM_DISCARDABLE |
665 COFF::IMAGE_SCN_MEM_READ,
666 SectionKind::getMetadata());
667 DwarfPubTypesSection =
668 Ctx->getCOFFSection(".debug_pubtypes",
669 COFF::IMAGE_SCN_MEM_DISCARDABLE |
670 COFF::IMAGE_SCN_MEM_READ,
671 SectionKind::getMetadata());
672 DwarfGnuPubNamesSection =
673 Ctx->getCOFFSection(".debug_gnu_pubnames",
674 COFF::IMAGE_SCN_MEM_DISCARDABLE |
675 COFF::IMAGE_SCN_MEM_READ,
676 SectionKind::getMetadata());
677 DwarfGnuPubTypesSection =
678 Ctx->getCOFFSection(".debug_gnu_pubtypes",
679 COFF::IMAGE_SCN_MEM_DISCARDABLE |
680 COFF::IMAGE_SCN_MEM_READ,
681 SectionKind::getMetadata());
683 Ctx->getCOFFSection(".debug_str",
684 COFF::IMAGE_SCN_MEM_DISCARDABLE |
685 COFF::IMAGE_SCN_MEM_READ,
686 SectionKind::getMetadata());
688 Ctx->getCOFFSection(".debug_loc",
689 COFF::IMAGE_SCN_MEM_DISCARDABLE |
690 COFF::IMAGE_SCN_MEM_READ,
691 SectionKind::getMetadata());
692 DwarfARangesSection =
693 Ctx->getCOFFSection(".debug_aranges",
694 COFF::IMAGE_SCN_MEM_DISCARDABLE |
695 COFF::IMAGE_SCN_MEM_READ,
696 SectionKind::getMetadata());
698 Ctx->getCOFFSection(".debug_ranges",
699 COFF::IMAGE_SCN_MEM_DISCARDABLE |
700 COFF::IMAGE_SCN_MEM_READ,
701 SectionKind::getMetadata());
702 DwarfMacroInfoSection =
703 Ctx->getCOFFSection(".debug_macinfo",
704 COFF::IMAGE_SCN_MEM_DISCARDABLE |
705 COFF::IMAGE_SCN_MEM_READ,
706 SectionKind::getMetadata());
707 DwarfInfoDWOSection =
708 Ctx->getCOFFSection(".debug_info.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
709 COFF::IMAGE_SCN_MEM_READ,
710 SectionKind::getMetadata());
711 DwarfAbbrevDWOSection =
712 Ctx->getCOFFSection(".debug_abbrev.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
713 COFF::IMAGE_SCN_MEM_READ,
714 SectionKind::getMetadata());
716 Ctx->getCOFFSection(".debug_str.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
717 COFF::IMAGE_SCN_MEM_READ,
718 SectionKind::getMetadata());
719 DwarfLineDWOSection =
720 Ctx->getCOFFSection(".debug_line.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
721 COFF::IMAGE_SCN_MEM_READ,
722 SectionKind::getMetadata());
724 Ctx->getCOFFSection(".debug_loc.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
725 COFF::IMAGE_SCN_MEM_READ,
726 SectionKind::getMetadata());
727 DwarfStrOffDWOSection =
728 Ctx->getCOFFSection(".debug_str_offsets.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
729 COFF::IMAGE_SCN_MEM_READ,
730 SectionKind::getMetadata());
731 DwarfAddrSection = Ctx->getCOFFSection(
732 ".debug_addr", COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_MEM_READ,
733 SectionKind::getMetadata());
736 Ctx->getCOFFSection(".drectve",
737 COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
738 SectionKind::getMetadata());
741 Ctx->getCOFFSection(".pdata",
742 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
743 COFF::IMAGE_SCN_MEM_READ,
744 SectionKind::getDataRel());
747 Ctx->getCOFFSection(".xdata",
748 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
749 COFF::IMAGE_SCN_MEM_READ,
750 SectionKind::getDataRel());
752 Ctx->getCOFFSection(".tls$",
753 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
754 COFF::IMAGE_SCN_MEM_READ |
755 COFF::IMAGE_SCN_MEM_WRITE,
756 SectionKind::getDataRel());
759 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
767 CommDirectiveSupportsAlignment = true;
768 SupportsWeakOmittedEHFrame = true;
769 IsFunctionEHFrameSymbolPrivate = true;
770 SupportsCompactUnwindWithoutEHFrame = false;
772 PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
773 dwarf::DW_EH_PE_absptr;
775 CompactUnwindDwarfEHFrameOnly = 0;
777 EHFrameSection = nullptr; // Created on demand.
778 CompactUnwindSection = nullptr; // Used only by selected targets.
779 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
780 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
781 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
782 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
785 Triple::ArchType Arch = T.getArch();
786 // FIXME: Checking for Arch here to filter out bogus triples such as
787 // cellspu-apple-darwin. Perhaps we should fix in Triple?
788 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
789 Arch == Triple::arm || Arch == Triple::thumb ||
790 Arch == Triple::arm64 || Arch == Triple::aarch64 ||
791 Arch == Triple::ppc || Arch == Triple::ppc64 ||
792 Arch == Triple::UnknownArch) &&
793 (T.isOSDarwin() || T.isOSBinFormatMachO())) {
795 InitMachOMCObjectFileInfo(T);
796 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
797 Arch == Triple::arm || Arch == Triple::thumb) &&
798 (T.isOSWindows() && T.getObjectFormat() == Triple::COFF)) {
800 InitCOFFMCObjectFileInfo(T);
803 InitELFMCObjectFileInfo(T);
807 const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
808 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
809 SectionKind::getMetadata(), 0, utostr(Hash));
813 MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
814 return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS,
815 ELF::SHF_GROUP, SectionKind::getMetadata(), 0,
819 void MCObjectFileInfo::InitEHFrameSection() {
822 Ctx->getMachOSection("__TEXT", "__eh_frame",
824 MachO::S_ATTR_NO_TOC |
825 MachO::S_ATTR_STRIP_STATIC_SYMS |
826 MachO::S_ATTR_LIVE_SUPPORT,
827 SectionKind::getReadOnly());
828 else if (Env == IsELF)
830 Ctx->getELFSection(".eh_frame", EHSectionType,
832 SectionKind::getDataRel());
835 Ctx->getCOFFSection(".eh_frame",
836 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
837 COFF::IMAGE_SCN_MEM_READ |
838 COFF::IMAGE_SCN_MEM_WRITE,
839 SectionKind::getDataRel());