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

source code of llvm/lib/MC/MCObjectFileInfo.cpp