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"
19 #include "llvm/Support/COFF.h"
23 static bool useCompactUnwind(const Triple &T) {
28 // aarch64 always has it.
29 if (T.getArch() == Triple::aarch64)
32 // armv7k always has it.
36 // Use it on newer version of OS X.
37 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
40 // And the iOS simulator.
42 (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86))
48 void MCObjectFileInfo::initMachOMCObjectFileInfo(Triple T) {
50 SupportsWeakOmittedEHFrame = false;
52 EHFrameSection = Ctx->getMachOSection(
53 "__TEXT", "__eh_frame",
54 MachO::S_COALESCED | MachO::S_ATTR_NO_TOC |
55 MachO::S_ATTR_STRIP_STATIC_SYMS | MachO::S_ATTR_LIVE_SUPPORT,
56 SectionKind::getReadOnly());
58 if (T.isOSDarwin() && T.getArch() == Triple::aarch64)
59 SupportsCompactUnwindWithoutEHFrame = true;
62 OmitDwarfIfHaveCompactUnwind = true;
64 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
65 | dwarf::DW_EH_PE_sdata4;
66 LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
67 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
68 dwarf::DW_EH_PE_sdata4;
70 // .comm doesn't support alignment before Leopard.
71 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
72 CommDirectiveSupportsAlignment = false;
75 = Ctx->getMachOSection("__TEXT", "__text",
76 MachO::S_ATTR_PURE_INSTRUCTIONS,
77 SectionKind::getText());
79 = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
81 // BSSSection might not be expected initialized on msvc.
84 TLSDataSection // .tdata
85 = Ctx->getMachOSection("__DATA", "__thread_data",
86 MachO::S_THREAD_LOCAL_REGULAR,
87 SectionKind::getData());
88 TLSBSSSection // .tbss
89 = Ctx->getMachOSection("__DATA", "__thread_bss",
90 MachO::S_THREAD_LOCAL_ZEROFILL,
91 SectionKind::getThreadBSS());
93 // TODO: Verify datarel below.
95 = Ctx->getMachOSection("__DATA", "__thread_vars",
96 MachO::S_THREAD_LOCAL_VARIABLES,
97 SectionKind::getData());
99 TLSThreadInitSection = Ctx->getMachOSection(
100 "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
101 SectionKind::getData());
103 CStringSection // .cstring
104 = Ctx->getMachOSection("__TEXT", "__cstring",
105 MachO::S_CSTRING_LITERALS,
106 SectionKind::getMergeable1ByteCString());
108 = Ctx->getMachOSection("__TEXT","__ustring", 0,
109 SectionKind::getMergeable2ByteCString());
110 FourByteConstantSection // .literal4
111 = Ctx->getMachOSection("__TEXT", "__literal4",
112 MachO::S_4BYTE_LITERALS,
113 SectionKind::getMergeableConst4());
114 EightByteConstantSection // .literal8
115 = Ctx->getMachOSection("__TEXT", "__literal8",
116 MachO::S_8BYTE_LITERALS,
117 SectionKind::getMergeableConst8());
119 SixteenByteConstantSection // .literal16
120 = Ctx->getMachOSection("__TEXT", "__literal16",
121 MachO::S_16BYTE_LITERALS,
122 SectionKind::getMergeableConst16());
124 ReadOnlySection // .const
125 = Ctx->getMachOSection("__TEXT", "__const", 0,
126 SectionKind::getReadOnly());
128 // If the target is not powerpc, map the coal sections to the non-coal
131 // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
132 // "__TEXT/__const_coal" => section "__TEXT/__const"
133 // "__DATA/__datacoal_nt" => section "__DATA/__data"
134 Triple::ArchType ArchTy = T.getArch();
136 if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
138 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
140 MachO::S_ATTR_PURE_INSTRUCTIONS,
141 SectionKind::getText());
143 = Ctx->getMachOSection("__TEXT", "__const_coal",
145 SectionKind::getReadOnly());
146 DataCoalSection = Ctx->getMachOSection(
147 "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());
149 TextCoalSection = TextSection;
150 ConstTextCoalSection = ReadOnlySection;
151 DataCoalSection = DataSection;
154 ConstDataSection // .const_data
155 = Ctx->getMachOSection("__DATA", "__const", 0,
156 SectionKind::getReadOnlyWithRel());
158 = Ctx->getMachOSection("__DATA","__common",
160 SectionKind::getBSS());
162 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
163 SectionKind::getBSS());
166 LazySymbolPointerSection
167 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
168 MachO::S_LAZY_SYMBOL_POINTERS,
169 SectionKind::getMetadata());
170 NonLazySymbolPointerSection
171 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
172 MachO::S_NON_LAZY_SYMBOL_POINTERS,
173 SectionKind::getMetadata());
175 if (RelocM == Reloc::Static) {
176 StaticCtorSection = Ctx->getMachOSection("__TEXT", "__constructor", 0,
177 SectionKind::getData());
178 StaticDtorSection = Ctx->getMachOSection("__TEXT", "__destructor", 0,
179 SectionKind::getData());
181 StaticCtorSection = Ctx->getMachOSection("__DATA", "__mod_init_func",
182 MachO::S_MOD_INIT_FUNC_POINTERS,
183 SectionKind::getData());
184 StaticDtorSection = Ctx->getMachOSection("__DATA", "__mod_term_func",
185 MachO::S_MOD_TERM_FUNC_POINTERS,
186 SectionKind::getData());
189 // Exception Handling.
190 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
191 SectionKind::getReadOnlyWithRel());
193 COFFDebugSymbolsSection = nullptr;
195 if (useCompactUnwind(T)) {
196 CompactUnwindSection =
197 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
198 SectionKind::getReadOnly());
200 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
201 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF
202 else if (T.getArch() == Triple::aarch64)
203 CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF
204 else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
205 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF
208 // Debug Information.
209 DwarfAccelNamesSection =
210 Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
211 SectionKind::getMetadata(), "names_begin");
212 DwarfAccelObjCSection =
213 Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
214 SectionKind::getMetadata(), "objc_begin");
215 // 16 character section limit...
216 DwarfAccelNamespaceSection =
217 Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
218 SectionKind::getMetadata(), "namespac_begin");
219 DwarfAccelTypesSection =
220 Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
221 SectionKind::getMetadata(), "types_begin");
224 Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
225 SectionKind::getMetadata(), "section_abbrev");
227 Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
228 SectionKind::getMetadata(), "section_info");
230 Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
231 SectionKind::getMetadata(), "section_line");
233 Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
234 SectionKind::getMetadata());
235 DwarfPubNamesSection =
236 Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
237 SectionKind::getMetadata());
238 DwarfPubTypesSection =
239 Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
240 SectionKind::getMetadata());
241 DwarfGnuPubNamesSection =
242 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
243 SectionKind::getMetadata());
244 DwarfGnuPubTypesSection =
245 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
246 SectionKind::getMetadata());
248 Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
249 SectionKind::getMetadata(), "info_string");
251 Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
252 SectionKind::getMetadata(), "section_debug_loc");
253 DwarfARangesSection =
254 Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
255 SectionKind::getMetadata());
257 Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
258 SectionKind::getMetadata(), "debug_range");
259 DwarfDebugInlineSection =
260 Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
261 SectionKind::getMetadata());
262 StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
263 0, SectionKind::getMetadata());
265 FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
266 0, SectionKind::getMetadata());
268 TLSExtraDataSection = TLSTLVSection;
271 void MCObjectFileInfo::initELFMCObjectFileInfo(Triple T) {
272 switch (T.getArch()) {
275 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
278 case Triple::mips64el:
279 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
282 FDECFIEncoding = dwarf::DW_EH_PE_pcrel |
283 ((CMModel == CodeModel::Large) ? dwarf::DW_EH_PE_sdata8
284 : dwarf::DW_EH_PE_sdata4);
287 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
291 switch (T.getArch()) {
295 case Triple::thumbeb:
296 if (Ctx->getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
298 // Fallthrough if not using EHABI
301 PersonalityEncoding = (RelocM == Reloc::PIC_)
302 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
303 : dwarf::DW_EH_PE_absptr;
304 LSDAEncoding = (RelocM == Reloc::PIC_)
305 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
306 : dwarf::DW_EH_PE_absptr;
307 TTypeEncoding = (RelocM == Reloc::PIC_)
308 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
309 : dwarf::DW_EH_PE_absptr;
312 if (RelocM == Reloc::PIC_) {
313 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
314 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
315 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
316 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
317 (CMModel == CodeModel::Small
318 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
319 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
320 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
321 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
323 PersonalityEncoding =
324 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
325 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
326 LSDAEncoding = (CMModel == CodeModel::Small)
327 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
328 TTypeEncoding = (CMModel == CodeModel::Small)
329 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
332 case Triple::aarch64:
333 case Triple::aarch64_be:
334 // The small model guarantees static code/data size < 4GB, but not where it
335 // will be in memory. Most of these could end up >2GB away so even a signed
336 // pc-relative 32-bit address is insufficient, theoretically.
337 if (RelocM == Reloc::PIC_) {
338 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
339 dwarf::DW_EH_PE_sdata8;
340 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
341 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
342 dwarf::DW_EH_PE_sdata8;
344 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
345 LSDAEncoding = dwarf::DW_EH_PE_absptr;
346 TTypeEncoding = dwarf::DW_EH_PE_absptr;
352 case Triple::mips64el:
353 // MIPS uses indirect pointer to refer personality functions and types, so
354 // that the eh_frame section can be read-only. DW.ref.personality will be
355 // generated for relocation.
356 PersonalityEncoding = dwarf::DW_EH_PE_indirect;
357 // FIXME: The N64 ABI probably ought to use DW_EH_PE_sdata8 but we can't
358 // identify N64 from just a triple.
359 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
360 dwarf::DW_EH_PE_sdata4;
361 // We don't support PC-relative LSDA references in GAS so we use the default
362 // DW_EH_PE_absptr for those.
365 case Triple::ppc64le:
366 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
367 dwarf::DW_EH_PE_udata8;
368 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
369 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
370 dwarf::DW_EH_PE_udata8;
372 case Triple::sparcel:
374 if (RelocM == Reloc::PIC_) {
375 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
376 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
377 dwarf::DW_EH_PE_sdata4;
378 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
379 dwarf::DW_EH_PE_sdata4;
381 LSDAEncoding = dwarf::DW_EH_PE_absptr;
382 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
383 TTypeEncoding = dwarf::DW_EH_PE_absptr;
386 case Triple::sparcv9:
387 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
388 if (RelocM == Reloc::PIC_) {
389 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
390 dwarf::DW_EH_PE_sdata4;
391 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
392 dwarf::DW_EH_PE_sdata4;
394 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
395 TTypeEncoding = dwarf::DW_EH_PE_absptr;
398 case Triple::systemz:
399 // All currently-defined code models guarantee that 4-byte PC-relative
400 // values will be in range.
401 if (RelocM == Reloc::PIC_) {
402 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
403 dwarf::DW_EH_PE_sdata4;
404 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
405 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
406 dwarf::DW_EH_PE_sdata4;
408 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
409 LSDAEncoding = dwarf::DW_EH_PE_absptr;
410 TTypeEncoding = dwarf::DW_EH_PE_absptr;
417 unsigned EHSectionType = T.getArch() == Triple::x86_64
418 ? ELF::SHT_X86_64_UNWIND
421 // Solaris requires different flags for .eh_frame to seemingly every other
423 unsigned EHSectionFlags = ELF::SHF_ALLOC;
424 if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
425 EHSectionFlags |= ELF::SHF_WRITE;
428 BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
429 ELF::SHF_WRITE | ELF::SHF_ALLOC);
431 TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
432 ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
434 DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
435 ELF::SHF_WRITE | ELF::SHF_ALLOC);
438 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
441 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
442 ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
444 TLSBSSSection = Ctx->getELFSection(
445 ".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
447 DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
448 ELF::SHF_ALLOC | ELF::SHF_WRITE);
450 MergeableConst4Section =
451 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
452 ELF::SHF_ALLOC | ELF::SHF_MERGE, 4, "");
454 MergeableConst8Section =
455 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
456 ELF::SHF_ALLOC | ELF::SHF_MERGE, 8, "");
458 MergeableConst16Section =
459 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
460 ELF::SHF_ALLOC | ELF::SHF_MERGE, 16, "");
462 StaticCtorSection = Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
463 ELF::SHF_ALLOC | ELF::SHF_WRITE);
465 StaticDtorSection = Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
466 ELF::SHF_ALLOC | ELF::SHF_WRITE);
468 // Exception Handling Sections.
470 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
471 // it contains relocatable pointers. In PIC mode, this is probably a big
472 // runtime hit for C++ apps. Either the contents of the LSDA need to be
473 // adjusted or this should be a data section.
474 LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
477 COFFDebugSymbolsSection = nullptr;
479 // Debug Info Sections.
480 DwarfAbbrevSection = Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
483 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0, "section_info");
484 DwarfLineSection = Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0);
485 DwarfFrameSection = Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0);
486 DwarfPubNamesSection =
487 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0);
488 DwarfPubTypesSection =
489 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0);
490 DwarfGnuPubNamesSection =
491 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0);
492 DwarfGnuPubTypesSection =
493 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0);
495 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
496 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
497 DwarfLocSection = Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0);
498 DwarfARangesSection =
499 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0);
501 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0, "debug_range");
503 // DWARF5 Experimental Debug Info
505 // Accelerator Tables
506 DwarfAccelNamesSection =
507 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0, "names_begin");
508 DwarfAccelObjCSection =
509 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0, "objc_begin");
510 DwarfAccelNamespaceSection = Ctx->getELFSection(
511 ".apple_namespaces", ELF::SHT_PROGBITS, 0, "namespac_begin");
512 DwarfAccelTypesSection =
513 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0, "types_begin");
516 DwarfInfoDWOSection =
517 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0);
518 DwarfTypesDWOSection =
519 Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS, 0);
520 DwarfAbbrevDWOSection =
521 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0);
523 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
524 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
525 DwarfLineDWOSection =
526 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0);
528 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0, "skel_loc");
529 DwarfStrOffDWOSection =
530 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0);
532 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0, "addr_sec");
535 Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
538 Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
541 Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
544 void MCObjectFileInfo::initCOFFMCObjectFileInfo(Triple T) {
545 EHFrameSection = Ctx->getCOFFSection(
546 ".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
547 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
548 SectionKind::getData());
550 bool IsWoA = T.getArch() == Triple::arm || T.getArch() == Triple::thumb;
552 CommDirectiveSupportsAlignment = true;
555 BSSSection = Ctx->getCOFFSection(
556 ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
557 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
558 SectionKind::getBSS());
559 TextSection = Ctx->getCOFFSection(
561 (IsWoA ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |
562 COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
563 COFF::IMAGE_SCN_MEM_READ,
564 SectionKind::getText());
565 DataSection = Ctx->getCOFFSection(
566 ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
567 COFF::IMAGE_SCN_MEM_WRITE,
568 SectionKind::getData());
569 ReadOnlySection = Ctx->getCOFFSection(
570 ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
571 SectionKind::getReadOnly());
573 if (T.isKnownWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
575 Ctx->getCOFFSection(".CRT$XCU", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
576 COFF::IMAGE_SCN_MEM_READ,
577 SectionKind::getReadOnly());
579 Ctx->getCOFFSection(".CRT$XTX", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
580 COFF::IMAGE_SCN_MEM_READ,
581 SectionKind::getReadOnly());
583 StaticCtorSection = Ctx->getCOFFSection(
584 ".ctors", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
585 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
586 SectionKind::getData());
587 StaticDtorSection = Ctx->getCOFFSection(
588 ".dtors", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
589 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
590 SectionKind::getData());
593 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
594 // though it contains relocatable pointers. In PIC mode, this is probably a
595 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
596 // adjusted or this should be a data section.
597 assert(T.isOSWindows() && "Windows is the only supported COFF target");
598 if (T.getArch() == Triple::x86_64) {
599 // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
600 LSDASection = nullptr;
602 LSDASection = Ctx->getCOFFSection(".gcc_except_table",
603 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
604 COFF::IMAGE_SCN_MEM_READ,
605 SectionKind::getReadOnly());
609 COFFDebugSymbolsSection =
610 Ctx->getCOFFSection(".debug$S", COFF::IMAGE_SCN_MEM_DISCARDABLE |
611 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
612 COFF::IMAGE_SCN_MEM_READ,
613 SectionKind::getMetadata());
615 DwarfAbbrevSection = Ctx->getCOFFSection(
617 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
618 COFF::IMAGE_SCN_MEM_READ,
619 SectionKind::getMetadata(), "section_abbrev");
620 DwarfInfoSection = Ctx->getCOFFSection(
622 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
623 COFF::IMAGE_SCN_MEM_READ,
624 SectionKind::getMetadata(), "section_info");
625 DwarfLineSection = Ctx->getCOFFSection(
627 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
628 COFF::IMAGE_SCN_MEM_READ,
629 SectionKind::getMetadata(), "section_line");
631 DwarfFrameSection = Ctx->getCOFFSection(
633 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
634 COFF::IMAGE_SCN_MEM_READ,
635 SectionKind::getMetadata());
636 DwarfPubNamesSection = Ctx->getCOFFSection(
638 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
639 COFF::IMAGE_SCN_MEM_READ,
640 SectionKind::getMetadata());
641 DwarfPubTypesSection = Ctx->getCOFFSection(
643 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
644 COFF::IMAGE_SCN_MEM_READ,
645 SectionKind::getMetadata());
646 DwarfGnuPubNamesSection = Ctx->getCOFFSection(
647 ".debug_gnu_pubnames",
648 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
649 COFF::IMAGE_SCN_MEM_READ,
650 SectionKind::getMetadata());
651 DwarfGnuPubTypesSection = Ctx->getCOFFSection(
652 ".debug_gnu_pubtypes",
653 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
654 COFF::IMAGE_SCN_MEM_READ,
655 SectionKind::getMetadata());
656 DwarfStrSection = Ctx->getCOFFSection(
658 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
659 COFF::IMAGE_SCN_MEM_READ,
660 SectionKind::getMetadata(), "info_string");
661 DwarfLocSection = Ctx->getCOFFSection(
663 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
664 COFF::IMAGE_SCN_MEM_READ,
665 SectionKind::getMetadata(), "section_debug_loc");
666 DwarfARangesSection = Ctx->getCOFFSection(
668 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
669 COFF::IMAGE_SCN_MEM_READ,
670 SectionKind::getMetadata());
671 DwarfRangesSection = Ctx->getCOFFSection(
673 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
674 COFF::IMAGE_SCN_MEM_READ,
675 SectionKind::getMetadata(), "debug_range");
676 DwarfInfoDWOSection = Ctx->getCOFFSection(
678 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
679 COFF::IMAGE_SCN_MEM_READ,
680 SectionKind::getMetadata(), "section_info_dwo");
681 DwarfTypesDWOSection = Ctx->getCOFFSection(
683 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
684 COFF::IMAGE_SCN_MEM_READ,
685 SectionKind::getMetadata(), "section_types_dwo");
686 DwarfAbbrevDWOSection = Ctx->getCOFFSection(
688 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
689 COFF::IMAGE_SCN_MEM_READ,
690 SectionKind::getMetadata(), "section_abbrev_dwo");
691 DwarfStrDWOSection = Ctx->getCOFFSection(
693 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
694 COFF::IMAGE_SCN_MEM_READ,
695 SectionKind::getMetadata(), "skel_string");
696 DwarfLineDWOSection = Ctx->getCOFFSection(
698 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
699 COFF::IMAGE_SCN_MEM_READ,
700 SectionKind::getMetadata());
701 DwarfLocDWOSection = Ctx->getCOFFSection(
703 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
704 COFF::IMAGE_SCN_MEM_READ,
705 SectionKind::getMetadata(), "skel_loc");
706 DwarfStrOffDWOSection = Ctx->getCOFFSection(
707 ".debug_str_offsets.dwo",
708 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
709 COFF::IMAGE_SCN_MEM_READ,
710 SectionKind::getMetadata());
711 DwarfAddrSection = Ctx->getCOFFSection(
713 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
714 COFF::IMAGE_SCN_MEM_READ,
715 SectionKind::getMetadata(), "addr_sec");
716 DwarfAccelNamesSection = Ctx->getCOFFSection(
718 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
719 COFF::IMAGE_SCN_MEM_READ,
720 SectionKind::getMetadata(), "names_begin");
721 DwarfAccelNamespaceSection = Ctx->getCOFFSection(
723 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
724 COFF::IMAGE_SCN_MEM_READ,
725 SectionKind::getMetadata(), "namespac_begin");
726 DwarfAccelTypesSection = Ctx->getCOFFSection(
728 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
729 COFF::IMAGE_SCN_MEM_READ,
730 SectionKind::getMetadata(), "types_begin");
731 DwarfAccelObjCSection = Ctx->getCOFFSection(
733 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
734 COFF::IMAGE_SCN_MEM_READ,
735 SectionKind::getMetadata(), "objc_begin");
737 DrectveSection = Ctx->getCOFFSection(
738 ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
739 SectionKind::getMetadata());
741 PDataSection = Ctx->getCOFFSection(
742 ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
743 SectionKind::getData());
745 XDataSection = Ctx->getCOFFSection(
746 ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
747 SectionKind::getData());
749 SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO,
750 SectionKind::getMetadata());
752 TLSDataSection = Ctx->getCOFFSection(
753 ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
754 COFF::IMAGE_SCN_MEM_WRITE,
755 SectionKind::getData());
757 StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
758 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
759 COFF::IMAGE_SCN_MEM_READ,
760 SectionKind::getReadOnly());
763 void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple,
772 CommDirectiveSupportsAlignment = true;
773 SupportsWeakOmittedEHFrame = true;
774 SupportsCompactUnwindWithoutEHFrame = false;
775 OmitDwarfIfHaveCompactUnwind = false;
777 PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
778 dwarf::DW_EH_PE_absptr;
780 CompactUnwindDwarfEHFrameOnly = 0;
782 EHFrameSection = nullptr; // Created on demand.
783 CompactUnwindSection = nullptr; // Used only by selected targets.
784 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
785 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
786 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
787 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
791 Triple::ArchType Arch = TT.getArch();
792 // FIXME: Checking for Arch here to filter out bogus triples such as
793 // cellspu-apple-darwin. Perhaps we should fix in Triple?
794 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
795 Arch == Triple::arm || Arch == Triple::thumb ||
796 Arch == Triple::aarch64 ||
797 Arch == Triple::ppc || Arch == Triple::ppc64 ||
798 Arch == Triple::UnknownArch) &&
799 TT.isOSBinFormatMachO()) {
801 initMachOMCObjectFileInfo(TT);
802 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
803 Arch == Triple::arm || Arch == Triple::thumb) &&
804 (TT.isOSWindows() && TT.getObjectFormat() == Triple::COFF)) {
806 initCOFFMCObjectFileInfo(TT);
809 initELFMCObjectFileInfo(TT);
813 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model RM,
816 InitMCObjectFileInfo(Triple(TT), RM, CM, ctx);
819 MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
820 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,