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/MCContext.h"
14 #include "llvm/MC/MCSection.h"
15 #include "llvm/MC/MCSectionCOFF.h"
16 #include "llvm/MC/MCSectionELF.h"
17 #include "llvm/MC/MCSectionMachO.h"
20 void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
22 IsFunctionEHFrameSymbolPrivate = false;
23 SupportsWeakOmittedEHFrame = false;
25 if (T.isOSDarwin() && T.getArch() == Triple::arm64)
26 SupportsCompactUnwindWithoutEHFrame = true;
28 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
29 | dwarf::DW_EH_PE_sdata4;
30 LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
31 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
32 dwarf::DW_EH_PE_sdata4;
34 // .comm doesn't support alignment before Leopard.
35 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
36 CommDirectiveSupportsAlignment = false;
39 = Ctx->getMachOSection("__TEXT", "__text",
40 MachO::S_ATTR_PURE_INSTRUCTIONS,
41 SectionKind::getText());
43 = Ctx->getMachOSection("__DATA", "__data", 0,
44 SectionKind::getDataRel());
46 // BSSSection might not be expected initialized on msvc.
49 TLSDataSection // .tdata
50 = Ctx->getMachOSection("__DATA", "__thread_data",
51 MachO::S_THREAD_LOCAL_REGULAR,
52 SectionKind::getDataRel());
53 TLSBSSSection // .tbss
54 = Ctx->getMachOSection("__DATA", "__thread_bss",
55 MachO::S_THREAD_LOCAL_ZEROFILL,
56 SectionKind::getThreadBSS());
58 // TODO: Verify datarel below.
60 = Ctx->getMachOSection("__DATA", "__thread_vars",
61 MachO::S_THREAD_LOCAL_VARIABLES,
62 SectionKind::getDataRel());
65 = Ctx->getMachOSection("__DATA", "__thread_init",
66 MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
67 SectionKind::getDataRel());
69 CStringSection // .cstring
70 = Ctx->getMachOSection("__TEXT", "__cstring",
71 MachO::S_CSTRING_LITERALS,
72 SectionKind::getMergeable1ByteCString());
74 = Ctx->getMachOSection("__TEXT","__ustring", 0,
75 SectionKind::getMergeable2ByteCString());
76 FourByteConstantSection // .literal4
77 = Ctx->getMachOSection("__TEXT", "__literal4",
78 MachO::S_4BYTE_LITERALS,
79 SectionKind::getMergeableConst4());
80 EightByteConstantSection // .literal8
81 = Ctx->getMachOSection("__TEXT", "__literal8",
82 MachO::S_8BYTE_LITERALS,
83 SectionKind::getMergeableConst8());
85 SixteenByteConstantSection // .literal16
86 = Ctx->getMachOSection("__TEXT", "__literal16",
87 MachO::S_16BYTE_LITERALS,
88 SectionKind::getMergeableConst16());
90 ReadOnlySection // .const
91 = Ctx->getMachOSection("__TEXT", "__const", 0,
92 SectionKind::getReadOnly());
95 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
97 MachO::S_ATTR_PURE_INSTRUCTIONS,
98 SectionKind::getText());
100 = Ctx->getMachOSection("__TEXT", "__const_coal",
102 SectionKind::getReadOnly());
103 ConstDataSection // .const_data
104 = Ctx->getMachOSection("__DATA", "__const", 0,
105 SectionKind::getReadOnlyWithRel());
107 = Ctx->getMachOSection("__DATA","__datacoal_nt",
109 SectionKind::getDataRel());
111 = Ctx->getMachOSection("__DATA","__common",
113 SectionKind::getBSS());
115 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
116 SectionKind::getBSS());
119 LazySymbolPointerSection
120 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
121 MachO::S_LAZY_SYMBOL_POINTERS,
122 SectionKind::getMetadata());
123 NonLazySymbolPointerSection
124 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
125 MachO::S_NON_LAZY_SYMBOL_POINTERS,
126 SectionKind::getMetadata());
128 if (RelocM == Reloc::Static) {
130 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
131 SectionKind::getDataRel());
133 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
134 SectionKind::getDataRel());
137 = Ctx->getMachOSection("__DATA", "__mod_init_func",
138 MachO::S_MOD_INIT_FUNC_POINTERS,
139 SectionKind::getDataRel());
141 = Ctx->getMachOSection("__DATA", "__mod_term_func",
142 MachO::S_MOD_TERM_FUNC_POINTERS,
143 SectionKind::getDataRel());
146 // Exception Handling.
147 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
148 SectionKind::getReadOnlyWithRel());
150 COFFDebugSymbolsSection = nullptr;
152 if ((T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) ||
153 (T.isOSDarwin() && T.getArch() == Triple::arm64)) {
154 CompactUnwindSection =
155 Ctx->getMachOSection("__LD", "__compact_unwind",
157 SectionKind::getReadOnly());
159 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
160 CompactUnwindDwarfEHFrameOnly = 0x04000000;
161 else if (T.getArch() == Triple::arm64)
162 CompactUnwindDwarfEHFrameOnly = 0x03000000;
165 // Debug Information.
166 DwarfAccelNamesSection =
167 Ctx->getMachOSection("__DWARF", "__apple_names",
169 SectionKind::getMetadata());
170 DwarfAccelObjCSection =
171 Ctx->getMachOSection("__DWARF", "__apple_objc",
173 SectionKind::getMetadata());
174 // 16 character section limit...
175 DwarfAccelNamespaceSection =
176 Ctx->getMachOSection("__DWARF", "__apple_namespac",
178 SectionKind::getMetadata());
179 DwarfAccelTypesSection =
180 Ctx->getMachOSection("__DWARF", "__apple_types",
182 SectionKind::getMetadata());
185 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
187 SectionKind::getMetadata());
189 Ctx->getMachOSection("__DWARF", "__debug_info",
191 SectionKind::getMetadata());
193 Ctx->getMachOSection("__DWARF", "__debug_line",
195 SectionKind::getMetadata());
197 Ctx->getMachOSection("__DWARF", "__debug_frame",
199 SectionKind::getMetadata());
200 DwarfPubNamesSection =
201 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
203 SectionKind::getMetadata());
204 DwarfPubTypesSection =
205 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
207 SectionKind::getMetadata());
208 DwarfGnuPubNamesSection =
209 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
211 SectionKind::getMetadata());
212 DwarfGnuPubTypesSection =
213 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
215 SectionKind::getMetadata());
217 Ctx->getMachOSection("__DWARF", "__debug_str",
219 SectionKind::getMetadata());
221 Ctx->getMachOSection("__DWARF", "__debug_loc",
223 SectionKind::getMetadata());
224 DwarfARangesSection =
225 Ctx->getMachOSection("__DWARF", "__debug_aranges",
227 SectionKind::getMetadata());
229 Ctx->getMachOSection("__DWARF", "__debug_ranges",
231 SectionKind::getMetadata());
232 DwarfMacroInfoSection =
233 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
235 SectionKind::getMetadata());
236 DwarfDebugInlineSection =
237 Ctx->getMachOSection("__DWARF", "__debug_inlined",
239 SectionKind::getMetadata());
241 Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
242 SectionKind::getMetadata());
244 TLSExtraDataSection = TLSTLVSection;
247 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
248 switch (T.getArch()) {
251 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
254 case Triple::mips64el:
255 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
258 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
262 switch (T.getArch()) {
266 case Triple::thumbeb:
268 PersonalityEncoding = (RelocM == Reloc::PIC_)
269 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
270 : dwarf::DW_EH_PE_absptr;
271 LSDAEncoding = (RelocM == Reloc::PIC_)
272 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
273 : dwarf::DW_EH_PE_absptr;
274 TTypeEncoding = (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;
279 if (RelocM == Reloc::PIC_) {
280 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
281 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
282 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
283 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
284 (CMModel == CodeModel::Small
285 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
286 TTypeEncoding = 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);
290 PersonalityEncoding =
291 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
292 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
293 LSDAEncoding = (CMModel == CodeModel::Small)
294 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
295 TTypeEncoding = (CMModel == CodeModel::Small)
296 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
299 case Triple::aarch64:
300 case Triple::aarch64_be:
302 case Triple::arm64_be:
303 // The small model guarantees static code/data size < 4GB, but not where it
304 // will be in memory. Most of these could end up >2GB away so even a signed
305 // pc-relative 32-bit address is insufficient, theoretically.
306 if (RelocM == Reloc::PIC_) {
307 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
308 dwarf::DW_EH_PE_sdata8;
309 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
310 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
311 dwarf::DW_EH_PE_sdata8;
313 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
314 LSDAEncoding = dwarf::DW_EH_PE_absptr;
315 TTypeEncoding = dwarf::DW_EH_PE_absptr;
319 case Triple::ppc64le:
320 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
321 dwarf::DW_EH_PE_udata8;
322 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
323 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
324 dwarf::DW_EH_PE_udata8;
327 if (RelocM == Reloc::PIC_) {
328 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
329 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
330 dwarf::DW_EH_PE_sdata4;
331 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
332 dwarf::DW_EH_PE_sdata4;
334 LSDAEncoding = dwarf::DW_EH_PE_absptr;
335 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
336 TTypeEncoding = dwarf::DW_EH_PE_absptr;
339 case Triple::sparcv9:
340 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
341 if (RelocM == Reloc::PIC_) {
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 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
348 TTypeEncoding = dwarf::DW_EH_PE_absptr;
351 case Triple::systemz:
352 // All currently-defined code models guarantee that 4-byte PC-relative
353 // values will be in range.
354 if (RelocM == Reloc::PIC_) {
355 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
356 dwarf::DW_EH_PE_sdata4;
357 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
358 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
359 dwarf::DW_EH_PE_sdata4;
361 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
362 LSDAEncoding = dwarf::DW_EH_PE_absptr;
363 TTypeEncoding = dwarf::DW_EH_PE_absptr;
370 // Solaris requires different flags for .eh_frame to seemingly every other
372 EHSectionType = ELF::SHT_PROGBITS;
373 EHSectionFlags = ELF::SHF_ALLOC;
374 if (T.getOS() == Triple::Solaris) {
375 if (T.getArch() == Triple::x86_64)
376 EHSectionType = ELF::SHT_X86_64_UNWIND;
378 EHSectionFlags |= ELF::SHF_WRITE;
384 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
385 ELF::SHF_WRITE | ELF::SHF_ALLOC,
386 SectionKind::getBSS());
389 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
392 SectionKind::getText());
395 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
396 ELF::SHF_WRITE |ELF::SHF_ALLOC,
397 SectionKind::getDataRel());
400 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
402 SectionKind::getReadOnly());
405 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
406 ELF::SHF_ALLOC | ELF::SHF_TLS |
408 SectionKind::getThreadData());
411 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
412 ELF::SHF_ALLOC | ELF::SHF_TLS |
414 SectionKind::getThreadBSS());
417 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
418 ELF::SHF_ALLOC |ELF::SHF_WRITE,
419 SectionKind::getDataRel());
421 DataRelLocalSection =
422 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
423 ELF::SHF_ALLOC |ELF::SHF_WRITE,
424 SectionKind::getDataRelLocal());
427 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
428 ELF::SHF_ALLOC |ELF::SHF_WRITE,
429 SectionKind::getReadOnlyWithRel());
431 DataRelROLocalSection =
432 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
433 ELF::SHF_ALLOC |ELF::SHF_WRITE,
434 SectionKind::getReadOnlyWithRelLocal());
436 MergeableConst4Section =
437 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
438 ELF::SHF_ALLOC |ELF::SHF_MERGE,
439 SectionKind::getMergeableConst4());
441 MergeableConst8Section =
442 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
443 ELF::SHF_ALLOC |ELF::SHF_MERGE,
444 SectionKind::getMergeableConst8());
446 MergeableConst16Section =
447 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
448 ELF::SHF_ALLOC |ELF::SHF_MERGE,
449 SectionKind::getMergeableConst16());
452 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
453 ELF::SHF_ALLOC |ELF::SHF_WRITE,
454 SectionKind::getDataRel());
457 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
458 ELF::SHF_ALLOC |ELF::SHF_WRITE,
459 SectionKind::getDataRel());
461 // Exception Handling Sections.
463 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
464 // it contains relocatable pointers. In PIC mode, this is probably a big
465 // runtime hit for C++ apps. Either the contents of the LSDA need to be
466 // adjusted or this should be a data section.
468 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
470 SectionKind::getReadOnly());
472 COFFDebugSymbolsSection = nullptr;
474 // Debug Info Sections.
476 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
477 SectionKind::getMetadata());
479 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
480 SectionKind::getMetadata());
482 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
483 SectionKind::getMetadata());
485 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
486 SectionKind::getMetadata());
487 DwarfPubNamesSection =
488 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
489 SectionKind::getMetadata());
490 DwarfPubTypesSection =
491 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
492 SectionKind::getMetadata());
493 DwarfGnuPubNamesSection =
494 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
495 SectionKind::getMetadata());
496 DwarfGnuPubTypesSection =
497 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
498 SectionKind::getMetadata());
500 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
501 ELF::SHF_MERGE | ELF::SHF_STRINGS,
502 SectionKind::getMergeable1ByteCString());
504 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
505 SectionKind::getMetadata());
506 DwarfARangesSection =
507 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
508 SectionKind::getMetadata());
510 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
511 SectionKind::getMetadata());
512 DwarfMacroInfoSection =
513 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
514 SectionKind::getMetadata());
516 // DWARF5 Experimental Debug Info
518 // Accelerator Tables
519 DwarfAccelNamesSection =
520 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
521 SectionKind::getMetadata());
522 DwarfAccelObjCSection =
523 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
524 SectionKind::getMetadata());
525 DwarfAccelNamespaceSection =
526 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
527 SectionKind::getMetadata());
528 DwarfAccelTypesSection =
529 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
530 SectionKind::getMetadata());
533 DwarfInfoDWOSection =
534 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
535 SectionKind::getMetadata());
536 DwarfAbbrevDWOSection =
537 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
538 SectionKind::getMetadata());
540 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
541 ELF::SHF_MERGE | ELF::SHF_STRINGS,
542 SectionKind::getMergeable1ByteCString());
543 DwarfLineDWOSection =
544 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
545 SectionKind::getMetadata());
547 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
548 SectionKind::getMetadata());
549 DwarfStrOffDWOSection =
550 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
551 SectionKind::getMetadata());
553 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
554 SectionKind::getMetadata());
558 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
559 // The object file format cannot represent common symbols with explicit
561 CommDirectiveSupportsAlignment = false;
565 Ctx->getCOFFSection(".bss",
566 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
567 COFF::IMAGE_SCN_MEM_READ |
568 COFF::IMAGE_SCN_MEM_WRITE,
569 SectionKind::getBSS());
571 Ctx->getCOFFSection(".text",
572 COFF::IMAGE_SCN_CNT_CODE |
573 COFF::IMAGE_SCN_MEM_EXECUTE |
574 COFF::IMAGE_SCN_MEM_READ,
575 SectionKind::getText());
577 Ctx->getCOFFSection(".data",
578 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
579 COFF::IMAGE_SCN_MEM_READ |
580 COFF::IMAGE_SCN_MEM_WRITE,
581 SectionKind::getDataRel());
583 Ctx->getCOFFSection(".rdata",
584 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
585 COFF::IMAGE_SCN_MEM_READ,
586 SectionKind::getReadOnly());
587 if (T.isKnownWindowsMSVCEnvironment()) {
589 Ctx->getCOFFSection(".CRT$XCU",
590 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
591 COFF::IMAGE_SCN_MEM_READ,
592 SectionKind::getReadOnly());
595 Ctx->getCOFFSection(".ctors",
596 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
597 COFF::IMAGE_SCN_MEM_READ |
598 COFF::IMAGE_SCN_MEM_WRITE,
599 SectionKind::getDataRel());
603 if (T.isKnownWindowsMSVCEnvironment()) {
605 Ctx->getCOFFSection(".CRT$XTX",
606 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
607 COFF::IMAGE_SCN_MEM_READ,
608 SectionKind::getReadOnly());
611 Ctx->getCOFFSection(".dtors",
612 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
613 COFF::IMAGE_SCN_MEM_READ |
614 COFF::IMAGE_SCN_MEM_WRITE,
615 SectionKind::getDataRel());
618 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
619 // though it contains relocatable pointers. In PIC mode, this is probably a
620 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
621 // adjusted or this should be a data section.
623 Ctx->getCOFFSection(".gcc_except_table",
624 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
625 COFF::IMAGE_SCN_MEM_READ,
626 SectionKind::getReadOnly());
629 COFFDebugSymbolsSection =
630 Ctx->getCOFFSection(".debug$S",
631 COFF::IMAGE_SCN_MEM_DISCARDABLE |
632 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
633 COFF::IMAGE_SCN_MEM_READ,
634 SectionKind::getMetadata());
637 Ctx->getCOFFSection(".debug_abbrev",
638 COFF::IMAGE_SCN_MEM_DISCARDABLE |
639 COFF::IMAGE_SCN_MEM_READ,
640 SectionKind::getMetadata());
642 Ctx->getCOFFSection(".debug_info",
643 COFF::IMAGE_SCN_MEM_DISCARDABLE |
644 COFF::IMAGE_SCN_MEM_READ,
645 SectionKind::getMetadata());
647 Ctx->getCOFFSection(".debug_line",
648 COFF::IMAGE_SCN_MEM_DISCARDABLE |
649 COFF::IMAGE_SCN_MEM_READ,
650 SectionKind::getMetadata());
652 Ctx->getCOFFSection(".debug_frame",
653 COFF::IMAGE_SCN_MEM_DISCARDABLE |
654 COFF::IMAGE_SCN_MEM_READ,
655 SectionKind::getMetadata());
656 DwarfPubNamesSection =
657 Ctx->getCOFFSection(".debug_pubnames",
658 COFF::IMAGE_SCN_MEM_DISCARDABLE |
659 COFF::IMAGE_SCN_MEM_READ,
660 SectionKind::getMetadata());
661 DwarfPubTypesSection =
662 Ctx->getCOFFSection(".debug_pubtypes",
663 COFF::IMAGE_SCN_MEM_DISCARDABLE |
664 COFF::IMAGE_SCN_MEM_READ,
665 SectionKind::getMetadata());
666 DwarfGnuPubNamesSection =
667 Ctx->getCOFFSection(".debug_gnu_pubnames",
668 COFF::IMAGE_SCN_MEM_DISCARDABLE |
669 COFF::IMAGE_SCN_MEM_READ,
670 SectionKind::getMetadata());
671 DwarfGnuPubTypesSection =
672 Ctx->getCOFFSection(".debug_gnu_pubtypes",
673 COFF::IMAGE_SCN_MEM_DISCARDABLE |
674 COFF::IMAGE_SCN_MEM_READ,
675 SectionKind::getMetadata());
677 Ctx->getCOFFSection(".debug_str",
678 COFF::IMAGE_SCN_MEM_DISCARDABLE |
679 COFF::IMAGE_SCN_MEM_READ,
680 SectionKind::getMetadata());
682 Ctx->getCOFFSection(".debug_loc",
683 COFF::IMAGE_SCN_MEM_DISCARDABLE |
684 COFF::IMAGE_SCN_MEM_READ,
685 SectionKind::getMetadata());
686 DwarfARangesSection =
687 Ctx->getCOFFSection(".debug_aranges",
688 COFF::IMAGE_SCN_MEM_DISCARDABLE |
689 COFF::IMAGE_SCN_MEM_READ,
690 SectionKind::getMetadata());
692 Ctx->getCOFFSection(".debug_ranges",
693 COFF::IMAGE_SCN_MEM_DISCARDABLE |
694 COFF::IMAGE_SCN_MEM_READ,
695 SectionKind::getMetadata());
696 DwarfMacroInfoSection =
697 Ctx->getCOFFSection(".debug_macinfo",
698 COFF::IMAGE_SCN_MEM_DISCARDABLE |
699 COFF::IMAGE_SCN_MEM_READ,
700 SectionKind::getMetadata());
701 DwarfInfoDWOSection =
702 Ctx->getCOFFSection(".debug_info.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
703 COFF::IMAGE_SCN_MEM_READ,
704 SectionKind::getMetadata());
705 DwarfAbbrevDWOSection =
706 Ctx->getCOFFSection(".debug_abbrev.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
707 COFF::IMAGE_SCN_MEM_READ,
708 SectionKind::getMetadata());
710 Ctx->getCOFFSection(".debug_str.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
711 COFF::IMAGE_SCN_MEM_READ,
712 SectionKind::getMetadata());
713 DwarfLineDWOSection =
714 Ctx->getCOFFSection(".debug_line.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
715 COFF::IMAGE_SCN_MEM_READ,
716 SectionKind::getMetadata());
718 Ctx->getCOFFSection(".debug_loc.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
719 COFF::IMAGE_SCN_MEM_READ,
720 SectionKind::getMetadata());
721 DwarfStrOffDWOSection =
722 Ctx->getCOFFSection(".debug_str_offsets.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
723 COFF::IMAGE_SCN_MEM_READ,
724 SectionKind::getMetadata());
725 DwarfAddrSection = Ctx->getCOFFSection(
726 ".debug_addr", COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_MEM_READ,
727 SectionKind::getMetadata());
730 Ctx->getCOFFSection(".drectve",
731 COFF::IMAGE_SCN_LNK_INFO,
732 SectionKind::getMetadata());
735 Ctx->getCOFFSection(".pdata",
736 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
737 COFF::IMAGE_SCN_MEM_READ,
738 SectionKind::getDataRel());
741 Ctx->getCOFFSection(".xdata",
742 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
743 COFF::IMAGE_SCN_MEM_READ,
744 SectionKind::getDataRel());
746 Ctx->getCOFFSection(".tls$",
747 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
748 COFF::IMAGE_SCN_MEM_READ |
749 COFF::IMAGE_SCN_MEM_WRITE,
750 SectionKind::getDataRel());
753 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
761 CommDirectiveSupportsAlignment = true;
762 SupportsWeakOmittedEHFrame = true;
763 IsFunctionEHFrameSymbolPrivate = true;
764 SupportsCompactUnwindWithoutEHFrame = false;
766 PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
767 dwarf::DW_EH_PE_absptr;
769 CompactUnwindDwarfEHFrameOnly = 0;
771 EHFrameSection = nullptr; // Created on demand.
772 CompactUnwindSection = nullptr; // Used only by selected targets.
773 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
774 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
775 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
776 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
779 Triple::ArchType Arch = T.getArch();
780 // FIXME: Checking for Arch here to filter out bogus triples such as
781 // cellspu-apple-darwin. Perhaps we should fix in Triple?
782 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
783 Arch == Triple::arm || Arch == Triple::thumb ||
784 Arch == Triple::arm64 ||
785 Arch == Triple::ppc || Arch == Triple::ppc64 ||
786 Arch == Triple::UnknownArch) &&
787 (T.isOSDarwin() || T.isOSBinFormatMachO())) {
789 InitMachOMCObjectFileInfo(T);
790 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
791 Arch == Triple::arm || Arch == Triple::thumb) &&
792 (T.isOSWindows() && T.getObjectFormat() == Triple::COFF)) {
794 InitCOFFMCObjectFileInfo(T);
797 InitELFMCObjectFileInfo(T);
801 const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
802 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
803 SectionKind::getMetadata(), 0, utostr(Hash));
807 MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
808 return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS,
809 ELF::SHF_GROUP, SectionKind::getMetadata(), 0,
813 void MCObjectFileInfo::InitEHFrameSection() {
816 Ctx->getMachOSection("__TEXT", "__eh_frame",
818 MachO::S_ATTR_NO_TOC |
819 MachO::S_ATTR_STRIP_STATIC_SYMS |
820 MachO::S_ATTR_LIVE_SUPPORT,
821 SectionKind::getReadOnly());
822 else if (Env == IsELF)
824 Ctx->getELFSection(".eh_frame", EHSectionType,
826 SectionKind::getDataRel());
829 Ctx->getCOFFSection(".eh_frame",
830 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
831 COFF::IMAGE_SCN_MEM_READ |
832 COFF::IMAGE_SCN_MEM_WRITE,
833 SectionKind::getDataRel());