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 FDECFIEncoding
= dwarf::DW_EH_PE_pcrel
;
68 // .comm doesn't support alignment before Leopard.
69 if (T
.isMacOSX() && T
.isMacOSXVersionLT(10, 5))
70 CommDirectiveSupportsAlignment
= false;
73 = Ctx
->getMachOSection("__TEXT", "__text",
74 MachO::S_ATTR_PURE_INSTRUCTIONS
,
75 SectionKind::getText());
77 = Ctx
->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
79 // BSSSection might not be expected initialized on msvc.
82 TLSDataSection
// .tdata
83 = Ctx
->getMachOSection("__DATA", "__thread_data",
84 MachO::S_THREAD_LOCAL_REGULAR
,
85 SectionKind::getData());
86 TLSBSSSection
// .tbss
87 = Ctx
->getMachOSection("__DATA", "__thread_bss",
88 MachO::S_THREAD_LOCAL_ZEROFILL
,
89 SectionKind::getThreadBSS());
91 // TODO: Verify datarel below.
93 = Ctx
->getMachOSection("__DATA", "__thread_vars",
94 MachO::S_THREAD_LOCAL_VARIABLES
,
95 SectionKind::getData());
97 TLSThreadInitSection
= Ctx
->getMachOSection(
98 "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS
,
99 SectionKind::getData());
101 CStringSection
// .cstring
102 = Ctx
->getMachOSection("__TEXT", "__cstring",
103 MachO::S_CSTRING_LITERALS
,
104 SectionKind::getMergeable1ByteCString());
106 = Ctx
->getMachOSection("__TEXT","__ustring", 0,
107 SectionKind::getMergeable2ByteCString());
108 FourByteConstantSection
// .literal4
109 = Ctx
->getMachOSection("__TEXT", "__literal4",
110 MachO::S_4BYTE_LITERALS
,
111 SectionKind::getMergeableConst4());
112 EightByteConstantSection
// .literal8
113 = Ctx
->getMachOSection("__TEXT", "__literal8",
114 MachO::S_8BYTE_LITERALS
,
115 SectionKind::getMergeableConst8());
117 SixteenByteConstantSection
// .literal16
118 = Ctx
->getMachOSection("__TEXT", "__literal16",
119 MachO::S_16BYTE_LITERALS
,
120 SectionKind::getMergeableConst16());
122 ReadOnlySection
// .const
123 = Ctx
->getMachOSection("__TEXT", "__const", 0,
124 SectionKind::getReadOnly());
126 // If the target is not powerpc, map the coal sections to the non-coal
129 // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
130 // "__TEXT/__const_coal" => section "__TEXT/__const"
131 // "__DATA/__datacoal_nt" => section "__DATA/__data"
132 Triple::ArchType ArchTy
= T
.getArch();
134 ConstDataSection
// .const_data
135 = Ctx
->getMachOSection("__DATA", "__const", 0,
136 SectionKind::getReadOnlyWithRel());
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());
150 ConstDataCoalSection
= DataCoalSection
;
152 TextCoalSection
= TextSection
;
153 ConstTextCoalSection
= ReadOnlySection
;
154 DataCoalSection
= DataSection
;
155 ConstDataCoalSection
= ConstDataSection
;
159 = Ctx
->getMachOSection("__DATA","__common",
161 SectionKind::getBSS());
163 = Ctx
->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL
,
164 SectionKind::getBSS());
167 LazySymbolPointerSection
168 = Ctx
->getMachOSection("__DATA", "__la_symbol_ptr",
169 MachO::S_LAZY_SYMBOL_POINTERS
,
170 SectionKind::getMetadata());
171 NonLazySymbolPointerSection
172 = Ctx
->getMachOSection("__DATA", "__nl_symbol_ptr",
173 MachO::S_NON_LAZY_SYMBOL_POINTERS
,
174 SectionKind::getMetadata());
176 ThreadLocalPointerSection
177 = Ctx
->getMachOSection("__DATA", "__thread_ptr",
178 MachO::S_THREAD_LOCAL_VARIABLE_POINTERS
,
179 SectionKind::getMetadata());
181 // Exception Handling.
182 LSDASection
= Ctx
->getMachOSection("__TEXT", "__gcc_except_tab", 0,
183 SectionKind::getReadOnlyWithRel());
185 COFFDebugSymbolsSection
= nullptr;
186 COFFDebugTypesSection
= nullptr;
187 COFFGlobalTypeHashesSection
= nullptr;
189 if (useCompactUnwind(T
)) {
190 CompactUnwindSection
=
191 Ctx
->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG
,
192 SectionKind::getReadOnly());
194 if (T
.getArch() == Triple::x86_64
|| T
.getArch() == Triple::x86
)
195 CompactUnwindDwarfEHFrameOnly
= 0x04000000; // UNWIND_X86_64_MODE_DWARF
196 else if (T
.getArch() == Triple::aarch64
)
197 CompactUnwindDwarfEHFrameOnly
= 0x03000000; // UNWIND_ARM64_MODE_DWARF
198 else if (T
.getArch() == Triple::arm
|| T
.getArch() == Triple::thumb
)
199 CompactUnwindDwarfEHFrameOnly
= 0x04000000; // UNWIND_ARM_MODE_DWARF
202 // Debug Information.
203 DwarfDebugNamesSection
=
204 Ctx
->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG
,
205 SectionKind::getMetadata(), "debug_names_begin");
206 DwarfAccelNamesSection
=
207 Ctx
->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG
,
208 SectionKind::getMetadata(), "names_begin");
209 DwarfAccelObjCSection
=
210 Ctx
->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG
,
211 SectionKind::getMetadata(), "objc_begin");
212 // 16 character section limit...
213 DwarfAccelNamespaceSection
=
214 Ctx
->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG
,
215 SectionKind::getMetadata(), "namespac_begin");
216 DwarfAccelTypesSection
=
217 Ctx
->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG
,
218 SectionKind::getMetadata(), "types_begin");
220 DwarfSwiftASTSection
=
221 Ctx
->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG
,
222 SectionKind::getMetadata());
225 Ctx
->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG
,
226 SectionKind::getMetadata(), "section_abbrev");
228 Ctx
->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG
,
229 SectionKind::getMetadata(), "section_info");
231 Ctx
->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG
,
232 SectionKind::getMetadata(), "section_line");
233 DwarfLineStrSection
=
234 Ctx
->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG
,
235 SectionKind::getMetadata(), "section_line_str");
237 Ctx
->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG
,
238 SectionKind::getMetadata());
239 DwarfPubNamesSection
=
240 Ctx
->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG
,
241 SectionKind::getMetadata());
242 DwarfPubTypesSection
=
243 Ctx
->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG
,
244 SectionKind::getMetadata());
245 DwarfGnuPubNamesSection
=
246 Ctx
->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG
,
247 SectionKind::getMetadata());
248 DwarfGnuPubTypesSection
=
249 Ctx
->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG
,
250 SectionKind::getMetadata());
252 Ctx
->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG
,
253 SectionKind::getMetadata(), "info_string");
255 Ctx
->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG
,
256 SectionKind::getMetadata(), "section_str_off");
258 Ctx
->getMachOSection("__DWARF", "__debug_addr", MachO::S_ATTR_DEBUG
,
259 SectionKind::getMetadata(), "section_info");
261 Ctx
->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG
,
262 SectionKind::getMetadata(), "section_debug_loc");
263 DwarfLoclistsSection
=
264 Ctx
->getMachOSection("__DWARF", "__debug_loclists", MachO::S_ATTR_DEBUG
,
265 SectionKind::getMetadata(), "section_debug_loc");
267 DwarfARangesSection
=
268 Ctx
->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG
,
269 SectionKind::getMetadata());
271 Ctx
->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG
,
272 SectionKind::getMetadata(), "debug_range");
273 DwarfRnglistsSection
=
274 Ctx
->getMachOSection("__DWARF", "__debug_rnglists", MachO::S_ATTR_DEBUG
,
275 SectionKind::getMetadata(), "debug_range");
276 DwarfMacinfoSection
=
277 Ctx
->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG
,
278 SectionKind::getMetadata(), "debug_macinfo");
279 DwarfDebugInlineSection
=
280 Ctx
->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG
,
281 SectionKind::getMetadata());
282 DwarfCUIndexSection
=
283 Ctx
->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG
,
284 SectionKind::getMetadata());
285 DwarfTUIndexSection
=
286 Ctx
->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG
,
287 SectionKind::getMetadata());
288 StackMapSection
= Ctx
->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
289 0, SectionKind::getMetadata());
291 FaultMapSection
= Ctx
->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
292 0, SectionKind::getMetadata());
294 TLSExtraDataSection
= TLSTLVSection
;
297 void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple
&T
, bool Large
) {
298 switch (T
.getArch()) {
302 case Triple::mips64el
:
303 FDECFIEncoding
= Ctx
->getAsmInfo()->getCodePointerSize() == 4
304 ? dwarf::DW_EH_PE_sdata4
305 : dwarf::DW_EH_PE_sdata8
;
308 case Triple::ppc64le
:
310 FDECFIEncoding
= dwarf::DW_EH_PE_pcrel
|
311 (Large
? dwarf::DW_EH_PE_sdata8
: dwarf::DW_EH_PE_sdata4
);
315 FDECFIEncoding
= dwarf::DW_EH_PE_sdata8
;
317 case Triple::hexagon
:
319 PositionIndependent
? dwarf::DW_EH_PE_pcrel
: dwarf::DW_EH_PE_absptr
;
322 FDECFIEncoding
= dwarf::DW_EH_PE_pcrel
| dwarf::DW_EH_PE_sdata4
;
326 unsigned EHSectionType
= T
.getArch() == Triple::x86_64
327 ? ELF::SHT_X86_64_UNWIND
330 // Solaris requires different flags for .eh_frame to seemingly every other
332 unsigned EHSectionFlags
= ELF::SHF_ALLOC
;
333 if (T
.isOSSolaris() && T
.getArch() != Triple::x86_64
)
334 EHSectionFlags
|= ELF::SHF_WRITE
;
337 BSSSection
= Ctx
->getELFSection(".bss", ELF::SHT_NOBITS
,
338 ELF::SHF_WRITE
| ELF::SHF_ALLOC
);
340 TextSection
= Ctx
->getELFSection(".text", ELF::SHT_PROGBITS
,
341 ELF::SHF_EXECINSTR
| ELF::SHF_ALLOC
);
343 DataSection
= Ctx
->getELFSection(".data", ELF::SHT_PROGBITS
,
344 ELF::SHF_WRITE
| ELF::SHF_ALLOC
);
347 Ctx
->getELFSection(".rodata", ELF::SHT_PROGBITS
, ELF::SHF_ALLOC
);
350 Ctx
->getELFSection(".tdata", ELF::SHT_PROGBITS
,
351 ELF::SHF_ALLOC
| ELF::SHF_TLS
| ELF::SHF_WRITE
);
353 TLSBSSSection
= Ctx
->getELFSection(
354 ".tbss", ELF::SHT_NOBITS
, ELF::SHF_ALLOC
| ELF::SHF_TLS
| ELF::SHF_WRITE
);
356 DataRelROSection
= Ctx
->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS
,
357 ELF::SHF_ALLOC
| ELF::SHF_WRITE
);
359 MergeableConst4Section
=
360 Ctx
->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS
,
361 ELF::SHF_ALLOC
| ELF::SHF_MERGE
, 4, "");
363 MergeableConst8Section
=
364 Ctx
->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS
,
365 ELF::SHF_ALLOC
| ELF::SHF_MERGE
, 8, "");
367 MergeableConst16Section
=
368 Ctx
->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS
,
369 ELF::SHF_ALLOC
| ELF::SHF_MERGE
, 16, "");
371 MergeableConst32Section
=
372 Ctx
->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS
,
373 ELF::SHF_ALLOC
| ELF::SHF_MERGE
, 32, "");
375 // Exception Handling Sections.
377 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
378 // it contains relocatable pointers. In PIC mode, this is probably a big
379 // runtime hit for C++ apps. Either the contents of the LSDA need to be
380 // adjusted or this should be a data section.
381 LSDASection
= Ctx
->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS
,
384 COFFDebugSymbolsSection
= nullptr;
385 COFFDebugTypesSection
= nullptr;
387 unsigned DebugSecType
= ELF::SHT_PROGBITS
;
389 // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
390 // to distinguish among sections contain DWARF and ECOFF debug formats.
391 // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
393 DebugSecType
= ELF::SHT_MIPS_DWARF
;
395 // Debug Info Sections.
397 Ctx
->getELFSection(".debug_abbrev", DebugSecType
, 0);
398 DwarfInfoSection
= Ctx
->getELFSection(".debug_info", DebugSecType
, 0);
399 DwarfLineSection
= Ctx
->getELFSection(".debug_line", DebugSecType
, 0);
400 DwarfLineStrSection
=
401 Ctx
->getELFSection(".debug_line_str", DebugSecType
,
402 ELF::SHF_MERGE
| ELF::SHF_STRINGS
, 1, "");
403 DwarfFrameSection
= Ctx
->getELFSection(".debug_frame", DebugSecType
, 0);
404 DwarfPubNamesSection
=
405 Ctx
->getELFSection(".debug_pubnames", DebugSecType
, 0);
406 DwarfPubTypesSection
=
407 Ctx
->getELFSection(".debug_pubtypes", DebugSecType
, 0);
408 DwarfGnuPubNamesSection
=
409 Ctx
->getELFSection(".debug_gnu_pubnames", DebugSecType
, 0);
410 DwarfGnuPubTypesSection
=
411 Ctx
->getELFSection(".debug_gnu_pubtypes", DebugSecType
, 0);
413 Ctx
->getELFSection(".debug_str", DebugSecType
,
414 ELF::SHF_MERGE
| ELF::SHF_STRINGS
, 1, "");
415 DwarfLocSection
= Ctx
->getELFSection(".debug_loc", DebugSecType
, 0);
416 DwarfARangesSection
=
417 Ctx
->getELFSection(".debug_aranges", DebugSecType
, 0);
419 Ctx
->getELFSection(".debug_ranges", DebugSecType
, 0);
420 DwarfMacinfoSection
=
421 Ctx
->getELFSection(".debug_macinfo", DebugSecType
, 0);
423 // DWARF5 Experimental Debug Info
425 // Accelerator Tables
426 DwarfDebugNamesSection
=
427 Ctx
->getELFSection(".debug_names", ELF::SHT_PROGBITS
, 0);
428 DwarfAccelNamesSection
=
429 Ctx
->getELFSection(".apple_names", ELF::SHT_PROGBITS
, 0);
430 DwarfAccelObjCSection
=
431 Ctx
->getELFSection(".apple_objc", ELF::SHT_PROGBITS
, 0);
432 DwarfAccelNamespaceSection
=
433 Ctx
->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS
, 0);
434 DwarfAccelTypesSection
=
435 Ctx
->getELFSection(".apple_types", ELF::SHT_PROGBITS
, 0);
437 // String Offset and Address Sections
439 Ctx
->getELFSection(".debug_str_offsets", DebugSecType
, 0);
440 DwarfAddrSection
= Ctx
->getELFSection(".debug_addr", DebugSecType
, 0);
441 DwarfRnglistsSection
= Ctx
->getELFSection(".debug_rnglists", DebugSecType
, 0);
442 DwarfLoclistsSection
= Ctx
->getELFSection(".debug_loclists", DebugSecType
, 0);
445 DwarfInfoDWOSection
=
446 Ctx
->getELFSection(".debug_info.dwo", DebugSecType
, ELF::SHF_EXCLUDE
);
447 DwarfTypesDWOSection
=
448 Ctx
->getELFSection(".debug_types.dwo", DebugSecType
, ELF::SHF_EXCLUDE
);
449 DwarfAbbrevDWOSection
=
450 Ctx
->getELFSection(".debug_abbrev.dwo", DebugSecType
, ELF::SHF_EXCLUDE
);
451 DwarfStrDWOSection
= Ctx
->getELFSection(
452 ".debug_str.dwo", DebugSecType
,
453 ELF::SHF_MERGE
| ELF::SHF_STRINGS
| ELF::SHF_EXCLUDE
, 1, "");
454 DwarfLineDWOSection
=
455 Ctx
->getELFSection(".debug_line.dwo", DebugSecType
, ELF::SHF_EXCLUDE
);
457 Ctx
->getELFSection(".debug_loc.dwo", DebugSecType
, ELF::SHF_EXCLUDE
);
458 DwarfStrOffDWOSection
= Ctx
->getELFSection(".debug_str_offsets.dwo",
459 DebugSecType
, ELF::SHF_EXCLUDE
);
460 DwarfRnglistsDWOSection
=
461 Ctx
->getELFSection(".debug_rnglists.dwo", DebugSecType
, ELF::SHF_EXCLUDE
);
464 DwarfCUIndexSection
=
465 Ctx
->getELFSection(".debug_cu_index", DebugSecType
, 0);
466 DwarfTUIndexSection
=
467 Ctx
->getELFSection(".debug_tu_index", DebugSecType
, 0);
470 Ctx
->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS
, ELF::SHF_ALLOC
);
473 Ctx
->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS
, ELF::SHF_ALLOC
);
476 Ctx
->getELFSection(".eh_frame", EHSectionType
, EHSectionFlags
);
478 StackSizesSection
= Ctx
->getELFSection(".stack_sizes", ELF::SHT_PROGBITS
, 0);
481 void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple
&T
) {
483 Ctx
->getCOFFSection(".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
484 COFF::IMAGE_SCN_MEM_READ
,
485 SectionKind::getData());
487 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
488 // used to indicate to the linker that the text segment contains thumb instructions
489 // and to set the ISA selection bit for calls accordingly.
490 const bool IsThumb
= T
.getArch() == Triple::thumb
;
492 CommDirectiveSupportsAlignment
= true;
495 BSSSection
= Ctx
->getCOFFSection(
496 ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA
|
497 COFF::IMAGE_SCN_MEM_READ
| COFF::IMAGE_SCN_MEM_WRITE
,
498 SectionKind::getBSS());
499 TextSection
= Ctx
->getCOFFSection(
501 (IsThumb
? COFF::IMAGE_SCN_MEM_16BIT
: (COFF::SectionCharacteristics
)0) |
502 COFF::IMAGE_SCN_CNT_CODE
| COFF::IMAGE_SCN_MEM_EXECUTE
|
503 COFF::IMAGE_SCN_MEM_READ
,
504 SectionKind::getText());
505 DataSection
= Ctx
->getCOFFSection(
506 ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
| COFF::IMAGE_SCN_MEM_READ
|
507 COFF::IMAGE_SCN_MEM_WRITE
,
508 SectionKind::getData());
509 ReadOnlySection
= Ctx
->getCOFFSection(
510 ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
| COFF::IMAGE_SCN_MEM_READ
,
511 SectionKind::getReadOnly());
513 if (T
.getArch() == Triple::x86_64
|| T
.getArch() == Triple::aarch64
) {
514 // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
515 LSDASection
= nullptr;
517 LSDASection
= Ctx
->getCOFFSection(".gcc_except_table",
518 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
519 COFF::IMAGE_SCN_MEM_READ
,
520 SectionKind::getReadOnly());
524 COFFDebugSymbolsSection
=
525 Ctx
->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE
|
526 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
527 COFF::IMAGE_SCN_MEM_READ
),
528 SectionKind::getMetadata());
529 COFFDebugTypesSection
=
530 Ctx
->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE
|
531 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
532 COFF::IMAGE_SCN_MEM_READ
),
533 SectionKind::getMetadata());
534 COFFGlobalTypeHashesSection
= Ctx
->getCOFFSection(
536 (COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
537 COFF::IMAGE_SCN_MEM_READ
),
538 SectionKind::getMetadata());
540 DwarfAbbrevSection
= Ctx
->getCOFFSection(
542 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
543 COFF::IMAGE_SCN_MEM_READ
,
544 SectionKind::getMetadata(), "section_abbrev");
545 DwarfInfoSection
= Ctx
->getCOFFSection(
547 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
548 COFF::IMAGE_SCN_MEM_READ
,
549 SectionKind::getMetadata(), "section_info");
550 DwarfLineSection
= Ctx
->getCOFFSection(
552 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
553 COFF::IMAGE_SCN_MEM_READ
,
554 SectionKind::getMetadata(), "section_line");
555 DwarfLineStrSection
= Ctx
->getCOFFSection(
557 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
558 COFF::IMAGE_SCN_MEM_READ
,
559 SectionKind::getMetadata(), "section_line_str");
560 DwarfFrameSection
= Ctx
->getCOFFSection(
562 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
563 COFF::IMAGE_SCN_MEM_READ
,
564 SectionKind::getMetadata());
565 DwarfPubNamesSection
= Ctx
->getCOFFSection(
567 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
568 COFF::IMAGE_SCN_MEM_READ
,
569 SectionKind::getMetadata());
570 DwarfPubTypesSection
= Ctx
->getCOFFSection(
572 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
573 COFF::IMAGE_SCN_MEM_READ
,
574 SectionKind::getMetadata());
575 DwarfGnuPubNamesSection
= Ctx
->getCOFFSection(
576 ".debug_gnu_pubnames",
577 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
578 COFF::IMAGE_SCN_MEM_READ
,
579 SectionKind::getMetadata());
580 DwarfGnuPubTypesSection
= Ctx
->getCOFFSection(
581 ".debug_gnu_pubtypes",
582 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
583 COFF::IMAGE_SCN_MEM_READ
,
584 SectionKind::getMetadata());
585 DwarfStrSection
= Ctx
->getCOFFSection(
587 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
588 COFF::IMAGE_SCN_MEM_READ
,
589 SectionKind::getMetadata(), "info_string");
590 DwarfStrOffSection
= Ctx
->getCOFFSection(
591 ".debug_str_offsets",
592 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
593 COFF::IMAGE_SCN_MEM_READ
,
594 SectionKind::getMetadata(), "section_str_off");
595 DwarfLocSection
= Ctx
->getCOFFSection(
597 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
598 COFF::IMAGE_SCN_MEM_READ
,
599 SectionKind::getMetadata(), "section_debug_loc");
600 DwarfARangesSection
= Ctx
->getCOFFSection(
602 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
603 COFF::IMAGE_SCN_MEM_READ
,
604 SectionKind::getMetadata());
605 DwarfRangesSection
= Ctx
->getCOFFSection(
607 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
608 COFF::IMAGE_SCN_MEM_READ
,
609 SectionKind::getMetadata(), "debug_range");
610 DwarfMacinfoSection
= Ctx
->getCOFFSection(
612 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
613 COFF::IMAGE_SCN_MEM_READ
,
614 SectionKind::getMetadata(), "debug_macinfo");
615 DwarfInfoDWOSection
= Ctx
->getCOFFSection(
617 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
618 COFF::IMAGE_SCN_MEM_READ
,
619 SectionKind::getMetadata(), "section_info_dwo");
620 DwarfTypesDWOSection
= Ctx
->getCOFFSection(
622 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
623 COFF::IMAGE_SCN_MEM_READ
,
624 SectionKind::getMetadata(), "section_types_dwo");
625 DwarfAbbrevDWOSection
= Ctx
->getCOFFSection(
627 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
628 COFF::IMAGE_SCN_MEM_READ
,
629 SectionKind::getMetadata(), "section_abbrev_dwo");
630 DwarfStrDWOSection
= Ctx
->getCOFFSection(
632 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
633 COFF::IMAGE_SCN_MEM_READ
,
634 SectionKind::getMetadata(), "skel_string");
635 DwarfLineDWOSection
= Ctx
->getCOFFSection(
637 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
638 COFF::IMAGE_SCN_MEM_READ
,
639 SectionKind::getMetadata());
640 DwarfLocDWOSection
= Ctx
->getCOFFSection(
642 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
643 COFF::IMAGE_SCN_MEM_READ
,
644 SectionKind::getMetadata(), "skel_loc");
645 DwarfStrOffDWOSection
= Ctx
->getCOFFSection(
646 ".debug_str_offsets.dwo",
647 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
648 COFF::IMAGE_SCN_MEM_READ
,
649 SectionKind::getMetadata(), "section_str_off_dwo");
650 DwarfAddrSection
= Ctx
->getCOFFSection(
652 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
653 COFF::IMAGE_SCN_MEM_READ
,
654 SectionKind::getMetadata(), "addr_sec");
655 DwarfCUIndexSection
= Ctx
->getCOFFSection(
657 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
658 COFF::IMAGE_SCN_MEM_READ
,
659 SectionKind::getMetadata());
660 DwarfTUIndexSection
= Ctx
->getCOFFSection(
662 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
663 COFF::IMAGE_SCN_MEM_READ
,
664 SectionKind::getMetadata());
665 DwarfDebugNamesSection
= Ctx
->getCOFFSection(
667 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
668 COFF::IMAGE_SCN_MEM_READ
,
669 SectionKind::getMetadata(), "debug_names_begin");
670 DwarfAccelNamesSection
= Ctx
->getCOFFSection(
672 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
673 COFF::IMAGE_SCN_MEM_READ
,
674 SectionKind::getMetadata(), "names_begin");
675 DwarfAccelNamespaceSection
= Ctx
->getCOFFSection(
677 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
678 COFF::IMAGE_SCN_MEM_READ
,
679 SectionKind::getMetadata(), "namespac_begin");
680 DwarfAccelTypesSection
= Ctx
->getCOFFSection(
682 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
683 COFF::IMAGE_SCN_MEM_READ
,
684 SectionKind::getMetadata(), "types_begin");
685 DwarfAccelObjCSection
= Ctx
->getCOFFSection(
687 COFF::IMAGE_SCN_MEM_DISCARDABLE
| COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
688 COFF::IMAGE_SCN_MEM_READ
,
689 SectionKind::getMetadata(), "objc_begin");
691 DrectveSection
= Ctx
->getCOFFSection(
692 ".drectve", COFF::IMAGE_SCN_LNK_INFO
| COFF::IMAGE_SCN_LNK_REMOVE
,
693 SectionKind::getMetadata());
695 PDataSection
= Ctx
->getCOFFSection(
696 ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
| COFF::IMAGE_SCN_MEM_READ
,
697 SectionKind::getData());
699 XDataSection
= Ctx
->getCOFFSection(
700 ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
| COFF::IMAGE_SCN_MEM_READ
,
701 SectionKind::getData());
703 SXDataSection
= Ctx
->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO
,
704 SectionKind::getMetadata());
706 GFIDsSection
= Ctx
->getCOFFSection(".gfids$y",
707 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
708 COFF::IMAGE_SCN_MEM_READ
,
709 SectionKind::getMetadata());
711 TLSDataSection
= Ctx
->getCOFFSection(
712 ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
| COFF::IMAGE_SCN_MEM_READ
|
713 COFF::IMAGE_SCN_MEM_WRITE
,
714 SectionKind::getData());
716 StackMapSection
= Ctx
->getCOFFSection(".llvm_stackmaps",
717 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
718 COFF::IMAGE_SCN_MEM_READ
,
719 SectionKind::getReadOnly());
722 void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple
&T
) {
723 TextSection
= Ctx
->getWasmSection(".text", SectionKind::getText());
724 DataSection
= Ctx
->getWasmSection(".data", SectionKind::getData());
727 Ctx
->getWasmSection(".debug_line", SectionKind::getMetadata());
728 DwarfLineStrSection
=
729 Ctx
->getWasmSection(".debug_line_str", SectionKind::getMetadata());
731 Ctx
->getWasmSection(".debug_str", SectionKind::getMetadata());
733 Ctx
->getWasmSection(".debug_loc", SectionKind::getMetadata());
735 Ctx
->getWasmSection(".debug_abbrev", SectionKind::getMetadata());
736 DwarfARangesSection
= Ctx
->getWasmSection(".debug_aranges", SectionKind::getMetadata());
738 Ctx
->getWasmSection(".debug_ranges", SectionKind::getMetadata());
739 DwarfMacinfoSection
=
740 Ctx
->getWasmSection(".debug_macinfo", SectionKind::getMetadata());
741 DwarfAddrSection
= Ctx
->getWasmSection(".debug_addr", SectionKind::getMetadata());
742 DwarfCUIndexSection
= Ctx
->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
743 DwarfTUIndexSection
= Ctx
->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
745 Ctx
->getWasmSection(".debug_info", SectionKind::getMetadata());
746 DwarfFrameSection
= Ctx
->getWasmSection(".debug_frame", SectionKind::getMetadata());
747 DwarfPubNamesSection
= Ctx
->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
748 DwarfPubTypesSection
= Ctx
->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
750 // Wasm use data section for LSDA.
751 // TODO Consider putting each function's exception table in a separate
752 // section, as in -function-sections, to facilitate lld's --gc-section.
753 LSDASection
= Ctx
->getWasmSection(".rodata.gcc_except_table",
754 SectionKind::getReadOnlyWithRel());
756 // TODO: Define more sections.
759 void MCObjectFileInfo::InitMCObjectFileInfo(const Triple
&TheTriple
, bool PIC
,
761 bool LargeCodeModel
) {
762 PositionIndependent
= PIC
;
766 CommDirectiveSupportsAlignment
= true;
767 SupportsWeakOmittedEHFrame
= true;
768 SupportsCompactUnwindWithoutEHFrame
= false;
769 OmitDwarfIfHaveCompactUnwind
= false;
771 FDECFIEncoding
= dwarf::DW_EH_PE_absptr
;
773 CompactUnwindDwarfEHFrameOnly
= 0;
775 EHFrameSection
= nullptr; // Created on demand.
776 CompactUnwindSection
= nullptr; // Used only by selected targets.
777 DwarfAccelNamesSection
= nullptr; // Used only by selected targets.
778 DwarfAccelObjCSection
= nullptr; // Used only by selected targets.
779 DwarfAccelNamespaceSection
= nullptr; // Used only by selected targets.
780 DwarfAccelTypesSection
= nullptr; // Used only by selected targets.
784 switch (TT
.getObjectFormat()) {
787 initMachOMCObjectFileInfo(TT
);
790 if (!TT
.isOSWindows())
792 "Cannot initialize MC for non-Windows COFF object files.");
795 initCOFFMCObjectFileInfo(TT
);
799 initELFMCObjectFileInfo(TT
, LargeCodeModel
);
803 initWasmMCObjectFileInfo(TT
);
805 case Triple::UnknownObjectFormat
:
806 report_fatal_error("Cannot initialize MC for unknown object file format.");
811 MCSection
*MCObjectFileInfo::getDwarfComdatSection(const char *Name
,
812 uint64_t Hash
) const {
813 switch (TT
.getObjectFormat()) {
815 return Ctx
->getELFSection(Name
, ELF::SHT_PROGBITS
, ELF::SHF_GROUP
, 0,
820 case Triple::UnknownObjectFormat
:
821 report_fatal_error("Cannot get DWARF comdat section for this object file "
822 "format: not implemented.");
825 llvm_unreachable("Unknown ObjectFormatType");
829 MCObjectFileInfo::getStackSizesSection(const MCSection
&TextSec
) const {
831 return StackSizesSection
;
833 const MCSectionELF
&ElfSec
= static_cast<const MCSectionELF
&>(TextSec
);
834 unsigned Flags
= ELF::SHF_LINK_ORDER
;
836 if (const MCSymbol
*Group
= ElfSec
.getGroup()) {
837 GroupName
= Group
->getName();
838 Flags
|= ELF::SHF_GROUP
;
841 const MCSymbol
*Link
= TextSec
.getBeginSymbol();
842 auto It
= StackSizesUniquing
.insert({Link
, StackSizesUniquing
.size()});
843 unsigned UniqueID
= It
.first
->second
;
845 return Ctx
->getELFSection(".stack_sizes", ELF::SHT_PROGBITS
, Flags
, 0,
846 GroupName
, UniqueID
, cast
<MCSymbolELF
>(Link
));