[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / lib / MC / MCObjectFileInfo.cpp
blobbebbc9d83f6a1026a2eb2faed1d38da3ad32e0e5
1 //===-- MCObjectFileInfo.cpp - Object File Information --------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/MC/MCObjectFileInfo.h"
10 #include "llvm/ADT/StringExtras.h"
11 #include "llvm/ADT/Triple.h"
12 #include "llvm/BinaryFormat/COFF.h"
13 #include "llvm/BinaryFormat/ELF.h"
14 #include "llvm/BinaryFormat/Wasm.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/MCSectionGOFF.h"
21 #include "llvm/MC/MCSectionMachO.h"
22 #include "llvm/MC/MCSectionWasm.h"
23 #include "llvm/MC/MCSectionXCOFF.h"
25 using namespace llvm;
27 static bool useCompactUnwind(const Triple &T) {
28 // Only on darwin.
29 if (!T.isOSDarwin())
30 return false;
32 // aarch64 always has it.
33 if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)
34 return true;
36 // armv7k always has it.
37 if (T.isWatchABI())
38 return true;
40 // Use it on newer version of OS X.
41 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
42 return true;
44 // And the iOS simulator.
45 if (T.isiOS() && T.isX86())
46 return true;
48 return false;
51 void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
52 // MachO
53 SupportsWeakOmittedEHFrame = false;
55 EHFrameSection = Ctx->getMachOSection(
56 "__TEXT", "__eh_frame",
57 MachO::S_COALESCED | MachO::S_ATTR_NO_TOC |
58 MachO::S_ATTR_STRIP_STATIC_SYMS | MachO::S_ATTR_LIVE_SUPPORT,
59 SectionKind::getReadOnly());
61 if (T.isOSDarwin() &&
62 (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32))
63 SupportsCompactUnwindWithoutEHFrame = true;
65 if (T.isWatchABI())
66 OmitDwarfIfHaveCompactUnwind = true;
68 FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
70 // .comm doesn't support alignment before Leopard.
71 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
72 CommDirectiveSupportsAlignment = false;
74 TextSection // .text
75 = Ctx->getMachOSection("__TEXT", "__text",
76 MachO::S_ATTR_PURE_INSTRUCTIONS,
77 SectionKind::getText());
78 DataSection // .data
79 = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
81 // BSSSection might not be expected initialized on msvc.
82 BSSSection = nullptr;
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.
94 TLSTLVSection // .tlv
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());
107 UStringSection
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
129 // sections.
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 ConstDataSection // .const_data
137 = Ctx->getMachOSection("__DATA", "__const", 0,
138 SectionKind::getReadOnlyWithRel());
140 if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
141 TextCoalSection
142 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
143 MachO::S_COALESCED |
144 MachO::S_ATTR_PURE_INSTRUCTIONS,
145 SectionKind::getText());
146 ConstTextCoalSection
147 = Ctx->getMachOSection("__TEXT", "__const_coal",
148 MachO::S_COALESCED,
149 SectionKind::getReadOnly());
150 DataCoalSection = Ctx->getMachOSection(
151 "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());
152 ConstDataCoalSection = DataCoalSection;
153 } else {
154 TextCoalSection = TextSection;
155 ConstTextCoalSection = ReadOnlySection;
156 DataCoalSection = DataSection;
157 ConstDataCoalSection = ConstDataSection;
160 DataCommonSection
161 = Ctx->getMachOSection("__DATA","__common",
162 MachO::S_ZEROFILL,
163 SectionKind::getBSS());
164 DataBSSSection
165 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
166 SectionKind::getBSS());
169 LazySymbolPointerSection
170 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
171 MachO::S_LAZY_SYMBOL_POINTERS,
172 SectionKind::getMetadata());
173 NonLazySymbolPointerSection
174 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
175 MachO::S_NON_LAZY_SYMBOL_POINTERS,
176 SectionKind::getMetadata());
178 ThreadLocalPointerSection
179 = Ctx->getMachOSection("__DATA", "__thread_ptr",
180 MachO::S_THREAD_LOCAL_VARIABLE_POINTERS,
181 SectionKind::getMetadata());
183 // Exception Handling.
184 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
185 SectionKind::getReadOnlyWithRel());
187 COFFDebugSymbolsSection = nullptr;
188 COFFDebugTypesSection = nullptr;
189 COFFGlobalTypeHashesSection = nullptr;
191 if (useCompactUnwind(T)) {
192 CompactUnwindSection =
193 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
194 SectionKind::getReadOnly());
196 if (T.isX86())
197 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF
198 else if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)
199 CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF
200 else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
201 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF
204 // Debug Information.
205 DwarfDebugNamesSection =
206 Ctx->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG,
207 SectionKind::getMetadata(), "debug_names_begin");
208 DwarfAccelNamesSection =
209 Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
210 SectionKind::getMetadata(), "names_begin");
211 DwarfAccelObjCSection =
212 Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
213 SectionKind::getMetadata(), "objc_begin");
214 // 16 character section limit...
215 DwarfAccelNamespaceSection =
216 Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
217 SectionKind::getMetadata(), "namespac_begin");
218 DwarfAccelTypesSection =
219 Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
220 SectionKind::getMetadata(), "types_begin");
222 DwarfSwiftASTSection =
223 Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG,
224 SectionKind::getMetadata());
226 DwarfAbbrevSection =
227 Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
228 SectionKind::getMetadata(), "section_abbrev");
229 DwarfInfoSection =
230 Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
231 SectionKind::getMetadata(), "section_info");
232 DwarfLineSection =
233 Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
234 SectionKind::getMetadata(), "section_line");
235 DwarfLineStrSection =
236 Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,
237 SectionKind::getMetadata(), "section_line_str");
238 DwarfFrameSection =
239 Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
240 SectionKind::getMetadata());
241 DwarfPubNamesSection =
242 Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
243 SectionKind::getMetadata());
244 DwarfPubTypesSection =
245 Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
246 SectionKind::getMetadata());
247 DwarfGnuPubNamesSection =
248 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
249 SectionKind::getMetadata());
250 DwarfGnuPubTypesSection =
251 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
252 SectionKind::getMetadata());
253 DwarfStrSection =
254 Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
255 SectionKind::getMetadata(), "info_string");
256 DwarfStrOffSection =
257 Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG,
258 SectionKind::getMetadata(), "section_str_off");
259 DwarfAddrSection =
260 Ctx->getMachOSection("__DWARF", "__debug_addr", MachO::S_ATTR_DEBUG,
261 SectionKind::getMetadata(), "section_info");
262 DwarfLocSection =
263 Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
264 SectionKind::getMetadata(), "section_debug_loc");
265 DwarfLoclistsSection =
266 Ctx->getMachOSection("__DWARF", "__debug_loclists", MachO::S_ATTR_DEBUG,
267 SectionKind::getMetadata(), "section_debug_loc");
269 DwarfARangesSection =
270 Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
271 SectionKind::getMetadata());
272 DwarfRangesSection =
273 Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
274 SectionKind::getMetadata(), "debug_range");
275 DwarfRnglistsSection =
276 Ctx->getMachOSection("__DWARF", "__debug_rnglists", MachO::S_ATTR_DEBUG,
277 SectionKind::getMetadata(), "debug_range");
278 DwarfMacinfoSection =
279 Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG,
280 SectionKind::getMetadata(), "debug_macinfo");
281 DwarfMacroSection =
282 Ctx->getMachOSection("__DWARF", "__debug_macro", MachO::S_ATTR_DEBUG,
283 SectionKind::getMetadata(), "debug_macro");
284 DwarfDebugInlineSection =
285 Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
286 SectionKind::getMetadata());
287 DwarfCUIndexSection =
288 Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,
289 SectionKind::getMetadata());
290 DwarfTUIndexSection =
291 Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG,
292 SectionKind::getMetadata());
293 StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
294 0, SectionKind::getMetadata());
296 FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
297 0, SectionKind::getMetadata());
299 RemarksSection = Ctx->getMachOSection(
300 "__LLVM", "__remarks", MachO::S_ATTR_DEBUG, SectionKind::getMetadata());
302 TLSExtraDataSection = TLSTLVSection;
305 void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
306 switch (T.getArch()) {
307 case Triple::mips:
308 case Triple::mipsel:
309 case Triple::mips64:
310 case Triple::mips64el:
311 // We cannot use DW_EH_PE_sdata8 for the large PositionIndependent case
312 // since there is no R_MIPS_PC64 relocation (only a 32-bit version).
313 if (PositionIndependent && !Large)
314 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
315 else
316 FDECFIEncoding = Ctx->getAsmInfo()->getCodePointerSize() == 4
317 ? dwarf::DW_EH_PE_sdata4
318 : dwarf::DW_EH_PE_sdata8;
319 break;
320 case Triple::ppc64:
321 case Triple::ppc64le:
322 case Triple::aarch64:
323 case Triple::aarch64_be:
324 case Triple::x86_64:
325 FDECFIEncoding = dwarf::DW_EH_PE_pcrel |
326 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
327 break;
328 case Triple::bpfel:
329 case Triple::bpfeb:
330 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
331 break;
332 case Triple::hexagon:
333 FDECFIEncoding =
334 PositionIndependent ? dwarf::DW_EH_PE_pcrel : dwarf::DW_EH_PE_absptr;
335 break;
336 default:
337 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
338 break;
341 unsigned EHSectionType = T.getArch() == Triple::x86_64
342 ? ELF::SHT_X86_64_UNWIND
343 : ELF::SHT_PROGBITS;
345 // Solaris requires different flags for .eh_frame to seemingly every other
346 // platform.
347 unsigned EHSectionFlags = ELF::SHF_ALLOC;
348 if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
349 EHSectionFlags |= ELF::SHF_WRITE;
351 // ELF
352 BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
353 ELF::SHF_WRITE | ELF::SHF_ALLOC);
355 TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
356 ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
358 DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
359 ELF::SHF_WRITE | ELF::SHF_ALLOC);
361 ReadOnlySection =
362 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
364 TLSDataSection =
365 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
366 ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
368 TLSBSSSection = Ctx->getELFSection(
369 ".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
371 DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
372 ELF::SHF_ALLOC | ELF::SHF_WRITE);
374 MergeableConst4Section =
375 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
376 ELF::SHF_ALLOC | ELF::SHF_MERGE, 4);
378 MergeableConst8Section =
379 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
380 ELF::SHF_ALLOC | ELF::SHF_MERGE, 8);
382 MergeableConst16Section =
383 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
384 ELF::SHF_ALLOC | ELF::SHF_MERGE, 16);
386 MergeableConst32Section =
387 Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS,
388 ELF::SHF_ALLOC | ELF::SHF_MERGE, 32);
390 // Exception Handling Sections.
392 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
393 // it contains relocatable pointers. In PIC mode, this is probably a big
394 // runtime hit for C++ apps. Either the contents of the LSDA need to be
395 // adjusted or this should be a data section.
396 LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
397 ELF::SHF_ALLOC);
399 COFFDebugSymbolsSection = nullptr;
400 COFFDebugTypesSection = nullptr;
402 unsigned DebugSecType = ELF::SHT_PROGBITS;
404 // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
405 // to distinguish among sections contain DWARF and ECOFF debug formats.
406 // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
407 if (T.isMIPS())
408 DebugSecType = ELF::SHT_MIPS_DWARF;
410 // Debug Info Sections.
411 DwarfAbbrevSection =
412 Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);
413 DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0);
414 DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0);
415 DwarfLineStrSection =
416 Ctx->getELFSection(".debug_line_str", DebugSecType,
417 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1);
418 DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0);
419 DwarfPubNamesSection =
420 Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);
421 DwarfPubTypesSection =
422 Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);
423 DwarfGnuPubNamesSection =
424 Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);
425 DwarfGnuPubTypesSection =
426 Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);
427 DwarfStrSection =
428 Ctx->getELFSection(".debug_str", DebugSecType,
429 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1);
430 DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0);
431 DwarfARangesSection =
432 Ctx->getELFSection(".debug_aranges", DebugSecType, 0);
433 DwarfRangesSection =
434 Ctx->getELFSection(".debug_ranges", DebugSecType, 0);
435 DwarfMacinfoSection =
436 Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);
437 DwarfMacroSection = Ctx->getELFSection(".debug_macro", DebugSecType, 0);
439 // DWARF5 Experimental Debug Info
441 // Accelerator Tables
442 DwarfDebugNamesSection =
443 Ctx->getELFSection(".debug_names", ELF::SHT_PROGBITS, 0);
444 DwarfAccelNamesSection =
445 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);
446 DwarfAccelObjCSection =
447 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);
448 DwarfAccelNamespaceSection =
449 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);
450 DwarfAccelTypesSection =
451 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);
453 // String Offset and Address Sections
454 DwarfStrOffSection =
455 Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);
456 DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);
457 DwarfRnglistsSection = Ctx->getELFSection(".debug_rnglists", DebugSecType, 0);
458 DwarfLoclistsSection = Ctx->getELFSection(".debug_loclists", DebugSecType, 0);
460 // Fission Sections
461 DwarfInfoDWOSection =
462 Ctx->getELFSection(".debug_info.dwo", DebugSecType, ELF::SHF_EXCLUDE);
463 DwarfTypesDWOSection =
464 Ctx->getELFSection(".debug_types.dwo", DebugSecType, ELF::SHF_EXCLUDE);
465 DwarfAbbrevDWOSection =
466 Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, ELF::SHF_EXCLUDE);
467 DwarfStrDWOSection = Ctx->getELFSection(
468 ".debug_str.dwo", DebugSecType,
469 ELF::SHF_MERGE | ELF::SHF_STRINGS | ELF::SHF_EXCLUDE, 1);
470 DwarfLineDWOSection =
471 Ctx->getELFSection(".debug_line.dwo", DebugSecType, ELF::SHF_EXCLUDE);
472 DwarfLocDWOSection =
473 Ctx->getELFSection(".debug_loc.dwo", DebugSecType, ELF::SHF_EXCLUDE);
474 DwarfStrOffDWOSection = Ctx->getELFSection(".debug_str_offsets.dwo",
475 DebugSecType, ELF::SHF_EXCLUDE);
476 DwarfRnglistsDWOSection =
477 Ctx->getELFSection(".debug_rnglists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
478 DwarfMacinfoDWOSection =
479 Ctx->getELFSection(".debug_macinfo.dwo", DebugSecType, ELF::SHF_EXCLUDE);
480 DwarfMacroDWOSection =
481 Ctx->getELFSection(".debug_macro.dwo", DebugSecType, ELF::SHF_EXCLUDE);
483 DwarfLoclistsDWOSection =
484 Ctx->getELFSection(".debug_loclists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
486 // DWP Sections
487 DwarfCUIndexSection =
488 Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);
489 DwarfTUIndexSection =
490 Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);
492 StackMapSection =
493 Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
495 FaultMapSection =
496 Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
498 EHFrameSection =
499 Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
501 StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);
503 PseudoProbeSection = Ctx->getELFSection(".pseudo_probe", DebugSecType, 0);
504 PseudoProbeDescSection =
505 Ctx->getELFSection(".pseudo_probe_desc", DebugSecType, 0);
508 void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) {
509 TextSection = Ctx->getGOFFSection(".text", SectionKind::getText());
510 BSSSection = Ctx->getGOFFSection(".bss", SectionKind::getBSS());
513 void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
514 EHFrameSection =
515 Ctx->getCOFFSection(".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
516 COFF::IMAGE_SCN_MEM_READ,
517 SectionKind::getData());
519 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
520 // used to indicate to the linker that the text segment contains thumb instructions
521 // and to set the ISA selection bit for calls accordingly.
522 const bool IsThumb = T.getArch() == Triple::thumb;
524 CommDirectiveSupportsAlignment = true;
526 // COFF
527 BSSSection = Ctx->getCOFFSection(
528 ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
529 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
530 SectionKind::getBSS());
531 TextSection = Ctx->getCOFFSection(
532 ".text",
533 (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |
534 COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
535 COFF::IMAGE_SCN_MEM_READ,
536 SectionKind::getText());
537 DataSection = Ctx->getCOFFSection(
538 ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
539 COFF::IMAGE_SCN_MEM_WRITE,
540 SectionKind::getData());
541 ReadOnlySection = Ctx->getCOFFSection(
542 ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
543 SectionKind::getReadOnly());
545 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64) {
546 // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
547 LSDASection = nullptr;
548 } else {
549 LSDASection = Ctx->getCOFFSection(".gcc_except_table",
550 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
551 COFF::IMAGE_SCN_MEM_READ,
552 SectionKind::getReadOnly());
555 // Debug info.
556 COFFDebugSymbolsSection =
557 Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
558 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
559 COFF::IMAGE_SCN_MEM_READ),
560 SectionKind::getMetadata());
561 COFFDebugTypesSection =
562 Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
563 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
564 COFF::IMAGE_SCN_MEM_READ),
565 SectionKind::getMetadata());
566 COFFGlobalTypeHashesSection = Ctx->getCOFFSection(
567 ".debug$H",
568 (COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
569 COFF::IMAGE_SCN_MEM_READ),
570 SectionKind::getMetadata());
572 DwarfAbbrevSection = Ctx->getCOFFSection(
573 ".debug_abbrev",
574 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
575 COFF::IMAGE_SCN_MEM_READ,
576 SectionKind::getMetadata(), "section_abbrev");
577 DwarfInfoSection = Ctx->getCOFFSection(
578 ".debug_info",
579 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
580 COFF::IMAGE_SCN_MEM_READ,
581 SectionKind::getMetadata(), "section_info");
582 DwarfLineSection = Ctx->getCOFFSection(
583 ".debug_line",
584 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
585 COFF::IMAGE_SCN_MEM_READ,
586 SectionKind::getMetadata(), "section_line");
587 DwarfLineStrSection = Ctx->getCOFFSection(
588 ".debug_line_str",
589 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
590 COFF::IMAGE_SCN_MEM_READ,
591 SectionKind::getMetadata(), "section_line_str");
592 DwarfFrameSection = Ctx->getCOFFSection(
593 ".debug_frame",
594 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
595 COFF::IMAGE_SCN_MEM_READ,
596 SectionKind::getMetadata());
597 DwarfPubNamesSection = Ctx->getCOFFSection(
598 ".debug_pubnames",
599 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
600 COFF::IMAGE_SCN_MEM_READ,
601 SectionKind::getMetadata());
602 DwarfPubTypesSection = Ctx->getCOFFSection(
603 ".debug_pubtypes",
604 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
605 COFF::IMAGE_SCN_MEM_READ,
606 SectionKind::getMetadata());
607 DwarfGnuPubNamesSection = Ctx->getCOFFSection(
608 ".debug_gnu_pubnames",
609 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
610 COFF::IMAGE_SCN_MEM_READ,
611 SectionKind::getMetadata());
612 DwarfGnuPubTypesSection = Ctx->getCOFFSection(
613 ".debug_gnu_pubtypes",
614 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
615 COFF::IMAGE_SCN_MEM_READ,
616 SectionKind::getMetadata());
617 DwarfStrSection = Ctx->getCOFFSection(
618 ".debug_str",
619 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
620 COFF::IMAGE_SCN_MEM_READ,
621 SectionKind::getMetadata(), "info_string");
622 DwarfStrOffSection = Ctx->getCOFFSection(
623 ".debug_str_offsets",
624 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
625 COFF::IMAGE_SCN_MEM_READ,
626 SectionKind::getMetadata(), "section_str_off");
627 DwarfLocSection = Ctx->getCOFFSection(
628 ".debug_loc",
629 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
630 COFF::IMAGE_SCN_MEM_READ,
631 SectionKind::getMetadata(), "section_debug_loc");
632 DwarfLoclistsSection = Ctx->getCOFFSection(
633 ".debug_loclists",
634 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
635 COFF::IMAGE_SCN_MEM_READ,
636 SectionKind::getMetadata(), "section_debug_loclists");
637 DwarfARangesSection = Ctx->getCOFFSection(
638 ".debug_aranges",
639 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
640 COFF::IMAGE_SCN_MEM_READ,
641 SectionKind::getMetadata());
642 DwarfRangesSection = Ctx->getCOFFSection(
643 ".debug_ranges",
644 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
645 COFF::IMAGE_SCN_MEM_READ,
646 SectionKind::getMetadata(), "debug_range");
647 DwarfRnglistsSection = Ctx->getCOFFSection(
648 ".debug_rnglists",
649 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
650 COFF::IMAGE_SCN_MEM_READ,
651 SectionKind::getMetadata(), "debug_rnglists");
652 DwarfMacinfoSection = Ctx->getCOFFSection(
653 ".debug_macinfo",
654 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
655 COFF::IMAGE_SCN_MEM_READ,
656 SectionKind::getMetadata(), "debug_macinfo");
657 DwarfMacroSection = Ctx->getCOFFSection(
658 ".debug_macro",
659 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
660 COFF::IMAGE_SCN_MEM_READ,
661 SectionKind::getMetadata(), "debug_macro");
662 DwarfMacinfoDWOSection = Ctx->getCOFFSection(
663 ".debug_macinfo.dwo",
664 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
665 COFF::IMAGE_SCN_MEM_READ,
666 SectionKind::getMetadata(), "debug_macinfo.dwo");
667 DwarfMacroDWOSection = Ctx->getCOFFSection(
668 ".debug_macro.dwo",
669 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
670 COFF::IMAGE_SCN_MEM_READ,
671 SectionKind::getMetadata(), "debug_macro.dwo");
672 DwarfInfoDWOSection = Ctx->getCOFFSection(
673 ".debug_info.dwo",
674 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
675 COFF::IMAGE_SCN_MEM_READ,
676 SectionKind::getMetadata(), "section_info_dwo");
677 DwarfTypesDWOSection = Ctx->getCOFFSection(
678 ".debug_types.dwo",
679 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
680 COFF::IMAGE_SCN_MEM_READ,
681 SectionKind::getMetadata(), "section_types_dwo");
682 DwarfAbbrevDWOSection = Ctx->getCOFFSection(
683 ".debug_abbrev.dwo",
684 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
685 COFF::IMAGE_SCN_MEM_READ,
686 SectionKind::getMetadata(), "section_abbrev_dwo");
687 DwarfStrDWOSection = Ctx->getCOFFSection(
688 ".debug_str.dwo",
689 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
690 COFF::IMAGE_SCN_MEM_READ,
691 SectionKind::getMetadata(), "skel_string");
692 DwarfLineDWOSection = Ctx->getCOFFSection(
693 ".debug_line.dwo",
694 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
695 COFF::IMAGE_SCN_MEM_READ,
696 SectionKind::getMetadata());
697 DwarfLocDWOSection = Ctx->getCOFFSection(
698 ".debug_loc.dwo",
699 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
700 COFF::IMAGE_SCN_MEM_READ,
701 SectionKind::getMetadata(), "skel_loc");
702 DwarfStrOffDWOSection = Ctx->getCOFFSection(
703 ".debug_str_offsets.dwo",
704 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
705 COFF::IMAGE_SCN_MEM_READ,
706 SectionKind::getMetadata(), "section_str_off_dwo");
707 DwarfAddrSection = Ctx->getCOFFSection(
708 ".debug_addr",
709 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
710 COFF::IMAGE_SCN_MEM_READ,
711 SectionKind::getMetadata(), "addr_sec");
712 DwarfCUIndexSection = Ctx->getCOFFSection(
713 ".debug_cu_index",
714 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
715 COFF::IMAGE_SCN_MEM_READ,
716 SectionKind::getMetadata());
717 DwarfTUIndexSection = Ctx->getCOFFSection(
718 ".debug_tu_index",
719 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
720 COFF::IMAGE_SCN_MEM_READ,
721 SectionKind::getMetadata());
722 DwarfDebugNamesSection = Ctx->getCOFFSection(
723 ".debug_names",
724 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
725 COFF::IMAGE_SCN_MEM_READ,
726 SectionKind::getMetadata(), "debug_names_begin");
727 DwarfAccelNamesSection = Ctx->getCOFFSection(
728 ".apple_names",
729 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
730 COFF::IMAGE_SCN_MEM_READ,
731 SectionKind::getMetadata(), "names_begin");
732 DwarfAccelNamespaceSection = Ctx->getCOFFSection(
733 ".apple_namespaces",
734 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
735 COFF::IMAGE_SCN_MEM_READ,
736 SectionKind::getMetadata(), "namespac_begin");
737 DwarfAccelTypesSection = Ctx->getCOFFSection(
738 ".apple_types",
739 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
740 COFF::IMAGE_SCN_MEM_READ,
741 SectionKind::getMetadata(), "types_begin");
742 DwarfAccelObjCSection = Ctx->getCOFFSection(
743 ".apple_objc",
744 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
745 COFF::IMAGE_SCN_MEM_READ,
746 SectionKind::getMetadata(), "objc_begin");
748 DrectveSection = Ctx->getCOFFSection(
749 ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
750 SectionKind::getMetadata());
752 PDataSection = Ctx->getCOFFSection(
753 ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
754 SectionKind::getData());
756 XDataSection = Ctx->getCOFFSection(
757 ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
758 SectionKind::getData());
760 SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO,
761 SectionKind::getMetadata());
763 GEHContSection = Ctx->getCOFFSection(".gehcont$y",
764 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
765 COFF::IMAGE_SCN_MEM_READ,
766 SectionKind::getMetadata());
768 GFIDsSection = Ctx->getCOFFSection(".gfids$y",
769 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
770 COFF::IMAGE_SCN_MEM_READ,
771 SectionKind::getMetadata());
773 GIATsSection = Ctx->getCOFFSection(".giats$y",
774 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
775 COFF::IMAGE_SCN_MEM_READ,
776 SectionKind::getMetadata());
778 GLJMPSection = Ctx->getCOFFSection(".gljmp$y",
779 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
780 COFF::IMAGE_SCN_MEM_READ,
781 SectionKind::getMetadata());
783 TLSDataSection = Ctx->getCOFFSection(
784 ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
785 COFF::IMAGE_SCN_MEM_WRITE,
786 SectionKind::getData());
788 StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
789 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
790 COFF::IMAGE_SCN_MEM_READ,
791 SectionKind::getReadOnly());
794 void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
795 TextSection = Ctx->getWasmSection(".text", SectionKind::getText());
796 DataSection = Ctx->getWasmSection(".data", SectionKind::getData());
798 DwarfLineSection =
799 Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());
800 DwarfLineStrSection =
801 Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata(),
802 wasm::WASM_SEG_FLAG_STRINGS);
803 DwarfStrSection = Ctx->getWasmSection(
804 ".debug_str", SectionKind::getMetadata(), wasm::WASM_SEG_FLAG_STRINGS);
805 DwarfLocSection =
806 Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());
807 DwarfAbbrevSection =
808 Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata());
809 DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());
810 DwarfRangesSection =
811 Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata());
812 DwarfMacinfoSection =
813 Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata());
814 DwarfMacroSection =
815 Ctx->getWasmSection(".debug_macro", SectionKind::getMetadata());
816 DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
817 DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
818 DwarfInfoSection =
819 Ctx->getWasmSection(".debug_info", SectionKind::getMetadata());
820 DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());
821 DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
822 DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
823 DwarfGnuPubNamesSection =
824 Ctx->getWasmSection(".debug_gnu_pubnames", SectionKind::getMetadata());
825 DwarfGnuPubTypesSection =
826 Ctx->getWasmSection(".debug_gnu_pubtypes", SectionKind::getMetadata());
828 DwarfDebugNamesSection =
829 Ctx->getWasmSection(".debug_names", SectionKind::getMetadata());
830 DwarfStrOffSection =
831 Ctx->getWasmSection(".debug_str_offsets", SectionKind::getMetadata());
832 DwarfAddrSection =
833 Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata());
834 DwarfRnglistsSection =
835 Ctx->getWasmSection(".debug_rnglists", SectionKind::getMetadata());
836 DwarfLoclistsSection =
837 Ctx->getWasmSection(".debug_loclists", SectionKind::getMetadata());
839 // Fission Sections
840 DwarfInfoDWOSection =
841 Ctx->getWasmSection(".debug_info.dwo", SectionKind::getMetadata());
842 DwarfTypesDWOSection =
843 Ctx->getWasmSection(".debug_types.dwo", SectionKind::getMetadata());
844 DwarfAbbrevDWOSection =
845 Ctx->getWasmSection(".debug_abbrev.dwo", SectionKind::getMetadata());
846 DwarfStrDWOSection =
847 Ctx->getWasmSection(".debug_str.dwo", SectionKind::getMetadata(),
848 wasm::WASM_SEG_FLAG_STRINGS);
849 DwarfLineDWOSection =
850 Ctx->getWasmSection(".debug_line.dwo", SectionKind::getMetadata());
851 DwarfLocDWOSection =
852 Ctx->getWasmSection(".debug_loc.dwo", SectionKind::getMetadata());
853 DwarfStrOffDWOSection =
854 Ctx->getWasmSection(".debug_str_offsets.dwo", SectionKind::getMetadata());
855 DwarfRnglistsDWOSection =
856 Ctx->getWasmSection(".debug_rnglists.dwo", SectionKind::getMetadata());
857 DwarfMacinfoDWOSection =
858 Ctx->getWasmSection(".debug_macinfo.dwo", SectionKind::getMetadata());
859 DwarfMacroDWOSection =
860 Ctx->getWasmSection(".debug_macro.dwo", SectionKind::getMetadata());
862 DwarfLoclistsDWOSection =
863 Ctx->getWasmSection(".debug_loclists.dwo", SectionKind::getMetadata());
865 // DWP Sections
866 DwarfCUIndexSection =
867 Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
868 DwarfTUIndexSection =
869 Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
871 // Wasm use data section for LSDA.
872 // TODO Consider putting each function's exception table in a separate
873 // section, as in -function-sections, to facilitate lld's --gc-section.
874 LSDASection = Ctx->getWasmSection(".rodata.gcc_except_table",
875 SectionKind::getReadOnlyWithRel());
877 // TODO: Define more sections.
880 void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) {
881 // The default csect for program code. Functions without a specified section
882 // get placed into this csect. The choice of csect name is not a property of
883 // the ABI or object file format. For example, the XL compiler uses an unnamed
884 // csect for program code.
885 TextSection = Ctx->getXCOFFSection(
886 ".text", SectionKind::getText(),
887 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD),
888 /* MultiSymbolsAllowed*/ true);
890 DataSection = Ctx->getXCOFFSection(
891 ".data", SectionKind::getData(),
892 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD),
893 /* MultiSymbolsAllowed*/ true);
895 ReadOnlySection = Ctx->getXCOFFSection(
896 ".rodata", SectionKind::getReadOnly(),
897 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
898 /* MultiSymbolsAllowed*/ true);
899 ReadOnlySection->setAlignment(Align(4));
901 ReadOnly8Section = Ctx->getXCOFFSection(
902 ".rodata.8", SectionKind::getReadOnly(),
903 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
904 /* MultiSymbolsAllowed*/ true);
905 ReadOnly8Section->setAlignment(Align(8));
907 ReadOnly16Section = Ctx->getXCOFFSection(
908 ".rodata.16", SectionKind::getReadOnly(),
909 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
910 /* MultiSymbolsAllowed*/ true);
911 ReadOnly16Section->setAlignment(Align(16));
913 TLSDataSection = Ctx->getXCOFFSection(
914 ".tdata", SectionKind::getThreadData(),
915 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TL, XCOFF::XTY_SD),
916 /* MultiSymbolsAllowed*/ true);
918 TOCBaseSection = Ctx->getXCOFFSection(
919 "TOC", SectionKind::getData(),
920 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TC0,
921 XCOFF::XTY_SD));
923 // The TOC-base always has 0 size, but 4 byte alignment.
924 TOCBaseSection->setAlignment(Align(4));
926 LSDASection = Ctx->getXCOFFSection(
927 ".gcc_except_table", SectionKind::getReadOnly(),
928 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO,
929 XCOFF::XTY_SD));
931 CompactUnwindSection = Ctx->getXCOFFSection(
932 ".eh_info_table", SectionKind::getData(),
933 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW,
934 XCOFF::XTY_SD));
936 // DWARF sections for XCOFF are not csects. They are special STYP_DWARF
937 // sections, and the individual DWARF sections are distinguished by their
938 // section subtype.
939 DwarfAbbrevSection = Ctx->getXCOFFSection(
940 ".dwabrev", SectionKind::getMetadata(), /* CsectProperties */ None,
941 /* MultiSymbolsAllowed */ true, ".dwabrev", XCOFF::SSUBTYP_DWABREV);
943 DwarfInfoSection = Ctx->getXCOFFSection(
944 ".dwinfo", SectionKind::getMetadata(), /* CsectProperties */ None,
945 /* MultiSymbolsAllowed */ true, ".dwinfo", XCOFF::SSUBTYP_DWINFO);
947 DwarfLineSection = Ctx->getXCOFFSection(
948 ".dwline", SectionKind::getMetadata(), /* CsectProperties */ None,
949 /* MultiSymbolsAllowed */ true, ".dwline", XCOFF::SSUBTYP_DWLINE);
951 DwarfFrameSection = Ctx->getXCOFFSection(
952 ".dwframe", SectionKind::getMetadata(), /* CsectProperties */ None,
953 /* MultiSymbolsAllowed */ true, ".dwframe", XCOFF::SSUBTYP_DWFRAME);
955 DwarfPubNamesSection = Ctx->getXCOFFSection(
956 ".dwpbnms", SectionKind::getMetadata(), /* CsectProperties */ None,
957 /* MultiSymbolsAllowed */ true, ".dwpbnms", XCOFF::SSUBTYP_DWPBNMS);
959 DwarfPubTypesSection = Ctx->getXCOFFSection(
960 ".dwpbtyp", SectionKind::getMetadata(), /* CsectProperties */ None,
961 /* MultiSymbolsAllowed */ true, ".dwpbtyp", XCOFF::SSUBTYP_DWPBTYP);
963 DwarfStrSection = Ctx->getXCOFFSection(
964 ".dwstr", SectionKind::getMetadata(), /* CsectProperties */ None,
965 /* MultiSymbolsAllowed */ true, ".dwstr", XCOFF::SSUBTYP_DWSTR);
967 DwarfLocSection = Ctx->getXCOFFSection(
968 ".dwloc", SectionKind::getMetadata(), /* CsectProperties */ None,
969 /* MultiSymbolsAllowed */ true, ".dwloc", XCOFF::SSUBTYP_DWLOC);
971 DwarfARangesSection = Ctx->getXCOFFSection(
972 ".dwarnge", SectionKind::getMetadata(), /* CsectProperties */ None,
973 /* MultiSymbolsAllowed */ true, ".dwarnge", XCOFF::SSUBTYP_DWARNGE);
975 DwarfRangesSection = Ctx->getXCOFFSection(
976 ".dwrnges", SectionKind::getMetadata(), /* CsectProperties */ None,
977 /* MultiSymbolsAllowed */ true, ".dwrnges", XCOFF::SSUBTYP_DWRNGES);
979 DwarfMacinfoSection = Ctx->getXCOFFSection(
980 ".dwmac", SectionKind::getMetadata(), /* CsectProperties */ None,
981 /* MultiSymbolsAllowed */ true, ".dwmac", XCOFF::SSUBTYP_DWMAC);
984 void MCObjectFileInfo::initMCObjectFileInfo(MCContext &MCCtx, bool PIC,
985 bool LargeCodeModel) {
986 PositionIndependent = PIC;
987 Ctx = &MCCtx;
989 // Common.
990 CommDirectiveSupportsAlignment = true;
991 SupportsWeakOmittedEHFrame = true;
992 SupportsCompactUnwindWithoutEHFrame = false;
993 OmitDwarfIfHaveCompactUnwind = false;
995 FDECFIEncoding = dwarf::DW_EH_PE_absptr;
997 CompactUnwindDwarfEHFrameOnly = 0;
999 EHFrameSection = nullptr; // Created on demand.
1000 CompactUnwindSection = nullptr; // Used only by selected targets.
1001 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
1002 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
1003 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
1004 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
1006 Triple TheTriple = Ctx->getTargetTriple();
1007 switch (Ctx->getObjectFileType()) {
1008 case MCContext::IsMachO:
1009 initMachOMCObjectFileInfo(TheTriple);
1010 break;
1011 case MCContext::IsCOFF:
1012 initCOFFMCObjectFileInfo(TheTriple);
1013 break;
1014 case MCContext::IsELF:
1015 initELFMCObjectFileInfo(TheTriple, LargeCodeModel);
1016 break;
1017 case MCContext::IsGOFF:
1018 initGOFFMCObjectFileInfo(TheTriple);
1019 break;
1020 case MCContext::IsWasm:
1021 initWasmMCObjectFileInfo(TheTriple);
1022 break;
1023 case MCContext::IsXCOFF:
1024 initXCOFFMCObjectFileInfo(TheTriple);
1025 break;
1029 MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
1030 uint64_t Hash) const {
1031 switch (Ctx->getTargetTriple().getObjectFormat()) {
1032 case Triple::ELF:
1033 return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0,
1034 utostr(Hash), /*IsComdat=*/true);
1035 case Triple::Wasm:
1036 return Ctx->getWasmSection(Name, SectionKind::getMetadata(), 0,
1037 utostr(Hash), MCContext::GenericSectionID);
1038 case Triple::MachO:
1039 case Triple::COFF:
1040 case Triple::GOFF:
1041 case Triple::XCOFF:
1042 case Triple::UnknownObjectFormat:
1043 report_fatal_error("Cannot get DWARF comdat section for this object file "
1044 "format: not implemented.");
1045 break;
1047 llvm_unreachable("Unknown ObjectFormatType");
1050 MCSection *
1051 MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const {
1052 if (Ctx->getObjectFileType() != MCContext::IsELF)
1053 return StackSizesSection;
1055 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1056 unsigned Flags = ELF::SHF_LINK_ORDER;
1057 StringRef GroupName;
1058 if (const MCSymbol *Group = ElfSec.getGroup()) {
1059 GroupName = Group->getName();
1060 Flags |= ELF::SHF_GROUP;
1063 return Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, Flags, 0,
1064 GroupName, true, ElfSec.getUniqueID(),
1065 cast<MCSymbolELF>(TextSec.getBeginSymbol()));
1068 MCSection *
1069 MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const {
1070 if (Ctx->getObjectFileType() != MCContext::IsELF)
1071 return nullptr;
1073 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1074 unsigned Flags = ELF::SHF_LINK_ORDER;
1075 StringRef GroupName;
1076 if (const MCSymbol *Group = ElfSec.getGroup()) {
1077 GroupName = Group->getName();
1078 Flags |= ELF::SHF_GROUP;
1081 // Use the text section's begin symbol and unique ID to create a separate
1082 // .llvm_bb_addr_map section associated with every unique text section.
1083 return Ctx->getELFSection(".llvm_bb_addr_map", ELF::SHT_LLVM_BB_ADDR_MAP,
1084 Flags, 0, GroupName, true, ElfSec.getUniqueID(),
1085 cast<MCSymbolELF>(TextSec.getBeginSymbol()));
1088 MCSection *
1089 MCObjectFileInfo::getPseudoProbeSection(const MCSection *TextSec) const {
1090 if (Ctx->getObjectFileType() == MCContext::IsELF) {
1091 const auto *ElfSec = static_cast<const MCSectionELF *>(TextSec);
1092 // Create a separate section for probes that comes with a comdat function.
1093 if (const MCSymbol *Group = ElfSec->getGroup()) {
1094 auto *S = static_cast<MCSectionELF *>(PseudoProbeSection);
1095 auto Flags = S->getFlags() | ELF::SHF_GROUP;
1096 return Ctx->getELFSection(S->getName(), S->getType(), Flags,
1097 S->getEntrySize(), Group->getName(),
1098 /*IsComdat=*/true);
1101 return PseudoProbeSection;
1104 MCSection *
1105 MCObjectFileInfo::getPseudoProbeDescSection(StringRef FuncName) const {
1106 if (Ctx->getObjectFileType() == MCContext::IsELF) {
1107 // Create a separate comdat group for each function's descriptor in order
1108 // for the linker to deduplicate. The duplication, must be from different
1109 // tranlation unit, can come from:
1110 // 1. Inline functions defined in header files;
1111 // 2. ThinLTO imported funcions;
1112 // 3. Weak-linkage definitions.
1113 // Use a concatenation of the section name and the function name as the
1114 // group name so that descriptor-only groups won't be folded with groups of
1115 // code.
1116 if (Ctx->getTargetTriple().supportsCOMDAT() && !FuncName.empty()) {
1117 auto *S = static_cast<MCSectionELF *>(PseudoProbeDescSection);
1118 auto Flags = S->getFlags() | ELF::SHF_GROUP;
1119 return Ctx->getELFSection(S->getName(), S->getType(), Flags,
1120 S->getEntrySize(),
1121 S->getName() + "_" + FuncName,
1122 /*IsComdat=*/true);
1125 return PseudoProbeDescSection;