1 //===-- MCObjectFileInfo.cpp - Object File Information --------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/MC/MCObjectFileInfo.h"
10 #include "llvm/ADT/StringExtras.h"
11 #include "llvm/BinaryFormat/COFF.h"
12 #include "llvm/BinaryFormat/ELF.h"
13 #include "llvm/BinaryFormat/Wasm.h"
14 #include "llvm/MC/MCAsmInfo.h"
15 #include "llvm/MC/MCContext.h"
16 #include "llvm/MC/MCSection.h"
17 #include "llvm/MC/MCSectionCOFF.h"
18 #include "llvm/MC/MCSectionDXContainer.h"
19 #include "llvm/MC/MCSectionELF.h"
20 #include "llvm/MC/MCSectionGOFF.h"
21 #include "llvm/MC/MCSectionMachO.h"
22 #include "llvm/MC/MCSectionSPIRV.h"
23 #include "llvm/MC/MCSectionWasm.h"
24 #include "llvm/MC/MCSectionXCOFF.h"
25 #include "llvm/Support/Casting.h"
26 #include "llvm/TargetParser/Triple.h"
30 static bool useCompactUnwind(const Triple
&T
) {
35 // aarch64 always has it.
36 if (T
.getArch() == Triple::aarch64
|| T
.getArch() == Triple::aarch64_32
)
39 // armv7k always has it.
43 // Use it on newer version of OS X.
44 if (T
.isMacOSX() && !T
.isMacOSXVersionLT(10, 6))
47 // And the iOS simulator.
48 if (T
.isiOS() && T
.isX86())
54 void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple
&T
) {
56 SupportsWeakOmittedEHFrame
= false;
58 EHFrameSection
= Ctx
->getMachOSection(
59 "__TEXT", "__eh_frame",
60 MachO::S_COALESCED
| MachO::S_ATTR_NO_TOC
|
61 MachO::S_ATTR_STRIP_STATIC_SYMS
| MachO::S_ATTR_LIVE_SUPPORT
,
62 SectionKind::getReadOnly());
65 (T
.getArch() == Triple::aarch64
|| T
.getArch() == Triple::aarch64_32
))
66 SupportsCompactUnwindWithoutEHFrame
= true;
68 switch (Ctx
->emitDwarfUnwindInfo()) {
69 case EmitDwarfUnwindType::Always
:
70 OmitDwarfIfHaveCompactUnwind
= false;
72 case EmitDwarfUnwindType::NoCompactUnwind
:
73 OmitDwarfIfHaveCompactUnwind
= true;
75 case EmitDwarfUnwindType::Default
:
76 OmitDwarfIfHaveCompactUnwind
=
77 T
.isWatchABI() || SupportsCompactUnwindWithoutEHFrame
;
81 FDECFIEncoding
= dwarf::DW_EH_PE_pcrel
;
84 = Ctx
->getMachOSection("__TEXT", "__text",
85 MachO::S_ATTR_PURE_INSTRUCTIONS
,
86 SectionKind::getText());
88 = Ctx
->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
90 // BSSSection might not be expected initialized on msvc.
93 TLSDataSection
// .tdata
94 = Ctx
->getMachOSection("__DATA", "__thread_data",
95 MachO::S_THREAD_LOCAL_REGULAR
,
96 SectionKind::getData());
97 TLSBSSSection
// .tbss
98 = Ctx
->getMachOSection("__DATA", "__thread_bss",
99 MachO::S_THREAD_LOCAL_ZEROFILL
,
100 SectionKind::getThreadBSS());
102 // TODO: Verify datarel below.
103 TLSTLVSection
// .tlv
104 = Ctx
->getMachOSection("__DATA", "__thread_vars",
105 MachO::S_THREAD_LOCAL_VARIABLES
,
106 SectionKind::getData());
108 TLSThreadInitSection
= Ctx
->getMachOSection(
109 "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS
,
110 SectionKind::getData());
112 CStringSection
// .cstring
113 = Ctx
->getMachOSection("__TEXT", "__cstring",
114 MachO::S_CSTRING_LITERALS
,
115 SectionKind::getMergeable1ByteCString());
117 = Ctx
->getMachOSection("__TEXT","__ustring", 0,
118 SectionKind::getMergeable2ByteCString());
119 FourByteConstantSection
// .literal4
120 = Ctx
->getMachOSection("__TEXT", "__literal4",
121 MachO::S_4BYTE_LITERALS
,
122 SectionKind::getMergeableConst4());
123 EightByteConstantSection
// .literal8
124 = Ctx
->getMachOSection("__TEXT", "__literal8",
125 MachO::S_8BYTE_LITERALS
,
126 SectionKind::getMergeableConst8());
128 SixteenByteConstantSection
// .literal16
129 = Ctx
->getMachOSection("__TEXT", "__literal16",
130 MachO::S_16BYTE_LITERALS
,
131 SectionKind::getMergeableConst16());
133 ReadOnlySection
// .const
134 = Ctx
->getMachOSection("__TEXT", "__const", 0,
135 SectionKind::getReadOnly());
137 // If the target is not powerpc, map the coal sections to the non-coal
140 // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
141 // "__TEXT/__const_coal" => section "__TEXT/__const"
142 // "__DATA/__datacoal_nt" => section "__DATA/__data"
143 Triple::ArchType ArchTy
= T
.getArch();
145 ConstDataSection
// .const_data
146 = Ctx
->getMachOSection("__DATA", "__const", 0,
147 SectionKind::getReadOnlyWithRel());
149 if (ArchTy
== Triple::ppc
|| ArchTy
== Triple::ppc64
) {
151 = Ctx
->getMachOSection("__TEXT", "__textcoal_nt",
153 MachO::S_ATTR_PURE_INSTRUCTIONS
,
154 SectionKind::getText());
156 = Ctx
->getMachOSection("__TEXT", "__const_coal",
158 SectionKind::getReadOnly());
159 DataCoalSection
= Ctx
->getMachOSection(
160 "__DATA", "__datacoal_nt", MachO::S_COALESCED
, SectionKind::getData());
161 ConstDataCoalSection
= DataCoalSection
;
163 TextCoalSection
= TextSection
;
164 ConstTextCoalSection
= ReadOnlySection
;
165 DataCoalSection
= DataSection
;
166 ConstDataCoalSection
= ConstDataSection
;
170 = Ctx
->getMachOSection("__DATA","__common",
172 SectionKind::getBSS());
174 = Ctx
->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL
,
175 SectionKind::getBSS());
178 LazySymbolPointerSection
179 = Ctx
->getMachOSection("__DATA", "__la_symbol_ptr",
180 MachO::S_LAZY_SYMBOL_POINTERS
,
181 SectionKind::getMetadata());
182 NonLazySymbolPointerSection
183 = Ctx
->getMachOSection("__DATA", "__nl_symbol_ptr",
184 MachO::S_NON_LAZY_SYMBOL_POINTERS
,
185 SectionKind::getMetadata());
187 ThreadLocalPointerSection
188 = Ctx
->getMachOSection("__DATA", "__thread_ptr",
189 MachO::S_THREAD_LOCAL_VARIABLE_POINTERS
,
190 SectionKind::getMetadata());
192 AddrSigSection
= Ctx
->getMachOSection("__DATA", "__llvm_addrsig", 0,
193 SectionKind::getData());
195 // Exception Handling.
196 LSDASection
= Ctx
->getMachOSection("__TEXT", "__gcc_except_tab", 0,
197 SectionKind::getReadOnlyWithRel());
199 COFFDebugSymbolsSection
= nullptr;
200 COFFDebugTypesSection
= nullptr;
201 COFFGlobalTypeHashesSection
= nullptr;
203 if (useCompactUnwind(T
)) {
204 CompactUnwindSection
=
205 Ctx
->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG
,
206 SectionKind::getReadOnly());
209 CompactUnwindDwarfEHFrameOnly
= 0x04000000; // UNWIND_X86_64_MODE_DWARF
210 else if (T
.getArch() == Triple::aarch64
|| T
.getArch() == Triple::aarch64_32
)
211 CompactUnwindDwarfEHFrameOnly
= 0x03000000; // UNWIND_ARM64_MODE_DWARF
212 else if (T
.getArch() == Triple::arm
|| T
.getArch() == Triple::thumb
)
213 CompactUnwindDwarfEHFrameOnly
= 0x04000000; // UNWIND_ARM_MODE_DWARF
216 // Debug Information.
217 DwarfDebugNamesSection
=
218 Ctx
->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG
,
219 SectionKind::getMetadata(), "debug_names_begin");
220 DwarfAccelNamesSection
=
221 Ctx
->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG
,
222 SectionKind::getMetadata(), "names_begin");
223 DwarfAccelObjCSection
=
224 Ctx
->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG
,
225 SectionKind::getMetadata(), "objc_begin");
226 // 16 character section limit...
227 DwarfAccelNamespaceSection
=
228 Ctx
->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG
,
229 SectionKind::getMetadata(), "namespac_begin");
230 DwarfAccelTypesSection
=
231 Ctx
->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG
,
232 SectionKind::getMetadata(), "types_begin");
234 DwarfSwiftASTSection
=
235 Ctx
->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG
,
236 SectionKind::getMetadata());
239 Ctx
->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG
,
240 SectionKind::getMetadata(), "section_abbrev");
242 Ctx
->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG
,
243 SectionKind::getMetadata(), "section_info");
245 Ctx
->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG
,
246 SectionKind::getMetadata(), "section_line");
247 DwarfLineStrSection
=
248 Ctx
->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG
,
249 SectionKind::getMetadata(), "section_line_str");
251 Ctx
->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG
,
252 SectionKind::getMetadata());
253 DwarfPubNamesSection
=
254 Ctx
->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG
,
255 SectionKind::getMetadata());
256 DwarfPubTypesSection
=
257 Ctx
->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG
,
258 SectionKind::getMetadata());
259 DwarfGnuPubNamesSection
=
260 Ctx
->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG
,
261 SectionKind::getMetadata());
262 DwarfGnuPubTypesSection
=
263 Ctx
->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG
,
264 SectionKind::getMetadata());
266 Ctx
->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG
,
267 SectionKind::getMetadata(), "info_string");
269 Ctx
->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG
,
270 SectionKind::getMetadata(), "section_str_off");
272 Ctx
->getMachOSection("__DWARF", "__debug_addr", MachO::S_ATTR_DEBUG
,
273 SectionKind::getMetadata(), "section_info");
275 Ctx
->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG
,
276 SectionKind::getMetadata(), "section_debug_loc");
277 DwarfLoclistsSection
=
278 Ctx
->getMachOSection("__DWARF", "__debug_loclists", MachO::S_ATTR_DEBUG
,
279 SectionKind::getMetadata(), "section_debug_loc");
281 DwarfARangesSection
=
282 Ctx
->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG
,
283 SectionKind::getMetadata());
285 Ctx
->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG
,
286 SectionKind::getMetadata(), "debug_range");
287 DwarfRnglistsSection
=
288 Ctx
->getMachOSection("__DWARF", "__debug_rnglists", MachO::S_ATTR_DEBUG
,
289 SectionKind::getMetadata(), "debug_range");
290 DwarfMacinfoSection
=
291 Ctx
->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG
,
292 SectionKind::getMetadata(), "debug_macinfo");
294 Ctx
->getMachOSection("__DWARF", "__debug_macro", MachO::S_ATTR_DEBUG
,
295 SectionKind::getMetadata(), "debug_macro");
296 DwarfDebugInlineSection
=
297 Ctx
->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG
,
298 SectionKind::getMetadata());
299 DwarfCUIndexSection
=
300 Ctx
->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG
,
301 SectionKind::getMetadata());
302 DwarfTUIndexSection
=
303 Ctx
->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG
,
304 SectionKind::getMetadata());
305 StackMapSection
= Ctx
->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
306 0, SectionKind::getMetadata());
308 FaultMapSection
= Ctx
->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
309 0, SectionKind::getMetadata());
311 RemarksSection
= Ctx
->getMachOSection(
312 "__LLVM", "__remarks", MachO::S_ATTR_DEBUG
, SectionKind::getMetadata());
314 // The architecture of dsymutil makes it very difficult to copy the Swift
315 // reflection metadata sections into the __TEXT segment, so dsymutil creates
316 // these sections in the __DWARF segment instead.
317 if (!Ctx
->getSwift5ReflectionSegmentName().empty()) {
318 #define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) \
319 Swift5ReflectionSections \
320 [llvm::binaryformat::Swift5ReflectionSectionKind::KIND] = \
321 Ctx->getMachOSection(Ctx->getSwift5ReflectionSegmentName().data(), \
322 MACHO, 0, SectionKind::getMetadata());
323 #include "llvm/BinaryFormat/Swift.def"
326 TLSExtraDataSection
= TLSTLVSection
;
329 void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple
&T
, bool Large
) {
330 switch (T
.getArch()) {
334 case Triple::mips64el
:
335 // We cannot use DW_EH_PE_sdata8 for the large PositionIndependent case
336 // since there is no R_MIPS_PC64 relocation (only a 32-bit version).
337 if (PositionIndependent
&& !Large
)
338 FDECFIEncoding
= dwarf::DW_EH_PE_pcrel
| dwarf::DW_EH_PE_sdata4
;
340 FDECFIEncoding
= Ctx
->getAsmInfo()->getCodePointerSize() == 4
341 ? dwarf::DW_EH_PE_sdata4
342 : dwarf::DW_EH_PE_sdata8
;
345 case Triple::ppc64le
:
346 case Triple::aarch64
:
347 case Triple::aarch64_be
:
349 FDECFIEncoding
= dwarf::DW_EH_PE_pcrel
|
350 (Large
? dwarf::DW_EH_PE_sdata8
: dwarf::DW_EH_PE_sdata4
);
354 FDECFIEncoding
= dwarf::DW_EH_PE_sdata8
;
356 case Triple::hexagon
:
358 PositionIndependent
? dwarf::DW_EH_PE_pcrel
: dwarf::DW_EH_PE_absptr
;
361 FDECFIEncoding
= dwarf::DW_EH_PE_sdata4
;
364 FDECFIEncoding
= dwarf::DW_EH_PE_pcrel
| dwarf::DW_EH_PE_sdata4
;
368 unsigned EHSectionType
= T
.getArch() == Triple::x86_64
369 ? ELF::SHT_X86_64_UNWIND
372 // Solaris requires different flags for .eh_frame to seemingly every other
374 unsigned EHSectionFlags
= ELF::SHF_ALLOC
;
375 if (T
.isOSSolaris() && T
.getArch() != Triple::x86_64
)
376 EHSectionFlags
|= ELF::SHF_WRITE
;
379 BSSSection
= Ctx
->getELFSection(".bss", ELF::SHT_NOBITS
,
380 ELF::SHF_WRITE
| ELF::SHF_ALLOC
);
382 TextSection
= Ctx
->getELFSection(".text", ELF::SHT_PROGBITS
,
383 ELF::SHF_EXECINSTR
| ELF::SHF_ALLOC
);
385 DataSection
= Ctx
->getELFSection(".data", ELF::SHT_PROGBITS
,
386 ELF::SHF_WRITE
| ELF::SHF_ALLOC
);
389 Ctx
->getELFSection(".rodata", ELF::SHT_PROGBITS
, ELF::SHF_ALLOC
);
392 Ctx
->getELFSection(".tdata", ELF::SHT_PROGBITS
,
393 ELF::SHF_ALLOC
| ELF::SHF_TLS
| ELF::SHF_WRITE
);
395 TLSBSSSection
= Ctx
->getELFSection(
396 ".tbss", ELF::SHT_NOBITS
, ELF::SHF_ALLOC
| ELF::SHF_TLS
| ELF::SHF_WRITE
);
398 DataRelROSection
= Ctx
->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS
,
399 ELF::SHF_ALLOC
| ELF::SHF_WRITE
);
401 MergeableConst4Section
=
402 Ctx
->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS
,
403 ELF::SHF_ALLOC
| ELF::SHF_MERGE
, 4);
405 MergeableConst8Section
=
406 Ctx
->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS
,
407 ELF::SHF_ALLOC
| ELF::SHF_MERGE
, 8);
409 MergeableConst16Section
=
410 Ctx
->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS
,
411 ELF::SHF_ALLOC
| ELF::SHF_MERGE
, 16);
413 MergeableConst32Section
=
414 Ctx
->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS
,
415 ELF::SHF_ALLOC
| ELF::SHF_MERGE
, 32);
417 // Exception Handling Sections.
419 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
420 // it contains relocatable pointers. In PIC mode, this is probably a big
421 // runtime hit for C++ apps. Either the contents of the LSDA need to be
422 // adjusted or this should be a data section.
423 LSDASection
= Ctx
->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS
,
426 COFFDebugSymbolsSection
= nullptr;
427 COFFDebugTypesSection
= nullptr;
429 unsigned DebugSecType
= ELF::SHT_PROGBITS
;
431 // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
432 // to distinguish among sections contain DWARF and ECOFF debug formats.
433 // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
435 DebugSecType
= ELF::SHT_MIPS_DWARF
;
437 // Debug Info Sections.
439 Ctx
->getELFSection(".debug_abbrev", DebugSecType
, 0);
440 DwarfInfoSection
= Ctx
->getELFSection(".debug_info", DebugSecType
, 0);
441 DwarfLineSection
= Ctx
->getELFSection(".debug_line", DebugSecType
, 0);
442 DwarfLineStrSection
=
443 Ctx
->getELFSection(".debug_line_str", DebugSecType
,
444 ELF::SHF_MERGE
| ELF::SHF_STRINGS
, 1);
445 DwarfFrameSection
= Ctx
->getELFSection(".debug_frame", DebugSecType
, 0);
446 DwarfPubNamesSection
=
447 Ctx
->getELFSection(".debug_pubnames", DebugSecType
, 0);
448 DwarfPubTypesSection
=
449 Ctx
->getELFSection(".debug_pubtypes", DebugSecType
, 0);
450 DwarfGnuPubNamesSection
=
451 Ctx
->getELFSection(".debug_gnu_pubnames", DebugSecType
, 0);
452 DwarfGnuPubTypesSection
=
453 Ctx
->getELFSection(".debug_gnu_pubtypes", DebugSecType
, 0);
455 Ctx
->getELFSection(".debug_str", DebugSecType
,
456 ELF::SHF_MERGE
| ELF::SHF_STRINGS
, 1);
457 DwarfLocSection
= Ctx
->getELFSection(".debug_loc", DebugSecType
, 0);
458 DwarfARangesSection
=
459 Ctx
->getELFSection(".debug_aranges", DebugSecType
, 0);
461 Ctx
->getELFSection(".debug_ranges", DebugSecType
, 0);
462 DwarfMacinfoSection
=
463 Ctx
->getELFSection(".debug_macinfo", DebugSecType
, 0);
464 DwarfMacroSection
= Ctx
->getELFSection(".debug_macro", DebugSecType
, 0);
466 // DWARF5 Experimental Debug Info
468 // Accelerator Tables
469 DwarfDebugNamesSection
=
470 Ctx
->getELFSection(".debug_names", ELF::SHT_PROGBITS
, 0);
471 DwarfAccelNamesSection
=
472 Ctx
->getELFSection(".apple_names", ELF::SHT_PROGBITS
, 0);
473 DwarfAccelObjCSection
=
474 Ctx
->getELFSection(".apple_objc", ELF::SHT_PROGBITS
, 0);
475 DwarfAccelNamespaceSection
=
476 Ctx
->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS
, 0);
477 DwarfAccelTypesSection
=
478 Ctx
->getELFSection(".apple_types", ELF::SHT_PROGBITS
, 0);
480 // String Offset and Address Sections
482 Ctx
->getELFSection(".debug_str_offsets", DebugSecType
, 0);
483 DwarfAddrSection
= Ctx
->getELFSection(".debug_addr", DebugSecType
, 0);
484 DwarfRnglistsSection
= Ctx
->getELFSection(".debug_rnglists", DebugSecType
, 0);
485 DwarfLoclistsSection
= Ctx
->getELFSection(".debug_loclists", DebugSecType
, 0);
488 DwarfInfoDWOSection
=
489 Ctx
->getELFSection(".debug_info.dwo", DebugSecType
, ELF::SHF_EXCLUDE
);
490 DwarfTypesDWOSection
=
491 Ctx
->getELFSection(".debug_types.dwo", DebugSecType
, ELF::SHF_EXCLUDE
);
492 DwarfAbbrevDWOSection
=
493 Ctx
->getELFSection(".debug_abbrev.dwo", DebugSecType
, ELF::SHF_EXCLUDE
);
494 DwarfStrDWOSection
= Ctx
->getELFSection(
495 ".debug_str.dwo", DebugSecType
,
496 ELF::SHF_MERGE
| ELF::SHF_STRINGS
| ELF::SHF_EXCLUDE
, 1);
497 DwarfLineDWOSection
=
498 Ctx
->getELFSection(".debug_line.dwo", DebugSecType
, ELF::SHF_EXCLUDE
);
500 Ctx
->getELFSection(".debug_loc.dwo", DebugSecType
, ELF::SHF_EXCLUDE
);
501 DwarfStrOffDWOSection
= Ctx
->getELFSection(".debug_str_offsets.dwo",
502 DebugSecType
, ELF::SHF_EXCLUDE
);
503 DwarfRnglistsDWOSection
=
504 Ctx
->getELFSection(".debug_rnglists.dwo", DebugSecType
, ELF::SHF_EXCLUDE
);
505 DwarfMacinfoDWOSection
=
506 Ctx
->getELFSection(".debug_macinfo.dwo", DebugSecType
, ELF::SHF_EXCLUDE
);
507 DwarfMacroDWOSection
=
508 Ctx
->getELFSection(".debug_macro.dwo", DebugSecType
, ELF::SHF_EXCLUDE
);
510 DwarfLoclistsDWOSection
=
511 Ctx
->getELFSection(".debug_loclists.dwo", DebugSecType
, ELF::SHF_EXCLUDE
);
514 DwarfCUIndexSection
=
515 Ctx
->getELFSection(".debug_cu_index", DebugSecType
, 0);
516 DwarfTUIndexSection
=
517 Ctx
->getELFSection(".debug_tu_index", DebugSecType
, 0);
520 Ctx
->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS
, ELF::SHF_ALLOC
);
523 Ctx
->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS
, ELF::SHF_ALLOC
);
526 Ctx
->getELFSection(".eh_frame", EHSectionType
, EHSectionFlags
);
528 StackSizesSection
= Ctx
->getELFSection(".stack_sizes", ELF::SHT_PROGBITS
, 0);
530 PseudoProbeSection
= Ctx
->getELFSection(".pseudo_probe", DebugSecType
, 0);
531 PseudoProbeDescSection
=
532 Ctx
->getELFSection(".pseudo_probe_desc", DebugSecType
, 0);
534 LLVMStatsSection
= Ctx
->getELFSection(".llvm_stats", ELF::SHT_PROGBITS
, 0);
537 void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple
&T
) {
539 Ctx
->getGOFFSection(".text", SectionKind::getText(), nullptr, nullptr);
541 Ctx
->getGOFFSection(".bss", SectionKind::getBSS(), nullptr, nullptr);
543 Ctx
->getGOFFSection(".ppa1", SectionKind::getMetadata(), TextSection
,
544 MCConstantExpr::create(GOFF::SK_PPA1
, *Ctx
));
547 void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple
&T
) {
549 Ctx
->getCOFFSection(".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
550 COFF::IMAGE_SCN_MEM_READ
,
551 SectionKind::getData());
553 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
554 // used to indicate to the linker that the text segment contains thumb instructions
555 // and to set the ISA selection bit for calls accordingly.
556 const bool IsThumb
= T
.getArch() == Triple::thumb
;
559 BSSSection
= Ctx
->getCOFFSection(
560 ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA
|
561 COFF::IMAGE_SCN_MEM_READ
| COFF::IMAGE_SCN_MEM_WRITE
,
562 SectionKind::getBSS());
563 TextSection
= Ctx
->getCOFFSection(
565 (IsThumb
? COFF::IMAGE_SCN_MEM_16BIT
: (COFF::SectionCharacteristics
)0) |
566 COFF::IMAGE_SCN_CNT_CODE
| COFF::IMAGE_SCN_MEM_EXECUTE
|
567 COFF::IMAGE_SCN_MEM_READ
,
568 SectionKind::getText());
569 DataSection
= Ctx
->getCOFFSection(
570 ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
| COFF::IMAGE_SCN_MEM_READ
|
571 COFF::IMAGE_SCN_MEM_WRITE
,
572 SectionKind::getData());
573 ReadOnlySection
= Ctx
->getCOFFSection(
574 ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
| COFF::IMAGE_SCN_MEM_READ
,
575 SectionKind::getReadOnly());
577 if (T
.getArch() == Triple::x86_64
|| T
.getArch() == Triple::aarch64
||
578 T
.getArch() == Triple::arm
|| T
.getArch() == Triple::thumb
) {
579 // On Windows with SEH, the LSDA is emitted into the .xdata section
580 LSDASection
= nullptr;
582 LSDASection
= Ctx
->getCOFFSection(".gcc_except_table",
583 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
584 COFF::IMAGE_SCN_MEM_READ
,
585 SectionKind::getReadOnly());
589 COFFDebugSymbolsSection
=
590 Ctx
->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE
|
591 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
592 COFF::IMAGE_SCN_MEM_READ
),
593 SectionKind::getMetadata());
594 COFFDebugTypesSection
=
595 Ctx
->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE
|
596 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
597 COFF::IMAGE_SCN_MEM_READ
),
598 SectionKind::getMetadata());
599 COFFGlobalTypeHashesSection
= Ctx
->getCOFFSection(
601 (COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
602 COFF::IMAGE_SCN_MEM_READ
),
603 SectionKind::getMetadata());
605 DwarfAbbrevSection
= Ctx
->getCOFFSection(
607 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
608 COFF::IMAGE_SCN_MEM_READ
,
609 SectionKind::getMetadata(), "section_abbrev");
610 DwarfInfoSection
= Ctx
->getCOFFSection(
612 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
613 COFF::IMAGE_SCN_MEM_READ
,
614 SectionKind::getMetadata(), "section_info");
615 DwarfLineSection
= Ctx
->getCOFFSection(
617 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
618 COFF::IMAGE_SCN_MEM_READ
,
619 SectionKind::getMetadata(), "section_line");
620 DwarfLineStrSection
= Ctx
->getCOFFSection(
622 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
623 COFF::IMAGE_SCN_MEM_READ
,
624 SectionKind::getMetadata(), "section_line_str");
625 DwarfFrameSection
= Ctx
->getCOFFSection(
627 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
628 COFF::IMAGE_SCN_MEM_READ
,
629 SectionKind::getMetadata());
630 DwarfPubNamesSection
= Ctx
->getCOFFSection(
632 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
633 COFF::IMAGE_SCN_MEM_READ
,
634 SectionKind::getMetadata());
635 DwarfPubTypesSection
= Ctx
->getCOFFSection(
637 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
638 COFF::IMAGE_SCN_MEM_READ
,
639 SectionKind::getMetadata());
640 DwarfGnuPubNamesSection
= Ctx
->getCOFFSection(
641 ".debug_gnu_pubnames",
642 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
643 COFF::IMAGE_SCN_MEM_READ
,
644 SectionKind::getMetadata());
645 DwarfGnuPubTypesSection
= Ctx
->getCOFFSection(
646 ".debug_gnu_pubtypes",
647 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
648 COFF::IMAGE_SCN_MEM_READ
,
649 SectionKind::getMetadata());
650 DwarfStrSection
= Ctx
->getCOFFSection(
652 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
653 COFF::IMAGE_SCN_MEM_READ
,
654 SectionKind::getMetadata(), "info_string");
655 DwarfStrOffSection
= Ctx
->getCOFFSection(
656 ".debug_str_offsets",
657 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
658 COFF::IMAGE_SCN_MEM_READ
,
659 SectionKind::getMetadata(), "section_str_off");
660 DwarfLocSection
= Ctx
->getCOFFSection(
662 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
663 COFF::IMAGE_SCN_MEM_READ
,
664 SectionKind::getMetadata(), "section_debug_loc");
665 DwarfLoclistsSection
= Ctx
->getCOFFSection(
667 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
668 COFF::IMAGE_SCN_MEM_READ
,
669 SectionKind::getMetadata(), "section_debug_loclists");
670 DwarfARangesSection
= Ctx
->getCOFFSection(
672 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
673 COFF::IMAGE_SCN_MEM_READ
,
674 SectionKind::getMetadata());
675 DwarfRangesSection
= Ctx
->getCOFFSection(
677 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
678 COFF::IMAGE_SCN_MEM_READ
,
679 SectionKind::getMetadata(), "debug_range");
680 DwarfRnglistsSection
= Ctx
->getCOFFSection(
682 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
683 COFF::IMAGE_SCN_MEM_READ
,
684 SectionKind::getMetadata(), "debug_rnglists");
685 DwarfMacinfoSection
= Ctx
->getCOFFSection(
687 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
688 COFF::IMAGE_SCN_MEM_READ
,
689 SectionKind::getMetadata(), "debug_macinfo");
690 DwarfMacroSection
= Ctx
->getCOFFSection(
692 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
693 COFF::IMAGE_SCN_MEM_READ
,
694 SectionKind::getMetadata(), "debug_macro");
695 DwarfMacinfoDWOSection
= Ctx
->getCOFFSection(
696 ".debug_macinfo.dwo",
697 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
698 COFF::IMAGE_SCN_MEM_READ
,
699 SectionKind::getMetadata(), "debug_macinfo.dwo");
700 DwarfMacroDWOSection
= Ctx
->getCOFFSection(
702 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
703 COFF::IMAGE_SCN_MEM_READ
,
704 SectionKind::getMetadata(), "debug_macro.dwo");
705 DwarfInfoDWOSection
= Ctx
->getCOFFSection(
707 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
708 COFF::IMAGE_SCN_MEM_READ
,
709 SectionKind::getMetadata(), "section_info_dwo");
710 DwarfTypesDWOSection
= Ctx
->getCOFFSection(
712 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
713 COFF::IMAGE_SCN_MEM_READ
,
714 SectionKind::getMetadata(), "section_types_dwo");
715 DwarfAbbrevDWOSection
= Ctx
->getCOFFSection(
717 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
718 COFF::IMAGE_SCN_MEM_READ
,
719 SectionKind::getMetadata(), "section_abbrev_dwo");
720 DwarfStrDWOSection
= Ctx
->getCOFFSection(
722 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
723 COFF::IMAGE_SCN_MEM_READ
,
724 SectionKind::getMetadata(), "skel_string");
725 DwarfLineDWOSection
= Ctx
->getCOFFSection(
727 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
728 COFF::IMAGE_SCN_MEM_READ
,
729 SectionKind::getMetadata());
730 DwarfLocDWOSection
= Ctx
->getCOFFSection(
732 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
733 COFF::IMAGE_SCN_MEM_READ
,
734 SectionKind::getMetadata(), "skel_loc");
735 DwarfStrOffDWOSection
= Ctx
->getCOFFSection(
736 ".debug_str_offsets.dwo",
737 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
738 COFF::IMAGE_SCN_MEM_READ
,
739 SectionKind::getMetadata(), "section_str_off_dwo");
740 DwarfAddrSection
= Ctx
->getCOFFSection(
742 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
743 COFF::IMAGE_SCN_MEM_READ
,
744 SectionKind::getMetadata(), "addr_sec");
745 DwarfCUIndexSection
= Ctx
->getCOFFSection(
747 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
748 COFF::IMAGE_SCN_MEM_READ
,
749 SectionKind::getMetadata());
750 DwarfTUIndexSection
= Ctx
->getCOFFSection(
752 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
753 COFF::IMAGE_SCN_MEM_READ
,
754 SectionKind::getMetadata());
755 DwarfDebugNamesSection
= Ctx
->getCOFFSection(
757 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
758 COFF::IMAGE_SCN_MEM_READ
,
759 SectionKind::getMetadata(), "debug_names_begin");
760 DwarfAccelNamesSection
= Ctx
->getCOFFSection(
762 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
763 COFF::IMAGE_SCN_MEM_READ
,
764 SectionKind::getMetadata(), "names_begin");
765 DwarfAccelNamespaceSection
= Ctx
->getCOFFSection(
767 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
768 COFF::IMAGE_SCN_MEM_READ
,
769 SectionKind::getMetadata(), "namespac_begin");
770 DwarfAccelTypesSection
= Ctx
->getCOFFSection(
772 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
773 COFF::IMAGE_SCN_MEM_READ
,
774 SectionKind::getMetadata(), "types_begin");
775 DwarfAccelObjCSection
= Ctx
->getCOFFSection(
777 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
778 COFF::IMAGE_SCN_MEM_READ
,
779 SectionKind::getMetadata(), "objc_begin");
781 DrectveSection
= Ctx
->getCOFFSection(
782 ".drectve", COFF::IMAGE_SCN_LNK_INFO
| COFF::IMAGE_SCN_LNK_REMOVE
,
783 SectionKind::getMetadata());
785 PDataSection
= Ctx
->getCOFFSection(
786 ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
| COFF::IMAGE_SCN_MEM_READ
,
787 SectionKind::getData());
789 XDataSection
= Ctx
->getCOFFSection(
790 ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
| COFF::IMAGE_SCN_MEM_READ
,
791 SectionKind::getData());
793 SXDataSection
= Ctx
->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO
,
794 SectionKind::getMetadata());
796 GEHContSection
= Ctx
->getCOFFSection(".gehcont$y",
797 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
798 COFF::IMAGE_SCN_MEM_READ
,
799 SectionKind::getMetadata());
801 GFIDsSection
= Ctx
->getCOFFSection(".gfids$y",
802 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
803 COFF::IMAGE_SCN_MEM_READ
,
804 SectionKind::getMetadata());
806 GIATsSection
= Ctx
->getCOFFSection(".giats$y",
807 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
808 COFF::IMAGE_SCN_MEM_READ
,
809 SectionKind::getMetadata());
811 GLJMPSection
= Ctx
->getCOFFSection(".gljmp$y",
812 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
813 COFF::IMAGE_SCN_MEM_READ
,
814 SectionKind::getMetadata());
816 TLSDataSection
= Ctx
->getCOFFSection(
817 ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
| COFF::IMAGE_SCN_MEM_READ
|
818 COFF::IMAGE_SCN_MEM_WRITE
,
819 SectionKind::getData());
821 StackMapSection
= Ctx
->getCOFFSection(".llvm_stackmaps",
822 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
823 COFF::IMAGE_SCN_MEM_READ
,
824 SectionKind::getReadOnly());
827 void MCObjectFileInfo::initSPIRVMCObjectFileInfo(const Triple
&T
) {
828 // Put everything in a single binary section.
829 TextSection
= Ctx
->getSPIRVSection();
832 void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple
&T
) {
833 TextSection
= Ctx
->getWasmSection(".text", SectionKind::getText());
834 DataSection
= Ctx
->getWasmSection(".data", SectionKind::getData());
837 Ctx
->getWasmSection(".debug_line", SectionKind::getMetadata());
838 DwarfLineStrSection
=
839 Ctx
->getWasmSection(".debug_line_str", SectionKind::getMetadata(),
840 wasm::WASM_SEG_FLAG_STRINGS
);
841 DwarfStrSection
= Ctx
->getWasmSection(
842 ".debug_str", SectionKind::getMetadata(), wasm::WASM_SEG_FLAG_STRINGS
);
844 Ctx
->getWasmSection(".debug_loc", SectionKind::getMetadata());
846 Ctx
->getWasmSection(".debug_abbrev", SectionKind::getMetadata());
847 DwarfARangesSection
= Ctx
->getWasmSection(".debug_aranges", SectionKind::getMetadata());
849 Ctx
->getWasmSection(".debug_ranges", SectionKind::getMetadata());
850 DwarfMacinfoSection
=
851 Ctx
->getWasmSection(".debug_macinfo", SectionKind::getMetadata());
853 Ctx
->getWasmSection(".debug_macro", SectionKind::getMetadata());
854 DwarfCUIndexSection
= Ctx
->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
855 DwarfTUIndexSection
= Ctx
->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
857 Ctx
->getWasmSection(".debug_info", SectionKind::getMetadata());
858 DwarfFrameSection
= Ctx
->getWasmSection(".debug_frame", SectionKind::getMetadata());
859 DwarfPubNamesSection
= Ctx
->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
860 DwarfPubTypesSection
= Ctx
->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
861 DwarfGnuPubNamesSection
=
862 Ctx
->getWasmSection(".debug_gnu_pubnames", SectionKind::getMetadata());
863 DwarfGnuPubTypesSection
=
864 Ctx
->getWasmSection(".debug_gnu_pubtypes", SectionKind::getMetadata());
866 DwarfDebugNamesSection
=
867 Ctx
->getWasmSection(".debug_names", SectionKind::getMetadata());
869 Ctx
->getWasmSection(".debug_str_offsets", SectionKind::getMetadata());
871 Ctx
->getWasmSection(".debug_addr", SectionKind::getMetadata());
872 DwarfRnglistsSection
=
873 Ctx
->getWasmSection(".debug_rnglists", SectionKind::getMetadata());
874 DwarfLoclistsSection
=
875 Ctx
->getWasmSection(".debug_loclists", SectionKind::getMetadata());
878 DwarfInfoDWOSection
=
879 Ctx
->getWasmSection(".debug_info.dwo", SectionKind::getMetadata());
880 DwarfTypesDWOSection
=
881 Ctx
->getWasmSection(".debug_types.dwo", SectionKind::getMetadata());
882 DwarfAbbrevDWOSection
=
883 Ctx
->getWasmSection(".debug_abbrev.dwo", SectionKind::getMetadata());
885 Ctx
->getWasmSection(".debug_str.dwo", SectionKind::getMetadata(),
886 wasm::WASM_SEG_FLAG_STRINGS
);
887 DwarfLineDWOSection
=
888 Ctx
->getWasmSection(".debug_line.dwo", SectionKind::getMetadata());
890 Ctx
->getWasmSection(".debug_loc.dwo", SectionKind::getMetadata());
891 DwarfStrOffDWOSection
=
892 Ctx
->getWasmSection(".debug_str_offsets.dwo", SectionKind::getMetadata());
893 DwarfRnglistsDWOSection
=
894 Ctx
->getWasmSection(".debug_rnglists.dwo", SectionKind::getMetadata());
895 DwarfMacinfoDWOSection
=
896 Ctx
->getWasmSection(".debug_macinfo.dwo", SectionKind::getMetadata());
897 DwarfMacroDWOSection
=
898 Ctx
->getWasmSection(".debug_macro.dwo", SectionKind::getMetadata());
900 DwarfLoclistsDWOSection
=
901 Ctx
->getWasmSection(".debug_loclists.dwo", SectionKind::getMetadata());
904 DwarfCUIndexSection
=
905 Ctx
->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
906 DwarfTUIndexSection
=
907 Ctx
->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
909 // Wasm use data section for LSDA.
910 // TODO Consider putting each function's exception table in a separate
911 // section, as in -function-sections, to facilitate lld's --gc-section.
912 LSDASection
= Ctx
->getWasmSection(".rodata.gcc_except_table",
913 SectionKind::getReadOnlyWithRel());
915 // TODO: Define more sections.
918 void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple
&T
) {
919 // The default csect for program code. Functions without a specified section
920 // get placed into this csect. The choice of csect name is not a property of
921 // the ABI or object file format. For example, the XL compiler uses an unnamed
922 // csect for program code.
923 TextSection
= Ctx
->getXCOFFSection(
924 ".text", SectionKind::getText(),
925 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_PR
, XCOFF::XTY_SD
),
926 /* MultiSymbolsAllowed*/ true);
928 DataSection
= Ctx
->getXCOFFSection(
929 ".data", SectionKind::getData(),
930 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW
, XCOFF::XTY_SD
),
931 /* MultiSymbolsAllowed*/ true);
933 ReadOnlySection
= Ctx
->getXCOFFSection(
934 ".rodata", SectionKind::getReadOnly(),
935 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO
, XCOFF::XTY_SD
),
936 /* MultiSymbolsAllowed*/ true);
937 ReadOnlySection
->setAlignment(Align(4));
939 ReadOnly8Section
= Ctx
->getXCOFFSection(
940 ".rodata.8", SectionKind::getReadOnly(),
941 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO
, XCOFF::XTY_SD
),
942 /* MultiSymbolsAllowed*/ true);
943 ReadOnly8Section
->setAlignment(Align(8));
945 ReadOnly16Section
= Ctx
->getXCOFFSection(
946 ".rodata.16", SectionKind::getReadOnly(),
947 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO
, XCOFF::XTY_SD
),
948 /* MultiSymbolsAllowed*/ true);
949 ReadOnly16Section
->setAlignment(Align(16));
951 TLSDataSection
= Ctx
->getXCOFFSection(
952 ".tdata", SectionKind::getThreadData(),
953 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TL
, XCOFF::XTY_SD
),
954 /* MultiSymbolsAllowed*/ true);
956 TOCBaseSection
= Ctx
->getXCOFFSection(
957 "TOC", SectionKind::getData(),
958 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TC0
,
961 // The TOC-base always has 0 size, but 4 byte alignment.
962 TOCBaseSection
->setAlignment(Align(4));
964 LSDASection
= Ctx
->getXCOFFSection(
965 ".gcc_except_table", SectionKind::getReadOnly(),
966 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO
,
969 CompactUnwindSection
= Ctx
->getXCOFFSection(
970 ".eh_info_table", SectionKind::getData(),
971 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW
,
974 // DWARF sections for XCOFF are not csects. They are special STYP_DWARF
975 // sections, and the individual DWARF sections are distinguished by their
977 DwarfAbbrevSection
= Ctx
->getXCOFFSection(
978 ".dwabrev", SectionKind::getMetadata(),
979 /* CsectProperties */ std::nullopt
,
980 /* MultiSymbolsAllowed */ true, ".dwabrev", XCOFF::SSUBTYP_DWABREV
);
982 DwarfInfoSection
= Ctx
->getXCOFFSection(
983 ".dwinfo", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt
,
984 /* MultiSymbolsAllowed */ true, ".dwinfo", XCOFF::SSUBTYP_DWINFO
);
986 DwarfLineSection
= Ctx
->getXCOFFSection(
987 ".dwline", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt
,
988 /* MultiSymbolsAllowed */ true, ".dwline", XCOFF::SSUBTYP_DWLINE
);
990 DwarfFrameSection
= Ctx
->getXCOFFSection(
991 ".dwframe", SectionKind::getMetadata(),
992 /* CsectProperties */ std::nullopt
,
993 /* MultiSymbolsAllowed */ true, ".dwframe", XCOFF::SSUBTYP_DWFRAME
);
995 DwarfPubNamesSection
= Ctx
->getXCOFFSection(
996 ".dwpbnms", SectionKind::getMetadata(),
997 /* CsectProperties */ std::nullopt
,
998 /* MultiSymbolsAllowed */ true, ".dwpbnms", XCOFF::SSUBTYP_DWPBNMS
);
1000 DwarfPubTypesSection
= Ctx
->getXCOFFSection(
1001 ".dwpbtyp", SectionKind::getMetadata(),
1002 /* CsectProperties */ std::nullopt
,
1003 /* MultiSymbolsAllowed */ true, ".dwpbtyp", XCOFF::SSUBTYP_DWPBTYP
);
1005 DwarfStrSection
= Ctx
->getXCOFFSection(
1006 ".dwstr", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt
,
1007 /* MultiSymbolsAllowed */ true, ".dwstr", XCOFF::SSUBTYP_DWSTR
);
1009 DwarfLocSection
= Ctx
->getXCOFFSection(
1010 ".dwloc", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt
,
1011 /* MultiSymbolsAllowed */ true, ".dwloc", XCOFF::SSUBTYP_DWLOC
);
1013 DwarfARangesSection
= Ctx
->getXCOFFSection(
1014 ".dwarnge", SectionKind::getMetadata(),
1015 /* CsectProperties */ std::nullopt
,
1016 /* MultiSymbolsAllowed */ true, ".dwarnge", XCOFF::SSUBTYP_DWARNGE
);
1018 DwarfRangesSection
= Ctx
->getXCOFFSection(
1019 ".dwrnges", SectionKind::getMetadata(),
1020 /* CsectProperties */ std::nullopt
,
1021 /* MultiSymbolsAllowed */ true, ".dwrnges", XCOFF::SSUBTYP_DWRNGES
);
1023 DwarfMacinfoSection
= Ctx
->getXCOFFSection(
1024 ".dwmac", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt
,
1025 /* MultiSymbolsAllowed */ true, ".dwmac", XCOFF::SSUBTYP_DWMAC
);
1028 void MCObjectFileInfo::initDXContainerObjectFileInfo(const Triple
&T
) {
1029 // At the moment the DXBC section should end up empty.
1030 TextSection
= Ctx
->getDXContainerSection("DXBC", SectionKind::getText());
1033 MCObjectFileInfo::~MCObjectFileInfo() = default;
1035 void MCObjectFileInfo::initMCObjectFileInfo(MCContext
&MCCtx
, bool PIC
,
1036 bool LargeCodeModel
) {
1037 PositionIndependent
= PIC
;
1041 SupportsWeakOmittedEHFrame
= true;
1042 SupportsCompactUnwindWithoutEHFrame
= false;
1043 OmitDwarfIfHaveCompactUnwind
= false;
1045 FDECFIEncoding
= dwarf::DW_EH_PE_absptr
;
1047 CompactUnwindDwarfEHFrameOnly
= 0;
1049 EHFrameSection
= nullptr; // Created on demand.
1050 CompactUnwindSection
= nullptr; // Used only by selected targets.
1051 DwarfAccelNamesSection
= nullptr; // Used only by selected targets.
1052 DwarfAccelObjCSection
= nullptr; // Used only by selected targets.
1053 DwarfAccelNamespaceSection
= nullptr; // Used only by selected targets.
1054 DwarfAccelTypesSection
= nullptr; // Used only by selected targets.
1056 Triple TheTriple
= Ctx
->getTargetTriple();
1057 switch (Ctx
->getObjectFileType()) {
1058 case MCContext::IsMachO
:
1059 initMachOMCObjectFileInfo(TheTriple
);
1061 case MCContext::IsCOFF
:
1062 initCOFFMCObjectFileInfo(TheTriple
);
1064 case MCContext::IsELF
:
1065 initELFMCObjectFileInfo(TheTriple
, LargeCodeModel
);
1067 case MCContext::IsGOFF
:
1068 initGOFFMCObjectFileInfo(TheTriple
);
1070 case MCContext::IsSPIRV
:
1071 initSPIRVMCObjectFileInfo(TheTriple
);
1073 case MCContext::IsWasm
:
1074 initWasmMCObjectFileInfo(TheTriple
);
1076 case MCContext::IsXCOFF
:
1077 initXCOFFMCObjectFileInfo(TheTriple
);
1079 case MCContext::IsDXContainer
:
1080 initDXContainerObjectFileInfo(TheTriple
);
1085 MCSection
*MCObjectFileInfo::getDwarfComdatSection(const char *Name
,
1086 uint64_t Hash
) const {
1087 switch (Ctx
->getTargetTriple().getObjectFormat()) {
1089 return Ctx
->getELFSection(Name
, ELF::SHT_PROGBITS
, ELF::SHF_GROUP
, 0,
1090 utostr(Hash
), /*IsComdat=*/true);
1092 return Ctx
->getWasmSection(Name
, SectionKind::getMetadata(), 0,
1093 utostr(Hash
), MCContext::GenericSectionID
);
1099 case Triple::DXContainer
:
1100 case Triple::UnknownObjectFormat
:
1101 report_fatal_error("Cannot get DWARF comdat section for this object file "
1102 "format: not implemented.");
1105 llvm_unreachable("Unknown ObjectFormatType");
1109 MCObjectFileInfo::getStackSizesSection(const MCSection
&TextSec
) const {
1110 if ((Ctx
->getObjectFileType() != MCContext::IsELF
) ||
1111 Ctx
->getTargetTriple().isPS4())
1112 return StackSizesSection
;
1114 const MCSectionELF
&ElfSec
= static_cast<const MCSectionELF
&>(TextSec
);
1115 unsigned Flags
= ELF::SHF_LINK_ORDER
;
1116 StringRef GroupName
;
1117 if (const MCSymbol
*Group
= ElfSec
.getGroup()) {
1118 GroupName
= Group
->getName();
1119 Flags
|= ELF::SHF_GROUP
;
1122 return Ctx
->getELFSection(".stack_sizes", ELF::SHT_PROGBITS
, Flags
, 0,
1123 GroupName
, true, ElfSec
.getUniqueID(),
1124 cast
<MCSymbolELF
>(TextSec
.getBeginSymbol()));
1128 MCObjectFileInfo::getBBAddrMapSection(const MCSection
&TextSec
) const {
1129 if (Ctx
->getObjectFileType() != MCContext::IsELF
)
1132 const MCSectionELF
&ElfSec
= static_cast<const MCSectionELF
&>(TextSec
);
1133 unsigned Flags
= ELF::SHF_LINK_ORDER
;
1134 StringRef GroupName
;
1135 if (const MCSymbol
*Group
= ElfSec
.getGroup()) {
1136 GroupName
= Group
->getName();
1137 Flags
|= ELF::SHF_GROUP
;
1140 // Use the text section's begin symbol and unique ID to create a separate
1141 // .llvm_bb_addr_map section associated with every unique text section.
1142 return Ctx
->getELFSection(".llvm_bb_addr_map", ELF::SHT_LLVM_BB_ADDR_MAP
,
1143 Flags
, 0, GroupName
, true, ElfSec
.getUniqueID(),
1144 cast
<MCSymbolELF
>(TextSec
.getBeginSymbol()));
1148 MCObjectFileInfo::getKCFITrapSection(const MCSection
&TextSec
) const {
1149 if (Ctx
->getObjectFileType() != MCContext::IsELF
)
1152 const MCSectionELF
&ElfSec
= static_cast<const MCSectionELF
&>(TextSec
);
1153 unsigned Flags
= ELF::SHF_LINK_ORDER
| ELF::SHF_ALLOC
;
1154 StringRef GroupName
;
1155 if (const MCSymbol
*Group
= ElfSec
.getGroup()) {
1156 GroupName
= Group
->getName();
1157 Flags
|= ELF::SHF_GROUP
;
1160 return Ctx
->getELFSection(".kcfi_traps", ELF::SHT_PROGBITS
, Flags
, 0,
1162 /*IsComdat=*/true, ElfSec
.getUniqueID(),
1163 cast
<MCSymbolELF
>(TextSec
.getBeginSymbol()));
1167 MCObjectFileInfo::getPseudoProbeSection(const MCSection
&TextSec
) const {
1168 if (Ctx
->getObjectFileType() == MCContext::IsELF
) {
1169 const auto &ElfSec
= static_cast<const MCSectionELF
&>(TextSec
);
1170 // Create a separate section for probes that comes with a comdat function.
1171 if (const MCSymbol
*Group
= ElfSec
.getGroup()) {
1172 auto *S
= static_cast<MCSectionELF
*>(PseudoProbeSection
);
1173 auto Flags
= S
->getFlags() | ELF::SHF_GROUP
;
1174 return Ctx
->getELFSection(S
->getName(), S
->getType(), Flags
,
1175 S
->getEntrySize(), Group
->getName(),
1179 return PseudoProbeSection
;
1183 MCObjectFileInfo::getPseudoProbeDescSection(StringRef FuncName
) const {
1184 if (Ctx
->getObjectFileType() == MCContext::IsELF
) {
1185 // Create a separate comdat group for each function's descriptor in order
1186 // for the linker to deduplicate. The duplication, must be from different
1187 // tranlation unit, can come from:
1188 // 1. Inline functions defined in header files;
1189 // 2. ThinLTO imported funcions;
1190 // 3. Weak-linkage definitions.
1191 // Use a concatenation of the section name and the function name as the
1192 // group name so that descriptor-only groups won't be folded with groups of
1194 if (Ctx
->getTargetTriple().supportsCOMDAT() && !FuncName
.empty()) {
1195 auto *S
= static_cast<MCSectionELF
*>(PseudoProbeDescSection
);
1196 auto Flags
= S
->getFlags() | ELF::SHF_GROUP
;
1197 return Ctx
->getELFSection(S
->getName(), S
->getType(), Flags
,
1199 S
->getName() + "_" + FuncName
,
1203 return PseudoProbeDescSection
;
1206 MCSection
*MCObjectFileInfo::getLLVMStatsSection() const {
1207 return LLVMStatsSection
;
1210 MCSection
*MCObjectFileInfo::getPCSection(StringRef Name
,
1211 const MCSection
*TextSec
) const {
1212 if (Ctx
->getObjectFileType() != MCContext::IsELF
)
1215 // SHF_WRITE for relocations, and let user post-process data in-place.
1216 unsigned Flags
= ELF::SHF_WRITE
| ELF::SHF_ALLOC
| ELF::SHF_LINK_ORDER
;
1219 TextSec
= getTextSection();
1221 StringRef GroupName
;
1222 const auto &ElfSec
= static_cast<const MCSectionELF
&>(*TextSec
);
1223 if (const MCSymbol
*Group
= ElfSec
.getGroup()) {
1224 GroupName
= Group
->getName();
1225 Flags
|= ELF::SHF_GROUP
;
1227 return Ctx
->getELFSection(Name
, ELF::SHT_PROGBITS
, Flags
, 0, GroupName
, true,
1228 ElfSec
.getUniqueID(),
1229 cast
<MCSymbolELF
>(TextSec
->getBeginSymbol()));