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