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