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 = FDEEncoding = 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 FDEEncoding = (RelocM == Reloc::PIC_)
275 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
276 : dwarf::DW_EH_PE_absptr;
277 TTypeEncoding = (RelocM == Reloc::PIC_)
278 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
279 : dwarf::DW_EH_PE_absptr;
282 if (RelocM == Reloc::PIC_) {
283 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
284 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
285 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
286 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
287 (CMModel == CodeModel::Small
288 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
289 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
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 FDEEncoding = dwarf::DW_EH_PE_udata4;
300 TTypeEncoding = (CMModel == CodeModel::Small)
301 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
304 case Triple::aarch64:
305 case Triple::aarch64_be:
307 case Triple::arm64_be:
308 // The small model guarantees static code/data size < 4GB, but not where it
309 // will be in memory. Most of these could end up >2GB away so even a signed
310 // pc-relative 32-bit address is insufficient, theoretically.
311 if (RelocM == Reloc::PIC_) {
312 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
313 dwarf::DW_EH_PE_sdata8;
314 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
315 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
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 FDEEncoding = dwarf::DW_EH_PE_udata4;
322 TTypeEncoding = dwarf::DW_EH_PE_absptr;
326 case Triple::ppc64le:
327 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
328 dwarf::DW_EH_PE_udata8;
329 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
330 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
331 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
332 dwarf::DW_EH_PE_udata8;
335 if (RelocM == Reloc::PIC_) {
336 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
337 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
338 dwarf::DW_EH_PE_sdata4;
339 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
340 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
341 dwarf::DW_EH_PE_sdata4;
343 LSDAEncoding = dwarf::DW_EH_PE_absptr;
344 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
345 FDEEncoding = dwarf::DW_EH_PE_udata4;
346 TTypeEncoding = dwarf::DW_EH_PE_absptr;
349 case Triple::sparcv9:
350 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
351 if (RelocM == Reloc::PIC_) {
352 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
353 dwarf::DW_EH_PE_sdata4;
354 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
355 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
356 dwarf::DW_EH_PE_sdata4;
358 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
359 FDEEncoding = dwarf::DW_EH_PE_udata4;
360 TTypeEncoding = dwarf::DW_EH_PE_absptr;
363 case Triple::systemz:
364 // All currently-defined code models guarantee that 4-byte PC-relative
365 // values will be in range.
366 if (RelocM == Reloc::PIC_) {
367 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
368 dwarf::DW_EH_PE_sdata4;
369 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
370 FDEEncoding = 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 FDEEncoding = dwarf::DW_EH_PE_absptr;
377 TTypeEncoding = dwarf::DW_EH_PE_absptr;
384 // Solaris requires different flags for .eh_frame to seemingly every other
386 EHSectionType = ELF::SHT_PROGBITS;
387 EHSectionFlags = ELF::SHF_ALLOC;
388 if (T.getOS() == Triple::Solaris) {
389 if (T.getArch() == Triple::x86_64)
390 EHSectionType = ELF::SHT_X86_64_UNWIND;
392 EHSectionFlags |= ELF::SHF_WRITE;
398 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
399 ELF::SHF_WRITE | ELF::SHF_ALLOC,
400 SectionKind::getBSS());
403 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
406 SectionKind::getText());
409 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
410 ELF::SHF_WRITE |ELF::SHF_ALLOC,
411 SectionKind::getDataRel());
414 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
416 SectionKind::getReadOnly());
419 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
420 ELF::SHF_ALLOC | ELF::SHF_TLS |
422 SectionKind::getThreadData());
425 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
426 ELF::SHF_ALLOC | ELF::SHF_TLS |
428 SectionKind::getThreadBSS());
431 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
432 ELF::SHF_ALLOC |ELF::SHF_WRITE,
433 SectionKind::getDataRel());
435 DataRelLocalSection =
436 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
437 ELF::SHF_ALLOC |ELF::SHF_WRITE,
438 SectionKind::getDataRelLocal());
441 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
442 ELF::SHF_ALLOC |ELF::SHF_WRITE,
443 SectionKind::getReadOnlyWithRel());
445 DataRelROLocalSection =
446 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
447 ELF::SHF_ALLOC |ELF::SHF_WRITE,
448 SectionKind::getReadOnlyWithRelLocal());
450 MergeableConst4Section =
451 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
452 ELF::SHF_ALLOC |ELF::SHF_MERGE,
453 SectionKind::getMergeableConst4());
455 MergeableConst8Section =
456 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
457 ELF::SHF_ALLOC |ELF::SHF_MERGE,
458 SectionKind::getMergeableConst8());
460 MergeableConst16Section =
461 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
462 ELF::SHF_ALLOC |ELF::SHF_MERGE,
463 SectionKind::getMergeableConst16());
466 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
467 ELF::SHF_ALLOC |ELF::SHF_WRITE,
468 SectionKind::getDataRel());
471 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
472 ELF::SHF_ALLOC |ELF::SHF_WRITE,
473 SectionKind::getDataRel());
475 // Exception Handling Sections.
477 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
478 // it contains relocatable pointers. In PIC mode, this is probably a big
479 // runtime hit for C++ apps. Either the contents of the LSDA need to be
480 // adjusted or this should be a data section.
482 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
484 SectionKind::getReadOnly());
486 COFFDebugSymbolsSection = nullptr;
488 // Debug Info Sections.
490 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
491 SectionKind::getMetadata());
493 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
494 SectionKind::getMetadata());
496 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
497 SectionKind::getMetadata());
499 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
500 SectionKind::getMetadata());
501 DwarfPubNamesSection =
502 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
503 SectionKind::getMetadata());
504 DwarfPubTypesSection =
505 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
506 SectionKind::getMetadata());
507 DwarfGnuPubNamesSection =
508 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
509 SectionKind::getMetadata());
510 DwarfGnuPubTypesSection =
511 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
512 SectionKind::getMetadata());
514 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
515 ELF::SHF_MERGE | ELF::SHF_STRINGS,
516 SectionKind::getMergeable1ByteCString());
518 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
519 SectionKind::getMetadata());
520 DwarfARangesSection =
521 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
522 SectionKind::getMetadata());
524 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
525 SectionKind::getMetadata());
526 DwarfMacroInfoSection =
527 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
528 SectionKind::getMetadata());
530 // DWARF5 Experimental Debug Info
532 // Accelerator Tables
533 DwarfAccelNamesSection =
534 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
535 SectionKind::getMetadata());
536 DwarfAccelObjCSection =
537 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
538 SectionKind::getMetadata());
539 DwarfAccelNamespaceSection =
540 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
541 SectionKind::getMetadata());
542 DwarfAccelTypesSection =
543 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
544 SectionKind::getMetadata());
547 DwarfInfoDWOSection =
548 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
549 SectionKind::getMetadata());
550 DwarfAbbrevDWOSection =
551 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
552 SectionKind::getMetadata());
554 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
555 ELF::SHF_MERGE | ELF::SHF_STRINGS,
556 SectionKind::getMergeable1ByteCString());
557 DwarfLineDWOSection =
558 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
559 SectionKind::getMetadata());
561 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
562 SectionKind::getMetadata());
563 DwarfStrOffDWOSection =
564 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
565 SectionKind::getMetadata());
567 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
568 SectionKind::getMetadata());
572 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
573 // The object file format cannot represent common symbols with explicit
575 CommDirectiveSupportsAlignment = false;
579 Ctx->getCOFFSection(".bss",
580 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
581 COFF::IMAGE_SCN_MEM_READ |
582 COFF::IMAGE_SCN_MEM_WRITE,
583 SectionKind::getBSS());
585 Ctx->getCOFFSection(".text",
586 COFF::IMAGE_SCN_CNT_CODE |
587 COFF::IMAGE_SCN_MEM_EXECUTE |
588 COFF::IMAGE_SCN_MEM_READ,
589 SectionKind::getText());
591 Ctx->getCOFFSection(".data",
592 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
593 COFF::IMAGE_SCN_MEM_READ |
594 COFF::IMAGE_SCN_MEM_WRITE,
595 SectionKind::getDataRel());
597 Ctx->getCOFFSection(".rdata",
598 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
599 COFF::IMAGE_SCN_MEM_READ,
600 SectionKind::getReadOnly());
601 if (T.isKnownWindowsMSVCEnvironment()) {
603 Ctx->getCOFFSection(".CRT$XCU",
604 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
605 COFF::IMAGE_SCN_MEM_READ,
606 SectionKind::getReadOnly());
609 Ctx->getCOFFSection(".ctors",
610 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
611 COFF::IMAGE_SCN_MEM_READ |
612 COFF::IMAGE_SCN_MEM_WRITE,
613 SectionKind::getDataRel());
617 if (T.isKnownWindowsMSVCEnvironment()) {
619 Ctx->getCOFFSection(".CRT$XTX",
620 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
621 COFF::IMAGE_SCN_MEM_READ,
622 SectionKind::getReadOnly());
625 Ctx->getCOFFSection(".dtors",
626 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
627 COFF::IMAGE_SCN_MEM_READ |
628 COFF::IMAGE_SCN_MEM_WRITE,
629 SectionKind::getDataRel());
632 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
633 // though it contains relocatable pointers. In PIC mode, this is probably a
634 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
635 // adjusted or this should be a data section.
637 Ctx->getCOFFSection(".gcc_except_table",
638 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
639 COFF::IMAGE_SCN_MEM_READ,
640 SectionKind::getReadOnly());
643 COFFDebugSymbolsSection =
644 Ctx->getCOFFSection(".debug$S",
645 COFF::IMAGE_SCN_MEM_DISCARDABLE |
646 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
647 COFF::IMAGE_SCN_MEM_READ,
648 SectionKind::getMetadata());
651 Ctx->getCOFFSection(".debug_abbrev",
652 COFF::IMAGE_SCN_MEM_DISCARDABLE |
653 COFF::IMAGE_SCN_MEM_READ,
654 SectionKind::getMetadata());
656 Ctx->getCOFFSection(".debug_info",
657 COFF::IMAGE_SCN_MEM_DISCARDABLE |
658 COFF::IMAGE_SCN_MEM_READ,
659 SectionKind::getMetadata());
661 Ctx->getCOFFSection(".debug_line",
662 COFF::IMAGE_SCN_MEM_DISCARDABLE |
663 COFF::IMAGE_SCN_MEM_READ,
664 SectionKind::getMetadata());
666 Ctx->getCOFFSection(".debug_frame",
667 COFF::IMAGE_SCN_MEM_DISCARDABLE |
668 COFF::IMAGE_SCN_MEM_READ,
669 SectionKind::getMetadata());
670 DwarfPubNamesSection =
671 Ctx->getCOFFSection(".debug_pubnames",
672 COFF::IMAGE_SCN_MEM_DISCARDABLE |
673 COFF::IMAGE_SCN_MEM_READ,
674 SectionKind::getMetadata());
675 DwarfPubTypesSection =
676 Ctx->getCOFFSection(".debug_pubtypes",
677 COFF::IMAGE_SCN_MEM_DISCARDABLE |
678 COFF::IMAGE_SCN_MEM_READ,
679 SectionKind::getMetadata());
680 DwarfGnuPubNamesSection =
681 Ctx->getCOFFSection(".debug_gnu_pubnames",
682 COFF::IMAGE_SCN_MEM_DISCARDABLE |
683 COFF::IMAGE_SCN_MEM_READ,
684 SectionKind::getMetadata());
685 DwarfGnuPubTypesSection =
686 Ctx->getCOFFSection(".debug_gnu_pubtypes",
687 COFF::IMAGE_SCN_MEM_DISCARDABLE |
688 COFF::IMAGE_SCN_MEM_READ,
689 SectionKind::getMetadata());
691 Ctx->getCOFFSection(".debug_str",
692 COFF::IMAGE_SCN_MEM_DISCARDABLE |
693 COFF::IMAGE_SCN_MEM_READ,
694 SectionKind::getMetadata());
696 Ctx->getCOFFSection(".debug_loc",
697 COFF::IMAGE_SCN_MEM_DISCARDABLE |
698 COFF::IMAGE_SCN_MEM_READ,
699 SectionKind::getMetadata());
700 DwarfARangesSection =
701 Ctx->getCOFFSection(".debug_aranges",
702 COFF::IMAGE_SCN_MEM_DISCARDABLE |
703 COFF::IMAGE_SCN_MEM_READ,
704 SectionKind::getMetadata());
706 Ctx->getCOFFSection(".debug_ranges",
707 COFF::IMAGE_SCN_MEM_DISCARDABLE |
708 COFF::IMAGE_SCN_MEM_READ,
709 SectionKind::getMetadata());
710 DwarfMacroInfoSection =
711 Ctx->getCOFFSection(".debug_macinfo",
712 COFF::IMAGE_SCN_MEM_DISCARDABLE |
713 COFF::IMAGE_SCN_MEM_READ,
714 SectionKind::getMetadata());
715 DwarfInfoDWOSection =
716 Ctx->getCOFFSection(".debug_info.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
717 COFF::IMAGE_SCN_MEM_READ,
718 SectionKind::getMetadata());
719 DwarfAbbrevDWOSection =
720 Ctx->getCOFFSection(".debug_abbrev.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
721 COFF::IMAGE_SCN_MEM_READ,
722 SectionKind::getMetadata());
724 Ctx->getCOFFSection(".debug_str.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
725 COFF::IMAGE_SCN_MEM_READ,
726 SectionKind::getMetadata());
727 DwarfLineDWOSection =
728 Ctx->getCOFFSection(".debug_line.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
729 COFF::IMAGE_SCN_MEM_READ,
730 SectionKind::getMetadata());
732 Ctx->getCOFFSection(".debug_loc.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
733 COFF::IMAGE_SCN_MEM_READ,
734 SectionKind::getMetadata());
735 DwarfStrOffDWOSection =
736 Ctx->getCOFFSection(".debug_str_offsets.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
737 COFF::IMAGE_SCN_MEM_READ,
738 SectionKind::getMetadata());
739 DwarfAddrSection = Ctx->getCOFFSection(
740 ".debug_addr", COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_MEM_READ,
741 SectionKind::getMetadata());
744 Ctx->getCOFFSection(".drectve",
745 COFF::IMAGE_SCN_LNK_INFO,
746 SectionKind::getMetadata());
749 Ctx->getCOFFSection(".pdata",
750 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
751 COFF::IMAGE_SCN_MEM_READ,
752 SectionKind::getDataRel());
755 Ctx->getCOFFSection(".xdata",
756 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
757 COFF::IMAGE_SCN_MEM_READ,
758 SectionKind::getDataRel());
760 Ctx->getCOFFSection(".tls$",
761 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
762 COFF::IMAGE_SCN_MEM_READ |
763 COFF::IMAGE_SCN_MEM_WRITE,
764 SectionKind::getDataRel());
767 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
775 CommDirectiveSupportsAlignment = true;
776 SupportsWeakOmittedEHFrame = true;
777 IsFunctionEHFrameSymbolPrivate = true;
778 SupportsCompactUnwindWithoutEHFrame = false;
780 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
781 TTypeEncoding = dwarf::DW_EH_PE_absptr;
783 CompactUnwindDwarfEHFrameOnly = 0;
785 EHFrameSection = nullptr; // Created on demand.
786 CompactUnwindSection = nullptr; // Used only by selected targets.
787 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
788 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
789 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
790 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
793 Triple::ArchType Arch = T.getArch();
794 // FIXME: Checking for Arch here to filter out bogus triples such as
795 // cellspu-apple-darwin. Perhaps we should fix in Triple?
796 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
797 Arch == Triple::arm || Arch == Triple::thumb ||
798 Arch == Triple::arm64 ||
799 Arch == Triple::ppc || Arch == Triple::ppc64 ||
800 Arch == Triple::UnknownArch) &&
801 (T.isOSDarwin() || T.isOSBinFormatMachO())) {
803 InitMachOMCObjectFileInfo(T);
804 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
805 Arch == Triple::arm || Arch == Triple::thumb) &&
806 (T.isOSWindows() && T.getObjectFormat() == Triple::COFF)) {
808 InitCOFFMCObjectFileInfo(T);
811 InitELFMCObjectFileInfo(T);
815 const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
816 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
817 SectionKind::getMetadata(), 0, utostr(Hash));
821 MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
822 return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS,
823 ELF::SHF_GROUP, SectionKind::getMetadata(), 0,
827 void MCObjectFileInfo::InitEHFrameSection() {
830 Ctx->getMachOSection("__TEXT", "__eh_frame",
832 MachO::S_ATTR_NO_TOC |
833 MachO::S_ATTR_STRIP_STATIC_SYMS |
834 MachO::S_ATTR_LIVE_SUPPORT,
835 SectionKind::getReadOnly());
836 else if (Env == IsELF)
838 Ctx->getELFSection(".eh_frame", EHSectionType,
840 SectionKind::getDataRel());
843 Ctx->getCOFFSection(".eh_frame",
844 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
845 COFF::IMAGE_SCN_MEM_READ |
846 COFF::IMAGE_SCN_MEM_WRITE,
847 SectionKind::getDataRel());