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//===----------------------------------------------------------------------===//
8
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/GOFF.h"
14#include "llvm/BinaryFormat/SFrame.h"
15#include "llvm/BinaryFormat/Wasm.h"
16#include "llvm/MC/MCAsmInfo.h"
17#include "llvm/MC/MCContext.h"
18#include "llvm/MC/MCGOFFAttributes.h"
19#include "llvm/MC/MCSection.h"
20#include "llvm/MC/MCSectionCOFF.h"
21#include "llvm/MC/MCSectionDXContainer.h"
22#include "llvm/MC/MCSectionELF.h"
23#include "llvm/MC/MCSectionGOFF.h"
24#include "llvm/MC/MCSectionMachO.h"
25#include "llvm/MC/MCSectionSPIRV.h"
26#include "llvm/MC/MCSectionWasm.h"
27#include "llvm/MC/MCSectionXCOFF.h"
28#include "llvm/MC/MCSymbolGOFF.h"
29#include "llvm/MC/SectionKind.h"
30#include "llvm/TargetParser/Triple.h"
31
32using namespace llvm;
33
34static bool useCompactUnwind(const Triple &T) {
35 // Only on darwin.
36 if (!T.isOSDarwin())
37 return false;
38
39 // aarch64 always has it.
40 if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)
41 return true;
42
43 // armv7k always has it.
44 if (T.isWatchABI())
45 return true;
46
47 // Use it on newer version of OS X.
48 if (T.isMacOSX() && !T.isMacOSXVersionLT(Major: 10, Minor: 6))
49 return true;
50
51 // And the iOS simulator.
52 if (T.isiOS() && T.isX86())
53 return true;
54
55 // The rest of the simulators always have it.
56 if (T.isSimulatorEnvironment())
57 return true;
58
59 // XROS always has it.
60 if (T.isXROS())
61 return true;
62
63 return false;
64}
65
66void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
67 EHFrameSection = Ctx->getMachOSection(
68 Segment: "__TEXT", Section: "__eh_frame",
69 TypeAndAttributes: MachO::S_COALESCED | MachO::S_ATTR_NO_TOC |
70 MachO::S_ATTR_STRIP_STATIC_SYMS | MachO::S_ATTR_LIVE_SUPPORT,
71 K: SectionKind::getReadOnly());
72
73 if (T.isOSDarwin() &&
74 (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32 ||
75 T.isSimulatorEnvironment()))
76 SupportsCompactUnwindWithoutEHFrame = true;
77
78 switch (Ctx->emitDwarfUnwindInfo()) {
79 case EmitDwarfUnwindType::Always:
80 OmitDwarfIfHaveCompactUnwind = false;
81 break;
82 case EmitDwarfUnwindType::NoCompactUnwind:
83 OmitDwarfIfHaveCompactUnwind = true;
84 break;
85 case EmitDwarfUnwindType::Default:
86 OmitDwarfIfHaveCompactUnwind =
87 T.isWatchABI() || SupportsCompactUnwindWithoutEHFrame;
88 break;
89 }
90
91 FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
92
93 TextSection // .text
94 = Ctx->getMachOSection(Segment: "__TEXT", Section: "__text",
95 TypeAndAttributes: MachO::S_ATTR_PURE_INSTRUCTIONS,
96 K: SectionKind::getText());
97 DataSection // .data
98 = Ctx->getMachOSection(Segment: "__DATA", Section: "__data", TypeAndAttributes: 0, K: SectionKind::getData());
99
100 // BSSSection might not be expected initialized on msvc.
101 BSSSection = nullptr;
102
103 TLSDataSection // .tdata
104 = Ctx->getMachOSection(Segment: "__DATA", Section: "__thread_data",
105 TypeAndAttributes: MachO::S_THREAD_LOCAL_REGULAR,
106 K: SectionKind::getData());
107 TLSBSSSection // .tbss
108 = Ctx->getMachOSection(Segment: "__DATA", Section: "__thread_bss",
109 TypeAndAttributes: MachO::S_THREAD_LOCAL_ZEROFILL,
110 K: SectionKind::getThreadBSS());
111
112 // TODO: Verify datarel below.
113 TLSTLVSection // .tlv
114 = Ctx->getMachOSection(Segment: "__DATA", Section: "__thread_vars",
115 TypeAndAttributes: MachO::S_THREAD_LOCAL_VARIABLES,
116 K: SectionKind::getData());
117
118 TLSThreadInitSection = Ctx->getMachOSection(
119 Segment: "__DATA", Section: "__thread_init", TypeAndAttributes: MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
120 K: SectionKind::getData());
121
122 CStringSection // .cstring
123 = Ctx->getMachOSection(Segment: "__TEXT", Section: "__cstring",
124 TypeAndAttributes: MachO::S_CSTRING_LITERALS,
125 K: SectionKind::getMergeable1ByteCString());
126 UStringSection
127 = Ctx->getMachOSection(Segment: "__TEXT",Section: "__ustring", TypeAndAttributes: 0,
128 K: SectionKind::getMergeable2ByteCString());
129 FourByteConstantSection // .literal4
130 = Ctx->getMachOSection(Segment: "__TEXT", Section: "__literal4",
131 TypeAndAttributes: MachO::S_4BYTE_LITERALS,
132 K: SectionKind::getMergeableConst4());
133 EightByteConstantSection // .literal8
134 = Ctx->getMachOSection(Segment: "__TEXT", Section: "__literal8",
135 TypeAndAttributes: MachO::S_8BYTE_LITERALS,
136 K: SectionKind::getMergeableConst8());
137
138 SixteenByteConstantSection // .literal16
139 = Ctx->getMachOSection(Segment: "__TEXT", Section: "__literal16",
140 TypeAndAttributes: MachO::S_16BYTE_LITERALS,
141 K: SectionKind::getMergeableConst16());
142
143 ReadOnlySection // .const
144 = Ctx->getMachOSection(Segment: "__TEXT", Section: "__const", TypeAndAttributes: 0,
145 K: SectionKind::getReadOnly());
146
147 // If the target is not powerpc, map the coal sections to the non-coal
148 // sections.
149 //
150 // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
151 // "__TEXT/__const_coal" => section "__TEXT/__const"
152 // "__DATA/__datacoal_nt" => section "__DATA/__data"
153 Triple::ArchType ArchTy = T.getArch();
154
155 ConstDataSection // .const_data
156 = Ctx->getMachOSection(Segment: "__DATA", Section: "__const", TypeAndAttributes: 0,
157 K: SectionKind::getReadOnlyWithRel());
158
159 if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
160 TextCoalSection
161 = Ctx->getMachOSection(Segment: "__TEXT", Section: "__textcoal_nt",
162 TypeAndAttributes: MachO::S_COALESCED |
163 MachO::S_ATTR_PURE_INSTRUCTIONS,
164 K: SectionKind::getText());
165 ConstTextCoalSection
166 = Ctx->getMachOSection(Segment: "__TEXT", Section: "__const_coal",
167 TypeAndAttributes: MachO::S_COALESCED,
168 K: SectionKind::getReadOnly());
169 DataCoalSection = Ctx->getMachOSection(
170 Segment: "__DATA", Section: "__datacoal_nt", TypeAndAttributes: MachO::S_COALESCED, K: SectionKind::getData());
171 ConstDataCoalSection = DataCoalSection;
172 } else {
173 TextCoalSection = TextSection;
174 ConstTextCoalSection = ReadOnlySection;
175 DataCoalSection = DataSection;
176 ConstDataCoalSection = ConstDataSection;
177 }
178
179 DataCommonSection
180 = Ctx->getMachOSection(Segment: "__DATA",Section: "__common",
181 TypeAndAttributes: MachO::S_ZEROFILL,
182 K: SectionKind::getBSS());
183 DataBSSSection
184 = Ctx->getMachOSection(Segment: "__DATA",Section: "__bss", TypeAndAttributes: MachO::S_ZEROFILL,
185 K: SectionKind::getBSS());
186
187
188 LazySymbolPointerSection
189 = Ctx->getMachOSection(Segment: "__DATA", Section: "__la_symbol_ptr",
190 TypeAndAttributes: MachO::S_LAZY_SYMBOL_POINTERS,
191 K: SectionKind::getMetadata());
192 NonLazySymbolPointerSection
193 = Ctx->getMachOSection(Segment: "__DATA", Section: "__nl_symbol_ptr",
194 TypeAndAttributes: MachO::S_NON_LAZY_SYMBOL_POINTERS,
195 K: SectionKind::getMetadata());
196
197 ThreadLocalPointerSection
198 = Ctx->getMachOSection(Segment: "__DATA", Section: "__thread_ptr",
199 TypeAndAttributes: MachO::S_THREAD_LOCAL_VARIABLE_POINTERS,
200 K: SectionKind::getMetadata());
201
202 AddrSigSection = Ctx->getMachOSection(Segment: "__DATA", Section: "__llvm_addrsig", TypeAndAttributes: 0,
203 K: SectionKind::getData());
204
205 // Exception Handling.
206 LSDASection = Ctx->getMachOSection(Segment: "__TEXT", Section: "__gcc_except_tab", TypeAndAttributes: 0,
207 K: SectionKind::getReadOnlyWithRel());
208
209 COFFDebugSymbolsSection = nullptr;
210 COFFDebugTypesSection = nullptr;
211 COFFGlobalTypeHashesSection = nullptr;
212
213 if (useCompactUnwind(T)) {
214 CompactUnwindSection =
215 Ctx->getMachOSection(Segment: "__LD", Section: "__compact_unwind", TypeAndAttributes: MachO::S_ATTR_DEBUG,
216 K: SectionKind::getReadOnly());
217
218 if (T.isX86())
219 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF
220 else if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)
221 CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF
222 else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
223 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF
224 }
225
226 // Debug Information.
227 DwarfDebugNamesSection =
228 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_names", TypeAndAttributes: MachO::S_ATTR_DEBUG,
229 K: SectionKind::getMetadata(), BeginSymName: "debug_names_begin");
230 DwarfAccelNamesSection =
231 Ctx->getMachOSection(Segment: "__DWARF", Section: "__apple_names", TypeAndAttributes: MachO::S_ATTR_DEBUG,
232 K: SectionKind::getMetadata(), BeginSymName: "names_begin");
233 DwarfAccelObjCSection =
234 Ctx->getMachOSection(Segment: "__DWARF", Section: "__apple_objc", TypeAndAttributes: MachO::S_ATTR_DEBUG,
235 K: SectionKind::getMetadata(), BeginSymName: "objc_begin");
236 // 16 character section limit...
237 DwarfAccelNamespaceSection =
238 Ctx->getMachOSection(Segment: "__DWARF", Section: "__apple_namespac", TypeAndAttributes: MachO::S_ATTR_DEBUG,
239 K: SectionKind::getMetadata(), BeginSymName: "namespac_begin");
240 DwarfAccelTypesSection =
241 Ctx->getMachOSection(Segment: "__DWARF", Section: "__apple_types", TypeAndAttributes: MachO::S_ATTR_DEBUG,
242 K: SectionKind::getMetadata(), BeginSymName: "types_begin");
243
244 DwarfSwiftASTSection =
245 Ctx->getMachOSection(Segment: "__DWARF", Section: "__swift_ast", TypeAndAttributes: MachO::S_ATTR_DEBUG,
246 K: SectionKind::getMetadata());
247
248 DwarfAbbrevSection =
249 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_abbrev", TypeAndAttributes: MachO::S_ATTR_DEBUG,
250 K: SectionKind::getMetadata(), BeginSymName: "section_abbrev");
251 DwarfInfoSection =
252 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_info", TypeAndAttributes: MachO::S_ATTR_DEBUG,
253 K: SectionKind::getMetadata(), BeginSymName: "section_info");
254 DwarfLineSection =
255 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_line", TypeAndAttributes: MachO::S_ATTR_DEBUG,
256 K: SectionKind::getMetadata(), BeginSymName: "section_line");
257 DwarfLineStrSection =
258 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_line_str", TypeAndAttributes: MachO::S_ATTR_DEBUG,
259 K: SectionKind::getMetadata(), BeginSymName: "section_line_str");
260 DwarfFrameSection =
261 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_frame", TypeAndAttributes: MachO::S_ATTR_DEBUG,
262 K: SectionKind::getMetadata(), BeginSymName: "section_frame");
263 DwarfPubNamesSection =
264 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_pubnames", TypeAndAttributes: MachO::S_ATTR_DEBUG,
265 K: SectionKind::getMetadata());
266 DwarfPubTypesSection =
267 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_pubtypes", TypeAndAttributes: MachO::S_ATTR_DEBUG,
268 K: SectionKind::getMetadata());
269 DwarfGnuPubNamesSection =
270 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_gnu_pubn", TypeAndAttributes: MachO::S_ATTR_DEBUG,
271 K: SectionKind::getMetadata());
272 DwarfGnuPubTypesSection =
273 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_gnu_pubt", TypeAndAttributes: MachO::S_ATTR_DEBUG,
274 K: SectionKind::getMetadata());
275 DwarfStrSection =
276 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_str", TypeAndAttributes: MachO::S_ATTR_DEBUG,
277 K: SectionKind::getMetadata(), BeginSymName: "info_string");
278 DwarfStrOffSection =
279 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_str_offs", TypeAndAttributes: MachO::S_ATTR_DEBUG,
280 K: SectionKind::getMetadata(), BeginSymName: "section_str_off");
281 DwarfAddrSection =
282 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_addr", TypeAndAttributes: MachO::S_ATTR_DEBUG,
283 K: SectionKind::getMetadata(), BeginSymName: "section_info");
284 DwarfLocSection =
285 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_loc", TypeAndAttributes: MachO::S_ATTR_DEBUG,
286 K: SectionKind::getMetadata(), BeginSymName: "section_debug_loc");
287 DwarfLoclistsSection =
288 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_loclists", TypeAndAttributes: MachO::S_ATTR_DEBUG,
289 K: SectionKind::getMetadata(), BeginSymName: "section_debug_loc");
290
291 DwarfARangesSection =
292 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_aranges", TypeAndAttributes: MachO::S_ATTR_DEBUG,
293 K: SectionKind::getMetadata());
294 DwarfRangesSection =
295 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_ranges", TypeAndAttributes: MachO::S_ATTR_DEBUG,
296 K: SectionKind::getMetadata(), BeginSymName: "debug_range");
297 DwarfRnglistsSection =
298 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_rnglists", TypeAndAttributes: MachO::S_ATTR_DEBUG,
299 K: SectionKind::getMetadata(), BeginSymName: "debug_range");
300 DwarfMacinfoSection =
301 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_macinfo", TypeAndAttributes: MachO::S_ATTR_DEBUG,
302 K: SectionKind::getMetadata(), BeginSymName: "debug_macinfo");
303 DwarfMacroSection =
304 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_macro", TypeAndAttributes: MachO::S_ATTR_DEBUG,
305 K: SectionKind::getMetadata(), BeginSymName: "debug_macro");
306 DwarfDebugInlineSection =
307 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_inlined", TypeAndAttributes: MachO::S_ATTR_DEBUG,
308 K: SectionKind::getMetadata());
309 DwarfCUIndexSection =
310 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_cu_index", TypeAndAttributes: MachO::S_ATTR_DEBUG,
311 K: SectionKind::getMetadata());
312 DwarfTUIndexSection =
313 Ctx->getMachOSection(Segment: "__DWARF", Section: "__debug_tu_index", TypeAndAttributes: MachO::S_ATTR_DEBUG,
314 K: SectionKind::getMetadata());
315 StackMapSection = Ctx->getMachOSection(Segment: "__LLVM_STACKMAPS", Section: "__llvm_stackmaps",
316 TypeAndAttributes: 0, K: SectionKind::getMetadata());
317
318 FaultMapSection = Ctx->getMachOSection(Segment: "__LLVM_FAULTMAPS", Section: "__llvm_faultmaps",
319 TypeAndAttributes: 0, K: SectionKind::getMetadata());
320
321 RemarksSection = Ctx->getMachOSection(
322 Segment: "__LLVM", Section: "__remarks", TypeAndAttributes: MachO::S_ATTR_DEBUG, K: SectionKind::getMetadata());
323
324 PseudoProbeSection =
325 Ctx->getMachOSection(Segment: "__PSEUDO_PROBE", Section: "__probes",
326 TypeAndAttributes: MachO::S_ATTR_DEBUG | MachO::S_ATTR_NO_DEAD_STRIP,
327 K: SectionKind::getMetadata());
328 PseudoProbeDescSection =
329 Ctx->getMachOSection(Segment: "__PSEUDO_PROBE", Section: "__probe_descs",
330 TypeAndAttributes: MachO::S_ATTR_DEBUG | MachO::S_ATTR_NO_DEAD_STRIP,
331 K: SectionKind::getMetadata());
332
333 // The architecture of dsymutil makes it very difficult to copy the Swift
334 // reflection metadata sections into the __TEXT segment, so dsymutil creates
335 // these sections in the __DWARF segment instead.
336 if (!Ctx->getSwift5ReflectionSegmentName().empty()) {
337#define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) \
338 Swift5ReflectionSections \
339 [llvm::binaryformat::Swift5ReflectionSectionKind::KIND] = \
340 Ctx->getMachOSection(Ctx->getSwift5ReflectionSegmentName().data(), \
341 MACHO, 0, SectionKind::getMetadata());
342#include "llvm/BinaryFormat/Swift.def"
343 }
344
345 TLSExtraDataSection = TLSTLVSection;
346}
347
348void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
349 switch (T.getArch()) {
350 case Triple::mips:
351 case Triple::mipsel:
352 case Triple::mips64:
353 case Triple::mips64el:
354 // We cannot use DW_EH_PE_sdata8 for the large PositionIndependent case
355 // since there is no R_MIPS_PC64 relocation (only a 32-bit version).
356 // In fact DW_EH_PE_sdata4 is enough for us now, and GNU ld doesn't
357 // support pcrel|sdata8 well. Let's use sdata4 for now.
358 if (PositionIndependent)
359 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
360 else
361 FDECFIEncoding = Ctx->getAsmInfo()->getCodePointerSize() == 4
362 ? dwarf::DW_EH_PE_sdata4
363 : dwarf::DW_EH_PE_sdata8;
364 break;
365 case Triple::ppc64:
366 case Triple::ppc64le:
367 case Triple::aarch64:
368 case Triple::aarch64_be:
369 case Triple::x86_64:
370 FDECFIEncoding = dwarf::DW_EH_PE_pcrel |
371 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
372 break;
373 case Triple::bpfel:
374 case Triple::bpfeb:
375 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
376 break;
377 case Triple::hexagon:
378 FDECFIEncoding =
379 PositionIndependent ? dwarf::DW_EH_PE_pcrel : dwarf::DW_EH_PE_absptr;
380 break;
381 case Triple::xtensa:
382 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
383 break;
384 default:
385 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
386 break;
387 }
388
389 unsigned EHSectionType = T.getArch() == Triple::x86_64
390 ? ELF::SHT_X86_64_UNWIND
391 : ELF::SHT_PROGBITS;
392 switch (T.getArch()) {
393 case Triple::x86_64:
394 SFrameABIArch = sframe::ABI::AMD64EndianLittle;
395 break;
396 case Triple::aarch64:
397 SFrameABIArch = sframe::ABI::AArch64EndianLittle;
398 break;
399 case Triple::aarch64_be:
400 SFrameABIArch = sframe::ABI::AArch64EndianBig;
401 break;
402 default:
403 break;
404 }
405
406 // Solaris requires different flags for .eh_frame to seemingly every other
407 // platform.
408 unsigned EHSectionFlags = ELF::SHF_ALLOC;
409 if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
410 EHSectionFlags |= ELF::SHF_WRITE;
411
412 // ELF
413 BSSSection = Ctx->getELFSection(Section: ".bss", Type: ELF::SHT_NOBITS,
414 Flags: ELF::SHF_WRITE | ELF::SHF_ALLOC);
415
416 TextSection = Ctx->getELFSection(Section: ".text", Type: ELF::SHT_PROGBITS,
417 Flags: ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
418
419 DataSection = Ctx->getELFSection(Section: ".data", Type: ELF::SHT_PROGBITS,
420 Flags: ELF::SHF_WRITE | ELF::SHF_ALLOC);
421
422 ReadOnlySection =
423 Ctx->getELFSection(Section: ".rodata", Type: ELF::SHT_PROGBITS, Flags: ELF::SHF_ALLOC);
424
425 TLSDataSection =
426 Ctx->getELFSection(Section: ".tdata", Type: ELF::SHT_PROGBITS,
427 Flags: ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
428
429 TLSBSSSection = Ctx->getELFSection(
430 Section: ".tbss", Type: ELF::SHT_NOBITS, Flags: ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
431
432 DataRelROSection = Ctx->getELFSection(Section: ".data.rel.ro", Type: ELF::SHT_PROGBITS,
433 Flags: ELF::SHF_ALLOC | ELF::SHF_WRITE);
434
435 MergeableConst4Section =
436 Ctx->getELFSection(Section: ".rodata.cst4", Type: ELF::SHT_PROGBITS,
437 Flags: ELF::SHF_ALLOC | ELF::SHF_MERGE, EntrySize: 4);
438
439 MergeableConst8Section =
440 Ctx->getELFSection(Section: ".rodata.cst8", Type: ELF::SHT_PROGBITS,
441 Flags: ELF::SHF_ALLOC | ELF::SHF_MERGE, EntrySize: 8);
442
443 MergeableConst16Section =
444 Ctx->getELFSection(Section: ".rodata.cst16", Type: ELF::SHT_PROGBITS,
445 Flags: ELF::SHF_ALLOC | ELF::SHF_MERGE, EntrySize: 16);
446
447 MergeableConst32Section =
448 Ctx->getELFSection(Section: ".rodata.cst32", Type: ELF::SHT_PROGBITS,
449 Flags: ELF::SHF_ALLOC | ELF::SHF_MERGE, EntrySize: 32);
450
451 // Exception Handling Sections.
452
453 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
454 // it contains relocatable pointers. In PIC mode, this is probably a big
455 // runtime hit for C++ apps. Either the contents of the LSDA need to be
456 // adjusted or this should be a data section.
457 LSDASection = Ctx->getELFSection(Section: ".gcc_except_table", Type: ELF::SHT_PROGBITS,
458 Flags: ELF::SHF_ALLOC);
459
460 COFFDebugSymbolsSection = nullptr;
461 COFFDebugTypesSection = nullptr;
462
463 unsigned DebugSecType = ELF::SHT_PROGBITS;
464
465 // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
466 // to distinguish among sections contain DWARF and ECOFF debug formats.
467 // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
468 if (T.isMIPS())
469 DebugSecType = ELF::SHT_MIPS_DWARF;
470
471 // Debug Info Sections.
472 DwarfAbbrevSection =
473 Ctx->getELFSection(Section: ".debug_abbrev", Type: DebugSecType, Flags: 0);
474 DwarfInfoSection = Ctx->getELFSection(Section: ".debug_info", Type: DebugSecType, Flags: 0);
475 DwarfLineSection = Ctx->getELFSection(Section: ".debug_line", Type: DebugSecType, Flags: 0);
476 DwarfLineStrSection =
477 Ctx->getELFSection(Section: ".debug_line_str", Type: DebugSecType,
478 Flags: ELF::SHF_MERGE | ELF::SHF_STRINGS, EntrySize: 1);
479 DwarfFrameSection = Ctx->getELFSection(Section: ".debug_frame", Type: DebugSecType, Flags: 0);
480 DwarfPubNamesSection =
481 Ctx->getELFSection(Section: ".debug_pubnames", Type: DebugSecType, Flags: 0);
482 DwarfPubTypesSection =
483 Ctx->getELFSection(Section: ".debug_pubtypes", Type: DebugSecType, Flags: 0);
484 DwarfGnuPubNamesSection =
485 Ctx->getELFSection(Section: ".debug_gnu_pubnames", Type: DebugSecType, Flags: 0);
486 DwarfGnuPubTypesSection =
487 Ctx->getELFSection(Section: ".debug_gnu_pubtypes", Type: DebugSecType, Flags: 0);
488 DwarfStrSection =
489 Ctx->getELFSection(Section: ".debug_str", Type: DebugSecType,
490 Flags: ELF::SHF_MERGE | ELF::SHF_STRINGS, EntrySize: 1);
491 DwarfLocSection = Ctx->getELFSection(Section: ".debug_loc", Type: DebugSecType, Flags: 0);
492 DwarfARangesSection =
493 Ctx->getELFSection(Section: ".debug_aranges", Type: DebugSecType, Flags: 0);
494 DwarfRangesSection =
495 Ctx->getELFSection(Section: ".debug_ranges", Type: DebugSecType, Flags: 0);
496 DwarfMacinfoSection =
497 Ctx->getELFSection(Section: ".debug_macinfo", Type: DebugSecType, Flags: 0);
498 DwarfMacroSection = Ctx->getELFSection(Section: ".debug_macro", Type: DebugSecType, Flags: 0);
499
500 // DWARF5 Experimental Debug Info
501
502 // Accelerator Tables
503 DwarfDebugNamesSection =
504 Ctx->getELFSection(Section: ".debug_names", Type: ELF::SHT_PROGBITS, Flags: 0);
505 DwarfAccelNamesSection =
506 Ctx->getELFSection(Section: ".apple_names", Type: ELF::SHT_PROGBITS, Flags: 0);
507 DwarfAccelObjCSection =
508 Ctx->getELFSection(Section: ".apple_objc", Type: ELF::SHT_PROGBITS, Flags: 0);
509 DwarfAccelNamespaceSection =
510 Ctx->getELFSection(Section: ".apple_namespaces", Type: ELF::SHT_PROGBITS, Flags: 0);
511 DwarfAccelTypesSection =
512 Ctx->getELFSection(Section: ".apple_types", Type: ELF::SHT_PROGBITS, Flags: 0);
513
514 // String Offset and Address Sections
515 DwarfStrOffSection =
516 Ctx->getELFSection(Section: ".debug_str_offsets", Type: DebugSecType, Flags: 0);
517 DwarfAddrSection = Ctx->getELFSection(Section: ".debug_addr", Type: DebugSecType, Flags: 0);
518 DwarfRnglistsSection = Ctx->getELFSection(Section: ".debug_rnglists", Type: DebugSecType, Flags: 0);
519 DwarfLoclistsSection = Ctx->getELFSection(Section: ".debug_loclists", Type: DebugSecType, Flags: 0);
520
521 // Fission Sections
522 DwarfInfoDWOSection =
523 Ctx->getELFSection(Section: ".debug_info.dwo", Type: DebugSecType, Flags: ELF::SHF_EXCLUDE);
524 DwarfTypesDWOSection =
525 Ctx->getELFSection(Section: ".debug_types.dwo", Type: DebugSecType, Flags: ELF::SHF_EXCLUDE);
526 DwarfAbbrevDWOSection =
527 Ctx->getELFSection(Section: ".debug_abbrev.dwo", Type: DebugSecType, Flags: ELF::SHF_EXCLUDE);
528 DwarfStrDWOSection = Ctx->getELFSection(
529 Section: ".debug_str.dwo", Type: DebugSecType,
530 Flags: ELF::SHF_MERGE | ELF::SHF_STRINGS | ELF::SHF_EXCLUDE, EntrySize: 1);
531 DwarfLineDWOSection =
532 Ctx->getELFSection(Section: ".debug_line.dwo", Type: DebugSecType, Flags: ELF::SHF_EXCLUDE);
533 DwarfLocDWOSection =
534 Ctx->getELFSection(Section: ".debug_loc.dwo", Type: DebugSecType, Flags: ELF::SHF_EXCLUDE);
535 DwarfStrOffDWOSection = Ctx->getELFSection(Section: ".debug_str_offsets.dwo",
536 Type: DebugSecType, Flags: ELF::SHF_EXCLUDE);
537 DwarfRnglistsDWOSection =
538 Ctx->getELFSection(Section: ".debug_rnglists.dwo", Type: DebugSecType, Flags: ELF::SHF_EXCLUDE);
539 DwarfMacinfoDWOSection =
540 Ctx->getELFSection(Section: ".debug_macinfo.dwo", Type: DebugSecType, Flags: ELF::SHF_EXCLUDE);
541 DwarfMacroDWOSection =
542 Ctx->getELFSection(Section: ".debug_macro.dwo", Type: DebugSecType, Flags: ELF::SHF_EXCLUDE);
543
544 DwarfLoclistsDWOSection =
545 Ctx->getELFSection(Section: ".debug_loclists.dwo", Type: DebugSecType, Flags: ELF::SHF_EXCLUDE);
546
547 // DWP Sections
548 DwarfCUIndexSection =
549 Ctx->getELFSection(Section: ".debug_cu_index", Type: DebugSecType, Flags: 0);
550 DwarfTUIndexSection =
551 Ctx->getELFSection(Section: ".debug_tu_index", Type: DebugSecType, Flags: 0);
552
553 StackMapSection =
554 Ctx->getELFSection(Section: ".llvm_stackmaps", Type: ELF::SHT_PROGBITS, Flags: ELF::SHF_ALLOC);
555
556 FaultMapSection =
557 Ctx->getELFSection(Section: ".llvm_faultmaps", Type: ELF::SHT_PROGBITS, Flags: ELF::SHF_ALLOC);
558
559 EHFrameSection =
560 Ctx->getELFSection(Section: ".eh_frame", Type: EHSectionType, Flags: EHSectionFlags);
561
562 SFrameSection =
563 Ctx->getELFSection(Section: ".sframe", Type: ELF::SHT_GNU_SFRAME, Flags: ELF::SHF_ALLOC);
564
565 CallGraphSection =
566 Ctx->getELFSection(Section: ".llvm.callgraph", Type: ELF::SHT_LLVM_CALL_GRAPH, Flags: 0);
567
568 StackSizesSection = Ctx->getELFSection(Section: ".stack_sizes", Type: ELF::SHT_PROGBITS, Flags: 0);
569
570 PseudoProbeSection = Ctx->getELFSection(Section: ".pseudo_probe", Type: DebugSecType, Flags: 0);
571 PseudoProbeDescSection =
572 Ctx->getELFSection(Section: ".pseudo_probe_desc", Type: DebugSecType, Flags: 0);
573
574 LLVMStatsSection = Ctx->getELFSection(Section: ".llvm_stats", Type: ELF::SHT_PROGBITS, Flags: 0);
575}
576
577void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) {
578 MCSectionGOFF *RootSDSection = Ctx->getGOFFSection(
579 Kind: SectionKind::getMetadata(), Name: "#C",
580 SDAttributes: GOFF::SDAttr{.TaskingBehavior: GOFF::ESD_TA_Rent, .BindingScope: GOFF::ESD_BSC_Section});
581
582 MCSectionGOFF *ADAEDSection = Ctx->getGOFFSection(
583 Kind: SectionKind::getMetadata(), Name: GOFF::CLASS_WSA,
584 EDAttributes: GOFF::EDAttr{.IsReadOnly: false, .Rmode: GOFF::ESD_RMODE_64, .NameSpace: GOFF::ESD_NS_Parts,
585 .TextStyle: GOFF::ESD_TS_ByteOriented, .BindAlgorithm: GOFF::ESD_BA_Merge,
586 .LoadBehavior: GOFF::ESD_LB_Deferred, .ReservedQwords: GOFF::ESD_RQ_1,
587 .Alignment: GOFF::ESD_ALIGN_Quadword, .FillByteValue: 0},
588 Parent: RootSDSection);
589 ADASection = Ctx->getGOFFSection(Kind: SectionKind::getData(), Name: "#S",
590 PRAttributes: GOFF::PRAttr{.IsRenamable: false, .Executable: GOFF::ESD_EXE_DATA,
591 .Linkage: GOFF::ESD_LT_XPLink,
592 .BindingScope: GOFF::ESD_BSC_Section, .SortKey: 0},
593 Parent: ADAEDSection);
594
595 TextSection = Ctx->getGOFFSection(
596 Kind: SectionKind::getText(), Name: GOFF::CLASS_CODE,
597 EDAttributes: GOFF::EDAttr{.IsReadOnly: true, .Rmode: GOFF::ESD_RMODE_64, .NameSpace: GOFF::ESD_NS_NormalName,
598 .TextStyle: GOFF::ESD_TS_ByteOriented, .BindAlgorithm: GOFF::ESD_BA_Concatenate,
599 .LoadBehavior: GOFF::ESD_LB_Initial, .ReservedQwords: GOFF::ESD_RQ_0,
600 .Alignment: GOFF::ESD_ALIGN_Doubleword, .FillByteValue: 0},
601 Parent: RootSDSection);
602
603 MCSectionGOFF *PPA2ListEDSection = Ctx->getGOFFSection(
604 Kind: SectionKind::getMetadata(), Name: GOFF::CLASS_PPA2,
605 EDAttributes: GOFF::EDAttr{.IsReadOnly: true, .Rmode: GOFF::ESD_RMODE_64, .NameSpace: GOFF::ESD_NS_Parts,
606 .TextStyle: GOFF::ESD_TS_ByteOriented, .BindAlgorithm: GOFF::ESD_BA_Merge,
607 .LoadBehavior: GOFF::ESD_LB_Initial, .ReservedQwords: GOFF::ESD_RQ_0,
608 .Alignment: GOFF::ESD_ALIGN_Doubleword, .FillByteValue: 0},
609 Parent: RootSDSection);
610 PPA2ListSection = Ctx->getGOFFSection(Kind: SectionKind::getData(), Name: ".&ppa2",
611 PRAttributes: GOFF::PRAttr{.IsRenamable: true, .Executable: GOFF::ESD_EXE_DATA,
612 .Linkage: GOFF::ESD_LT_OS,
613 .BindingScope: GOFF::ESD_BSC_Section, .SortKey: 0},
614 Parent: PPA2ListEDSection);
615
616 IDRLSection = Ctx->getGOFFSection(
617 Kind: SectionKind::getData(), Name: "B_IDRL",
618 EDAttributes: GOFF::EDAttr{.IsReadOnly: true, .Rmode: GOFF::ESD_RMODE_64, .NameSpace: GOFF::ESD_NS_NormalName,
619 .TextStyle: GOFF::ESD_TS_Structured, .BindAlgorithm: GOFF::ESD_BA_Concatenate,
620 .LoadBehavior: GOFF::ESD_LB_NoLoad, .ReservedQwords: GOFF::ESD_RQ_0,
621 .Alignment: GOFF::ESD_ALIGN_Doubleword, .FillByteValue: 0},
622 Parent: RootSDSection);
623
624 // Debug Info Sections. The ED name is the same used by the XL compiler.
625 auto InitDebugSection = [this,
626 RootSDSection](StringRef EDName,
627 StringRef LDName) -> MCSectionGOFF * {
628 MCSectionGOFF *ED = Ctx->getGOFFSection(
629 Kind: SectionKind::getMetadata(), Name: EDName,
630 EDAttributes: GOFF::EDAttr{.IsReadOnly: false, .Rmode: GOFF::ESD_RMODE_64, .NameSpace: GOFF::ESD_NS_Parts,
631 .TextStyle: GOFF::ESD_TS_ByteOriented, .BindAlgorithm: GOFF::ESD_BA_Concatenate,
632 .LoadBehavior: GOFF::ESD_LB_NoLoad, .ReservedQwords: GOFF::ESD_RQ_0,
633 .Alignment: GOFF::ESD_ALIGN_Doubleword, .FillByteValue: 0},
634 Parent: RootSDSection);
635 // At least for llc, this function is called twice! (See function
636 // compileModule() in llc.cpp). Since the context is not cleared, the
637 // already allocated section is returned above. We only add the begin symbol
638 // if it is not yet set to avoid an assertion.
639 MCSymbolGOFF *LD = static_cast<MCSymbolGOFF *>(ED->getBeginSymbol());
640 if (!LD) {
641 LD = static_cast<MCSymbolGOFF *>(getContext().getOrCreateSymbol(Name: LDName));
642 LD->setCodeData(GOFF::ESD_EXE_DATA);
643 LD->setWeak(false);
644 LD->setLinkage(GOFF::ESD_LT_XPLink);
645 LD->setExternal(false);
646 ED->setBeginSymbol(LD);
647 } else
648 assert(LD->getName() == LDName && "Wrong label name");
649 return ED;
650 };
651 DwarfAbbrevSection = InitDebugSection("D_ABREV", ".debug_abbrev");
652 DwarfInfoSection = InitDebugSection("D_INFO", ".debug_info");
653 DwarfLineSection = InitDebugSection("D_LINE", ".debug_line");
654 DwarfFrameSection = InitDebugSection("D_FRAME", ".debug_frame");
655 DwarfPubNamesSection = InitDebugSection("D_PBNMS", ".debug_pubnames");
656 DwarfPubTypesSection = InitDebugSection("D_PTYPES", ".debug_pubtypes");
657 DwarfStrSection = InitDebugSection("D_STR", ".debug_str");
658 DwarfLocSection = InitDebugSection("D_LOC", ".debug_loc");
659 DwarfARangesSection = InitDebugSection("D_ARNGE", ".debug_aranges");
660 DwarfRangesSection = InitDebugSection("D_RNGES", ".debug_ranges");
661 DwarfMacinfoSection = InitDebugSection("D_MACIN", ".debug_macinfo");
662
663 // DWARF 5 sections.
664 DwarfDebugNamesSection = InitDebugSection("D_NAMES", ".debug_names");
665 DwarfStrOffSection = InitDebugSection("D_STROFFS", ".debug_str_offsets");
666 DwarfAddrSection = InitDebugSection("D_ADDR", ".debug_addr");
667 DwarfRnglistsSection = InitDebugSection("D_RNGLISTS", ".debug_rnglists");
668 DwarfLoclistsSection = InitDebugSection("D_LOCLISTS", ".debug_loclists");
669 DwarfLineStrSection = InitDebugSection("D_LINESTR", ".debug_line_str");
670
671 // Special GNU sections.
672 DwarfGnuPubNamesSection = InitDebugSection("D_GPBNMS", ".debug_gnu_pubnames");
673 DwarfGnuPubTypesSection =
674 InitDebugSection("D_GPTYPES", ".debug_gnu_pubtypes");
675
676 // Accelerator Tables.
677 DwarfAccelNamesSection = InitDebugSection("D_APPLNMS", ".apple_names");
678 DwarfAccelNamespaceSection =
679 InitDebugSection("D_APPLNMSP", ".apple_namespaces");
680 DwarfAccelTypesSection = InitDebugSection("D_APPLTYPS", ".apple_types");
681 DwarfAccelObjCSection = InitDebugSection("D_APPLOBJC", ".apple_objc");
682}
683
684void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
685 EHFrameSection =
686 Ctx->getCOFFSection(Section: ".eh_frame", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
687 COFF::IMAGE_SCN_MEM_READ);
688
689 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
690 // used to indicate to the linker that the text segment contains thumb instructions
691 // and to set the ISA selection bit for calls accordingly.
692 const bool IsThumb = T.getArch() == Triple::thumb;
693
694 // COFF
695 BSSSection = Ctx->getCOFFSection(
696 Section: ".bss", Characteristics: COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
697 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE);
698 TextSection = Ctx->getCOFFSection(
699 Section: ".text",
700 Characteristics: (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |
701 COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
702 COFF::IMAGE_SCN_MEM_READ);
703 DataSection = Ctx->getCOFFSection(
704 Section: ".data", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
705 COFF::IMAGE_SCN_MEM_WRITE);
706 ReadOnlySection =
707 Ctx->getCOFFSection(Section: ".rdata", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
708 COFF::IMAGE_SCN_MEM_READ);
709
710 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64 ||
711 T.getArch() == Triple::arm || T.getArch() == Triple::thumb) {
712 // On Windows with SEH, the LSDA is emitted into the .xdata section
713 LSDASection = nullptr;
714 } else {
715 LSDASection = Ctx->getCOFFSection(Section: ".gcc_except_table",
716 Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
717 COFF::IMAGE_SCN_MEM_READ);
718 }
719
720 if (T.getArch() == Triple::aarch64) {
721 ImportCallSection =
722 Ctx->getCOFFSection(Section: ".impcall", Characteristics: COFF::IMAGE_SCN_LNK_INFO);
723 } else if (T.getArch() == Triple::x86_64) {
724 // Import Call Optimization on x64 leverages the same metadata as the
725 // retpoline mitigation, hence the unusual section name.
726 ImportCallSection =
727 Ctx->getCOFFSection(Section: ".retplne", Characteristics: COFF::IMAGE_SCN_LNK_INFO);
728 }
729
730 // Debug info.
731 COFFDebugSymbolsSection =
732 Ctx->getCOFFSection(Section: ".debug$S", Characteristics: (COFF::IMAGE_SCN_MEM_DISCARDABLE |
733 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
734 COFF::IMAGE_SCN_MEM_READ));
735 COFFDebugTypesSection =
736 Ctx->getCOFFSection(Section: ".debug$T", Characteristics: (COFF::IMAGE_SCN_MEM_DISCARDABLE |
737 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
738 COFF::IMAGE_SCN_MEM_READ));
739 COFFGlobalTypeHashesSection =
740 Ctx->getCOFFSection(Section: ".debug$H", Characteristics: (COFF::IMAGE_SCN_MEM_DISCARDABLE |
741 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
742 COFF::IMAGE_SCN_MEM_READ));
743
744 DwarfAbbrevSection = Ctx->getCOFFSection(
745 Section: ".debug_abbrev", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
746 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
747 COFF::IMAGE_SCN_MEM_READ);
748 DwarfInfoSection = Ctx->getCOFFSection(
749 Section: ".debug_info", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
750 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
751 COFF::IMAGE_SCN_MEM_READ);
752 DwarfLineSection = Ctx->getCOFFSection(
753 Section: ".debug_line", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
754 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
755 COFF::IMAGE_SCN_MEM_READ);
756 DwarfLineStrSection = Ctx->getCOFFSection(
757 Section: ".debug_line_str", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
758 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
759 COFF::IMAGE_SCN_MEM_READ);
760 DwarfFrameSection = Ctx->getCOFFSection(
761 Section: ".debug_frame", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
762 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
763 COFF::IMAGE_SCN_MEM_READ);
764 DwarfPubNamesSection = Ctx->getCOFFSection(
765 Section: ".debug_pubnames", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
766 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
767 COFF::IMAGE_SCN_MEM_READ);
768 DwarfPubTypesSection = Ctx->getCOFFSection(
769 Section: ".debug_pubtypes", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
770 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
771 COFF::IMAGE_SCN_MEM_READ);
772 DwarfGnuPubNamesSection = Ctx->getCOFFSection(
773 Section: ".debug_gnu_pubnames", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
774 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
775 COFF::IMAGE_SCN_MEM_READ);
776 DwarfGnuPubTypesSection = Ctx->getCOFFSection(
777 Section: ".debug_gnu_pubtypes", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
778 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
779 COFF::IMAGE_SCN_MEM_READ);
780 DwarfStrSection = Ctx->getCOFFSection(
781 Section: ".debug_str", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
782 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
783 COFF::IMAGE_SCN_MEM_READ);
784 DwarfStrOffSection = Ctx->getCOFFSection(
785 Section: ".debug_str_offsets", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
786 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
787 COFF::IMAGE_SCN_MEM_READ);
788 DwarfLocSection = Ctx->getCOFFSection(
789 Section: ".debug_loc", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
790 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
791 COFF::IMAGE_SCN_MEM_READ);
792 DwarfLoclistsSection = Ctx->getCOFFSection(
793 Section: ".debug_loclists", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
794 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
795 COFF::IMAGE_SCN_MEM_READ);
796 DwarfARangesSection = Ctx->getCOFFSection(
797 Section: ".debug_aranges", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
798 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
799 COFF::IMAGE_SCN_MEM_READ);
800 DwarfRangesSection = Ctx->getCOFFSection(
801 Section: ".debug_ranges", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
802 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
803 COFF::IMAGE_SCN_MEM_READ);
804 DwarfRnglistsSection = Ctx->getCOFFSection(
805 Section: ".debug_rnglists", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
806 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
807 COFF::IMAGE_SCN_MEM_READ);
808 DwarfMacinfoSection = Ctx->getCOFFSection(
809 Section: ".debug_macinfo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
810 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
811 COFF::IMAGE_SCN_MEM_READ);
812 DwarfMacroSection = Ctx->getCOFFSection(
813 Section: ".debug_macro", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
814 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
815 COFF::IMAGE_SCN_MEM_READ);
816 DwarfMacinfoDWOSection = Ctx->getCOFFSection(
817 Section: ".debug_macinfo.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
818 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
819 COFF::IMAGE_SCN_MEM_READ);
820 DwarfMacroDWOSection = Ctx->getCOFFSection(
821 Section: ".debug_macro.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
822 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
823 COFF::IMAGE_SCN_MEM_READ);
824 DwarfInfoDWOSection = Ctx->getCOFFSection(
825 Section: ".debug_info.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
826 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
827 COFF::IMAGE_SCN_MEM_READ);
828 DwarfTypesDWOSection = Ctx->getCOFFSection(
829 Section: ".debug_types.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
830 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
831 COFF::IMAGE_SCN_MEM_READ);
832 DwarfAbbrevDWOSection = Ctx->getCOFFSection(
833 Section: ".debug_abbrev.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
834 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
835 COFF::IMAGE_SCN_MEM_READ);
836 DwarfStrDWOSection = Ctx->getCOFFSection(
837 Section: ".debug_str.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
838 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
839 COFF::IMAGE_SCN_MEM_READ);
840 DwarfLineDWOSection = Ctx->getCOFFSection(
841 Section: ".debug_line.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
842 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
843 COFF::IMAGE_SCN_MEM_READ);
844 DwarfLocDWOSection = Ctx->getCOFFSection(
845 Section: ".debug_loc.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
846 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
847 COFF::IMAGE_SCN_MEM_READ);
848 DwarfLoclistsDWOSection = Ctx->getCOFFSection(
849 Section: ".debug_loclists.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
850 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
851 COFF::IMAGE_SCN_MEM_READ);
852 DwarfStrOffDWOSection = Ctx->getCOFFSection(
853 Section: ".debug_str_offsets.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
854 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
855 COFF::IMAGE_SCN_MEM_READ);
856 DwarfRnglistsDWOSection = Ctx->getCOFFSection(
857 Section: ".debug_rnglists.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
858 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
859 COFF::IMAGE_SCN_MEM_READ);
860 DwarfAddrSection = Ctx->getCOFFSection(
861 Section: ".debug_addr", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
862 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
863 COFF::IMAGE_SCN_MEM_READ);
864 DwarfCUIndexSection = Ctx->getCOFFSection(
865 Section: ".debug_cu_index", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
866 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
867 COFF::IMAGE_SCN_MEM_READ);
868 DwarfTUIndexSection = Ctx->getCOFFSection(
869 Section: ".debug_tu_index", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
870 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
871 COFF::IMAGE_SCN_MEM_READ);
872 DwarfDebugNamesSection = Ctx->getCOFFSection(
873 Section: ".debug_names", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
874 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
875 COFF::IMAGE_SCN_MEM_READ);
876 DwarfAccelNamesSection = Ctx->getCOFFSection(
877 Section: ".apple_names", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
878 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
879 COFF::IMAGE_SCN_MEM_READ);
880 DwarfAccelNamespaceSection = Ctx->getCOFFSection(
881 Section: ".apple_namespaces", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
882 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
883 COFF::IMAGE_SCN_MEM_READ);
884 DwarfAccelTypesSection = Ctx->getCOFFSection(
885 Section: ".apple_types", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
886 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
887 COFF::IMAGE_SCN_MEM_READ);
888 DwarfAccelObjCSection = Ctx->getCOFFSection(
889 Section: ".apple_objc", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
890 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
891 COFF::IMAGE_SCN_MEM_READ);
892
893 DrectveSection = Ctx->getCOFFSection(
894 Section: ".drectve", Characteristics: COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE);
895
896 PDataSection =
897 Ctx->getCOFFSection(Section: ".pdata", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
898 COFF::IMAGE_SCN_MEM_READ);
899
900 XDataSection =
901 Ctx->getCOFFSection(Section: ".xdata", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
902 COFF::IMAGE_SCN_MEM_READ);
903
904 SXDataSection = Ctx->getCOFFSection(Section: ".sxdata", Characteristics: COFF::IMAGE_SCN_LNK_INFO);
905
906 GEHContSection =
907 Ctx->getCOFFSection(Section: ".gehcont$y", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
908 COFF::IMAGE_SCN_MEM_READ);
909
910 GFIDsSection =
911 Ctx->getCOFFSection(Section: ".gfids$y", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
912 COFF::IMAGE_SCN_MEM_READ);
913
914 GIATsSection =
915 Ctx->getCOFFSection(Section: ".giats$y", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
916 COFF::IMAGE_SCN_MEM_READ);
917
918 GLJMPSection =
919 Ctx->getCOFFSection(Section: ".gljmp$y", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
920 COFF::IMAGE_SCN_MEM_READ);
921
922 TLSDataSection = Ctx->getCOFFSection(
923 Section: ".tls$", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
924 COFF::IMAGE_SCN_MEM_WRITE);
925
926 StackMapSection = Ctx->getCOFFSection(Section: ".llvm_stackmaps",
927 Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
928 COFF::IMAGE_SCN_MEM_READ);
929
930 // Set IMAGE_SCN_MEM_DISCARDABLE so that lld will not truncate section name.
931 PseudoProbeSection = Ctx->getCOFFSection(
932 Section: ".pseudo_probe", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
933 COFF::IMAGE_SCN_MEM_DISCARDABLE |
934 COFF::IMAGE_SCN_MEM_READ);
935 PseudoProbeDescSection = Ctx->getCOFFSection(
936 Section: ".pseudo_probe_desc", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
937 COFF::IMAGE_SCN_MEM_DISCARDABLE |
938 COFF::IMAGE_SCN_MEM_READ);
939}
940
941void MCObjectFileInfo::initSPIRVMCObjectFileInfo(const Triple &T) {
942 // Put everything in a single binary section.
943 TextSection = Ctx->getSPIRVSection();
944}
945
946void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
947 TextSection = Ctx->getWasmSection(Section: ".text", K: SectionKind::getText());
948 DataSection = Ctx->getWasmSection(Section: ".data", K: SectionKind::getData());
949
950 DwarfLineSection =
951 Ctx->getWasmSection(Section: ".debug_line", K: SectionKind::getMetadata());
952 DwarfLineStrSection =
953 Ctx->getWasmSection(Section: ".debug_line_str", K: SectionKind::getMetadata(),
954 Flags: wasm::WASM_SEG_FLAG_STRINGS);
955 DwarfStrSection = Ctx->getWasmSection(
956 Section: ".debug_str", K: SectionKind::getMetadata(), Flags: wasm::WASM_SEG_FLAG_STRINGS);
957 DwarfLocSection =
958 Ctx->getWasmSection(Section: ".debug_loc", K: SectionKind::getMetadata());
959 DwarfAbbrevSection =
960 Ctx->getWasmSection(Section: ".debug_abbrev", K: SectionKind::getMetadata());
961 DwarfARangesSection = Ctx->getWasmSection(Section: ".debug_aranges", K: SectionKind::getMetadata());
962 DwarfRangesSection =
963 Ctx->getWasmSection(Section: ".debug_ranges", K: SectionKind::getMetadata());
964 DwarfMacinfoSection =
965 Ctx->getWasmSection(Section: ".debug_macinfo", K: SectionKind::getMetadata());
966 DwarfMacroSection =
967 Ctx->getWasmSection(Section: ".debug_macro", K: SectionKind::getMetadata());
968 DwarfCUIndexSection = Ctx->getWasmSection(Section: ".debug_cu_index", K: SectionKind::getMetadata());
969 DwarfTUIndexSection = Ctx->getWasmSection(Section: ".debug_tu_index", K: SectionKind::getMetadata());
970 DwarfInfoSection =
971 Ctx->getWasmSection(Section: ".debug_info", K: SectionKind::getMetadata());
972 DwarfFrameSection = Ctx->getWasmSection(Section: ".debug_frame", K: SectionKind::getMetadata());
973 DwarfPubNamesSection = Ctx->getWasmSection(Section: ".debug_pubnames", K: SectionKind::getMetadata());
974 DwarfPubTypesSection = Ctx->getWasmSection(Section: ".debug_pubtypes", K: SectionKind::getMetadata());
975 DwarfGnuPubNamesSection =
976 Ctx->getWasmSection(Section: ".debug_gnu_pubnames", K: SectionKind::getMetadata());
977 DwarfGnuPubTypesSection =
978 Ctx->getWasmSection(Section: ".debug_gnu_pubtypes", K: SectionKind::getMetadata());
979
980 DwarfDebugNamesSection =
981 Ctx->getWasmSection(Section: ".debug_names", K: SectionKind::getMetadata());
982 DwarfStrOffSection =
983 Ctx->getWasmSection(Section: ".debug_str_offsets", K: SectionKind::getMetadata());
984 DwarfAddrSection =
985 Ctx->getWasmSection(Section: ".debug_addr", K: SectionKind::getMetadata());
986 DwarfRnglistsSection =
987 Ctx->getWasmSection(Section: ".debug_rnglists", K: SectionKind::getMetadata());
988 DwarfLoclistsSection =
989 Ctx->getWasmSection(Section: ".debug_loclists", K: SectionKind::getMetadata());
990
991 // Fission Sections
992 DwarfInfoDWOSection =
993 Ctx->getWasmSection(Section: ".debug_info.dwo", K: SectionKind::getMetadata());
994 DwarfTypesDWOSection =
995 Ctx->getWasmSection(Section: ".debug_types.dwo", K: SectionKind::getMetadata());
996 DwarfAbbrevDWOSection =
997 Ctx->getWasmSection(Section: ".debug_abbrev.dwo", K: SectionKind::getMetadata());
998 DwarfStrDWOSection =
999 Ctx->getWasmSection(Section: ".debug_str.dwo", K: SectionKind::getMetadata(),
1000 Flags: wasm::WASM_SEG_FLAG_STRINGS);
1001 DwarfLineDWOSection =
1002 Ctx->getWasmSection(Section: ".debug_line.dwo", K: SectionKind::getMetadata());
1003 DwarfLocDWOSection =
1004 Ctx->getWasmSection(Section: ".debug_loc.dwo", K: SectionKind::getMetadata());
1005 DwarfStrOffDWOSection =
1006 Ctx->getWasmSection(Section: ".debug_str_offsets.dwo", K: SectionKind::getMetadata());
1007 DwarfRnglistsDWOSection =
1008 Ctx->getWasmSection(Section: ".debug_rnglists.dwo", K: SectionKind::getMetadata());
1009 DwarfMacinfoDWOSection =
1010 Ctx->getWasmSection(Section: ".debug_macinfo.dwo", K: SectionKind::getMetadata());
1011 DwarfMacroDWOSection =
1012 Ctx->getWasmSection(Section: ".debug_macro.dwo", K: SectionKind::getMetadata());
1013
1014 DwarfLoclistsDWOSection =
1015 Ctx->getWasmSection(Section: ".debug_loclists.dwo", K: SectionKind::getMetadata());
1016
1017 // DWP Sections
1018 DwarfCUIndexSection =
1019 Ctx->getWasmSection(Section: ".debug_cu_index", K: SectionKind::getMetadata());
1020 DwarfTUIndexSection =
1021 Ctx->getWasmSection(Section: ".debug_tu_index", K: SectionKind::getMetadata());
1022
1023 // Wasm use data section for LSDA.
1024 // TODO Consider putting each function's exception table in a separate
1025 // section, as in -function-sections, to facilitate lld's --gc-section.
1026 LSDASection = Ctx->getWasmSection(Section: ".rodata.gcc_except_table",
1027 K: SectionKind::getReadOnlyWithRel());
1028
1029 // TODO: Define more sections.
1030}
1031
1032void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) {
1033 // The default csect for program code. Functions without a specified section
1034 // get placed into this csect. The choice of csect name is not a property of
1035 // the ABI or object file format, but various tools rely on the section
1036 // name being empty (considering named symbols to be "user symbol names").
1037 TextSection = Ctx->getXCOFFSection(
1038 Section: "..text..", // Use a non-null name to work around an AIX assembler bug...
1039 K: SectionKind::getText(),
1040 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD),
1041 /* MultiSymbolsAllowed*/ true);
1042
1043 // ... but use a null name when generating the symbol table.
1044 MCSectionXCOFF *TS = static_cast<MCSectionXCOFF *>(TextSection);
1045 TS->getQualNameSymbol()->setSymbolTableName("");
1046 TS->setSymbolTableName("");
1047
1048 DataSection = Ctx->getXCOFFSection(
1049 Section: ".data", K: SectionKind::getData(),
1050 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD),
1051 /* MultiSymbolsAllowed*/ true);
1052
1053 ReadOnlySection = Ctx->getXCOFFSection(
1054 Section: ".rodata", K: SectionKind::getReadOnly(),
1055 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
1056 /* MultiSymbolsAllowed*/ true);
1057 ReadOnlySection->setAlignment(Align(4));
1058
1059 ReadOnly8Section = Ctx->getXCOFFSection(
1060 Section: ".rodata.8", K: SectionKind::getReadOnly(),
1061 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
1062 /* MultiSymbolsAllowed*/ true);
1063 ReadOnly8Section->setAlignment(Align(8));
1064
1065 ReadOnly16Section = Ctx->getXCOFFSection(
1066 Section: ".rodata.16", K: SectionKind::getReadOnly(),
1067 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
1068 /* MultiSymbolsAllowed*/ true);
1069 ReadOnly16Section->setAlignment(Align(16));
1070
1071 TLSDataSection = Ctx->getXCOFFSection(
1072 Section: ".tdata", K: SectionKind::getThreadData(),
1073 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TL, XCOFF::XTY_SD),
1074 /* MultiSymbolsAllowed*/ true);
1075
1076 TOCBaseSection = Ctx->getXCOFFSection(
1077 Section: "TOC", K: SectionKind::getData(),
1078 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TC0,
1079 XCOFF::XTY_SD));
1080
1081 // The TOC-base always has 0 size, but 4 byte alignment.
1082 TOCBaseSection->setAlignment(Align(4));
1083
1084 LSDASection = Ctx->getXCOFFSection(
1085 Section: ".gcc_except_table", K: SectionKind::getReadOnly(),
1086 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO,
1087 XCOFF::XTY_SD));
1088
1089 CompactUnwindSection = Ctx->getXCOFFSection(
1090 Section: ".eh_info_table", K: SectionKind::getData(),
1091 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW,
1092 XCOFF::XTY_SD));
1093
1094 // DWARF sections for XCOFF are not csects. They are special STYP_DWARF
1095 // sections, and the individual DWARF sections are distinguished by their
1096 // section subtype.
1097 DwarfAbbrevSection = Ctx->getXCOFFSection(
1098 Section: ".dwabrev", K: SectionKind::getMetadata(),
1099 /* CsectProperties */ CsectProp: std::nullopt,
1100 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWABREV);
1101
1102 DwarfInfoSection = Ctx->getXCOFFSection(
1103 Section: ".dwinfo", K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt,
1104 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWINFO);
1105
1106 DwarfLineSection = Ctx->getXCOFFSection(
1107 Section: ".dwline", K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt,
1108 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWLINE);
1109
1110 DwarfFrameSection = Ctx->getXCOFFSection(
1111 Section: ".dwframe", K: SectionKind::getMetadata(),
1112 /* CsectProperties */ CsectProp: std::nullopt,
1113 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWFRAME);
1114
1115 DwarfPubNamesSection = Ctx->getXCOFFSection(
1116 Section: ".dwpbnms", K: SectionKind::getMetadata(),
1117 /* CsectProperties */ CsectProp: std::nullopt,
1118 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWPBNMS);
1119
1120 DwarfPubTypesSection = Ctx->getXCOFFSection(
1121 Section: ".dwpbtyp", K: SectionKind::getMetadata(),
1122 /* CsectProperties */ CsectProp: std::nullopt,
1123 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWPBTYP);
1124
1125 DwarfStrSection = Ctx->getXCOFFSection(
1126 Section: ".dwstr", K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt,
1127 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWSTR);
1128
1129 DwarfLocSection = Ctx->getXCOFFSection(
1130 Section: ".dwloc", K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt,
1131 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWLOC);
1132
1133 DwarfARangesSection = Ctx->getXCOFFSection(
1134 Section: ".dwarnge", K: SectionKind::getMetadata(),
1135 /* CsectProperties */ CsectProp: std::nullopt,
1136 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWARNGE);
1137
1138 DwarfRangesSection = Ctx->getXCOFFSection(
1139 Section: ".dwrnges", K: SectionKind::getMetadata(),
1140 /* CsectProperties */ CsectProp: std::nullopt,
1141 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWRNGES);
1142
1143 DwarfMacinfoSection = Ctx->getXCOFFSection(
1144 Section: ".dwmac", K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt,
1145 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWMAC);
1146}
1147
1148void MCObjectFileInfo::initDXContainerObjectFileInfo(const Triple &T) {
1149 // At the moment the DXBC section should end up empty.
1150 TextSection = Ctx->getDXContainerSection(Section: "DXBC", K: SectionKind::getText());
1151}
1152
1153MCObjectFileInfo::~MCObjectFileInfo() = default;
1154
1155void MCObjectFileInfo::initMCObjectFileInfo(MCContext &MCCtx, bool PIC,
1156 bool LargeCodeModel) {
1157 PositionIndependent = PIC;
1158 Ctx = &MCCtx;
1159
1160 // Common.
1161 SupportsCompactUnwindWithoutEHFrame = false;
1162 OmitDwarfIfHaveCompactUnwind = false;
1163
1164 FDECFIEncoding = dwarf::DW_EH_PE_absptr;
1165
1166 CompactUnwindDwarfEHFrameOnly = 0;
1167
1168 EHFrameSection = nullptr; // Created on demand.
1169 SFrameSection = nullptr; // Created on demand.
1170 CompactUnwindSection = nullptr; // Used only by selected targets.
1171 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
1172 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
1173 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
1174 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
1175
1176 const Triple &TheTriple = Ctx->getTargetTriple();
1177 switch (Ctx->getObjectFileType()) {
1178 case MCContext::IsMachO:
1179 initMachOMCObjectFileInfo(T: TheTriple);
1180 break;
1181 case MCContext::IsCOFF:
1182 initCOFFMCObjectFileInfo(T: TheTriple);
1183 break;
1184 case MCContext::IsELF:
1185 initELFMCObjectFileInfo(T: TheTriple, Large: LargeCodeModel);
1186 break;
1187 case MCContext::IsGOFF:
1188 initGOFFMCObjectFileInfo(T: TheTriple);
1189 break;
1190 case MCContext::IsSPIRV:
1191 initSPIRVMCObjectFileInfo(T: TheTriple);
1192 break;
1193 case MCContext::IsWasm:
1194 initWasmMCObjectFileInfo(T: TheTriple);
1195 break;
1196 case MCContext::IsXCOFF:
1197 initXCOFFMCObjectFileInfo(T: TheTriple);
1198 break;
1199 case MCContext::IsDXContainer:
1200 initDXContainerObjectFileInfo(T: TheTriple);
1201 break;
1202 }
1203}
1204
1205MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
1206 uint64_t Hash) const {
1207 switch (Ctx->getTargetTriple().getObjectFormat()) {
1208 case Triple::ELF:
1209 return Ctx->getELFSection(Section: Name, Type: ELF::SHT_PROGBITS, Flags: ELF::SHF_GROUP, EntrySize: 0,
1210 Group: utostr(X: Hash), /*IsComdat=*/true);
1211 case Triple::Wasm:
1212 return Ctx->getWasmSection(Section: Name, K: SectionKind::getMetadata(), Flags: 0,
1213 Group: utostr(X: Hash), UniqueID: MCSection::NonUniqueID);
1214 case Triple::MachO:
1215 case Triple::COFF:
1216 case Triple::GOFF:
1217 case Triple::SPIRV:
1218 case Triple::XCOFF:
1219 case Triple::DXContainer:
1220 case Triple::UnknownObjectFormat:
1221 report_fatal_error(reason: "Cannot get DWARF comdat section for this object file "
1222 "format: not implemented.");
1223 break;
1224 }
1225 llvm_unreachable("Unknown ObjectFormatType");
1226}
1227
1228MCSection *
1229MCObjectFileInfo::getCallGraphSection(const MCSection &TextSec) const {
1230 if (Ctx->getObjectFileType() != MCContext::IsELF)
1231 return CallGraphSection;
1232
1233 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1234 unsigned Flags = ELF::SHF_LINK_ORDER;
1235 StringRef GroupName;
1236 if (const MCSymbol *Group = ElfSec.getGroup()) {
1237 GroupName = Group->getName();
1238 Flags |= ELF::SHF_GROUP;
1239 }
1240
1241 return Ctx->getELFSection(
1242 Section: ".llvm.callgraph", Type: ELF::SHT_LLVM_CALL_GRAPH, Flags, EntrySize: 0, Group: GroupName,
1243 /*IsComdat=*/true, UniqueID: ElfSec.getUniqueID(),
1244 LinkedToSym: static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1245}
1246
1247MCSection *
1248MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const {
1249 if ((Ctx->getObjectFileType() != MCContext::IsELF) ||
1250 Ctx->getTargetTriple().isPS4())
1251 return StackSizesSection;
1252
1253 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1254 unsigned Flags = ELF::SHF_LINK_ORDER;
1255 StringRef GroupName;
1256 if (const MCSymbol *Group = ElfSec.getGroup()) {
1257 GroupName = Group->getName();
1258 Flags |= ELF::SHF_GROUP;
1259 }
1260
1261 return Ctx->getELFSection(
1262 Section: ".stack_sizes", Type: ELF::SHT_PROGBITS, Flags, EntrySize: 0, Group: GroupName, IsComdat: true,
1263 UniqueID: ElfSec.getUniqueID(),
1264 LinkedToSym: static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1265}
1266
1267MCSection *
1268MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const {
1269 if (Ctx->getObjectFileType() != MCContext::IsELF)
1270 return nullptr;
1271
1272 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1273 unsigned Flags = ELF::SHF_LINK_ORDER;
1274 StringRef GroupName;
1275 if (const MCSymbol *Group = ElfSec.getGroup()) {
1276 GroupName = Group->getName();
1277 Flags |= ELF::SHF_GROUP;
1278 }
1279
1280 // Use the text section's begin symbol and unique ID to create a separate
1281 // .llvm_bb_addr_map section associated with every unique text section.
1282 return Ctx->getELFSection(
1283 Section: ".llvm_bb_addr_map", Type: ELF::SHT_LLVM_BB_ADDR_MAP, Flags, EntrySize: 0, Group: GroupName, IsComdat: true,
1284 UniqueID: ElfSec.getUniqueID(),
1285 LinkedToSym: static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1286}
1287
1288MCSection *
1289MCObjectFileInfo::getKCFITrapSection(const MCSection &TextSec) const {
1290 if (Ctx->getObjectFileType() != MCContext::IsELF)
1291 return nullptr;
1292
1293 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1294 unsigned Flags = ELF::SHF_LINK_ORDER | ELF::SHF_ALLOC;
1295 StringRef GroupName;
1296 if (const MCSymbol *Group = ElfSec.getGroup()) {
1297 GroupName = Group->getName();
1298 Flags |= ELF::SHF_GROUP;
1299 }
1300
1301 return Ctx->getELFSection(
1302 Section: ".kcfi_traps", Type: ELF::SHT_PROGBITS, Flags, EntrySize: 0, Group: GroupName,
1303 /*IsComdat=*/true, UniqueID: ElfSec.getUniqueID(),
1304 LinkedToSym: static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1305}
1306
1307MCSection *
1308MCObjectFileInfo::getPseudoProbeSection(const MCSection &TextSec) const {
1309 auto ObjFileType = Ctx->getObjectFileType();
1310 if (ObjFileType == MCContext::IsELF) {
1311 const auto &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1312 unsigned Flags = ELF::SHF_LINK_ORDER;
1313 StringRef GroupName;
1314 if (const MCSymbol *Group = ElfSec.getGroup()) {
1315 GroupName = Group->getName();
1316 Flags |= ELF::SHF_GROUP;
1317 }
1318 return Ctx->getELFSection(
1319 Section: PseudoProbeSection->getName(), Type: ELF::SHT_PROGBITS, Flags, EntrySize: 0, Group: GroupName,
1320 IsComdat: true, UniqueID: ElfSec.getUniqueID(),
1321 LinkedToSym: static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1322 } else if (ObjFileType == MCContext::IsCOFF) {
1323 StringRef COMDATSymName = "";
1324 int Selection = 0;
1325 unsigned Characteristics =
1326 static_cast<MCSectionCOFF *>(PseudoProbeSection)->getCharacteristics();
1327 const auto &COFFSec = static_cast<const MCSectionCOFF &>(TextSec);
1328 if (const MCSymbol *COMDATSym = COFFSec.getCOMDATSymbol()) {
1329 // Associate .pseudo_probe to its function section.
1330 COMDATSymName = COMDATSym->getName();
1331 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
1332 Selection = COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE;
1333 }
1334 return Ctx->getCOFFSection(Section: PseudoProbeSection->getName(), Characteristics,
1335 COMDATSymName, Selection, UniqueID: COFFSec.getUniqueID());
1336 }
1337
1338 return PseudoProbeSection;
1339}
1340
1341MCSection *
1342MCObjectFileInfo::getPseudoProbeDescSection(StringRef FuncName) const {
1343 if (!Ctx->getTargetTriple().supportsCOMDAT() || FuncName.empty())
1344 return PseudoProbeDescSection;
1345
1346 // Create a separate comdat group for each function's descriptor in order
1347 // for the linker to deduplicate. The duplication, must be from different
1348 // tranlation unit, can come from:
1349 // 1. Inline functions defined in header files;
1350 // 2. ThinLTO imported funcions;
1351 // 3. Weak-linkage definitions.
1352 // Use a concatenation of the section name and the function name as the
1353 // group name so that descriptor-only groups won't be folded with groups of
1354 // code.
1355 auto ObjFileType = Ctx->getObjectFileType();
1356 if (ObjFileType == MCContext::IsELF) {
1357 auto *S = static_cast<MCSectionELF *>(PseudoProbeDescSection);
1358 auto Flags = S->getFlags() | ELF::SHF_GROUP;
1359 return Ctx->getELFSection(Section: S->getName(), Type: S->getType(), Flags,
1360 EntrySize: S->getEntrySize(), Group: S->getName() + "_" + FuncName,
1361 /*IsComdat=*/true);
1362 } else if (ObjFileType == MCContext::IsCOFF) {
1363 auto *S = static_cast<MCSectionCOFF *>(PseudoProbeDescSection);
1364 unsigned Characteristics =
1365 S->getCharacteristics() | COFF::IMAGE_SCN_LNK_COMDAT;
1366 std::string COMDATSymName = (S->getName() + "_" + FuncName).str();
1367 return Ctx->getCOFFSection(Section: S->getName(), Characteristics, COMDATSymName,
1368 Selection: COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH);
1369 }
1370
1371 return PseudoProbeDescSection;
1372}
1373
1374MCSection *MCObjectFileInfo::getLLVMStatsSection() const {
1375 return LLVMStatsSection;
1376}
1377
1378MCSection *MCObjectFileInfo::getPCSection(StringRef Name,
1379 const MCSection *TextSec) const {
1380 if (Ctx->getObjectFileType() != MCContext::IsELF)
1381 return nullptr;
1382
1383 // SHF_WRITE for relocations, and let user post-process data in-place.
1384 unsigned Flags = ELF::SHF_WRITE | ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER;
1385
1386 if (!TextSec)
1387 TextSec = getTextSection();
1388
1389 StringRef GroupName;
1390 const auto &ElfSec = static_cast<const MCSectionELF &>(*TextSec);
1391 if (const MCSymbol *Group = ElfSec.getGroup()) {
1392 GroupName = Group->getName();
1393 Flags |= ELF::SHF_GROUP;
1394 }
1395 return Ctx->getELFSection(
1396 Section: Name, Type: ELF::SHT_PROGBITS, Flags, EntrySize: 0, Group: GroupName, IsComdat: true, UniqueID: ElfSec.getUniqueID(),
1397 LinkedToSym: static_cast<const MCSymbolELF *>(TextSec->getBeginSymbol()));
1398}
1399