blob: 83da8ac1baee3d9e82f3c990ec1d268290061859 [file] [log] [blame]
Sean Eveson661e4fb2017-11-30 12:43:25 +00001//===-- MCObjectFileInfo.cpp - Object File Information --------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/MC/MCObjectFileInfo.h"
11#include "llvm/ADT/StringExtras.h"
12#include "llvm/ADT/Triple.h"
13#include "llvm/BinaryFormat/COFF.h"
14#include "llvm/BinaryFormat/ELF.h"
15#include "llvm/MC/MCAsmInfo.h"
16#include "llvm/MC/MCContext.h"
17#include "llvm/MC/MCSection.h"
18#include "llvm/MC/MCSectionCOFF.h"
19#include "llvm/MC/MCSectionELF.h"
20#include "llvm/MC/MCSectionMachO.h"
21#include "llvm/MC/MCSectionWasm.h"
22
23using namespace llvm;
24
25static bool useCompactUnwind(const Triple &T) {
26 // Only on darwin.
27 if (!T.isOSDarwin())
28 return false;
29
30 // aarch64 always has it.
31 if (T.getArch() == Triple::aarch64)
32 return true;
33
34 // armv7k always has it.
35 if (T.isWatchABI())
36 return true;
37
38 // Use it on newer version of OS X.
39 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
40 return true;
41
42 // And the iOS simulator.
43 if (T.isiOS() &&
44 (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86))
45 return true;
46
47 return false;
48}
49
50void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
51 // MachO
52 SupportsWeakOmittedEHFrame = false;
53
54 EHFrameSection = Ctx->getMachOSection(
55 "__TEXT", "__eh_frame",
56 MachO::S_COALESCED | MachO::S_ATTR_NO_TOC |
57 MachO::S_ATTR_STRIP_STATIC_SYMS | MachO::S_ATTR_LIVE_SUPPORT,
58 SectionKind::getReadOnly());
59
60 if (T.isOSDarwin() && T.getArch() == Triple::aarch64)
61 SupportsCompactUnwindWithoutEHFrame = true;
62
63 if (T.isWatchABI())
64 OmitDwarfIfHaveCompactUnwind = true;
65
66 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
67 | dwarf::DW_EH_PE_sdata4;
68 LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
69 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
70 dwarf::DW_EH_PE_sdata4;
71
72 // .comm doesn't support alignment before Leopard.
73 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
74 CommDirectiveSupportsAlignment = false;
75
76 TextSection // .text
77 = Ctx->getMachOSection("__TEXT", "__text",
78 MachO::S_ATTR_PURE_INSTRUCTIONS,
79 SectionKind::getText());
80 DataSection // .data
81 = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
82
83 // BSSSection might not be expected initialized on msvc.
84 BSSSection = nullptr;
85
86 TLSDataSection // .tdata
87 = Ctx->getMachOSection("__DATA", "__thread_data",
88 MachO::S_THREAD_LOCAL_REGULAR,
89 SectionKind::getData());
90 TLSBSSSection // .tbss
91 = Ctx->getMachOSection("__DATA", "__thread_bss",
92 MachO::S_THREAD_LOCAL_ZEROFILL,
93 SectionKind::getThreadBSS());
94
95 // TODO: Verify datarel below.
96 TLSTLVSection // .tlv
97 = Ctx->getMachOSection("__DATA", "__thread_vars",
98 MachO::S_THREAD_LOCAL_VARIABLES,
99 SectionKind::getData());
100
101 TLSThreadInitSection = Ctx->getMachOSection(
102 "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
103 SectionKind::getData());
104
105 CStringSection // .cstring
106 = Ctx->getMachOSection("__TEXT", "__cstring",
107 MachO::S_CSTRING_LITERALS,
108 SectionKind::getMergeable1ByteCString());
109 UStringSection
110 = Ctx->getMachOSection("__TEXT","__ustring", 0,
111 SectionKind::getMergeable2ByteCString());
112 FourByteConstantSection // .literal4
113 = Ctx->getMachOSection("__TEXT", "__literal4",
114 MachO::S_4BYTE_LITERALS,
115 SectionKind::getMergeableConst4());
116 EightByteConstantSection // .literal8
117 = Ctx->getMachOSection("__TEXT", "__literal8",
118 MachO::S_8BYTE_LITERALS,
119 SectionKind::getMergeableConst8());
120
121 SixteenByteConstantSection // .literal16
122 = Ctx->getMachOSection("__TEXT", "__literal16",
123 MachO::S_16BYTE_LITERALS,
124 SectionKind::getMergeableConst16());
125
126 ReadOnlySection // .const
127 = Ctx->getMachOSection("__TEXT", "__const", 0,
128 SectionKind::getReadOnly());
129
130 // If the target is not powerpc, map the coal sections to the non-coal
131 // sections.
132 //
133 // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
134 // "__TEXT/__const_coal" => section "__TEXT/__const"
135 // "__DATA/__datacoal_nt" => section "__DATA/__data"
136 Triple::ArchType ArchTy = T.getArch();
137
138 if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
139 TextCoalSection
140 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
141 MachO::S_COALESCED |
142 MachO::S_ATTR_PURE_INSTRUCTIONS,
143 SectionKind::getText());
144 ConstTextCoalSection
145 = Ctx->getMachOSection("__TEXT", "__const_coal",
146 MachO::S_COALESCED,
147 SectionKind::getReadOnly());
148 DataCoalSection = Ctx->getMachOSection(
149 "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());
150 } else {
151 TextCoalSection = TextSection;
152 ConstTextCoalSection = ReadOnlySection;
153 DataCoalSection = DataSection;
154 }
155
156 ConstDataSection // .const_data
157 = Ctx->getMachOSection("__DATA", "__const", 0,
158 SectionKind::getReadOnlyWithRel());
159 DataCommonSection
160 = Ctx->getMachOSection("__DATA","__common",
161 MachO::S_ZEROFILL,
162 SectionKind::getBSS());
163 DataBSSSection
164 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
165 SectionKind::getBSS());
166
167
168 LazySymbolPointerSection
169 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
170 MachO::S_LAZY_SYMBOL_POINTERS,
171 SectionKind::getMetadata());
172 NonLazySymbolPointerSection
173 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
174 MachO::S_NON_LAZY_SYMBOL_POINTERS,
175 SectionKind::getMetadata());
176
177 ThreadLocalPointerSection
178 = Ctx->getMachOSection("__DATA", "__thread_ptr",
179 MachO::S_THREAD_LOCAL_VARIABLE_POINTERS,
180 SectionKind::getMetadata());
181
182 // Exception Handling.
183 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
184 SectionKind::getReadOnlyWithRel());
185
186 COFFDebugSymbolsSection = nullptr;
187 COFFDebugTypesSection = nullptr;
Zachary Turner048f8f92017-12-13 22:33:58 +0000188 COFFGlobalTypeHashesSection = nullptr;
Sean Eveson661e4fb2017-11-30 12:43:25 +0000189
190 if (useCompactUnwind(T)) {
191 CompactUnwindSection =
192 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
193 SectionKind::getReadOnly());
194
195 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
196 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF
197 else if (T.getArch() == Triple::aarch64)
198 CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF
199 else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
200 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF
201 }
202
203 // Debug Information.
204 DwarfAccelNamesSection =
205 Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
206 SectionKind::getMetadata(), "names_begin");
207 DwarfAccelObjCSection =
208 Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
209 SectionKind::getMetadata(), "objc_begin");
210 // 16 character section limit...
211 DwarfAccelNamespaceSection =
212 Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
213 SectionKind::getMetadata(), "namespac_begin");
214 DwarfAccelTypesSection =
215 Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
216 SectionKind::getMetadata(), "types_begin");
217
218 DwarfSwiftASTSection =
219 Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG,
220 SectionKind::getMetadata());
221
222 DwarfAbbrevSection =
223 Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
224 SectionKind::getMetadata(), "section_abbrev");
225 DwarfInfoSection =
226 Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
227 SectionKind::getMetadata(), "section_info");
228 DwarfLineSection =
229 Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
230 SectionKind::getMetadata(), "section_line");
Paul Robinson1f900292018-02-06 20:29:21 +0000231 DwarfLineStrSection =
232 Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,
233 SectionKind::getMetadata(), "section_line_str");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000234 DwarfFrameSection =
235 Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
236 SectionKind::getMetadata());
237 DwarfPubNamesSection =
238 Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
239 SectionKind::getMetadata());
240 DwarfPubTypesSection =
241 Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
242 SectionKind::getMetadata());
243 DwarfGnuPubNamesSection =
244 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
245 SectionKind::getMetadata());
246 DwarfGnuPubTypesSection =
247 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
248 SectionKind::getMetadata());
249 DwarfStrSection =
250 Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
251 SectionKind::getMetadata(), "info_string");
252 DwarfStrOffSection =
253 Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG,
254 SectionKind::getMetadata(), "section_str_off");
255 DwarfLocSection =
256 Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
257 SectionKind::getMetadata(), "section_debug_loc");
258 DwarfARangesSection =
259 Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
260 SectionKind::getMetadata());
261 DwarfRangesSection =
262 Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
263 SectionKind::getMetadata(), "debug_range");
264 DwarfMacinfoSection =
265 Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG,
266 SectionKind::getMetadata(), "debug_macinfo");
267 DwarfDebugInlineSection =
268 Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
269 SectionKind::getMetadata());
270 DwarfCUIndexSection =
271 Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,
272 SectionKind::getMetadata());
273 DwarfTUIndexSection =
274 Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG,
275 SectionKind::getMetadata());
276 StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
277 0, SectionKind::getMetadata());
278
279 FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
280 0, SectionKind::getMetadata());
281
282 TLSExtraDataSection = TLSTLVSection;
283}
284
285void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
286 switch (T.getArch()) {
287 case Triple::mips:
288 case Triple::mipsel:
289 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
290 break;
291 case Triple::mips64:
292 case Triple::mips64el:
293 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
294 break;
Eric Christopherfe6e6d92018-03-24 00:07:38 +0000295 case Triple::ppc64:
296 case Triple::ppc64le:
Sean Eveson661e4fb2017-11-30 12:43:25 +0000297 case Triple::x86_64:
298 FDECFIEncoding = dwarf::DW_EH_PE_pcrel |
299 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
300 break;
301 case Triple::bpfel:
302 case Triple::bpfeb:
303 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
304 break;
305 default:
306 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
307 break;
308 }
309
310 switch (T.getArch()) {
311 case Triple::arm:
312 case Triple::armeb:
313 case Triple::thumb:
314 case Triple::thumbeb:
315 if (Ctx->getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
316 break;
317 // Fallthrough if not using EHABI
318 LLVM_FALLTHROUGH;
319 case Triple::ppc:
320 case Triple::x86:
321 PersonalityEncoding = PositionIndependent
322 ? dwarf::DW_EH_PE_indirect |
323 dwarf::DW_EH_PE_pcrel |
324 dwarf::DW_EH_PE_sdata4
325 : dwarf::DW_EH_PE_absptr;
326 LSDAEncoding = PositionIndependent
327 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
328 : dwarf::DW_EH_PE_absptr;
329 TTypeEncoding = PositionIndependent
330 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
331 dwarf::DW_EH_PE_sdata4
332 : dwarf::DW_EH_PE_absptr;
333 break;
334 case Triple::x86_64:
335 if (PositionIndependent) {
336 PersonalityEncoding =
337 dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
338 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
339 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
340 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
341 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
342 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
343 } else {
344 PersonalityEncoding =
345 Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
346 LSDAEncoding = Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
347 TTypeEncoding = Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
348 }
349 break;
350 case Triple::hexagon:
351 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
352 LSDAEncoding = dwarf::DW_EH_PE_absptr;
353 FDECFIEncoding = dwarf::DW_EH_PE_absptr;
354 TTypeEncoding = dwarf::DW_EH_PE_absptr;
355 if (PositionIndependent) {
356 PersonalityEncoding |= dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel;
357 LSDAEncoding |= dwarf::DW_EH_PE_pcrel;
358 FDECFIEncoding |= dwarf::DW_EH_PE_pcrel;
359 TTypeEncoding |= dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel;
360 }
361 break;
362 case Triple::aarch64:
363 case Triple::aarch64_be:
364 // The small model guarantees static code/data size < 4GB, but not where it
365 // will be in memory. Most of these could end up >2GB away so even a signed
366 // pc-relative 32-bit address is insufficient, theoretically.
367 if (PositionIndependent) {
368 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
369 dwarf::DW_EH_PE_sdata8;
370 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
371 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
372 dwarf::DW_EH_PE_sdata8;
373 } else {
374 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
375 LSDAEncoding = dwarf::DW_EH_PE_absptr;
376 TTypeEncoding = dwarf::DW_EH_PE_absptr;
377 }
378 break;
379 case Triple::lanai:
380 LSDAEncoding = dwarf::DW_EH_PE_absptr;
381 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
382 TTypeEncoding = dwarf::DW_EH_PE_absptr;
383 break;
384 case Triple::mips:
385 case Triple::mipsel:
386 case Triple::mips64:
387 case Triple::mips64el:
388 // MIPS uses indirect pointer to refer personality functions and types, so
389 // that the eh_frame section can be read-only. DW.ref.personality will be
390 // generated for relocation.
391 PersonalityEncoding = dwarf::DW_EH_PE_indirect;
392 // FIXME: The N64 ABI probably ought to use DW_EH_PE_sdata8 but we can't
393 // identify N64 from just a triple.
394 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
395 dwarf::DW_EH_PE_sdata4;
396 // We don't support PC-relative LSDA references in GAS so we use the default
397 // DW_EH_PE_absptr for those.
398
399 // FreeBSD must be explicit about the data size and using pcrel since it's
400 // assembler/linker won't do the automatic conversion that the Linux tools
401 // do.
402 if (T.isOSFreeBSD()) {
403 PersonalityEncoding |= dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
404 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
405 }
406 break;
407 case Triple::ppc64:
408 case Triple::ppc64le:
409 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
410 dwarf::DW_EH_PE_udata8;
411 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
412 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
413 dwarf::DW_EH_PE_udata8;
414 break;
415 case Triple::sparcel:
416 case Triple::sparc:
417 if (PositionIndependent) {
418 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
419 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
420 dwarf::DW_EH_PE_sdata4;
421 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
422 dwarf::DW_EH_PE_sdata4;
423 } else {
424 LSDAEncoding = dwarf::DW_EH_PE_absptr;
425 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
426 TTypeEncoding = dwarf::DW_EH_PE_absptr;
427 }
428 break;
429 case Triple::sparcv9:
430 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
431 if (PositionIndependent) {
432 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
433 dwarf::DW_EH_PE_sdata4;
434 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
435 dwarf::DW_EH_PE_sdata4;
436 } else {
437 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
438 TTypeEncoding = dwarf::DW_EH_PE_absptr;
439 }
440 break;
441 case Triple::systemz:
442 // All currently-defined code models guarantee that 4-byte PC-relative
443 // values will be in range.
444 if (PositionIndependent) {
445 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
446 dwarf::DW_EH_PE_sdata4;
447 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
448 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
449 dwarf::DW_EH_PE_sdata4;
450 } else {
451 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
452 LSDAEncoding = dwarf::DW_EH_PE_absptr;
453 TTypeEncoding = dwarf::DW_EH_PE_absptr;
454 }
455 break;
456 default:
457 break;
458 }
459
460 unsigned EHSectionType = T.getArch() == Triple::x86_64
461 ? ELF::SHT_X86_64_UNWIND
462 : ELF::SHT_PROGBITS;
463
464 // Solaris requires different flags for .eh_frame to seemingly every other
465 // platform.
466 unsigned EHSectionFlags = ELF::SHF_ALLOC;
467 if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
468 EHSectionFlags |= ELF::SHF_WRITE;
469
470 // ELF
471 BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
472 ELF::SHF_WRITE | ELF::SHF_ALLOC);
473
474 TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
475 ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
476
477 DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
478 ELF::SHF_WRITE | ELF::SHF_ALLOC);
479
480 ReadOnlySection =
481 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
482
483 TLSDataSection =
484 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
485 ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
486
487 TLSBSSSection = Ctx->getELFSection(
488 ".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
489
490 DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
491 ELF::SHF_ALLOC | ELF::SHF_WRITE);
492
493 MergeableConst4Section =
494 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
495 ELF::SHF_ALLOC | ELF::SHF_MERGE, 4, "");
496
497 MergeableConst8Section =
498 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
499 ELF::SHF_ALLOC | ELF::SHF_MERGE, 8, "");
500
501 MergeableConst16Section =
502 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
503 ELF::SHF_ALLOC | ELF::SHF_MERGE, 16, "");
504
505 MergeableConst32Section =
506 Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS,
507 ELF::SHF_ALLOC | ELF::SHF_MERGE, 32, "");
508
509 // Exception Handling Sections.
510
511 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
512 // it contains relocatable pointers. In PIC mode, this is probably a big
513 // runtime hit for C++ apps. Either the contents of the LSDA need to be
514 // adjusted or this should be a data section.
515 LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
516 ELF::SHF_ALLOC);
517
518 COFFDebugSymbolsSection = nullptr;
519 COFFDebugTypesSection = nullptr;
520
521 unsigned DebugSecType = ELF::SHT_PROGBITS;
522
523 // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
524 // to distinguish among sections contain DWARF and ECOFF debug formats.
525 // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
526 if (T.getArch() == Triple::mips || T.getArch() == Triple::mipsel ||
527 T.getArch() == Triple::mips64 || T.getArch() == Triple::mips64el)
528 DebugSecType = ELF::SHT_MIPS_DWARF;
529
530 // Debug Info Sections.
531 DwarfAbbrevSection =
532 Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);
533 DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0);
534 DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0);
Paul Robinson1f900292018-02-06 20:29:21 +0000535 DwarfLineStrSection =
536 Ctx->getELFSection(".debug_line_str", DebugSecType,
537 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000538 DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0);
539 DwarfPubNamesSection =
540 Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);
541 DwarfPubTypesSection =
542 Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);
543 DwarfGnuPubNamesSection =
544 Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);
545 DwarfGnuPubTypesSection =
546 Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);
547 DwarfStrSection =
548 Ctx->getELFSection(".debug_str", DebugSecType,
549 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
550 DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0);
551 DwarfARangesSection =
552 Ctx->getELFSection(".debug_aranges", DebugSecType, 0);
553 DwarfRangesSection =
554 Ctx->getELFSection(".debug_ranges", DebugSecType, 0);
555 DwarfMacinfoSection =
556 Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);
557
558 // DWARF5 Experimental Debug Info
559
560 // Accelerator Tables
561 DwarfAccelNamesSection =
562 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);
563 DwarfAccelObjCSection =
564 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);
565 DwarfAccelNamespaceSection =
566 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);
567 DwarfAccelTypesSection =
568 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);
569
570 // String Offset and Address Sections
571 DwarfStrOffSection =
572 Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);
573 DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);
574
575 // Fission Sections
576 DwarfInfoDWOSection =
577 Ctx->getELFSection(".debug_info.dwo", DebugSecType, 0);
578 DwarfTypesDWOSection =
579 Ctx->getELFSection(".debug_types.dwo", DebugSecType, 0);
580 DwarfAbbrevDWOSection =
581 Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, 0);
582 DwarfStrDWOSection =
583 Ctx->getELFSection(".debug_str.dwo", DebugSecType,
584 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
585 DwarfLineDWOSection =
586 Ctx->getELFSection(".debug_line.dwo", DebugSecType, 0);
587 DwarfLocDWOSection =
588 Ctx->getELFSection(".debug_loc.dwo", DebugSecType, 0);
589 DwarfStrOffDWOSection =
590 Ctx->getELFSection(".debug_str_offsets.dwo", DebugSecType, 0);
591
592 // DWP Sections
593 DwarfCUIndexSection =
594 Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);
595 DwarfTUIndexSection =
596 Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);
597
598 StackMapSection =
599 Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
600
601 FaultMapSection =
602 Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
603
604 EHFrameSection =
605 Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
Sean Evesona6bcd532017-11-30 13:05:14 +0000606
607 StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);
Sean Eveson661e4fb2017-11-30 12:43:25 +0000608}
609
610void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
611 EHFrameSection = Ctx->getCOFFSection(
612 ".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
613 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
614 SectionKind::getData());
615
616 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
617 // used to indicate to the linker that the text segment contains thumb instructions
618 // and to set the ISA selection bit for calls accordingly.
619 const bool IsThumb = T.getArch() == Triple::thumb;
620
621 CommDirectiveSupportsAlignment = true;
622
623 // COFF
624 BSSSection = Ctx->getCOFFSection(
625 ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
626 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
627 SectionKind::getBSS());
628 TextSection = Ctx->getCOFFSection(
629 ".text",
630 (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |
631 COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
632 COFF::IMAGE_SCN_MEM_READ,
633 SectionKind::getText());
634 DataSection = Ctx->getCOFFSection(
635 ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
636 COFF::IMAGE_SCN_MEM_WRITE,
637 SectionKind::getData());
638 ReadOnlySection = Ctx->getCOFFSection(
639 ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
640 SectionKind::getReadOnly());
641
642 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
643 // though it contains relocatable pointers. In PIC mode, this is probably a
644 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
645 // adjusted or this should be a data section.
646 if (T.getArch() == Triple::x86_64) {
647 // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
648 LSDASection = nullptr;
649 } else {
650 LSDASection = Ctx->getCOFFSection(".gcc_except_table",
651 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
652 COFF::IMAGE_SCN_MEM_READ,
653 SectionKind::getReadOnly());
654 }
655
656 // Debug info.
657 COFFDebugSymbolsSection =
658 Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
659 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
660 COFF::IMAGE_SCN_MEM_READ),
661 SectionKind::getMetadata());
662 COFFDebugTypesSection =
663 Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
664 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
665 COFF::IMAGE_SCN_MEM_READ),
666 SectionKind::getMetadata());
Zachary Turner048f8f92017-12-13 22:33:58 +0000667 COFFGlobalTypeHashesSection = Ctx->getCOFFSection(
668 ".debug$H",
669 (COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
670 COFF::IMAGE_SCN_MEM_READ),
671 SectionKind::getMetadata());
Sean Eveson661e4fb2017-11-30 12:43:25 +0000672
673 DwarfAbbrevSection = Ctx->getCOFFSection(
674 ".debug_abbrev",
675 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
676 COFF::IMAGE_SCN_MEM_READ,
677 SectionKind::getMetadata(), "section_abbrev");
678 DwarfInfoSection = Ctx->getCOFFSection(
679 ".debug_info",
680 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
681 COFF::IMAGE_SCN_MEM_READ,
682 SectionKind::getMetadata(), "section_info");
683 DwarfLineSection = Ctx->getCOFFSection(
684 ".debug_line",
685 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
686 COFF::IMAGE_SCN_MEM_READ,
687 SectionKind::getMetadata(), "section_line");
Paul Robinson1f900292018-02-06 20:29:21 +0000688 DwarfLineStrSection = Ctx->getCOFFSection(
689 ".debug_line_str",
690 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
691 COFF::IMAGE_SCN_MEM_READ,
692 SectionKind::getMetadata(), "section_line_str");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000693 DwarfFrameSection = Ctx->getCOFFSection(
694 ".debug_frame",
695 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
696 COFF::IMAGE_SCN_MEM_READ,
697 SectionKind::getMetadata());
698 DwarfPubNamesSection = Ctx->getCOFFSection(
699 ".debug_pubnames",
700 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
701 COFF::IMAGE_SCN_MEM_READ,
702 SectionKind::getMetadata());
703 DwarfPubTypesSection = Ctx->getCOFFSection(
704 ".debug_pubtypes",
705 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
706 COFF::IMAGE_SCN_MEM_READ,
707 SectionKind::getMetadata());
708 DwarfGnuPubNamesSection = Ctx->getCOFFSection(
709 ".debug_gnu_pubnames",
710 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
711 COFF::IMAGE_SCN_MEM_READ,
712 SectionKind::getMetadata());
713 DwarfGnuPubTypesSection = Ctx->getCOFFSection(
714 ".debug_gnu_pubtypes",
715 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
716 COFF::IMAGE_SCN_MEM_READ,
717 SectionKind::getMetadata());
718 DwarfStrSection = Ctx->getCOFFSection(
719 ".debug_str",
720 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
721 COFF::IMAGE_SCN_MEM_READ,
722 SectionKind::getMetadata(), "info_string");
723 DwarfStrOffSection = Ctx->getCOFFSection(
724 ".debug_str_offsets",
725 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
726 COFF::IMAGE_SCN_MEM_READ,
727 SectionKind::getMetadata(), "section_str_off");
728 DwarfLocSection = Ctx->getCOFFSection(
729 ".debug_loc",
730 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
731 COFF::IMAGE_SCN_MEM_READ,
732 SectionKind::getMetadata(), "section_debug_loc");
733 DwarfARangesSection = Ctx->getCOFFSection(
734 ".debug_aranges",
735 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
736 COFF::IMAGE_SCN_MEM_READ,
737 SectionKind::getMetadata());
738 DwarfRangesSection = Ctx->getCOFFSection(
739 ".debug_ranges",
740 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
741 COFF::IMAGE_SCN_MEM_READ,
742 SectionKind::getMetadata(), "debug_range");
743 DwarfMacinfoSection = Ctx->getCOFFSection(
744 ".debug_macinfo",
745 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
746 COFF::IMAGE_SCN_MEM_READ,
747 SectionKind::getMetadata(), "debug_macinfo");
748 DwarfInfoDWOSection = Ctx->getCOFFSection(
749 ".debug_info.dwo",
750 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
751 COFF::IMAGE_SCN_MEM_READ,
752 SectionKind::getMetadata(), "section_info_dwo");
753 DwarfTypesDWOSection = Ctx->getCOFFSection(
754 ".debug_types.dwo",
755 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
756 COFF::IMAGE_SCN_MEM_READ,
757 SectionKind::getMetadata(), "section_types_dwo");
758 DwarfAbbrevDWOSection = Ctx->getCOFFSection(
759 ".debug_abbrev.dwo",
760 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
761 COFF::IMAGE_SCN_MEM_READ,
762 SectionKind::getMetadata(), "section_abbrev_dwo");
763 DwarfStrDWOSection = Ctx->getCOFFSection(
764 ".debug_str.dwo",
765 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
766 COFF::IMAGE_SCN_MEM_READ,
767 SectionKind::getMetadata(), "skel_string");
768 DwarfLineDWOSection = Ctx->getCOFFSection(
769 ".debug_line.dwo",
770 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
771 COFF::IMAGE_SCN_MEM_READ,
772 SectionKind::getMetadata());
773 DwarfLocDWOSection = Ctx->getCOFFSection(
774 ".debug_loc.dwo",
775 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
776 COFF::IMAGE_SCN_MEM_READ,
777 SectionKind::getMetadata(), "skel_loc");
778 DwarfStrOffDWOSection = Ctx->getCOFFSection(
779 ".debug_str_offsets.dwo",
780 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
781 COFF::IMAGE_SCN_MEM_READ,
782 SectionKind::getMetadata(), "section_str_off_dwo");
783 DwarfAddrSection = Ctx->getCOFFSection(
784 ".debug_addr",
785 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
786 COFF::IMAGE_SCN_MEM_READ,
787 SectionKind::getMetadata(), "addr_sec");
788 DwarfCUIndexSection = Ctx->getCOFFSection(
789 ".debug_cu_index",
790 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
791 COFF::IMAGE_SCN_MEM_READ,
792 SectionKind::getMetadata());
793 DwarfTUIndexSection = Ctx->getCOFFSection(
794 ".debug_tu_index",
795 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
796 COFF::IMAGE_SCN_MEM_READ,
797 SectionKind::getMetadata());
798 DwarfAccelNamesSection = Ctx->getCOFFSection(
799 ".apple_names",
800 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
801 COFF::IMAGE_SCN_MEM_READ,
802 SectionKind::getMetadata(), "names_begin");
803 DwarfAccelNamespaceSection = Ctx->getCOFFSection(
804 ".apple_namespaces",
805 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
806 COFF::IMAGE_SCN_MEM_READ,
807 SectionKind::getMetadata(), "namespac_begin");
808 DwarfAccelTypesSection = Ctx->getCOFFSection(
809 ".apple_types",
810 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
811 COFF::IMAGE_SCN_MEM_READ,
812 SectionKind::getMetadata(), "types_begin");
813 DwarfAccelObjCSection = Ctx->getCOFFSection(
814 ".apple_objc",
815 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
816 COFF::IMAGE_SCN_MEM_READ,
817 SectionKind::getMetadata(), "objc_begin");
818
819 DrectveSection = Ctx->getCOFFSection(
820 ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
821 SectionKind::getMetadata());
822
823 PDataSection = Ctx->getCOFFSection(
824 ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
825 SectionKind::getData());
826
827 XDataSection = Ctx->getCOFFSection(
828 ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
829 SectionKind::getData());
830
831 SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO,
832 SectionKind::getMetadata());
833
Adrian McCarthydb2736d2018-01-09 23:49:30 +0000834 GFIDsSection = Ctx->getCOFFSection(".gfids$y",
835 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
836 COFF::IMAGE_SCN_MEM_READ,
837 SectionKind::getMetadata());
838
Sean Eveson661e4fb2017-11-30 12:43:25 +0000839 TLSDataSection = Ctx->getCOFFSection(
840 ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
841 COFF::IMAGE_SCN_MEM_WRITE,
842 SectionKind::getData());
843
844 StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
845 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
846 COFF::IMAGE_SCN_MEM_READ,
847 SectionKind::getReadOnly());
848}
849
850void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
851 // TODO: Set the section types and flags.
852 TextSection = Ctx->getWasmSection(".text", SectionKind::getText());
853 DataSection = Ctx->getWasmSection(".data", SectionKind::getData());
854
855 // TODO: Set the section types and flags.
856 DwarfLineSection = Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());
Paul Robinson1f900292018-02-06 20:29:21 +0000857 DwarfLineStrSection =
858 Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata());
Sean Eveson661e4fb2017-11-30 12:43:25 +0000859 DwarfStrSection = Ctx->getWasmSection(".debug_str", SectionKind::getMetadata());
860 DwarfLocSection = Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());
861 DwarfAbbrevSection = Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata(), "section_abbrev");
862 DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());
863 DwarfRangesSection = Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata(), "debug_range");
864 DwarfMacinfoSection = Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata(), "debug_macinfo");
865 DwarfAddrSection = Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata());
866 DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
867 DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
868 DwarfInfoSection = Ctx->getWasmSection(".debug_info", SectionKind::getMetadata(), "section_info");
869 DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());
870 DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
871 DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
872
873 // TODO: Define more sections.
874}
875
876void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
877 MCContext &ctx,
878 bool LargeCodeModel) {
879 PositionIndependent = PIC;
880 Ctx = &ctx;
881
882 // Common.
883 CommDirectiveSupportsAlignment = true;
884 SupportsWeakOmittedEHFrame = true;
885 SupportsCompactUnwindWithoutEHFrame = false;
886 OmitDwarfIfHaveCompactUnwind = false;
887
888 PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
889 dwarf::DW_EH_PE_absptr;
890
891 CompactUnwindDwarfEHFrameOnly = 0;
892
893 EHFrameSection = nullptr; // Created on demand.
894 CompactUnwindSection = nullptr; // Used only by selected targets.
895 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
896 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
897 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
898 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
899
900 TT = TheTriple;
901
902 switch (TT.getObjectFormat()) {
903 case Triple::MachO:
904 Env = IsMachO;
905 initMachOMCObjectFileInfo(TT);
906 break;
907 case Triple::COFF:
908 if (!TT.isOSWindows())
909 report_fatal_error(
910 "Cannot initialize MC for non-Windows COFF object files.");
911
912 Env = IsCOFF;
913 initCOFFMCObjectFileInfo(TT);
914 break;
915 case Triple::ELF:
916 Env = IsELF;
917 initELFMCObjectFileInfo(TT, LargeCodeModel);
918 break;
919 case Triple::Wasm:
920 Env = IsWasm;
921 initWasmMCObjectFileInfo(TT);
922 break;
923 case Triple::UnknownObjectFormat:
924 report_fatal_error("Cannot initialize MC for unknown object file format.");
925 break;
926 }
927}
928
929MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
930 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
931 0, utostr(Hash));
932}