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 StackSizesSection = Ctx->getELFSection(Section: ".stack_sizes", Type: ELF::SHT_PROGBITS, Flags: 0);
567
568 PseudoProbeSection = Ctx->getELFSection(Section: ".pseudo_probe", Type: DebugSecType, Flags: 0);
569 PseudoProbeDescSection =
570 Ctx->getELFSection(Section: ".pseudo_probe_desc", Type: DebugSecType, Flags: 0);
571
572 LLVMStatsSection = Ctx->getELFSection(Section: ".llvm_stats", Type: ELF::SHT_PROGBITS, Flags: 0);
573}
574
575void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) {
576 MCSectionGOFF *RootSDSection = Ctx->getGOFFSection(
577 Kind: SectionKind::getMetadata(), Name: "#C",
578 SDAttributes: GOFF::SDAttr{.TaskingBehavior: GOFF::ESD_TA_Rent, .BindingScope: GOFF::ESD_BSC_Section});
579
580 MCSectionGOFF *ADAEDSection = Ctx->getGOFFSection(
581 Kind: SectionKind::getMetadata(), Name: GOFF::CLASS_WSA,
582 EDAttributes: GOFF::EDAttr{.IsReadOnly: false, .Rmode: GOFF::ESD_RMODE_64, .NameSpace: GOFF::ESD_NS_Parts,
583 .TextStyle: GOFF::ESD_TS_ByteOriented, .BindAlgorithm: GOFF::ESD_BA_Merge,
584 .LoadBehavior: GOFF::ESD_LB_Deferred, .ReservedQwords: GOFF::ESD_RQ_1, .FillByteValue: 0},
585 Parent: RootSDSection);
586 ADAEDSection->setAlignment(Align(16)); // Quadword
587 ADASection = Ctx->getGOFFSection(Kind: SectionKind::getData(), Name: "#S",
588 PRAttributes: GOFF::PRAttr{.IsRenamable: false, .Executable: GOFF::ESD_EXE_DATA,
589 .Linkage: GOFF::ESD_LT_XPLink,
590 .BindingScope: GOFF::ESD_BSC_Section, .SortKey: 0},
591 Parent: ADAEDSection);
592
593 TextSection = Ctx->getGOFFSection(
594 Kind: SectionKind::getText(), Name: GOFF::CLASS_CODE,
595 EDAttributes: GOFF::EDAttr{.IsReadOnly: true, .Rmode: GOFF::ESD_RMODE_64, .NameSpace: GOFF::ESD_NS_NormalName,
596 .TextStyle: GOFF::ESD_TS_ByteOriented, .BindAlgorithm: GOFF::ESD_BA_Concatenate,
597 .LoadBehavior: GOFF::ESD_LB_Initial, .ReservedQwords: GOFF::ESD_RQ_0, .FillByteValue: 0},
598 Parent: RootSDSection);
599 TextSection->setAlignment(Align(8)); // Doubleword
600
601 MCSectionGOFF *PPA2ListEDSection = Ctx->getGOFFSection(
602 Kind: SectionKind::getMetadata(), Name: GOFF::CLASS_PPA2,
603 EDAttributes: GOFF::EDAttr{.IsReadOnly: true, .Rmode: GOFF::ESD_RMODE_64, .NameSpace: GOFF::ESD_NS_Parts,
604 .TextStyle: GOFF::ESD_TS_ByteOriented, .BindAlgorithm: GOFF::ESD_BA_Merge,
605 .LoadBehavior: GOFF::ESD_LB_Initial, .ReservedQwords: GOFF::ESD_RQ_0, .FillByteValue: 0},
606 Parent: RootSDSection);
607 PPA2ListEDSection->setAlignment(Align(8)); // Doubleword
608 PPA2ListSection = Ctx->getGOFFSection(Kind: SectionKind::getData(), Name: ".&ppa2",
609 PRAttributes: GOFF::PRAttr{.IsRenamable: true, .Executable: GOFF::ESD_EXE_DATA,
610 .Linkage: GOFF::ESD_LT_OS,
611 .BindingScope: GOFF::ESD_BSC_Section, .SortKey: 0},
612 Parent: PPA2ListEDSection);
613
614 IDRLSection = Ctx->getGOFFSection(
615 Kind: SectionKind::getData(), Name: "B_IDRL",
616 EDAttributes: GOFF::EDAttr{.IsReadOnly: true, .Rmode: GOFF::ESD_RMODE_64, .NameSpace: GOFF::ESD_NS_NormalName,
617 .TextStyle: GOFF::ESD_TS_Structured, .BindAlgorithm: GOFF::ESD_BA_Concatenate,
618 .LoadBehavior: GOFF::ESD_LB_NoLoad, .ReservedQwords: GOFF::ESD_RQ_0, .FillByteValue: 0},
619 Parent: RootSDSection);
620 IDRLSection->setAlignment(Align(8)); // Doubleword
621
622 // Debug Info Sections. The ED name is the same used by the XL compiler.
623 auto InitDebugSection = [this,
624 RootSDSection](StringRef EDName,
625 StringRef LDName) -> MCSectionGOFF * {
626 MCSectionGOFF *ED = Ctx->getGOFFSection(
627 Kind: SectionKind::getMetadata(), Name: EDName,
628 EDAttributes: GOFF::EDAttr{.IsReadOnly: false, .Rmode: GOFF::ESD_RMODE_64, .NameSpace: GOFF::ESD_NS_Parts,
629 .TextStyle: GOFF::ESD_TS_ByteOriented, .BindAlgorithm: GOFF::ESD_BA_Concatenate,
630 .LoadBehavior: GOFF::ESD_LB_NoLoad, .ReservedQwords: GOFF::ESD_RQ_0, .FillByteValue: 0},
631 Parent: RootSDSection);
632 ED->setAlignment(Align(8)); // Doubleword
633 // At least for llc, this function is called twice! (See function
634 // compileModule() in llc.cpp). Since the context is not cleared, the
635 // already allocated section is returned above. We only add the begin symbol
636 // if it is not yet set to avoid an assertion.
637 MCSymbolGOFF *LD = static_cast<MCSymbolGOFF *>(ED->getBeginSymbol());
638 if (!LD) {
639 LD = static_cast<MCSymbolGOFF *>(getContext().getOrCreateSymbol(Name: LDName));
640 LD->setCodeData(GOFF::ESD_EXE_DATA);
641 LD->setWeak(false);
642 LD->setLinkage(GOFF::ESD_LT_XPLink);
643 LD->setExternal(false);
644 ED->setBeginSymbol(LD);
645 } else
646 assert(LD->getName() == LDName && "Wrong label name");
647 return ED;
648 };
649 DwarfAbbrevSection = InitDebugSection("D_ABREV", ".debug_abbrev");
650 DwarfInfoSection = InitDebugSection("D_INFO", ".debug_info");
651 DwarfLineSection = InitDebugSection("D_LINE", ".debug_line");
652 DwarfFrameSection = InitDebugSection("D_FRAME", ".debug_frame");
653 DwarfPubNamesSection = InitDebugSection("D_PBNMS", ".debug_pubnames");
654 DwarfPubTypesSection = InitDebugSection("D_PTYPES", ".debug_pubtypes");
655 DwarfStrSection = InitDebugSection("D_STR", ".debug_str");
656 DwarfLocSection = InitDebugSection("D_LOC", ".debug_loc");
657 DwarfARangesSection = InitDebugSection("D_ARNGE", ".debug_aranges");
658 DwarfRangesSection = InitDebugSection("D_RNGES", ".debug_ranges");
659 DwarfMacinfoSection = InitDebugSection("D_MACIN", ".debug_macinfo");
660
661 // DWARF 5 sections.
662 DwarfDebugNamesSection = InitDebugSection("D_NAMES", ".debug_names");
663 DwarfStrOffSection = InitDebugSection("D_STROFFS", ".debug_str_offsets");
664 DwarfAddrSection = InitDebugSection("D_ADDR", ".debug_addr");
665 DwarfRnglistsSection = InitDebugSection("D_RNGLISTS", ".debug_rnglists");
666 DwarfLoclistsSection = InitDebugSection("D_LOCLISTS", ".debug_loclists");
667 DwarfLineStrSection = InitDebugSection("D_LINESTR", ".debug_line_str");
668
669 // Special GNU sections.
670 DwarfGnuPubNamesSection = InitDebugSection("D_GPBNMS", ".debug_gnu_pubnames");
671 DwarfGnuPubTypesSection =
672 InitDebugSection("D_GPTYPES", ".debug_gnu_pubtypes");
673
674 // Accelerator Tables.
675 DwarfAccelNamesSection = InitDebugSection("D_APPLNMS", ".apple_names");
676 DwarfAccelNamespaceSection =
677 InitDebugSection("D_APPLNMSP", ".apple_namespaces");
678 DwarfAccelTypesSection = InitDebugSection("D_APPLTYPS", ".apple_types");
679 DwarfAccelObjCSection = InitDebugSection("D_APPLOBJC", ".apple_objc");
680
681 // Fission Sections
682 DwarfInfoDWOSection = InitDebugSection("D_INFO_DWO", ".debug_info.dwo");
683 DwarfTypesDWOSection = InitDebugSection("D_TYPES_DWO", ".debug_types.dwo");
684 DwarfAbbrevDWOSection = InitDebugSection("D_ABREV_DWO", ".debug_abbrev.dwo");
685 DwarfStrDWOSection = InitDebugSection("D_STR_DWO", ".debug_str.dwo");
686 DwarfLineDWOSection = InitDebugSection("D_LINE_DWO", ".debug_line.dwo");
687 DwarfLocDWOSection = InitDebugSection("D_LOC_DWO", ".debug_loc.dwo");
688 DwarfStrOffDWOSection =
689 InitDebugSection("D_STROFFS_DWO", ".debug_str_offsets.dwo");
690 DwarfRnglistsDWOSection =
691 InitDebugSection("D_RNGLISTS_DWO", ".debug_rnglists.dwo");
692 DwarfMacinfoDWOSection =
693 InitDebugSection("D_MACINFO_DWO", ".debug_macinfo.dwo");
694 DwarfMacroDWOSection = InitDebugSection("D_MACRO_DWO", ".debug_macro.dwo");
695 DwarfLoclistsDWOSection =
696 InitDebugSection("D_LOCLISTS_DWO", ".debug_loclists.dwo");
697}
698
699void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
700 EHFrameSection =
701 Ctx->getCOFFSection(Section: ".eh_frame", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
702 COFF::IMAGE_SCN_MEM_READ);
703
704 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
705 // used to indicate to the linker that the text segment contains thumb instructions
706 // and to set the ISA selection bit for calls accordingly.
707 const bool IsThumb = T.getArch() == Triple::thumb;
708
709 // COFF
710 BSSSection = Ctx->getCOFFSection(
711 Section: ".bss", Characteristics: COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
712 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE);
713 TextSection = Ctx->getCOFFSection(
714 Section: ".text",
715 Characteristics: (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |
716 COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
717 COFF::IMAGE_SCN_MEM_READ);
718 DataSection = Ctx->getCOFFSection(
719 Section: ".data", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
720 COFF::IMAGE_SCN_MEM_WRITE);
721 ReadOnlySection =
722 Ctx->getCOFFSection(Section: ".rdata", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
723 COFF::IMAGE_SCN_MEM_READ);
724
725 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64 ||
726 T.getArch() == Triple::arm || T.getArch() == Triple::thumb) {
727 // On Windows with SEH, the LSDA is emitted into the .xdata section
728 LSDASection = nullptr;
729 } else {
730 LSDASection = Ctx->getCOFFSection(Section: ".gcc_except_table",
731 Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
732 COFF::IMAGE_SCN_MEM_READ);
733 }
734
735 if (T.getArch() == Triple::aarch64) {
736 ImportCallSection =
737 Ctx->getCOFFSection(Section: ".impcall", Characteristics: COFF::IMAGE_SCN_LNK_INFO);
738 } else if (T.getArch() == Triple::x86_64) {
739 // Import Call Optimization on x64 leverages the same metadata as the
740 // retpoline mitigation, hence the unusual section name.
741 ImportCallSection =
742 Ctx->getCOFFSection(Section: ".retplne", Characteristics: COFF::IMAGE_SCN_LNK_INFO);
743 }
744
745 // Debug info.
746 COFFDebugSymbolsSection =
747 Ctx->getCOFFSection(Section: ".debug$S", Characteristics: (COFF::IMAGE_SCN_MEM_DISCARDABLE |
748 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
749 COFF::IMAGE_SCN_MEM_READ));
750 COFFDebugTypesSection =
751 Ctx->getCOFFSection(Section: ".debug$T", Characteristics: (COFF::IMAGE_SCN_MEM_DISCARDABLE |
752 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
753 COFF::IMAGE_SCN_MEM_READ));
754 COFFGlobalTypeHashesSection =
755 Ctx->getCOFFSection(Section: ".debug$H", Characteristics: (COFF::IMAGE_SCN_MEM_DISCARDABLE |
756 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
757 COFF::IMAGE_SCN_MEM_READ));
758
759 DwarfAbbrevSection = Ctx->getCOFFSection(
760 Section: ".debug_abbrev", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
761 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
762 COFF::IMAGE_SCN_MEM_READ);
763 DwarfInfoSection = Ctx->getCOFFSection(
764 Section: ".debug_info", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
765 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
766 COFF::IMAGE_SCN_MEM_READ);
767 DwarfLineSection = Ctx->getCOFFSection(
768 Section: ".debug_line", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
769 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
770 COFF::IMAGE_SCN_MEM_READ);
771 DwarfLineStrSection = Ctx->getCOFFSection(
772 Section: ".debug_line_str", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
773 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
774 COFF::IMAGE_SCN_MEM_READ);
775 DwarfFrameSection = Ctx->getCOFFSection(
776 Section: ".debug_frame", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
777 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
778 COFF::IMAGE_SCN_MEM_READ);
779 DwarfPubNamesSection = Ctx->getCOFFSection(
780 Section: ".debug_pubnames", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
781 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
782 COFF::IMAGE_SCN_MEM_READ);
783 DwarfPubTypesSection = Ctx->getCOFFSection(
784 Section: ".debug_pubtypes", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
785 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
786 COFF::IMAGE_SCN_MEM_READ);
787 DwarfGnuPubNamesSection = Ctx->getCOFFSection(
788 Section: ".debug_gnu_pubnames", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
789 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
790 COFF::IMAGE_SCN_MEM_READ);
791 DwarfGnuPubTypesSection = Ctx->getCOFFSection(
792 Section: ".debug_gnu_pubtypes", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
793 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
794 COFF::IMAGE_SCN_MEM_READ);
795 DwarfStrSection = Ctx->getCOFFSection(
796 Section: ".debug_str", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
797 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
798 COFF::IMAGE_SCN_MEM_READ);
799 DwarfStrOffSection = Ctx->getCOFFSection(
800 Section: ".debug_str_offsets", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
801 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
802 COFF::IMAGE_SCN_MEM_READ);
803 DwarfLocSection = Ctx->getCOFFSection(
804 Section: ".debug_loc", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
805 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
806 COFF::IMAGE_SCN_MEM_READ);
807 DwarfLoclistsSection = Ctx->getCOFFSection(
808 Section: ".debug_loclists", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
809 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
810 COFF::IMAGE_SCN_MEM_READ);
811 DwarfARangesSection = Ctx->getCOFFSection(
812 Section: ".debug_aranges", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
813 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
814 COFF::IMAGE_SCN_MEM_READ);
815 DwarfRangesSection = Ctx->getCOFFSection(
816 Section: ".debug_ranges", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
817 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
818 COFF::IMAGE_SCN_MEM_READ);
819 DwarfRnglistsSection = Ctx->getCOFFSection(
820 Section: ".debug_rnglists", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
821 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
822 COFF::IMAGE_SCN_MEM_READ);
823 DwarfMacinfoSection = Ctx->getCOFFSection(
824 Section: ".debug_macinfo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
825 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
826 COFF::IMAGE_SCN_MEM_READ);
827 DwarfMacroSection = Ctx->getCOFFSection(
828 Section: ".debug_macro", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
829 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
830 COFF::IMAGE_SCN_MEM_READ);
831 DwarfMacinfoDWOSection = Ctx->getCOFFSection(
832 Section: ".debug_macinfo.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
833 COFF::IMAGE_SCN_LNK_REMOVE |
834 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
835 COFF::IMAGE_SCN_MEM_READ);
836 DwarfMacroDWOSection = Ctx->getCOFFSection(
837 Section: ".debug_macro.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
838 COFF::IMAGE_SCN_LNK_REMOVE |
839 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
840 COFF::IMAGE_SCN_MEM_READ);
841 DwarfInfoDWOSection = Ctx->getCOFFSection(
842 Section: ".debug_info.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
843 COFF::IMAGE_SCN_LNK_REMOVE |
844 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
845 COFF::IMAGE_SCN_MEM_READ);
846 DwarfTypesDWOSection = Ctx->getCOFFSection(
847 Section: ".debug_types.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
848 COFF::IMAGE_SCN_LNK_REMOVE |
849 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
850 COFF::IMAGE_SCN_MEM_READ);
851 DwarfAbbrevDWOSection = Ctx->getCOFFSection(
852 Section: ".debug_abbrev.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
853 COFF::IMAGE_SCN_LNK_REMOVE |
854 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
855 COFF::IMAGE_SCN_MEM_READ);
856 DwarfStrDWOSection = Ctx->getCOFFSection(
857 Section: ".debug_str.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
858 COFF::IMAGE_SCN_LNK_REMOVE |
859 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
860 COFF::IMAGE_SCN_MEM_READ);
861 DwarfLineDWOSection = Ctx->getCOFFSection(
862 Section: ".debug_line.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
863 COFF::IMAGE_SCN_LNK_REMOVE |
864 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
865 COFF::IMAGE_SCN_MEM_READ);
866 DwarfLocDWOSection = Ctx->getCOFFSection(
867 Section: ".debug_loc.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
868 COFF::IMAGE_SCN_LNK_REMOVE |
869 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
870 COFF::IMAGE_SCN_MEM_READ);
871 DwarfLoclistsDWOSection = Ctx->getCOFFSection(
872 Section: ".debug_loclists.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
873 COFF::IMAGE_SCN_LNK_REMOVE |
874 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
875 COFF::IMAGE_SCN_MEM_READ);
876 DwarfStrOffDWOSection = Ctx->getCOFFSection(
877 Section: ".debug_str_offsets.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
878 COFF::IMAGE_SCN_LNK_REMOVE |
879 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
880 COFF::IMAGE_SCN_MEM_READ);
881 DwarfRnglistsDWOSection = Ctx->getCOFFSection(
882 Section: ".debug_rnglists.dwo", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
883 COFF::IMAGE_SCN_LNK_REMOVE |
884 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
885 COFF::IMAGE_SCN_MEM_READ);
886 DwarfAddrSection = Ctx->getCOFFSection(
887 Section: ".debug_addr", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
888 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
889 COFF::IMAGE_SCN_MEM_READ);
890 DwarfCUIndexSection = Ctx->getCOFFSection(
891 Section: ".debug_cu_index", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
892 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
893 COFF::IMAGE_SCN_MEM_READ);
894 DwarfTUIndexSection = Ctx->getCOFFSection(
895 Section: ".debug_tu_index", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
896 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
897 COFF::IMAGE_SCN_MEM_READ);
898 DwarfDebugNamesSection = Ctx->getCOFFSection(
899 Section: ".debug_names", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
900 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
901 COFF::IMAGE_SCN_MEM_READ);
902 DwarfAccelNamesSection = Ctx->getCOFFSection(
903 Section: ".apple_names", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
904 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
905 COFF::IMAGE_SCN_MEM_READ);
906 DwarfAccelNamespaceSection = Ctx->getCOFFSection(
907 Section: ".apple_namespaces", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
908 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
909 COFF::IMAGE_SCN_MEM_READ);
910 DwarfAccelTypesSection = Ctx->getCOFFSection(
911 Section: ".apple_types", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
912 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
913 COFF::IMAGE_SCN_MEM_READ);
914 DwarfAccelObjCSection = Ctx->getCOFFSection(
915 Section: ".apple_objc", Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE |
916 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
917 COFF::IMAGE_SCN_MEM_READ);
918
919 DrectveSection = Ctx->getCOFFSection(
920 Section: ".drectve", Characteristics: COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE);
921
922 PDataSection =
923 Ctx->getCOFFSection(Section: ".pdata", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
924 COFF::IMAGE_SCN_MEM_READ);
925
926 XDataSection =
927 Ctx->getCOFFSection(Section: ".xdata", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
928 COFF::IMAGE_SCN_MEM_READ);
929
930 SXDataSection = Ctx->getCOFFSection(Section: ".sxdata", Characteristics: COFF::IMAGE_SCN_LNK_INFO);
931
932 GEHContSection =
933 Ctx->getCOFFSection(Section: ".gehcont$y", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
934 COFF::IMAGE_SCN_MEM_READ);
935
936 GFIDsSection =
937 Ctx->getCOFFSection(Section: ".gfids$y", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
938 COFF::IMAGE_SCN_MEM_READ);
939
940 GIATsSection =
941 Ctx->getCOFFSection(Section: ".giats$y", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
942 COFF::IMAGE_SCN_MEM_READ);
943
944 GLJMPSection =
945 Ctx->getCOFFSection(Section: ".gljmp$y", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
946 COFF::IMAGE_SCN_MEM_READ);
947
948 TLSDataSection = Ctx->getCOFFSection(
949 Section: ".tls$", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
950 COFF::IMAGE_SCN_MEM_WRITE);
951
952 StackMapSection = Ctx->getCOFFSection(Section: ".llvm_stackmaps",
953 Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
954 COFF::IMAGE_SCN_MEM_READ);
955
956 // Set IMAGE_SCN_MEM_DISCARDABLE so that lld will not truncate section name.
957 PseudoProbeSection = Ctx->getCOFFSection(
958 Section: ".pseudo_probe", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
959 COFF::IMAGE_SCN_MEM_DISCARDABLE |
960 COFF::IMAGE_SCN_MEM_READ);
961 PseudoProbeDescSection = Ctx->getCOFFSection(
962 Section: ".pseudo_probe_desc", Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
963 COFF::IMAGE_SCN_MEM_DISCARDABLE |
964 COFF::IMAGE_SCN_MEM_READ);
965}
966
967void MCObjectFileInfo::initSPIRVMCObjectFileInfo(const Triple &T) {
968 // Put everything in a single binary section.
969 TextSection = Ctx->getSPIRVSection();
970}
971
972void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
973 TextSection = Ctx->getWasmSection(Section: ".text", K: SectionKind::getText());
974 DataSection = Ctx->getWasmSection(Section: ".data", K: SectionKind::getData());
975
976 DwarfLineSection =
977 Ctx->getWasmSection(Section: ".debug_line", K: SectionKind::getMetadata());
978 DwarfLineStrSection =
979 Ctx->getWasmSection(Section: ".debug_line_str", K: SectionKind::getMetadata(),
980 Flags: wasm::WASM_SEG_FLAG_STRINGS);
981 DwarfStrSection = Ctx->getWasmSection(
982 Section: ".debug_str", K: SectionKind::getMetadata(), Flags: wasm::WASM_SEG_FLAG_STRINGS);
983 DwarfLocSection =
984 Ctx->getWasmSection(Section: ".debug_loc", K: SectionKind::getMetadata());
985 DwarfAbbrevSection =
986 Ctx->getWasmSection(Section: ".debug_abbrev", K: SectionKind::getMetadata());
987 DwarfARangesSection = Ctx->getWasmSection(Section: ".debug_aranges", K: SectionKind::getMetadata());
988 DwarfRangesSection =
989 Ctx->getWasmSection(Section: ".debug_ranges", K: SectionKind::getMetadata());
990 DwarfMacinfoSection =
991 Ctx->getWasmSection(Section: ".debug_macinfo", K: SectionKind::getMetadata());
992 DwarfMacroSection =
993 Ctx->getWasmSection(Section: ".debug_macro", K: SectionKind::getMetadata());
994 DwarfCUIndexSection = Ctx->getWasmSection(Section: ".debug_cu_index", K: SectionKind::getMetadata());
995 DwarfTUIndexSection = Ctx->getWasmSection(Section: ".debug_tu_index", K: SectionKind::getMetadata());
996 DwarfInfoSection =
997 Ctx->getWasmSection(Section: ".debug_info", K: SectionKind::getMetadata());
998 DwarfFrameSection = Ctx->getWasmSection(Section: ".debug_frame", K: SectionKind::getMetadata());
999 DwarfPubNamesSection = Ctx->getWasmSection(Section: ".debug_pubnames", K: SectionKind::getMetadata());
1000 DwarfPubTypesSection = Ctx->getWasmSection(Section: ".debug_pubtypes", K: SectionKind::getMetadata());
1001 DwarfGnuPubNamesSection =
1002 Ctx->getWasmSection(Section: ".debug_gnu_pubnames", K: SectionKind::getMetadata());
1003 DwarfGnuPubTypesSection =
1004 Ctx->getWasmSection(Section: ".debug_gnu_pubtypes", K: SectionKind::getMetadata());
1005
1006 DwarfDebugNamesSection =
1007 Ctx->getWasmSection(Section: ".debug_names", K: SectionKind::getMetadata());
1008 DwarfStrOffSection =
1009 Ctx->getWasmSection(Section: ".debug_str_offsets", K: SectionKind::getMetadata());
1010 DwarfAddrSection =
1011 Ctx->getWasmSection(Section: ".debug_addr", K: SectionKind::getMetadata());
1012 DwarfRnglistsSection =
1013 Ctx->getWasmSection(Section: ".debug_rnglists", K: SectionKind::getMetadata());
1014 DwarfLoclistsSection =
1015 Ctx->getWasmSection(Section: ".debug_loclists", K: SectionKind::getMetadata());
1016
1017 // Fission Sections
1018 DwarfInfoDWOSection =
1019 Ctx->getWasmSection(Section: ".debug_info.dwo", K: SectionKind::getMetadata());
1020 DwarfTypesDWOSection =
1021 Ctx->getWasmSection(Section: ".debug_types.dwo", K: SectionKind::getMetadata());
1022 DwarfAbbrevDWOSection =
1023 Ctx->getWasmSection(Section: ".debug_abbrev.dwo", K: SectionKind::getMetadata());
1024 DwarfStrDWOSection =
1025 Ctx->getWasmSection(Section: ".debug_str.dwo", K: SectionKind::getMetadata(),
1026 Flags: wasm::WASM_SEG_FLAG_STRINGS);
1027 DwarfLineDWOSection =
1028 Ctx->getWasmSection(Section: ".debug_line.dwo", K: SectionKind::getMetadata());
1029 DwarfLocDWOSection =
1030 Ctx->getWasmSection(Section: ".debug_loc.dwo", K: SectionKind::getMetadata());
1031 DwarfStrOffDWOSection =
1032 Ctx->getWasmSection(Section: ".debug_str_offsets.dwo", K: SectionKind::getMetadata());
1033 DwarfRnglistsDWOSection =
1034 Ctx->getWasmSection(Section: ".debug_rnglists.dwo", K: SectionKind::getMetadata());
1035 DwarfMacinfoDWOSection =
1036 Ctx->getWasmSection(Section: ".debug_macinfo.dwo", K: SectionKind::getMetadata());
1037 DwarfMacroDWOSection =
1038 Ctx->getWasmSection(Section: ".debug_macro.dwo", K: SectionKind::getMetadata());
1039
1040 DwarfLoclistsDWOSection =
1041 Ctx->getWasmSection(Section: ".debug_loclists.dwo", K: SectionKind::getMetadata());
1042
1043 // DWP Sections
1044 DwarfCUIndexSection =
1045 Ctx->getWasmSection(Section: ".debug_cu_index", K: SectionKind::getMetadata());
1046 DwarfTUIndexSection =
1047 Ctx->getWasmSection(Section: ".debug_tu_index", K: SectionKind::getMetadata());
1048
1049 // Wasm use data section for LSDA.
1050 // TODO Consider putting each function's exception table in a separate
1051 // section, as in -function-sections, to facilitate lld's --gc-section.
1052 LSDASection = Ctx->getWasmSection(Section: ".rodata.gcc_except_table",
1053 K: SectionKind::getReadOnlyWithRel());
1054
1055 // TODO: Define more sections.
1056}
1057
1058void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) {
1059 // The default csect for program code. Functions without a specified section
1060 // get placed into this csect. The choice of csect name is not a property of
1061 // the ABI or object file format, but various tools rely on the section
1062 // name being empty (considering named symbols to be "user symbol names").
1063 TextSection = Ctx->getXCOFFSection(
1064 Section: "..text..", // Use a non-null name to work around an AIX assembler bug...
1065 K: SectionKind::getText(),
1066 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD),
1067 /* MultiSymbolsAllowed*/ true);
1068
1069 // ... but use a null name when generating the symbol table.
1070 MCSectionXCOFF *TS = static_cast<MCSectionXCOFF *>(TextSection);
1071 TS->getQualNameSymbol()->setSymbolTableName("");
1072 TS->setSymbolTableName("");
1073
1074 DataSection = Ctx->getXCOFFSection(
1075 Section: ".data", K: SectionKind::getData(),
1076 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD),
1077 /* MultiSymbolsAllowed*/ true);
1078
1079 ReadOnlySection = Ctx->getXCOFFSection(
1080 Section: ".rodata", K: SectionKind::getReadOnly(),
1081 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
1082 /* MultiSymbolsAllowed*/ true);
1083 ReadOnlySection->setAlignment(Align(4));
1084
1085 ReadOnly8Section = Ctx->getXCOFFSection(
1086 Section: ".rodata.8", K: SectionKind::getReadOnly(),
1087 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
1088 /* MultiSymbolsAllowed*/ true);
1089 ReadOnly8Section->setAlignment(Align(8));
1090
1091 ReadOnly16Section = Ctx->getXCOFFSection(
1092 Section: ".rodata.16", K: SectionKind::getReadOnly(),
1093 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
1094 /* MultiSymbolsAllowed*/ true);
1095 ReadOnly16Section->setAlignment(Align(16));
1096
1097 TLSDataSection = Ctx->getXCOFFSection(
1098 Section: ".tdata", K: SectionKind::getThreadData(),
1099 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TL, XCOFF::XTY_SD),
1100 /* MultiSymbolsAllowed*/ true);
1101
1102 TOCBaseSection = Ctx->getXCOFFSection(
1103 Section: "TOC", K: SectionKind::getData(),
1104 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TC0,
1105 XCOFF::XTY_SD));
1106
1107 // The TOC-base always has 0 size, but 4 byte alignment.
1108 TOCBaseSection->setAlignment(Align(4));
1109
1110 LSDASection = Ctx->getXCOFFSection(
1111 Section: ".gcc_except_table", K: SectionKind::getReadOnly(),
1112 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO,
1113 XCOFF::XTY_SD));
1114
1115 CompactUnwindSection = Ctx->getXCOFFSection(
1116 Section: ".eh_info_table", K: SectionKind::getData(),
1117 CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW,
1118 XCOFF::XTY_SD));
1119
1120 // DWARF sections for XCOFF are not csects. They are special STYP_DWARF
1121 // sections, and the individual DWARF sections are distinguished by their
1122 // section subtype.
1123 DwarfAbbrevSection = Ctx->getXCOFFSection(
1124 Section: ".dwabrev", K: SectionKind::getMetadata(),
1125 /* CsectProperties */ CsectProp: std::nullopt,
1126 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWABREV);
1127
1128 DwarfInfoSection = Ctx->getXCOFFSection(
1129 Section: ".dwinfo", K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt,
1130 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWINFO);
1131
1132 DwarfLineSection = Ctx->getXCOFFSection(
1133 Section: ".dwline", K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt,
1134 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWLINE);
1135
1136 DwarfFrameSection = Ctx->getXCOFFSection(
1137 Section: ".dwframe", K: SectionKind::getMetadata(),
1138 /* CsectProperties */ CsectProp: std::nullopt,
1139 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWFRAME);
1140
1141 DwarfPubNamesSection = Ctx->getXCOFFSection(
1142 Section: ".dwpbnms", K: SectionKind::getMetadata(),
1143 /* CsectProperties */ CsectProp: std::nullopt,
1144 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWPBNMS);
1145
1146 DwarfPubTypesSection = Ctx->getXCOFFSection(
1147 Section: ".dwpbtyp", K: SectionKind::getMetadata(),
1148 /* CsectProperties */ CsectProp: std::nullopt,
1149 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWPBTYP);
1150
1151 DwarfStrSection = Ctx->getXCOFFSection(
1152 Section: ".dwstr", K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt,
1153 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWSTR);
1154
1155 DwarfLocSection = Ctx->getXCOFFSection(
1156 Section: ".dwloc", K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt,
1157 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWLOC);
1158
1159 DwarfARangesSection = Ctx->getXCOFFSection(
1160 Section: ".dwarnge", K: SectionKind::getMetadata(),
1161 /* CsectProperties */ CsectProp: std::nullopt,
1162 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWARNGE);
1163
1164 DwarfRangesSection = Ctx->getXCOFFSection(
1165 Section: ".dwrnges", K: SectionKind::getMetadata(),
1166 /* CsectProperties */ CsectProp: std::nullopt,
1167 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWRNGES);
1168
1169 DwarfMacinfoSection = Ctx->getXCOFFSection(
1170 Section: ".dwmac", K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt,
1171 /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWMAC);
1172}
1173
1174void MCObjectFileInfo::initDXContainerObjectFileInfo(const Triple &T) {
1175 // At the moment the DXBC section should end up empty.
1176 TextSection = Ctx->getDXContainerSection(Section: "DXBC", K: SectionKind::getText());
1177}
1178
1179MCObjectFileInfo::~MCObjectFileInfo() = default;
1180
1181void MCObjectFileInfo::initMCObjectFileInfo(MCContext &MCCtx, bool PIC,
1182 bool LargeCodeModel) {
1183 PositionIndependent = PIC;
1184 Ctx = &MCCtx;
1185
1186 // Common.
1187 SupportsCompactUnwindWithoutEHFrame = false;
1188 OmitDwarfIfHaveCompactUnwind = false;
1189
1190 FDECFIEncoding = dwarf::DW_EH_PE_absptr;
1191
1192 CompactUnwindDwarfEHFrameOnly = 0;
1193
1194 EHFrameSection = nullptr; // Created on demand.
1195 SFrameSection = nullptr; // Created on demand.
1196 CompactUnwindSection = nullptr; // Used only by selected targets.
1197 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
1198 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
1199 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
1200 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
1201
1202 const Triple &TheTriple = Ctx->getTargetTriple();
1203 switch (Ctx->getObjectFileType()) {
1204 case MCContext::IsMachO:
1205 initMachOMCObjectFileInfo(T: TheTriple);
1206 break;
1207 case MCContext::IsCOFF:
1208 initCOFFMCObjectFileInfo(T: TheTriple);
1209 break;
1210 case MCContext::IsELF:
1211 initELFMCObjectFileInfo(T: TheTriple, Large: LargeCodeModel);
1212 break;
1213 case MCContext::IsGOFF:
1214 initGOFFMCObjectFileInfo(T: TheTriple);
1215 break;
1216 case MCContext::IsSPIRV:
1217 initSPIRVMCObjectFileInfo(T: TheTriple);
1218 break;
1219 case MCContext::IsWasm:
1220 initWasmMCObjectFileInfo(T: TheTriple);
1221 break;
1222 case MCContext::IsXCOFF:
1223 initXCOFFMCObjectFileInfo(T: TheTriple);
1224 break;
1225 case MCContext::IsDXContainer:
1226 initDXContainerObjectFileInfo(T: TheTriple);
1227 break;
1228 }
1229}
1230
1231MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
1232 uint64_t Hash) const {
1233 switch (Ctx->getTargetTriple().getObjectFormat()) {
1234 case Triple::ELF:
1235 return Ctx->getELFSection(Section: Name, Type: ELF::SHT_PROGBITS, Flags: ELF::SHF_GROUP, EntrySize: 0,
1236 Group: utostr(X: Hash), /*IsComdat=*/true);
1237 case Triple::Wasm:
1238 return Ctx->getWasmSection(Section: Name, K: SectionKind::getMetadata(), Flags: 0,
1239 Group: utostr(X: Hash), UniqueID: MCSection::NonUniqueID);
1240 case Triple::MachO:
1241 case Triple::COFF:
1242 case Triple::GOFF:
1243 case Triple::SPIRV:
1244 case Triple::XCOFF:
1245 case Triple::DXContainer:
1246 case Triple::UnknownObjectFormat:
1247 report_fatal_error(reason: "Cannot get DWARF comdat section for this object file "
1248 "format: not implemented.");
1249 break;
1250 }
1251 llvm_unreachable("Unknown ObjectFormatType");
1252}
1253
1254MCSection *
1255MCObjectFileInfo::getCallGraphSection(const MCSection &TextSec) const {
1256 if (Ctx->getObjectFileType() != MCContext::IsELF)
1257 return nullptr;
1258
1259 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1260 unsigned Flags = ELF::SHF_LINK_ORDER;
1261 StringRef GroupName;
1262 if (const MCSymbol *Group = ElfSec.getGroup()) {
1263 GroupName = Group->getName();
1264 Flags |= ELF::SHF_GROUP;
1265 }
1266
1267 return Ctx->getELFSection(
1268 Section: ".llvm.callgraph", Type: ELF::SHT_LLVM_CALL_GRAPH, Flags, EntrySize: 0, Group: GroupName,
1269 /*IsComdat=*/true, UniqueID: ElfSec.getUniqueID(),
1270 LinkedToSym: static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1271}
1272
1273MCSection *
1274MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const {
1275 if ((Ctx->getObjectFileType() != MCContext::IsELF) ||
1276 Ctx->getTargetTriple().isPS4())
1277 return StackSizesSection;
1278
1279 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1280 unsigned Flags = ELF::SHF_LINK_ORDER;
1281 StringRef GroupName;
1282 if (const MCSymbol *Group = ElfSec.getGroup()) {
1283 GroupName = Group->getName();
1284 Flags |= ELF::SHF_GROUP;
1285 }
1286
1287 return Ctx->getELFSection(
1288 Section: ".stack_sizes", Type: ELF::SHT_PROGBITS, Flags, EntrySize: 0, Group: GroupName, IsComdat: true,
1289 UniqueID: ElfSec.getUniqueID(),
1290 LinkedToSym: static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1291}
1292
1293MCSection *
1294MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const {
1295 constexpr StringLiteral Name = ".llvm_bb_addr_map";
1296 if (Ctx->getObjectFileType() == MCContext::IsELF) {
1297 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1298 unsigned Flags = ELF::SHF_LINK_ORDER;
1299 StringRef GroupName;
1300 if (const MCSymbol *Group = ElfSec.getGroup()) {
1301 GroupName = Group->getName();
1302 Flags |= ELF::SHF_GROUP;
1303 }
1304
1305 // Use the text section's begin symbol and unique ID to create a separate
1306 // .llvm_bb_addr_map section associated with every unique text section.
1307 return Ctx->getELFSection(
1308 Section: Name, Type: ELF::SHT_LLVM_BB_ADDR_MAP, Flags, EntrySize: 0, Group: GroupName, IsComdat: true,
1309 UniqueID: ElfSec.getUniqueID(),
1310 LinkedToSym: static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1311 } else if (Ctx->getObjectFileType() == MCContext::IsCOFF) {
1312 StringRef COMDATSymName;
1313 int Selection = 0;
1314 unsigned Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1315 COFF::IMAGE_SCN_MEM_DISCARDABLE |
1316 COFF::IMAGE_SCN_MEM_READ;
1317 const auto &COFFSec = static_cast<const MCSectionCOFF &>(TextSec);
1318 if (const MCSymbol *COMDATSym = COFFSec.getCOMDATSymbol()) {
1319 if (!Ctx->getAsmInfo().hasCOFFAssociativeComdats())
1320 report_fatal_error(reason: "BB address map requires associative COMDAT "
1321 "support for COMDAT functions");
1322 COMDATSymName = COMDATSym->getName();
1323 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
1324 Selection = COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE;
1325 }
1326 return Ctx->getCOFFSection(Section: Name, Characteristics, COMDATSymName, Selection,
1327 UniqueID: COFFSec.getUniqueID());
1328 }
1329
1330 return nullptr;
1331}
1332
1333MCSection *
1334MCObjectFileInfo::getKCFITrapSection(const MCSection &TextSec) const {
1335 if (Ctx->getObjectFileType() != MCContext::IsELF)
1336 return nullptr;
1337
1338 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1339 unsigned Flags = ELF::SHF_LINK_ORDER | ELF::SHF_ALLOC;
1340 StringRef GroupName;
1341 if (const MCSymbol *Group = ElfSec.getGroup()) {
1342 GroupName = Group->getName();
1343 Flags |= ELF::SHF_GROUP;
1344 }
1345
1346 return Ctx->getELFSection(
1347 Section: ".kcfi_traps", Type: ELF::SHT_PROGBITS, Flags, EntrySize: 0, Group: GroupName,
1348 /*IsComdat=*/true, UniqueID: ElfSec.getUniqueID(),
1349 LinkedToSym: static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1350}
1351
1352MCSection *
1353MCObjectFileInfo::getPseudoProbeSection(const MCSection &TextSec) const {
1354 auto ObjFileType = Ctx->getObjectFileType();
1355 if (ObjFileType == MCContext::IsELF) {
1356 const auto &ElfSec = static_cast<const MCSectionELF &>(TextSec);
1357 unsigned Flags = ELF::SHF_LINK_ORDER;
1358 StringRef GroupName;
1359 if (const MCSymbol *Group = ElfSec.getGroup()) {
1360 GroupName = Group->getName();
1361 Flags |= ELF::SHF_GROUP;
1362 }
1363 return Ctx->getELFSection(
1364 Section: PseudoProbeSection->getName(), Type: ELF::SHT_PROGBITS, Flags, EntrySize: 0, Group: GroupName,
1365 IsComdat: true, UniqueID: ElfSec.getUniqueID(),
1366 LinkedToSym: static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
1367 } else if (ObjFileType == MCContext::IsCOFF) {
1368 StringRef COMDATSymName = "";
1369 int Selection = 0;
1370 unsigned Characteristics =
1371 static_cast<MCSectionCOFF *>(PseudoProbeSection)->getCharacteristics();
1372 const auto &COFFSec = static_cast<const MCSectionCOFF &>(TextSec);
1373 if (const MCSymbol *COMDATSym = COFFSec.getCOMDATSymbol()) {
1374 // Associate .pseudo_probe to its function section.
1375 COMDATSymName = COMDATSym->getName();
1376 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
1377 Selection = COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE;
1378 }
1379 return Ctx->getCOFFSection(Section: PseudoProbeSection->getName(), Characteristics,
1380 COMDATSymName, Selection, UniqueID: COFFSec.getUniqueID());
1381 }
1382
1383 return PseudoProbeSection;
1384}
1385
1386MCSection *
1387MCObjectFileInfo::getPseudoProbeDescSection(StringRef FuncName,
1388 uint64_t FuncHash) const {
1389 if (!Ctx->getTargetTriple().supportsCOMDAT() || FuncName.empty())
1390 return PseudoProbeDescSection;
1391
1392 // Create a separate comdat group for each function's descriptor in order
1393 // for the linker to deduplicate. The duplication, must be from different
1394 // translation unit, can come from:
1395 // 1. Inline functions defined in header files;
1396 // 2. ThinLTO imported functions;
1397 // 3. Weak-linkage definitions.
1398 // Use a concatenation of the section name, function name, and function hash
1399 // as the group name so that descriptors with different hashes (due to user
1400 // code not following ODR or compiler codegen inconsistencies) get separate
1401 // COMDAT sections instead of being silently dropped (ELF) or causing linker
1402 // errors (COFF). Duplicate GUIDs with mismatching hashes are detected
1403 // during descriptor decoding and reported by llvm-profgen.
1404 auto ObjFileType = Ctx->getObjectFileType();
1405 if (ObjFileType == MCContext::IsELF) {
1406 auto *S = static_cast<MCSectionELF *>(PseudoProbeDescSection);
1407 auto Flags = S->getFlags() | ELF::SHF_GROUP;
1408 return Ctx->getELFSection(
1409 Section: S->getName(), Type: S->getType(), Flags, EntrySize: S->getEntrySize(),
1410 Group: S->getName() + "_" + FuncName + "." + Twine::utohexstr(Val: FuncHash),
1411 /*IsComdat=*/true);
1412 } else if (ObjFileType == MCContext::IsCOFF) {
1413 auto *S = static_cast<MCSectionCOFF *>(PseudoProbeDescSection);
1414 unsigned Characteristics =
1415 S->getCharacteristics() | COFF::IMAGE_SCN_LNK_COMDAT;
1416 std::string COMDATSymName =
1417 (S->getName() + "_" + FuncName + "." + Twine::utohexstr(Val: FuncHash))
1418 .str();
1419 return Ctx->getCOFFSection(Section: S->getName(), Characteristics, COMDATSymName,
1420 Selection: COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH);
1421 }
1422
1423 return PseudoProbeDescSection;
1424}
1425
1426MCSection *MCObjectFileInfo::getLLVMStatsSection() const {
1427 return LLVMStatsSection;
1428}
1429
1430MCSection *MCObjectFileInfo::getPCSection(StringRef Name,
1431 const MCSection *TextSec) const {
1432 if (Ctx->getObjectFileType() != MCContext::IsELF)
1433 return nullptr;
1434
1435 // SHF_WRITE for relocations, and let user post-process data in-place.
1436 unsigned Flags = ELF::SHF_WRITE | ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER;
1437
1438 if (!TextSec)
1439 TextSec = getTextSection();
1440
1441 StringRef GroupName;
1442 const auto &ElfSec = static_cast<const MCSectionELF &>(*TextSec);
1443 if (const MCSymbol *Group = ElfSec.getGroup()) {
1444 GroupName = Group->getName();
1445 Flags |= ELF::SHF_GROUP;
1446 }
1447 return Ctx->getELFSection(
1448 Section: Name, Type: ELF::SHT_PROGBITS, Flags, EntrySize: 0, Group: GroupName, IsComdat: true, UniqueID: ElfSec.getUniqueID(),
1449 LinkedToSym: static_cast<const MCSymbolELF *>(TextSec->getBeginSymbol()));
1450}
1451