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