1 //===-- MCObjectFileInfo.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/BinaryFormat/COFF.h"
14 #include "llvm/BinaryFormat/ELF.h"
15 #include "llvm/MC/MCAsmInfo.h"
16 #include "llvm/MC/MCContext.h"
17 #include "llvm/MC/MCSection.h"
18 #include "llvm/MC/MCSectionCOFF.h"
19 #include "llvm/MC/MCSectionELF.h"
20 #include "llvm/MC/MCSectionMachO.h"
21 #include "llvm/MC/MCSectionWasm.h"
25 static bool useCompactUnwind(const Triple &T) {
30 // aarch64 always has it.
31 if (T.getArch() == Triple::aarch64)
34 // armv7k always has it.
38 // Use it on newer version of OS X.
39 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
42 // And the iOS simulator.
44 (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86))
50 void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
52 SupportsWeakOmittedEHFrame = false;
54 EHFrameSection = Ctx->getMachOSection(
55 "__TEXT", "__eh_frame",
56 MachO::S_COALESCED | MachO::S_ATTR_NO_TOC |
57 MachO::S_ATTR_STRIP_STATIC_SYMS | MachO::S_ATTR_LIVE_SUPPORT,
58 SectionKind::getReadOnly());
60 if (T.isOSDarwin() && T.getArch() == Triple::aarch64)
61 SupportsCompactUnwindWithoutEHFrame = true;
64 OmitDwarfIfHaveCompactUnwind = true;
66 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
67 | dwarf::DW_EH_PE_sdata4;
68 LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
69 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
70 dwarf::DW_EH_PE_sdata4;
72 // .comm doesn't support alignment before Leopard.
73 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
74 CommDirectiveSupportsAlignment = false;
77 = Ctx->getMachOSection("__TEXT", "__text",
78 MachO::S_ATTR_PURE_INSTRUCTIONS,
79 SectionKind::getText());
81 = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
83 // BSSSection might not be expected initialized on msvc.
86 TLSDataSection // .tdata
87 = Ctx->getMachOSection("__DATA", "__thread_data",
88 MachO::S_THREAD_LOCAL_REGULAR,
89 SectionKind::getData());
90 TLSBSSSection // .tbss
91 = Ctx->getMachOSection("__DATA", "__thread_bss",
92 MachO::S_THREAD_LOCAL_ZEROFILL,
93 SectionKind::getThreadBSS());
95 // TODO: Verify datarel below.
97 = Ctx->getMachOSection("__DATA", "__thread_vars",
98 MachO::S_THREAD_LOCAL_VARIABLES,
99 SectionKind::getData());
101 TLSThreadInitSection = Ctx->getMachOSection(
102 "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
103 SectionKind::getData());
105 CStringSection // .cstring
106 = Ctx->getMachOSection("__TEXT", "__cstring",
107 MachO::S_CSTRING_LITERALS,
108 SectionKind::getMergeable1ByteCString());
110 = Ctx->getMachOSection("__TEXT","__ustring", 0,
111 SectionKind::getMergeable2ByteCString());
112 FourByteConstantSection // .literal4
113 = Ctx->getMachOSection("__TEXT", "__literal4",
114 MachO::S_4BYTE_LITERALS,
115 SectionKind::getMergeableConst4());
116 EightByteConstantSection // .literal8
117 = Ctx->getMachOSection("__TEXT", "__literal8",
118 MachO::S_8BYTE_LITERALS,
119 SectionKind::getMergeableConst8());
121 SixteenByteConstantSection // .literal16
122 = Ctx->getMachOSection("__TEXT", "__literal16",
123 MachO::S_16BYTE_LITERALS,
124 SectionKind::getMergeableConst16());
126 ReadOnlySection // .const
127 = Ctx->getMachOSection("__TEXT", "__const", 0,
128 SectionKind::getReadOnly());
130 // If the target is not powerpc, map the coal sections to the non-coal
133 // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
134 // "__TEXT/__const_coal" => section "__TEXT/__const"
135 // "__DATA/__datacoal_nt" => section "__DATA/__data"
136 Triple::ArchType ArchTy = T.getArch();
138 if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
140 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
142 MachO::S_ATTR_PURE_INSTRUCTIONS,
143 SectionKind::getText());
145 = Ctx->getMachOSection("__TEXT", "__const_coal",
147 SectionKind::getReadOnly());
148 DataCoalSection = Ctx->getMachOSection(
149 "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());
151 TextCoalSection = TextSection;
152 ConstTextCoalSection = ReadOnlySection;
153 DataCoalSection = DataSection;
156 ConstDataSection // .const_data
157 = Ctx->getMachOSection("__DATA", "__const", 0,
158 SectionKind::getReadOnlyWithRel());
160 = Ctx->getMachOSection("__DATA","__common",
162 SectionKind::getBSS());
164 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
165 SectionKind::getBSS());
168 LazySymbolPointerSection
169 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
170 MachO::S_LAZY_SYMBOL_POINTERS,
171 SectionKind::getMetadata());
172 NonLazySymbolPointerSection
173 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
174 MachO::S_NON_LAZY_SYMBOL_POINTERS,
175 SectionKind::getMetadata());
177 ThreadLocalPointerSection
178 = Ctx->getMachOSection("__DATA", "__thread_ptr",
179 MachO::S_THREAD_LOCAL_VARIABLE_POINTERS,
180 SectionKind::getMetadata());
182 // Exception Handling.
183 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
184 SectionKind::getReadOnlyWithRel());
186 COFFDebugSymbolsSection = nullptr;
187 COFFDebugTypesSection = nullptr;
188 COFFGlobalTypeHashesSection = nullptr;
190 if (useCompactUnwind(T)) {
191 CompactUnwindSection =
192 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
193 SectionKind::getReadOnly());
195 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
196 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF
197 else if (T.getArch() == Triple::aarch64)
198 CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF
199 else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
200 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF
203 // Debug Information.
204 DwarfAccelNamesSection =
205 Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
206 SectionKind::getMetadata(), "names_begin");
207 DwarfAccelObjCSection =
208 Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
209 SectionKind::getMetadata(), "objc_begin");
210 // 16 character section limit...
211 DwarfAccelNamespaceSection =
212 Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
213 SectionKind::getMetadata(), "namespac_begin");
214 DwarfAccelTypesSection =
215 Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
216 SectionKind::getMetadata(), "types_begin");
218 DwarfSwiftASTSection =
219 Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG,
220 SectionKind::getMetadata());
223 Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
224 SectionKind::getMetadata(), "section_abbrev");
226 Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
227 SectionKind::getMetadata(), "section_info");
229 Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
230 SectionKind::getMetadata(), "section_line");
232 Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
233 SectionKind::getMetadata());
234 DwarfPubNamesSection =
235 Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
236 SectionKind::getMetadata());
237 DwarfPubTypesSection =
238 Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
239 SectionKind::getMetadata());
240 DwarfGnuPubNamesSection =
241 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
242 SectionKind::getMetadata());
243 DwarfGnuPubTypesSection =
244 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
245 SectionKind::getMetadata());
247 Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
248 SectionKind::getMetadata(), "info_string");
250 Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG,
251 SectionKind::getMetadata(), "section_str_off");
253 Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
254 SectionKind::getMetadata(), "section_debug_loc");
255 DwarfARangesSection =
256 Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
257 SectionKind::getMetadata());
259 Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
260 SectionKind::getMetadata(), "debug_range");
261 DwarfMacinfoSection =
262 Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG,
263 SectionKind::getMetadata(), "debug_macinfo");
264 DwarfDebugInlineSection =
265 Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
266 SectionKind::getMetadata());
267 DwarfCUIndexSection =
268 Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,
269 SectionKind::getMetadata());
270 DwarfTUIndexSection =
271 Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG,
272 SectionKind::getMetadata());
273 StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
274 0, SectionKind::getMetadata());
276 FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
277 0, SectionKind::getMetadata());
279 TLSExtraDataSection = TLSTLVSection;
282 void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
283 switch (T.getArch()) {
286 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
289 case Triple::mips64el:
290 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
293 FDECFIEncoding = dwarf::DW_EH_PE_pcrel |
294 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
298 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
301 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
305 switch (T.getArch()) {
309 case Triple::thumbeb:
310 if (Ctx->getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
312 // Fallthrough if not using EHABI
316 PersonalityEncoding = PositionIndependent
317 ? dwarf::DW_EH_PE_indirect |
318 dwarf::DW_EH_PE_pcrel |
319 dwarf::DW_EH_PE_sdata4
320 : dwarf::DW_EH_PE_absptr;
321 LSDAEncoding = PositionIndependent
322 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
323 : dwarf::DW_EH_PE_absptr;
324 TTypeEncoding = PositionIndependent
325 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
326 dwarf::DW_EH_PE_sdata4
327 : dwarf::DW_EH_PE_absptr;
330 if (PositionIndependent) {
331 PersonalityEncoding =
332 dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
333 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
334 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
335 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
336 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
337 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
339 PersonalityEncoding =
340 Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
341 LSDAEncoding = Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
342 TTypeEncoding = Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
345 case Triple::hexagon:
346 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
347 LSDAEncoding = dwarf::DW_EH_PE_absptr;
348 FDECFIEncoding = dwarf::DW_EH_PE_absptr;
349 TTypeEncoding = dwarf::DW_EH_PE_absptr;
350 if (PositionIndependent) {
351 PersonalityEncoding |= dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel;
352 LSDAEncoding |= dwarf::DW_EH_PE_pcrel;
353 FDECFIEncoding |= dwarf::DW_EH_PE_pcrel;
354 TTypeEncoding |= dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel;
357 case Triple::aarch64:
358 case Triple::aarch64_be:
359 // The small model guarantees static code/data size < 4GB, but not where it
360 // will be in memory. Most of these could end up >2GB away so even a signed
361 // pc-relative 32-bit address is insufficient, theoretically.
362 if (PositionIndependent) {
363 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
364 dwarf::DW_EH_PE_sdata8;
365 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
366 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
367 dwarf::DW_EH_PE_sdata8;
369 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
370 LSDAEncoding = dwarf::DW_EH_PE_absptr;
371 TTypeEncoding = dwarf::DW_EH_PE_absptr;
375 LSDAEncoding = dwarf::DW_EH_PE_absptr;
376 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
377 TTypeEncoding = dwarf::DW_EH_PE_absptr;
382 case Triple::mips64el:
383 // MIPS uses indirect pointer to refer personality functions and types, so
384 // that the eh_frame section can be read-only. DW.ref.personality will be
385 // generated for relocation.
386 PersonalityEncoding = dwarf::DW_EH_PE_indirect;
387 // FIXME: The N64 ABI probably ought to use DW_EH_PE_sdata8 but we can't
388 // identify N64 from just a triple.
389 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
390 dwarf::DW_EH_PE_sdata4;
391 // We don't support PC-relative LSDA references in GAS so we use the default
392 // DW_EH_PE_absptr for those.
394 // FreeBSD must be explicit about the data size and using pcrel since it's
395 // assembler/linker won't do the automatic conversion that the Linux tools
397 if (T.isOSFreeBSD()) {
398 PersonalityEncoding |= dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
399 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
403 case Triple::ppc64le:
404 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
405 dwarf::DW_EH_PE_udata8;
406 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
407 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
408 dwarf::DW_EH_PE_udata8;
410 case Triple::sparcel:
412 if (PositionIndependent) {
413 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
414 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
415 dwarf::DW_EH_PE_sdata4;
416 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
417 dwarf::DW_EH_PE_sdata4;
419 LSDAEncoding = dwarf::DW_EH_PE_absptr;
420 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
421 TTypeEncoding = dwarf::DW_EH_PE_absptr;
424 case Triple::sparcv9:
425 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
426 if (PositionIndependent) {
427 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
428 dwarf::DW_EH_PE_sdata4;
429 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
430 dwarf::DW_EH_PE_sdata4;
432 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
433 TTypeEncoding = dwarf::DW_EH_PE_absptr;
436 case Triple::systemz:
437 // All currently-defined code models guarantee that 4-byte PC-relative
438 // values will be in range.
439 if (PositionIndependent) {
440 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
441 dwarf::DW_EH_PE_sdata4;
442 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
443 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
444 dwarf::DW_EH_PE_sdata4;
446 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
447 LSDAEncoding = dwarf::DW_EH_PE_absptr;
448 TTypeEncoding = dwarf::DW_EH_PE_absptr;
455 unsigned EHSectionType = T.getArch() == Triple::x86_64
456 ? ELF::SHT_X86_64_UNWIND
459 // Solaris requires different flags for .eh_frame to seemingly every other
461 unsigned EHSectionFlags = ELF::SHF_ALLOC;
462 if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
463 EHSectionFlags |= ELF::SHF_WRITE;
466 BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
467 ELF::SHF_WRITE | ELF::SHF_ALLOC);
469 TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
470 ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
472 DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
473 ELF::SHF_WRITE | ELF::SHF_ALLOC);
476 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
479 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
480 ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
482 TLSBSSSection = Ctx->getELFSection(
483 ".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
485 DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
486 ELF::SHF_ALLOC | ELF::SHF_WRITE);
488 MergeableConst4Section =
489 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
490 ELF::SHF_ALLOC | ELF::SHF_MERGE, 4, "");
492 MergeableConst8Section =
493 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
494 ELF::SHF_ALLOC | ELF::SHF_MERGE, 8, "");
496 MergeableConst16Section =
497 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
498 ELF::SHF_ALLOC | ELF::SHF_MERGE, 16, "");
500 MergeableConst32Section =
501 Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS,
502 ELF::SHF_ALLOC | ELF::SHF_MERGE, 32, "");
504 // Exception Handling Sections.
506 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
507 // it contains relocatable pointers. In PIC mode, this is probably a big
508 // runtime hit for C++ apps. Either the contents of the LSDA need to be
509 // adjusted or this should be a data section.
510 LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
513 COFFDebugSymbolsSection = nullptr;
514 COFFDebugTypesSection = nullptr;
516 unsigned DebugSecType = ELF::SHT_PROGBITS;
518 // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
519 // to distinguish among sections contain DWARF and ECOFF debug formats.
520 // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
521 if (T.getArch() == Triple::mips || T.getArch() == Triple::mipsel ||
522 T.getArch() == Triple::mips64 || T.getArch() == Triple::mips64el)
523 DebugSecType = ELF::SHT_MIPS_DWARF;
525 // Debug Info Sections.
527 Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);
528 DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0);
529 DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0);
530 DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0);
531 DwarfPubNamesSection =
532 Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);
533 DwarfPubTypesSection =
534 Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);
535 DwarfGnuPubNamesSection =
536 Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);
537 DwarfGnuPubTypesSection =
538 Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);
540 Ctx->getELFSection(".debug_str", DebugSecType,
541 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
542 DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0);
543 DwarfARangesSection =
544 Ctx->getELFSection(".debug_aranges", DebugSecType, 0);
546 Ctx->getELFSection(".debug_ranges", DebugSecType, 0);
547 DwarfMacinfoSection =
548 Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);
550 // DWARF5 Experimental Debug Info
552 // Accelerator Tables
553 DwarfAccelNamesSection =
554 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);
555 DwarfAccelObjCSection =
556 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);
557 DwarfAccelNamespaceSection =
558 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);
559 DwarfAccelTypesSection =
560 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);
562 // String Offset and Address Sections
564 Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);
565 DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);
568 DwarfInfoDWOSection =
569 Ctx->getELFSection(".debug_info.dwo", DebugSecType, 0);
570 DwarfTypesDWOSection =
571 Ctx->getELFSection(".debug_types.dwo", DebugSecType, 0);
572 DwarfAbbrevDWOSection =
573 Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, 0);
575 Ctx->getELFSection(".debug_str.dwo", DebugSecType,
576 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
577 DwarfLineDWOSection =
578 Ctx->getELFSection(".debug_line.dwo", DebugSecType, 0);
580 Ctx->getELFSection(".debug_loc.dwo", DebugSecType, 0);
581 DwarfStrOffDWOSection =
582 Ctx->getELFSection(".debug_str_offsets.dwo", DebugSecType, 0);
585 DwarfCUIndexSection =
586 Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);
587 DwarfTUIndexSection =
588 Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);
591 Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
594 Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
597 Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
599 StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);
602 void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
603 EHFrameSection = Ctx->getCOFFSection(
604 ".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
605 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
606 SectionKind::getData());
608 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
609 // used to indicate to the linker that the text segment contains thumb instructions
610 // and to set the ISA selection bit for calls accordingly.
611 const bool IsThumb = T.getArch() == Triple::thumb;
613 CommDirectiveSupportsAlignment = true;
616 BSSSection = Ctx->getCOFFSection(
617 ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
618 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
619 SectionKind::getBSS());
620 TextSection = Ctx->getCOFFSection(
622 (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |
623 COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
624 COFF::IMAGE_SCN_MEM_READ,
625 SectionKind::getText());
626 DataSection = Ctx->getCOFFSection(
627 ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
628 COFF::IMAGE_SCN_MEM_WRITE,
629 SectionKind::getData());
630 ReadOnlySection = Ctx->getCOFFSection(
631 ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
632 SectionKind::getReadOnly());
634 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
635 // though it contains relocatable pointers. In PIC mode, this is probably a
636 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
637 // adjusted or this should be a data section.
638 if (T.getArch() == Triple::x86_64) {
639 // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
640 LSDASection = nullptr;
642 LSDASection = Ctx->getCOFFSection(".gcc_except_table",
643 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
644 COFF::IMAGE_SCN_MEM_READ,
645 SectionKind::getReadOnly());
649 COFFDebugSymbolsSection =
650 Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
651 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
652 COFF::IMAGE_SCN_MEM_READ),
653 SectionKind::getMetadata());
654 COFFDebugTypesSection =
655 Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
656 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
657 COFF::IMAGE_SCN_MEM_READ),
658 SectionKind::getMetadata());
659 COFFGlobalTypeHashesSection = Ctx->getCOFFSection(
661 (COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
662 COFF::IMAGE_SCN_MEM_READ),
663 SectionKind::getMetadata());
665 DwarfAbbrevSection = Ctx->getCOFFSection(
667 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
668 COFF::IMAGE_SCN_MEM_READ,
669 SectionKind::getMetadata(), "section_abbrev");
670 DwarfInfoSection = Ctx->getCOFFSection(
672 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
673 COFF::IMAGE_SCN_MEM_READ,
674 SectionKind::getMetadata(), "section_info");
675 DwarfLineSection = Ctx->getCOFFSection(
677 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
678 COFF::IMAGE_SCN_MEM_READ,
679 SectionKind::getMetadata(), "section_line");
681 DwarfFrameSection = Ctx->getCOFFSection(
683 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
684 COFF::IMAGE_SCN_MEM_READ,
685 SectionKind::getMetadata());
686 DwarfPubNamesSection = Ctx->getCOFFSection(
688 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
689 COFF::IMAGE_SCN_MEM_READ,
690 SectionKind::getMetadata());
691 DwarfPubTypesSection = Ctx->getCOFFSection(
693 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
694 COFF::IMAGE_SCN_MEM_READ,
695 SectionKind::getMetadata());
696 DwarfGnuPubNamesSection = Ctx->getCOFFSection(
697 ".debug_gnu_pubnames",
698 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
699 COFF::IMAGE_SCN_MEM_READ,
700 SectionKind::getMetadata());
701 DwarfGnuPubTypesSection = Ctx->getCOFFSection(
702 ".debug_gnu_pubtypes",
703 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
704 COFF::IMAGE_SCN_MEM_READ,
705 SectionKind::getMetadata());
706 DwarfStrSection = Ctx->getCOFFSection(
708 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
709 COFF::IMAGE_SCN_MEM_READ,
710 SectionKind::getMetadata(), "info_string");
711 DwarfStrOffSection = Ctx->getCOFFSection(
712 ".debug_str_offsets",
713 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
714 COFF::IMAGE_SCN_MEM_READ,
715 SectionKind::getMetadata(), "section_str_off");
716 DwarfLocSection = Ctx->getCOFFSection(
718 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
719 COFF::IMAGE_SCN_MEM_READ,
720 SectionKind::getMetadata(), "section_debug_loc");
721 DwarfARangesSection = Ctx->getCOFFSection(
723 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
724 COFF::IMAGE_SCN_MEM_READ,
725 SectionKind::getMetadata());
726 DwarfRangesSection = Ctx->getCOFFSection(
728 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
729 COFF::IMAGE_SCN_MEM_READ,
730 SectionKind::getMetadata(), "debug_range");
731 DwarfMacinfoSection = Ctx->getCOFFSection(
733 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
734 COFF::IMAGE_SCN_MEM_READ,
735 SectionKind::getMetadata(), "debug_macinfo");
736 DwarfInfoDWOSection = Ctx->getCOFFSection(
738 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
739 COFF::IMAGE_SCN_MEM_READ,
740 SectionKind::getMetadata(), "section_info_dwo");
741 DwarfTypesDWOSection = Ctx->getCOFFSection(
743 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
744 COFF::IMAGE_SCN_MEM_READ,
745 SectionKind::getMetadata(), "section_types_dwo");
746 DwarfAbbrevDWOSection = Ctx->getCOFFSection(
748 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
749 COFF::IMAGE_SCN_MEM_READ,
750 SectionKind::getMetadata(), "section_abbrev_dwo");
751 DwarfStrDWOSection = Ctx->getCOFFSection(
753 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
754 COFF::IMAGE_SCN_MEM_READ,
755 SectionKind::getMetadata(), "skel_string");
756 DwarfLineDWOSection = Ctx->getCOFFSection(
758 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
759 COFF::IMAGE_SCN_MEM_READ,
760 SectionKind::getMetadata());
761 DwarfLocDWOSection = Ctx->getCOFFSection(
763 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
764 COFF::IMAGE_SCN_MEM_READ,
765 SectionKind::getMetadata(), "skel_loc");
766 DwarfStrOffDWOSection = Ctx->getCOFFSection(
767 ".debug_str_offsets.dwo",
768 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
769 COFF::IMAGE_SCN_MEM_READ,
770 SectionKind::getMetadata(), "section_str_off_dwo");
771 DwarfAddrSection = Ctx->getCOFFSection(
773 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
774 COFF::IMAGE_SCN_MEM_READ,
775 SectionKind::getMetadata(), "addr_sec");
776 DwarfCUIndexSection = Ctx->getCOFFSection(
778 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
779 COFF::IMAGE_SCN_MEM_READ,
780 SectionKind::getMetadata());
781 DwarfTUIndexSection = Ctx->getCOFFSection(
783 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
784 COFF::IMAGE_SCN_MEM_READ,
785 SectionKind::getMetadata());
786 DwarfAccelNamesSection = Ctx->getCOFFSection(
788 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
789 COFF::IMAGE_SCN_MEM_READ,
790 SectionKind::getMetadata(), "names_begin");
791 DwarfAccelNamespaceSection = Ctx->getCOFFSection(
793 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
794 COFF::IMAGE_SCN_MEM_READ,
795 SectionKind::getMetadata(), "namespac_begin");
796 DwarfAccelTypesSection = Ctx->getCOFFSection(
798 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
799 COFF::IMAGE_SCN_MEM_READ,
800 SectionKind::getMetadata(), "types_begin");
801 DwarfAccelObjCSection = Ctx->getCOFFSection(
803 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
804 COFF::IMAGE_SCN_MEM_READ,
805 SectionKind::getMetadata(), "objc_begin");
807 DrectveSection = Ctx->getCOFFSection(
808 ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
809 SectionKind::getMetadata());
811 PDataSection = Ctx->getCOFFSection(
812 ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
813 SectionKind::getData());
815 XDataSection = Ctx->getCOFFSection(
816 ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
817 SectionKind::getData());
819 SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO,
820 SectionKind::getMetadata());
822 TLSDataSection = Ctx->getCOFFSection(
823 ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
824 COFF::IMAGE_SCN_MEM_WRITE,
825 SectionKind::getData());
827 StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
828 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
829 COFF::IMAGE_SCN_MEM_READ,
830 SectionKind::getReadOnly());
833 void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
834 // TODO: Set the section types and flags.
835 TextSection = Ctx->getWasmSection(".text", SectionKind::getText());
836 DataSection = Ctx->getWasmSection(".data", SectionKind::getData());
838 // TODO: Set the section types and flags.
839 DwarfLineSection = Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());
840 DwarfStrSection = Ctx->getWasmSection(".debug_str", SectionKind::getMetadata());
841 DwarfLocSection = Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());
842 DwarfAbbrevSection = Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata(), "section_abbrev");
843 DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());
844 DwarfRangesSection = Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata(), "debug_range");
845 DwarfMacinfoSection = Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata(), "debug_macinfo");
846 DwarfAddrSection = Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata());
847 DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
848 DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
849 DwarfInfoSection = Ctx->getWasmSection(".debug_info", SectionKind::getMetadata(), "section_info");
850 DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());
851 DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
852 DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
854 // TODO: Define more sections.
857 void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
859 bool LargeCodeModel) {
860 PositionIndependent = PIC;
864 CommDirectiveSupportsAlignment = true;
865 SupportsWeakOmittedEHFrame = true;
866 SupportsCompactUnwindWithoutEHFrame = false;
867 OmitDwarfIfHaveCompactUnwind = false;
869 PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
870 dwarf::DW_EH_PE_absptr;
872 CompactUnwindDwarfEHFrameOnly = 0;
874 EHFrameSection = nullptr; // Created on demand.
875 CompactUnwindSection = nullptr; // Used only by selected targets.
876 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
877 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
878 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
879 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
883 switch (TT.getObjectFormat()) {
886 initMachOMCObjectFileInfo(TT);
889 if (!TT.isOSWindows())
891 "Cannot initialize MC for non-Windows COFF object files.");
894 initCOFFMCObjectFileInfo(TT);
898 initELFMCObjectFileInfo(TT, LargeCodeModel);
902 initWasmMCObjectFileInfo(TT);
904 case Triple::UnknownObjectFormat:
905 report_fatal_error("Cannot initialize MC for unknown object file format.");
910 MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
911 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,