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 | |
28 | using namespace llvm; |
29 | |
30 | static 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 | |
62 | void 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 | |
338 | void 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 | // In fact DW_EH_PE_sdata4 is enough for us now, and GNU ld doesn't |
347 | // support pcrel|sdata8 well. Let's use sdata4 for now. |
348 | if (PositionIndependent) |
349 | FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; |
350 | else |
351 | FDECFIEncoding = Ctx->getAsmInfo()->getCodePointerSize() == 4 |
352 | ? dwarf::DW_EH_PE_sdata4 |
353 | : dwarf::DW_EH_PE_sdata8; |
354 | break; |
355 | case Triple::ppc64: |
356 | case Triple::ppc64le: |
357 | case Triple::aarch64: |
358 | case Triple::aarch64_be: |
359 | case Triple::x86_64: |
360 | FDECFIEncoding = dwarf::DW_EH_PE_pcrel | |
361 | (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4); |
362 | break; |
363 | case Triple::bpfel: |
364 | case Triple::bpfeb: |
365 | FDECFIEncoding = dwarf::DW_EH_PE_sdata8; |
366 | break; |
367 | case Triple::hexagon: |
368 | FDECFIEncoding = |
369 | PositionIndependent ? dwarf::DW_EH_PE_pcrel : dwarf::DW_EH_PE_absptr; |
370 | break; |
371 | case Triple::xtensa: |
372 | FDECFIEncoding = dwarf::DW_EH_PE_sdata4; |
373 | break; |
374 | default: |
375 | FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; |
376 | break; |
377 | } |
378 | |
379 | unsigned EHSectionType = T.getArch() == Triple::x86_64 |
380 | ? ELF::SHT_X86_64_UNWIND |
381 | : ELF::SHT_PROGBITS; |
382 | |
383 | // Solaris requires different flags for .eh_frame to seemingly every other |
384 | // platform. |
385 | unsigned EHSectionFlags = ELF::SHF_ALLOC; |
386 | if (T.isOSSolaris() && T.getArch() != Triple::x86_64) |
387 | EHSectionFlags |= ELF::SHF_WRITE; |
388 | |
389 | // ELF |
390 | BSSSection = Ctx->getELFSection(Section: ".bss" , Type: ELF::SHT_NOBITS, |
391 | Flags: ELF::SHF_WRITE | ELF::SHF_ALLOC); |
392 | |
393 | TextSection = Ctx->getELFSection(Section: ".text" , Type: ELF::SHT_PROGBITS, |
394 | Flags: ELF::SHF_EXECINSTR | ELF::SHF_ALLOC); |
395 | |
396 | DataSection = Ctx->getELFSection(Section: ".data" , Type: ELF::SHT_PROGBITS, |
397 | Flags: ELF::SHF_WRITE | ELF::SHF_ALLOC); |
398 | |
399 | ReadOnlySection = |
400 | Ctx->getELFSection(Section: ".rodata" , Type: ELF::SHT_PROGBITS, Flags: ELF::SHF_ALLOC); |
401 | |
402 | TLSDataSection = |
403 | Ctx->getELFSection(Section: ".tdata" , Type: ELF::SHT_PROGBITS, |
404 | Flags: ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE); |
405 | |
406 | TLSBSSSection = Ctx->getELFSection( |
407 | Section: ".tbss" , Type: ELF::SHT_NOBITS, Flags: ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE); |
408 | |
409 | DataRelROSection = Ctx->getELFSection(Section: ".data.rel.ro" , Type: ELF::SHT_PROGBITS, |
410 | Flags: ELF::SHF_ALLOC | ELF::SHF_WRITE); |
411 | |
412 | MergeableConst4Section = |
413 | Ctx->getELFSection(Section: ".rodata.cst4" , Type: ELF::SHT_PROGBITS, |
414 | Flags: ELF::SHF_ALLOC | ELF::SHF_MERGE, EntrySize: 4); |
415 | |
416 | MergeableConst8Section = |
417 | Ctx->getELFSection(Section: ".rodata.cst8" , Type: ELF::SHT_PROGBITS, |
418 | Flags: ELF::SHF_ALLOC | ELF::SHF_MERGE, EntrySize: 8); |
419 | |
420 | MergeableConst16Section = |
421 | Ctx->getELFSection(Section: ".rodata.cst16" , Type: ELF::SHT_PROGBITS, |
422 | Flags: ELF::SHF_ALLOC | ELF::SHF_MERGE, EntrySize: 16); |
423 | |
424 | MergeableConst32Section = |
425 | Ctx->getELFSection(Section: ".rodata.cst32" , Type: ELF::SHT_PROGBITS, |
426 | Flags: ELF::SHF_ALLOC | ELF::SHF_MERGE, EntrySize: 32); |
427 | |
428 | // Exception Handling Sections. |
429 | |
430 | // FIXME: We're emitting LSDA info into a readonly section on ELF, even though |
431 | // it contains relocatable pointers. In PIC mode, this is probably a big |
432 | // runtime hit for C++ apps. Either the contents of the LSDA need to be |
433 | // adjusted or this should be a data section. |
434 | LSDASection = Ctx->getELFSection(Section: ".gcc_except_table" , Type: ELF::SHT_PROGBITS, |
435 | Flags: ELF::SHF_ALLOC); |
436 | |
437 | COFFDebugSymbolsSection = nullptr; |
438 | COFFDebugTypesSection = nullptr; |
439 | |
440 | unsigned DebugSecType = ELF::SHT_PROGBITS; |
441 | |
442 | // MIPS .debug_* sections should have SHT_MIPS_DWARF section type |
443 | // to distinguish among sections contain DWARF and ECOFF debug formats. |
444 | // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS. |
445 | if (T.isMIPS()) |
446 | DebugSecType = ELF::SHT_MIPS_DWARF; |
447 | |
448 | // Debug Info Sections. |
449 | DwarfAbbrevSection = |
450 | Ctx->getELFSection(Section: ".debug_abbrev" , Type: DebugSecType, Flags: 0); |
451 | DwarfInfoSection = Ctx->getELFSection(Section: ".debug_info" , Type: DebugSecType, Flags: 0); |
452 | DwarfLineSection = Ctx->getELFSection(Section: ".debug_line" , Type: DebugSecType, Flags: 0); |
453 | DwarfLineStrSection = |
454 | Ctx->getELFSection(Section: ".debug_line_str" , Type: DebugSecType, |
455 | Flags: ELF::SHF_MERGE | ELF::SHF_STRINGS, EntrySize: 1); |
456 | DwarfFrameSection = Ctx->getELFSection(Section: ".debug_frame" , Type: DebugSecType, Flags: 0); |
457 | DwarfPubNamesSection = |
458 | Ctx->getELFSection(Section: ".debug_pubnames" , Type: DebugSecType, Flags: 0); |
459 | DwarfPubTypesSection = |
460 | Ctx->getELFSection(Section: ".debug_pubtypes" , Type: DebugSecType, Flags: 0); |
461 | DwarfGnuPubNamesSection = |
462 | Ctx->getELFSection(Section: ".debug_gnu_pubnames" , Type: DebugSecType, Flags: 0); |
463 | DwarfGnuPubTypesSection = |
464 | Ctx->getELFSection(Section: ".debug_gnu_pubtypes" , Type: DebugSecType, Flags: 0); |
465 | DwarfStrSection = |
466 | Ctx->getELFSection(Section: ".debug_str" , Type: DebugSecType, |
467 | Flags: ELF::SHF_MERGE | ELF::SHF_STRINGS, EntrySize: 1); |
468 | DwarfLocSection = Ctx->getELFSection(Section: ".debug_loc" , Type: DebugSecType, Flags: 0); |
469 | DwarfARangesSection = |
470 | Ctx->getELFSection(Section: ".debug_aranges" , Type: DebugSecType, Flags: 0); |
471 | DwarfRangesSection = |
472 | Ctx->getELFSection(Section: ".debug_ranges" , Type: DebugSecType, Flags: 0); |
473 | DwarfMacinfoSection = |
474 | Ctx->getELFSection(Section: ".debug_macinfo" , Type: DebugSecType, Flags: 0); |
475 | DwarfMacroSection = Ctx->getELFSection(Section: ".debug_macro" , Type: DebugSecType, Flags: 0); |
476 | |
477 | // DWARF5 Experimental Debug Info |
478 | |
479 | // Accelerator Tables |
480 | DwarfDebugNamesSection = |
481 | Ctx->getELFSection(Section: ".debug_names" , Type: ELF::SHT_PROGBITS, Flags: 0); |
482 | DwarfAccelNamesSection = |
483 | Ctx->getELFSection(Section: ".apple_names" , Type: ELF::SHT_PROGBITS, Flags: 0); |
484 | DwarfAccelObjCSection = |
485 | Ctx->getELFSection(Section: ".apple_objc" , Type: ELF::SHT_PROGBITS, Flags: 0); |
486 | DwarfAccelNamespaceSection = |
487 | Ctx->getELFSection(Section: ".apple_namespaces" , Type: ELF::SHT_PROGBITS, Flags: 0); |
488 | DwarfAccelTypesSection = |
489 | Ctx->getELFSection(Section: ".apple_types" , Type: ELF::SHT_PROGBITS, Flags: 0); |
490 | |
491 | // String Offset and Address Sections |
492 | DwarfStrOffSection = |
493 | Ctx->getELFSection(Section: ".debug_str_offsets" , Type: DebugSecType, Flags: 0); |
494 | DwarfAddrSection = Ctx->getELFSection(Section: ".debug_addr" , Type: DebugSecType, Flags: 0); |
495 | DwarfRnglistsSection = Ctx->getELFSection(Section: ".debug_rnglists" , Type: DebugSecType, Flags: 0); |
496 | DwarfLoclistsSection = Ctx->getELFSection(Section: ".debug_loclists" , Type: DebugSecType, Flags: 0); |
497 | |
498 | // Fission Sections |
499 | DwarfInfoDWOSection = |
500 | Ctx->getELFSection(Section: ".debug_info.dwo" , Type: DebugSecType, Flags: ELF::SHF_EXCLUDE); |
501 | DwarfTypesDWOSection = |
502 | Ctx->getELFSection(Section: ".debug_types.dwo" , Type: DebugSecType, Flags: ELF::SHF_EXCLUDE); |
503 | DwarfAbbrevDWOSection = |
504 | Ctx->getELFSection(Section: ".debug_abbrev.dwo" , Type: DebugSecType, Flags: ELF::SHF_EXCLUDE); |
505 | DwarfStrDWOSection = Ctx->getELFSection( |
506 | Section: ".debug_str.dwo" , Type: DebugSecType, |
507 | Flags: ELF::SHF_MERGE | ELF::SHF_STRINGS | ELF::SHF_EXCLUDE, EntrySize: 1); |
508 | DwarfLineDWOSection = |
509 | Ctx->getELFSection(Section: ".debug_line.dwo" , Type: DebugSecType, Flags: ELF::SHF_EXCLUDE); |
510 | DwarfLocDWOSection = |
511 | Ctx->getELFSection(Section: ".debug_loc.dwo" , Type: DebugSecType, Flags: ELF::SHF_EXCLUDE); |
512 | DwarfStrOffDWOSection = Ctx->getELFSection(Section: ".debug_str_offsets.dwo" , |
513 | Type: DebugSecType, Flags: ELF::SHF_EXCLUDE); |
514 | DwarfRnglistsDWOSection = |
515 | Ctx->getELFSection(Section: ".debug_rnglists.dwo" , Type: DebugSecType, Flags: ELF::SHF_EXCLUDE); |
516 | DwarfMacinfoDWOSection = |
517 | Ctx->getELFSection(Section: ".debug_macinfo.dwo" , Type: DebugSecType, Flags: ELF::SHF_EXCLUDE); |
518 | DwarfMacroDWOSection = |
519 | Ctx->getELFSection(Section: ".debug_macro.dwo" , Type: DebugSecType, Flags: ELF::SHF_EXCLUDE); |
520 | |
521 | DwarfLoclistsDWOSection = |
522 | Ctx->getELFSection(Section: ".debug_loclists.dwo" , Type: DebugSecType, Flags: ELF::SHF_EXCLUDE); |
523 | |
524 | // DWP Sections |
525 | DwarfCUIndexSection = |
526 | Ctx->getELFSection(Section: ".debug_cu_index" , Type: DebugSecType, Flags: 0); |
527 | DwarfTUIndexSection = |
528 | Ctx->getELFSection(Section: ".debug_tu_index" , Type: DebugSecType, Flags: 0); |
529 | |
530 | StackMapSection = |
531 | Ctx->getELFSection(Section: ".llvm_stackmaps" , Type: ELF::SHT_PROGBITS, Flags: ELF::SHF_ALLOC); |
532 | |
533 | FaultMapSection = |
534 | Ctx->getELFSection(Section: ".llvm_faultmaps" , Type: ELF::SHT_PROGBITS, Flags: ELF::SHF_ALLOC); |
535 | |
536 | EHFrameSection = |
537 | Ctx->getELFSection(Section: ".eh_frame" , Type: EHSectionType, Flags: EHSectionFlags); |
538 | |
539 | StackSizesSection = Ctx->getELFSection(Section: ".stack_sizes" , Type: ELF::SHT_PROGBITS, Flags: 0); |
540 | |
541 | PseudoProbeSection = Ctx->getELFSection(Section: ".pseudo_probe" , Type: DebugSecType, Flags: 0); |
542 | PseudoProbeDescSection = |
543 | Ctx->getELFSection(Section: ".pseudo_probe_desc" , Type: DebugSecType, Flags: 0); |
544 | |
545 | LLVMStatsSection = Ctx->getELFSection(Section: ".llvm_stats" , Type: ELF::SHT_PROGBITS, Flags: 0); |
546 | } |
547 | |
548 | void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) { |
549 | TextSection = Ctx->getGOFFSection(Section: ".text" , Kind: SectionKind::getText(), Parent: nullptr); |
550 | BSSSection = Ctx->getGOFFSection(Section: ".bss" , Kind: SectionKind::getBSS(), Parent: nullptr); |
551 | PPA1Section = Ctx->getGOFFSection(Section: ".ppa1" , Kind: SectionKind::getMetadata(), |
552 | Parent: TextSection, Subsection: GOFF::SK_PPA1); |
553 | PPA2Section = Ctx->getGOFFSection(Section: ".ppa2" , Kind: SectionKind::getMetadata(), |
554 | Parent: TextSection, Subsection: GOFF::SK_PPA2); |
555 | |
556 | PPA2ListSection = |
557 | Ctx->getGOFFSection(Section: ".ppa2list" , Kind: SectionKind::getData(), Parent: nullptr); |
558 | |
559 | ADASection = Ctx->getGOFFSection(Section: ".ada" , Kind: SectionKind::getData(), Parent: nullptr); |
560 | IDRLSection = Ctx->getGOFFSection(Section: "B_IDRL" , Kind: SectionKind::getData(), Parent: nullptr); |
561 | } |
562 | |
563 | void 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 | |
568 | // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is |
569 | // used to indicate to the linker that the text segment contains thumb instructions |
570 | // and to set the ISA selection bit for calls accordingly. |
571 | const bool IsThumb = T.getArch() == Triple::thumb; |
572 | |
573 | // COFF |
574 | BSSSection = Ctx->getCOFFSection( |
575 | Section: ".bss" , Characteristics: COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA | |
576 | COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE); |
577 | TextSection = Ctx->getCOFFSection( |
578 | Section: ".text" , |
579 | Characteristics: (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) | |
580 | COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE | |
581 | COFF::IMAGE_SCN_MEM_READ); |
582 | DataSection = Ctx->getCOFFSection( |
583 | Section: ".data" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ | |
584 | COFF::IMAGE_SCN_MEM_WRITE); |
585 | ReadOnlySection = |
586 | Ctx->getCOFFSection(Section: ".rdata" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
587 | COFF::IMAGE_SCN_MEM_READ); |
588 | |
589 | if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64 || |
590 | T.getArch() == Triple::arm || T.getArch() == Triple::thumb) { |
591 | // On Windows with SEH, the LSDA is emitted into the .xdata section |
592 | LSDASection = nullptr; |
593 | } else { |
594 | LSDASection = Ctx->getCOFFSection(Section: ".gcc_except_table" , |
595 | Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
596 | COFF::IMAGE_SCN_MEM_READ); |
597 | } |
598 | |
599 | // Debug info. |
600 | COFFDebugSymbolsSection = |
601 | Ctx->getCOFFSection(Section: ".debug$S" , Characteristics: (COFF::IMAGE_SCN_MEM_DISCARDABLE | |
602 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
603 | COFF::IMAGE_SCN_MEM_READ)); |
604 | COFFDebugTypesSection = |
605 | Ctx->getCOFFSection(Section: ".debug$T" , Characteristics: (COFF::IMAGE_SCN_MEM_DISCARDABLE | |
606 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
607 | COFF::IMAGE_SCN_MEM_READ)); |
608 | COFFGlobalTypeHashesSection = |
609 | Ctx->getCOFFSection(Section: ".debug$H" , Characteristics: (COFF::IMAGE_SCN_MEM_DISCARDABLE | |
610 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
611 | COFF::IMAGE_SCN_MEM_READ)); |
612 | |
613 | DwarfAbbrevSection = Ctx->getCOFFSection( |
614 | Section: ".debug_abbrev" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
615 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
616 | COFF::IMAGE_SCN_MEM_READ); |
617 | DwarfInfoSection = Ctx->getCOFFSection( |
618 | Section: ".debug_info" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
619 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
620 | COFF::IMAGE_SCN_MEM_READ); |
621 | DwarfLineSection = Ctx->getCOFFSection( |
622 | Section: ".debug_line" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
623 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
624 | COFF::IMAGE_SCN_MEM_READ); |
625 | DwarfLineStrSection = Ctx->getCOFFSection( |
626 | Section: ".debug_line_str" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
627 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
628 | COFF::IMAGE_SCN_MEM_READ); |
629 | DwarfFrameSection = Ctx->getCOFFSection( |
630 | Section: ".debug_frame" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
631 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
632 | COFF::IMAGE_SCN_MEM_READ); |
633 | DwarfPubNamesSection = Ctx->getCOFFSection( |
634 | Section: ".debug_pubnames" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
635 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
636 | COFF::IMAGE_SCN_MEM_READ); |
637 | DwarfPubTypesSection = Ctx->getCOFFSection( |
638 | Section: ".debug_pubtypes" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
639 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
640 | COFF::IMAGE_SCN_MEM_READ); |
641 | DwarfGnuPubNamesSection = Ctx->getCOFFSection( |
642 | Section: ".debug_gnu_pubnames" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
643 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
644 | COFF::IMAGE_SCN_MEM_READ); |
645 | DwarfGnuPubTypesSection = Ctx->getCOFFSection( |
646 | Section: ".debug_gnu_pubtypes" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
647 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
648 | COFF::IMAGE_SCN_MEM_READ); |
649 | DwarfStrSection = Ctx->getCOFFSection( |
650 | Section: ".debug_str" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
651 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
652 | COFF::IMAGE_SCN_MEM_READ); |
653 | DwarfStrOffSection = Ctx->getCOFFSection( |
654 | Section: ".debug_str_offsets" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
655 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
656 | COFF::IMAGE_SCN_MEM_READ); |
657 | DwarfLocSection = Ctx->getCOFFSection( |
658 | Section: ".debug_loc" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
659 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
660 | COFF::IMAGE_SCN_MEM_READ); |
661 | DwarfLoclistsSection = Ctx->getCOFFSection( |
662 | Section: ".debug_loclists" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
663 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
664 | COFF::IMAGE_SCN_MEM_READ); |
665 | DwarfARangesSection = Ctx->getCOFFSection( |
666 | Section: ".debug_aranges" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
667 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
668 | COFF::IMAGE_SCN_MEM_READ); |
669 | DwarfRangesSection = Ctx->getCOFFSection( |
670 | Section: ".debug_ranges" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
671 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
672 | COFF::IMAGE_SCN_MEM_READ); |
673 | DwarfRnglistsSection = Ctx->getCOFFSection( |
674 | Section: ".debug_rnglists" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
675 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
676 | COFF::IMAGE_SCN_MEM_READ); |
677 | DwarfMacinfoSection = Ctx->getCOFFSection( |
678 | Section: ".debug_macinfo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
679 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
680 | COFF::IMAGE_SCN_MEM_READ); |
681 | DwarfMacroSection = Ctx->getCOFFSection( |
682 | Section: ".debug_macro" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
683 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
684 | COFF::IMAGE_SCN_MEM_READ); |
685 | DwarfMacinfoDWOSection = Ctx->getCOFFSection( |
686 | Section: ".debug_macinfo.dwo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
687 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
688 | COFF::IMAGE_SCN_MEM_READ); |
689 | DwarfMacroDWOSection = Ctx->getCOFFSection( |
690 | Section: ".debug_macro.dwo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
691 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
692 | COFF::IMAGE_SCN_MEM_READ); |
693 | DwarfInfoDWOSection = Ctx->getCOFFSection( |
694 | Section: ".debug_info.dwo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
695 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
696 | COFF::IMAGE_SCN_MEM_READ); |
697 | DwarfTypesDWOSection = Ctx->getCOFFSection( |
698 | Section: ".debug_types.dwo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
699 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
700 | COFF::IMAGE_SCN_MEM_READ); |
701 | DwarfAbbrevDWOSection = Ctx->getCOFFSection( |
702 | Section: ".debug_abbrev.dwo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
703 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
704 | COFF::IMAGE_SCN_MEM_READ); |
705 | DwarfStrDWOSection = Ctx->getCOFFSection( |
706 | Section: ".debug_str.dwo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
707 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
708 | COFF::IMAGE_SCN_MEM_READ); |
709 | DwarfLineDWOSection = Ctx->getCOFFSection( |
710 | Section: ".debug_line.dwo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
711 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
712 | COFF::IMAGE_SCN_MEM_READ); |
713 | DwarfLocDWOSection = Ctx->getCOFFSection( |
714 | Section: ".debug_loc.dwo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
715 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
716 | COFF::IMAGE_SCN_MEM_READ); |
717 | DwarfStrOffDWOSection = Ctx->getCOFFSection( |
718 | Section: ".debug_str_offsets.dwo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
719 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
720 | COFF::IMAGE_SCN_MEM_READ); |
721 | DwarfAddrSection = Ctx->getCOFFSection( |
722 | Section: ".debug_addr" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
723 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
724 | COFF::IMAGE_SCN_MEM_READ); |
725 | DwarfCUIndexSection = Ctx->getCOFFSection( |
726 | Section: ".debug_cu_index" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
727 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
728 | COFF::IMAGE_SCN_MEM_READ); |
729 | DwarfTUIndexSection = Ctx->getCOFFSection( |
730 | Section: ".debug_tu_index" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
731 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
732 | COFF::IMAGE_SCN_MEM_READ); |
733 | DwarfDebugNamesSection = Ctx->getCOFFSection( |
734 | Section: ".debug_names" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
735 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
736 | COFF::IMAGE_SCN_MEM_READ); |
737 | DwarfAccelNamesSection = Ctx->getCOFFSection( |
738 | Section: ".apple_names" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
739 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
740 | COFF::IMAGE_SCN_MEM_READ); |
741 | DwarfAccelNamespaceSection = Ctx->getCOFFSection( |
742 | Section: ".apple_namespaces" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
743 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
744 | COFF::IMAGE_SCN_MEM_READ); |
745 | DwarfAccelTypesSection = Ctx->getCOFFSection( |
746 | Section: ".apple_types" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
747 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
748 | COFF::IMAGE_SCN_MEM_READ); |
749 | DwarfAccelObjCSection = Ctx->getCOFFSection( |
750 | Section: ".apple_objc" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
751 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
752 | COFF::IMAGE_SCN_MEM_READ); |
753 | |
754 | DrectveSection = Ctx->getCOFFSection( |
755 | Section: ".drectve" , Characteristics: COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE); |
756 | |
757 | PDataSection = |
758 | Ctx->getCOFFSection(Section: ".pdata" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
759 | COFF::IMAGE_SCN_MEM_READ); |
760 | |
761 | XDataSection = |
762 | Ctx->getCOFFSection(Section: ".xdata" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
763 | COFF::IMAGE_SCN_MEM_READ); |
764 | |
765 | SXDataSection = Ctx->getCOFFSection(Section: ".sxdata" , Characteristics: COFF::IMAGE_SCN_LNK_INFO); |
766 | |
767 | GEHContSection = |
768 | Ctx->getCOFFSection(Section: ".gehcont$y" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
769 | COFF::IMAGE_SCN_MEM_READ); |
770 | |
771 | GFIDsSection = |
772 | Ctx->getCOFFSection(Section: ".gfids$y" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
773 | COFF::IMAGE_SCN_MEM_READ); |
774 | |
775 | GIATsSection = |
776 | Ctx->getCOFFSection(Section: ".giats$y" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
777 | COFF::IMAGE_SCN_MEM_READ); |
778 | |
779 | GLJMPSection = |
780 | Ctx->getCOFFSection(Section: ".gljmp$y" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
781 | COFF::IMAGE_SCN_MEM_READ); |
782 | |
783 | TLSDataSection = Ctx->getCOFFSection( |
784 | Section: ".tls$" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ | |
785 | COFF::IMAGE_SCN_MEM_WRITE); |
786 | |
787 | StackMapSection = Ctx->getCOFFSection(Section: ".llvm_stackmaps" , |
788 | Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
789 | COFF::IMAGE_SCN_MEM_READ); |
790 | } |
791 | |
792 | void MCObjectFileInfo::initSPIRVMCObjectFileInfo(const Triple &T) { |
793 | // Put everything in a single binary section. |
794 | TextSection = Ctx->getSPIRVSection(); |
795 | } |
796 | |
797 | void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) { |
798 | TextSection = Ctx->getWasmSection(Section: ".text" , K: SectionKind::getText()); |
799 | DataSection = Ctx->getWasmSection(Section: ".data" , K: SectionKind::getData()); |
800 | |
801 | DwarfLineSection = |
802 | Ctx->getWasmSection(Section: ".debug_line" , K: SectionKind::getMetadata()); |
803 | DwarfLineStrSection = |
804 | Ctx->getWasmSection(Section: ".debug_line_str" , K: SectionKind::getMetadata(), |
805 | Flags: wasm::WASM_SEG_FLAG_STRINGS); |
806 | DwarfStrSection = Ctx->getWasmSection( |
807 | Section: ".debug_str" , K: SectionKind::getMetadata(), Flags: wasm::WASM_SEG_FLAG_STRINGS); |
808 | DwarfLocSection = |
809 | Ctx->getWasmSection(Section: ".debug_loc" , K: SectionKind::getMetadata()); |
810 | DwarfAbbrevSection = |
811 | Ctx->getWasmSection(Section: ".debug_abbrev" , K: SectionKind::getMetadata()); |
812 | DwarfARangesSection = Ctx->getWasmSection(Section: ".debug_aranges" , K: SectionKind::getMetadata()); |
813 | DwarfRangesSection = |
814 | Ctx->getWasmSection(Section: ".debug_ranges" , K: SectionKind::getMetadata()); |
815 | DwarfMacinfoSection = |
816 | Ctx->getWasmSection(Section: ".debug_macinfo" , K: SectionKind::getMetadata()); |
817 | DwarfMacroSection = |
818 | Ctx->getWasmSection(Section: ".debug_macro" , K: SectionKind::getMetadata()); |
819 | DwarfCUIndexSection = Ctx->getWasmSection(Section: ".debug_cu_index" , K: SectionKind::getMetadata()); |
820 | DwarfTUIndexSection = Ctx->getWasmSection(Section: ".debug_tu_index" , K: SectionKind::getMetadata()); |
821 | DwarfInfoSection = |
822 | Ctx->getWasmSection(Section: ".debug_info" , K: SectionKind::getMetadata()); |
823 | DwarfFrameSection = Ctx->getWasmSection(Section: ".debug_frame" , K: SectionKind::getMetadata()); |
824 | DwarfPubNamesSection = Ctx->getWasmSection(Section: ".debug_pubnames" , K: SectionKind::getMetadata()); |
825 | DwarfPubTypesSection = Ctx->getWasmSection(Section: ".debug_pubtypes" , K: SectionKind::getMetadata()); |
826 | DwarfGnuPubNamesSection = |
827 | Ctx->getWasmSection(Section: ".debug_gnu_pubnames" , K: SectionKind::getMetadata()); |
828 | DwarfGnuPubTypesSection = |
829 | Ctx->getWasmSection(Section: ".debug_gnu_pubtypes" , K: SectionKind::getMetadata()); |
830 | |
831 | DwarfDebugNamesSection = |
832 | Ctx->getWasmSection(Section: ".debug_names" , K: SectionKind::getMetadata()); |
833 | DwarfStrOffSection = |
834 | Ctx->getWasmSection(Section: ".debug_str_offsets" , K: SectionKind::getMetadata()); |
835 | DwarfAddrSection = |
836 | Ctx->getWasmSection(Section: ".debug_addr" , K: SectionKind::getMetadata()); |
837 | DwarfRnglistsSection = |
838 | Ctx->getWasmSection(Section: ".debug_rnglists" , K: SectionKind::getMetadata()); |
839 | DwarfLoclistsSection = |
840 | Ctx->getWasmSection(Section: ".debug_loclists" , K: SectionKind::getMetadata()); |
841 | |
842 | // Fission Sections |
843 | DwarfInfoDWOSection = |
844 | Ctx->getWasmSection(Section: ".debug_info.dwo" , K: SectionKind::getMetadata()); |
845 | DwarfTypesDWOSection = |
846 | Ctx->getWasmSection(Section: ".debug_types.dwo" , K: SectionKind::getMetadata()); |
847 | DwarfAbbrevDWOSection = |
848 | Ctx->getWasmSection(Section: ".debug_abbrev.dwo" , K: SectionKind::getMetadata()); |
849 | DwarfStrDWOSection = |
850 | Ctx->getWasmSection(Section: ".debug_str.dwo" , K: SectionKind::getMetadata(), |
851 | Flags: wasm::WASM_SEG_FLAG_STRINGS); |
852 | DwarfLineDWOSection = |
853 | Ctx->getWasmSection(Section: ".debug_line.dwo" , K: SectionKind::getMetadata()); |
854 | DwarfLocDWOSection = |
855 | Ctx->getWasmSection(Section: ".debug_loc.dwo" , K: SectionKind::getMetadata()); |
856 | DwarfStrOffDWOSection = |
857 | Ctx->getWasmSection(Section: ".debug_str_offsets.dwo" , K: SectionKind::getMetadata()); |
858 | DwarfRnglistsDWOSection = |
859 | Ctx->getWasmSection(Section: ".debug_rnglists.dwo" , K: SectionKind::getMetadata()); |
860 | DwarfMacinfoDWOSection = |
861 | Ctx->getWasmSection(Section: ".debug_macinfo.dwo" , K: SectionKind::getMetadata()); |
862 | DwarfMacroDWOSection = |
863 | Ctx->getWasmSection(Section: ".debug_macro.dwo" , K: SectionKind::getMetadata()); |
864 | |
865 | DwarfLoclistsDWOSection = |
866 | Ctx->getWasmSection(Section: ".debug_loclists.dwo" , K: SectionKind::getMetadata()); |
867 | |
868 | // DWP Sections |
869 | DwarfCUIndexSection = |
870 | Ctx->getWasmSection(Section: ".debug_cu_index" , K: SectionKind::getMetadata()); |
871 | DwarfTUIndexSection = |
872 | Ctx->getWasmSection(Section: ".debug_tu_index" , K: SectionKind::getMetadata()); |
873 | |
874 | // Wasm use data section for LSDA. |
875 | // TODO Consider putting each function's exception table in a separate |
876 | // section, as in -function-sections, to facilitate lld's --gc-section. |
877 | LSDASection = Ctx->getWasmSection(Section: ".rodata.gcc_except_table" , |
878 | K: SectionKind::getReadOnlyWithRel()); |
879 | |
880 | // TODO: Define more sections. |
881 | } |
882 | |
883 | void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) { |
884 | // The default csect for program code. Functions without a specified section |
885 | // get placed into this csect. The choice of csect name is not a property of |
886 | // the ABI or object file format, but various tools rely on the section |
887 | // name being empty (considering named symbols to be "user symbol names"). |
888 | TextSection = Ctx->getXCOFFSection( |
889 | Section: "..text.." , // Use a non-null name to work around an AIX assembler bug... |
890 | K: SectionKind::getText(), |
891 | CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD), |
892 | /* MultiSymbolsAllowed*/ true); |
893 | |
894 | // ... but use a null name when generating the symbol table. |
895 | MCSectionXCOFF *TS = static_cast<MCSectionXCOFF *>(TextSection); |
896 | TS->getQualNameSymbol()->setSymbolTableName("" ); |
897 | TS->setSymbolTableName("" ); |
898 | |
899 | DataSection = Ctx->getXCOFFSection( |
900 | Section: ".data" , K: SectionKind::getData(), |
901 | CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD), |
902 | /* MultiSymbolsAllowed*/ true); |
903 | |
904 | ReadOnlySection = Ctx->getXCOFFSection( |
905 | Section: ".rodata" , K: SectionKind::getReadOnly(), |
906 | CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD), |
907 | /* MultiSymbolsAllowed*/ true); |
908 | ReadOnlySection->setAlignment(Align(4)); |
909 | |
910 | ReadOnly8Section = Ctx->getXCOFFSection( |
911 | Section: ".rodata.8" , K: SectionKind::getReadOnly(), |
912 | CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD), |
913 | /* MultiSymbolsAllowed*/ true); |
914 | ReadOnly8Section->setAlignment(Align(8)); |
915 | |
916 | ReadOnly16Section = Ctx->getXCOFFSection( |
917 | Section: ".rodata.16" , K: SectionKind::getReadOnly(), |
918 | CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD), |
919 | /* MultiSymbolsAllowed*/ true); |
920 | ReadOnly16Section->setAlignment(Align(16)); |
921 | |
922 | TLSDataSection = Ctx->getXCOFFSection( |
923 | Section: ".tdata" , K: SectionKind::getThreadData(), |
924 | CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TL, XCOFF::XTY_SD), |
925 | /* MultiSymbolsAllowed*/ true); |
926 | |
927 | TOCBaseSection = Ctx->getXCOFFSection( |
928 | Section: "TOC" , K: SectionKind::getData(), |
929 | CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TC0, |
930 | XCOFF::XTY_SD)); |
931 | |
932 | // The TOC-base always has 0 size, but 4 byte alignment. |
933 | TOCBaseSection->setAlignment(Align(4)); |
934 | |
935 | LSDASection = Ctx->getXCOFFSection( |
936 | Section: ".gcc_except_table" , K: SectionKind::getReadOnly(), |
937 | CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, |
938 | XCOFF::XTY_SD)); |
939 | |
940 | CompactUnwindSection = Ctx->getXCOFFSection( |
941 | Section: ".eh_info_table" , K: SectionKind::getData(), |
942 | CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, |
943 | XCOFF::XTY_SD)); |
944 | |
945 | // DWARF sections for XCOFF are not csects. They are special STYP_DWARF |
946 | // sections, and the individual DWARF sections are distinguished by their |
947 | // section subtype. |
948 | DwarfAbbrevSection = Ctx->getXCOFFSection( |
949 | Section: ".dwabrev" , K: SectionKind::getMetadata(), |
950 | /* CsectProperties */ CsectProp: std::nullopt, |
951 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWABREV); |
952 | |
953 | DwarfInfoSection = Ctx->getXCOFFSection( |
954 | Section: ".dwinfo" , K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt, |
955 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWINFO); |
956 | |
957 | DwarfLineSection = Ctx->getXCOFFSection( |
958 | Section: ".dwline" , K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt, |
959 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWLINE); |
960 | |
961 | DwarfFrameSection = Ctx->getXCOFFSection( |
962 | Section: ".dwframe" , K: SectionKind::getMetadata(), |
963 | /* CsectProperties */ CsectProp: std::nullopt, |
964 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWFRAME); |
965 | |
966 | DwarfPubNamesSection = Ctx->getXCOFFSection( |
967 | Section: ".dwpbnms" , K: SectionKind::getMetadata(), |
968 | /* CsectProperties */ CsectProp: std::nullopt, |
969 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWPBNMS); |
970 | |
971 | DwarfPubTypesSection = Ctx->getXCOFFSection( |
972 | Section: ".dwpbtyp" , K: SectionKind::getMetadata(), |
973 | /* CsectProperties */ CsectProp: std::nullopt, |
974 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWPBTYP); |
975 | |
976 | DwarfStrSection = Ctx->getXCOFFSection( |
977 | Section: ".dwstr" , K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt, |
978 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWSTR); |
979 | |
980 | DwarfLocSection = Ctx->getXCOFFSection( |
981 | Section: ".dwloc" , K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt, |
982 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWLOC); |
983 | |
984 | DwarfARangesSection = Ctx->getXCOFFSection( |
985 | Section: ".dwarnge" , K: SectionKind::getMetadata(), |
986 | /* CsectProperties */ CsectProp: std::nullopt, |
987 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWARNGE); |
988 | |
989 | DwarfRangesSection = Ctx->getXCOFFSection( |
990 | Section: ".dwrnges" , K: SectionKind::getMetadata(), |
991 | /* CsectProperties */ CsectProp: std::nullopt, |
992 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWRNGES); |
993 | |
994 | DwarfMacinfoSection = Ctx->getXCOFFSection( |
995 | Section: ".dwmac" , K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt, |
996 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWMAC); |
997 | } |
998 | |
999 | void MCObjectFileInfo::initDXContainerObjectFileInfo(const Triple &T) { |
1000 | // At the moment the DXBC section should end up empty. |
1001 | TextSection = Ctx->getDXContainerSection(Section: "DXBC" , K: SectionKind::getText()); |
1002 | } |
1003 | |
1004 | MCObjectFileInfo::~MCObjectFileInfo() = default; |
1005 | |
1006 | void MCObjectFileInfo::initMCObjectFileInfo(MCContext &MCCtx, bool PIC, |
1007 | bool LargeCodeModel) { |
1008 | PositionIndependent = PIC; |
1009 | Ctx = &MCCtx; |
1010 | |
1011 | // Common. |
1012 | SupportsWeakOmittedEHFrame = true; |
1013 | SupportsCompactUnwindWithoutEHFrame = false; |
1014 | OmitDwarfIfHaveCompactUnwind = false; |
1015 | |
1016 | FDECFIEncoding = dwarf::DW_EH_PE_absptr; |
1017 | |
1018 | CompactUnwindDwarfEHFrameOnly = 0; |
1019 | |
1020 | EHFrameSection = nullptr; // Created on demand. |
1021 | CompactUnwindSection = nullptr; // Used only by selected targets. |
1022 | DwarfAccelNamesSection = nullptr; // Used only by selected targets. |
1023 | DwarfAccelObjCSection = nullptr; // Used only by selected targets. |
1024 | DwarfAccelNamespaceSection = nullptr; // Used only by selected targets. |
1025 | DwarfAccelTypesSection = nullptr; // Used only by selected targets. |
1026 | |
1027 | Triple TheTriple = Ctx->getTargetTriple(); |
1028 | switch (Ctx->getObjectFileType()) { |
1029 | case MCContext::IsMachO: |
1030 | initMachOMCObjectFileInfo(T: TheTriple); |
1031 | break; |
1032 | case MCContext::IsCOFF: |
1033 | initCOFFMCObjectFileInfo(T: TheTriple); |
1034 | break; |
1035 | case MCContext::IsELF: |
1036 | initELFMCObjectFileInfo(T: TheTriple, Large: LargeCodeModel); |
1037 | break; |
1038 | case MCContext::IsGOFF: |
1039 | initGOFFMCObjectFileInfo(T: TheTriple); |
1040 | break; |
1041 | case MCContext::IsSPIRV: |
1042 | initSPIRVMCObjectFileInfo(T: TheTriple); |
1043 | break; |
1044 | case MCContext::IsWasm: |
1045 | initWasmMCObjectFileInfo(T: TheTriple); |
1046 | break; |
1047 | case MCContext::IsXCOFF: |
1048 | initXCOFFMCObjectFileInfo(T: TheTriple); |
1049 | break; |
1050 | case MCContext::IsDXContainer: |
1051 | initDXContainerObjectFileInfo(T: TheTriple); |
1052 | break; |
1053 | } |
1054 | } |
1055 | |
1056 | MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name, |
1057 | uint64_t Hash) const { |
1058 | switch (Ctx->getTargetTriple().getObjectFormat()) { |
1059 | case Triple::ELF: |
1060 | return Ctx->getELFSection(Section: Name, Type: ELF::SHT_PROGBITS, Flags: ELF::SHF_GROUP, EntrySize: 0, |
1061 | Group: utostr(X: Hash), /*IsComdat=*/true); |
1062 | case Triple::Wasm: |
1063 | return Ctx->getWasmSection(Section: Name, K: SectionKind::getMetadata(), Flags: 0, |
1064 | Group: utostr(X: Hash), UniqueID: MCContext::GenericSectionID); |
1065 | case Triple::MachO: |
1066 | case Triple::COFF: |
1067 | case Triple::GOFF: |
1068 | case Triple::SPIRV: |
1069 | case Triple::XCOFF: |
1070 | case Triple::DXContainer: |
1071 | case Triple::UnknownObjectFormat: |
1072 | report_fatal_error(reason: "Cannot get DWARF comdat section for this object file " |
1073 | "format: not implemented." ); |
1074 | break; |
1075 | } |
1076 | llvm_unreachable("Unknown ObjectFormatType" ); |
1077 | } |
1078 | |
1079 | MCSection * |
1080 | MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const { |
1081 | if ((Ctx->getObjectFileType() != MCContext::IsELF) || |
1082 | Ctx->getTargetTriple().isPS4()) |
1083 | return StackSizesSection; |
1084 | |
1085 | const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec); |
1086 | unsigned Flags = ELF::SHF_LINK_ORDER; |
1087 | StringRef GroupName; |
1088 | if (const MCSymbol *Group = ElfSec.getGroup()) { |
1089 | GroupName = Group->getName(); |
1090 | Flags |= ELF::SHF_GROUP; |
1091 | } |
1092 | |
1093 | return Ctx->getELFSection(Section: ".stack_sizes" , Type: ELF::SHT_PROGBITS, Flags, EntrySize: 0, |
1094 | Group: GroupName, IsComdat: true, UniqueID: ElfSec.getUniqueID(), |
1095 | LinkedToSym: cast<MCSymbolELF>(Val: TextSec.getBeginSymbol())); |
1096 | } |
1097 | |
1098 | MCSection * |
1099 | MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const { |
1100 | if (Ctx->getObjectFileType() != MCContext::IsELF) |
1101 | return nullptr; |
1102 | |
1103 | const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec); |
1104 | unsigned Flags = ELF::SHF_LINK_ORDER; |
1105 | StringRef GroupName; |
1106 | if (const MCSymbol *Group = ElfSec.getGroup()) { |
1107 | GroupName = Group->getName(); |
1108 | Flags |= ELF::SHF_GROUP; |
1109 | } |
1110 | |
1111 | // Use the text section's begin symbol and unique ID to create a separate |
1112 | // .llvm_bb_addr_map section associated with every unique text section. |
1113 | return Ctx->getELFSection(Section: ".llvm_bb_addr_map" , Type: ELF::SHT_LLVM_BB_ADDR_MAP, |
1114 | Flags, EntrySize: 0, Group: GroupName, IsComdat: true, UniqueID: ElfSec.getUniqueID(), |
1115 | LinkedToSym: cast<MCSymbolELF>(Val: TextSec.getBeginSymbol())); |
1116 | } |
1117 | |
1118 | MCSection * |
1119 | MCObjectFileInfo::getKCFITrapSection(const MCSection &TextSec) const { |
1120 | if (Ctx->getObjectFileType() != MCContext::IsELF) |
1121 | return nullptr; |
1122 | |
1123 | const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec); |
1124 | unsigned Flags = ELF::SHF_LINK_ORDER | ELF::SHF_ALLOC; |
1125 | StringRef GroupName; |
1126 | if (const MCSymbol *Group = ElfSec.getGroup()) { |
1127 | GroupName = Group->getName(); |
1128 | Flags |= ELF::SHF_GROUP; |
1129 | } |
1130 | |
1131 | return Ctx->getELFSection(Section: ".kcfi_traps" , Type: ELF::SHT_PROGBITS, Flags, EntrySize: 0, |
1132 | Group: GroupName, |
1133 | /*IsComdat=*/true, UniqueID: ElfSec.getUniqueID(), |
1134 | LinkedToSym: cast<MCSymbolELF>(Val: TextSec.getBeginSymbol())); |
1135 | } |
1136 | |
1137 | MCSection * |
1138 | MCObjectFileInfo::getPseudoProbeSection(const MCSection &TextSec) const { |
1139 | if (Ctx->getObjectFileType() != MCContext::IsELF) |
1140 | return PseudoProbeSection; |
1141 | |
1142 | const auto &ElfSec = static_cast<const MCSectionELF &>(TextSec); |
1143 | unsigned Flags = ELF::SHF_LINK_ORDER; |
1144 | StringRef GroupName; |
1145 | if (const MCSymbol *Group = ElfSec.getGroup()) { |
1146 | GroupName = Group->getName(); |
1147 | Flags |= ELF::SHF_GROUP; |
1148 | } |
1149 | |
1150 | return Ctx->getELFSection(Section: PseudoProbeSection->getName(), Type: ELF::SHT_PROGBITS, |
1151 | Flags, EntrySize: 0, Group: GroupName, IsComdat: true, UniqueID: ElfSec.getUniqueID(), |
1152 | LinkedToSym: cast<MCSymbolELF>(Val: TextSec.getBeginSymbol())); |
1153 | } |
1154 | |
1155 | MCSection * |
1156 | MCObjectFileInfo::getPseudoProbeDescSection(StringRef FuncName) const { |
1157 | if (Ctx->getObjectFileType() == MCContext::IsELF) { |
1158 | // Create a separate comdat group for each function's descriptor in order |
1159 | // for the linker to deduplicate. The duplication, must be from different |
1160 | // tranlation unit, can come from: |
1161 | // 1. Inline functions defined in header files; |
1162 | // 2. ThinLTO imported funcions; |
1163 | // 3. Weak-linkage definitions. |
1164 | // Use a concatenation of the section name and the function name as the |
1165 | // group name so that descriptor-only groups won't be folded with groups of |
1166 | // code. |
1167 | if (Ctx->getTargetTriple().supportsCOMDAT() && !FuncName.empty()) { |
1168 | auto *S = static_cast<MCSectionELF *>(PseudoProbeDescSection); |
1169 | auto Flags = S->getFlags() | ELF::SHF_GROUP; |
1170 | return Ctx->getELFSection(Section: S->getName(), Type: S->getType(), Flags, |
1171 | EntrySize: S->getEntrySize(), |
1172 | Group: S->getName() + "_" + FuncName, |
1173 | /*IsComdat=*/true); |
1174 | } |
1175 | } |
1176 | return PseudoProbeDescSection; |
1177 | } |
1178 | |
1179 | MCSection *MCObjectFileInfo::getLLVMStatsSection() const { |
1180 | return LLVMStatsSection; |
1181 | } |
1182 | |
1183 | MCSection *MCObjectFileInfo::getPCSection(StringRef Name, |
1184 | const MCSection *TextSec) const { |
1185 | if (Ctx->getObjectFileType() != MCContext::IsELF) |
1186 | return nullptr; |
1187 | |
1188 | // SHF_WRITE for relocations, and let user post-process data in-place. |
1189 | unsigned Flags = ELF::SHF_WRITE | ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER; |
1190 | |
1191 | if (!TextSec) |
1192 | TextSec = getTextSection(); |
1193 | |
1194 | StringRef GroupName; |
1195 | const auto &ElfSec = static_cast<const MCSectionELF &>(*TextSec); |
1196 | if (const MCSymbol *Group = ElfSec.getGroup()) { |
1197 | GroupName = Group->getName(); |
1198 | Flags |= ELF::SHF_GROUP; |
1199 | } |
1200 | return Ctx->getELFSection(Section: Name, Type: ELF::SHT_PROGBITS, Flags, EntrySize: 0, Group: GroupName, IsComdat: true, |
1201 | UniqueID: ElfSec.getUniqueID(), |
1202 | LinkedToSym: cast<MCSymbolELF>(Val: TextSec->getBeginSymbol())); |
1203 | } |
1204 | |