blob: 5b3636153d6ea882d2b071f7b6887739b4bcaf91 [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
Steven Wud0804aa2018-04-10 20:16:35 +0000138 ConstDataSection // .const_data
139 = Ctx->getMachOSection("__DATA", "__const", 0,
140 SectionKind::getReadOnlyWithRel());
141
Sean Eveson661e4fb2017-11-30 12:43:25 +0000142 if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
143 TextCoalSection
144 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
145 MachO::S_COALESCED |
146 MachO::S_ATTR_PURE_INSTRUCTIONS,
147 SectionKind::getText());
148 ConstTextCoalSection
149 = Ctx->getMachOSection("__TEXT", "__const_coal",
150 MachO::S_COALESCED,
151 SectionKind::getReadOnly());
152 DataCoalSection = Ctx->getMachOSection(
153 "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());
Steven Wud0804aa2018-04-10 20:16:35 +0000154 ConstDataCoalSection = DataCoalSection;
Sean Eveson661e4fb2017-11-30 12:43:25 +0000155 } else {
156 TextCoalSection = TextSection;
157 ConstTextCoalSection = ReadOnlySection;
158 DataCoalSection = DataSection;
Steven Wud0804aa2018-04-10 20:16:35 +0000159 ConstDataCoalSection = ConstDataSection;
Sean Eveson661e4fb2017-11-30 12:43:25 +0000160 }
161
Sean Eveson661e4fb2017-11-30 12:43:25 +0000162 DataCommonSection
163 = Ctx->getMachOSection("__DATA","__common",
164 MachO::S_ZEROFILL,
165 SectionKind::getBSS());
166 DataBSSSection
167 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
168 SectionKind::getBSS());
169
170
171 LazySymbolPointerSection
172 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
173 MachO::S_LAZY_SYMBOL_POINTERS,
174 SectionKind::getMetadata());
175 NonLazySymbolPointerSection
176 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
177 MachO::S_NON_LAZY_SYMBOL_POINTERS,
178 SectionKind::getMetadata());
179
180 ThreadLocalPointerSection
181 = Ctx->getMachOSection("__DATA", "__thread_ptr",
182 MachO::S_THREAD_LOCAL_VARIABLE_POINTERS,
183 SectionKind::getMetadata());
184
185 // Exception Handling.
186 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
187 SectionKind::getReadOnlyWithRel());
188
189 COFFDebugSymbolsSection = nullptr;
190 COFFDebugTypesSection = nullptr;
Zachary Turner048f8f92017-12-13 22:33:58 +0000191 COFFGlobalTypeHashesSection = nullptr;
Sean Eveson661e4fb2017-11-30 12:43:25 +0000192
193 if (useCompactUnwind(T)) {
194 CompactUnwindSection =
195 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
196 SectionKind::getReadOnly());
197
198 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
199 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF
200 else if (T.getArch() == Triple::aarch64)
201 CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF
202 else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
203 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF
204 }
205
206 // Debug Information.
Pavel Labath6088c232018-04-04 14:42:14 +0000207 DwarfDebugNamesSection =
208 Ctx->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG,
209 SectionKind::getMetadata(), "debug_names_begin");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000210 DwarfAccelNamesSection =
211 Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
212 SectionKind::getMetadata(), "names_begin");
213 DwarfAccelObjCSection =
214 Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
215 SectionKind::getMetadata(), "objc_begin");
216 // 16 character section limit...
217 DwarfAccelNamespaceSection =
218 Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
219 SectionKind::getMetadata(), "namespac_begin");
220 DwarfAccelTypesSection =
221 Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
222 SectionKind::getMetadata(), "types_begin");
223
224 DwarfSwiftASTSection =
225 Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG,
226 SectionKind::getMetadata());
227
228 DwarfAbbrevSection =
229 Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
230 SectionKind::getMetadata(), "section_abbrev");
231 DwarfInfoSection =
232 Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
233 SectionKind::getMetadata(), "section_info");
234 DwarfLineSection =
235 Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
236 SectionKind::getMetadata(), "section_line");
Paul Robinson1f900292018-02-06 20:29:21 +0000237 DwarfLineStrSection =
238 Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,
239 SectionKind::getMetadata(), "section_line_str");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000240 DwarfFrameSection =
241 Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
242 SectionKind::getMetadata());
243 DwarfPubNamesSection =
244 Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
245 SectionKind::getMetadata());
246 DwarfPubTypesSection =
247 Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
248 SectionKind::getMetadata());
249 DwarfGnuPubNamesSection =
250 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
251 SectionKind::getMetadata());
252 DwarfGnuPubTypesSection =
253 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
254 SectionKind::getMetadata());
255 DwarfStrSection =
256 Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
257 SectionKind::getMetadata(), "info_string");
258 DwarfStrOffSection =
259 Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG,
260 SectionKind::getMetadata(), "section_str_off");
261 DwarfLocSection =
262 Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
263 SectionKind::getMetadata(), "section_debug_loc");
264 DwarfARangesSection =
265 Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
266 SectionKind::getMetadata());
267 DwarfRangesSection =
268 Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
269 SectionKind::getMetadata(), "debug_range");
270 DwarfMacinfoSection =
271 Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG,
272 SectionKind::getMetadata(), "debug_macinfo");
273 DwarfDebugInlineSection =
274 Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
275 SectionKind::getMetadata());
276 DwarfCUIndexSection =
277 Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,
278 SectionKind::getMetadata());
279 DwarfTUIndexSection =
280 Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG,
281 SectionKind::getMetadata());
282 StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
283 0, SectionKind::getMetadata());
284
285 FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
286 0, SectionKind::getMetadata());
287
288 TLSExtraDataSection = TLSTLVSection;
289}
290
291void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
292 switch (T.getArch()) {
293 case Triple::mips:
294 case Triple::mipsel:
295 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
296 break;
297 case Triple::mips64:
298 case Triple::mips64el:
299 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
300 break;
Eric Christopherfe6e6d92018-03-24 00:07:38 +0000301 case Triple::ppc64:
302 case Triple::ppc64le:
Sean Eveson661e4fb2017-11-30 12:43:25 +0000303 case Triple::x86_64:
304 FDECFIEncoding = dwarf::DW_EH_PE_pcrel |
305 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
306 break;
307 case Triple::bpfel:
308 case Triple::bpfeb:
309 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
310 break;
311 default:
312 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
313 break;
314 }
315
316 switch (T.getArch()) {
317 case Triple::arm:
318 case Triple::armeb:
319 case Triple::thumb:
320 case Triple::thumbeb:
321 if (Ctx->getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
322 break;
323 // Fallthrough if not using EHABI
324 LLVM_FALLTHROUGH;
325 case Triple::ppc:
326 case Triple::x86:
327 PersonalityEncoding = PositionIndependent
328 ? dwarf::DW_EH_PE_indirect |
329 dwarf::DW_EH_PE_pcrel |
330 dwarf::DW_EH_PE_sdata4
331 : dwarf::DW_EH_PE_absptr;
332 LSDAEncoding = PositionIndependent
333 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
334 : dwarf::DW_EH_PE_absptr;
335 TTypeEncoding = PositionIndependent
336 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
337 dwarf::DW_EH_PE_sdata4
338 : dwarf::DW_EH_PE_absptr;
339 break;
340 case Triple::x86_64:
341 if (PositionIndependent) {
342 PersonalityEncoding =
343 dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
344 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
345 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
346 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
347 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
348 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
349 } else {
350 PersonalityEncoding =
351 Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
352 LSDAEncoding = Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
353 TTypeEncoding = Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
354 }
355 break;
356 case Triple::hexagon:
357 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
358 LSDAEncoding = dwarf::DW_EH_PE_absptr;
359 FDECFIEncoding = dwarf::DW_EH_PE_absptr;
360 TTypeEncoding = dwarf::DW_EH_PE_absptr;
361 if (PositionIndependent) {
362 PersonalityEncoding |= dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel;
363 LSDAEncoding |= dwarf::DW_EH_PE_pcrel;
364 FDECFIEncoding |= dwarf::DW_EH_PE_pcrel;
365 TTypeEncoding |= dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel;
366 }
367 break;
368 case Triple::aarch64:
369 case Triple::aarch64_be:
370 // The small model guarantees static code/data size < 4GB, but not where it
371 // will be in memory. Most of these could end up >2GB away so even a signed
372 // pc-relative 32-bit address is insufficient, theoretically.
373 if (PositionIndependent) {
374 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
375 dwarf::DW_EH_PE_sdata8;
376 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
377 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
378 dwarf::DW_EH_PE_sdata8;
379 } else {
380 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
381 LSDAEncoding = dwarf::DW_EH_PE_absptr;
382 TTypeEncoding = dwarf::DW_EH_PE_absptr;
383 }
384 break;
385 case Triple::lanai:
386 LSDAEncoding = dwarf::DW_EH_PE_absptr;
387 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
388 TTypeEncoding = dwarf::DW_EH_PE_absptr;
389 break;
390 case Triple::mips:
391 case Triple::mipsel:
392 case Triple::mips64:
393 case Triple::mips64el:
394 // MIPS uses indirect pointer to refer personality functions and types, so
395 // that the eh_frame section can be read-only. DW.ref.personality will be
396 // generated for relocation.
397 PersonalityEncoding = dwarf::DW_EH_PE_indirect;
398 // FIXME: The N64 ABI probably ought to use DW_EH_PE_sdata8 but we can't
399 // identify N64 from just a triple.
400 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
401 dwarf::DW_EH_PE_sdata4;
402 // We don't support PC-relative LSDA references in GAS so we use the default
403 // DW_EH_PE_absptr for those.
404
405 // FreeBSD must be explicit about the data size and using pcrel since it's
406 // assembler/linker won't do the automatic conversion that the Linux tools
407 // do.
408 if (T.isOSFreeBSD()) {
409 PersonalityEncoding |= dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
410 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
411 }
412 break;
413 case Triple::ppc64:
414 case Triple::ppc64le:
415 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
416 dwarf::DW_EH_PE_udata8;
417 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
418 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
419 dwarf::DW_EH_PE_udata8;
420 break;
421 case Triple::sparcel:
422 case Triple::sparc:
423 if (PositionIndependent) {
424 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
425 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
426 dwarf::DW_EH_PE_sdata4;
427 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
428 dwarf::DW_EH_PE_sdata4;
429 } else {
430 LSDAEncoding = dwarf::DW_EH_PE_absptr;
431 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
432 TTypeEncoding = dwarf::DW_EH_PE_absptr;
433 }
434 break;
435 case Triple::sparcv9:
436 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
437 if (PositionIndependent) {
438 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
439 dwarf::DW_EH_PE_sdata4;
440 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
441 dwarf::DW_EH_PE_sdata4;
442 } else {
443 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
444 TTypeEncoding = dwarf::DW_EH_PE_absptr;
445 }
446 break;
447 case Triple::systemz:
448 // All currently-defined code models guarantee that 4-byte PC-relative
449 // values will be in range.
450 if (PositionIndependent) {
451 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
452 dwarf::DW_EH_PE_sdata4;
453 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
454 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
455 dwarf::DW_EH_PE_sdata4;
456 } else {
457 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
458 LSDAEncoding = dwarf::DW_EH_PE_absptr;
459 TTypeEncoding = dwarf::DW_EH_PE_absptr;
460 }
461 break;
462 default:
463 break;
464 }
465
466 unsigned EHSectionType = T.getArch() == Triple::x86_64
467 ? ELF::SHT_X86_64_UNWIND
468 : ELF::SHT_PROGBITS;
469
470 // Solaris requires different flags for .eh_frame to seemingly every other
471 // platform.
472 unsigned EHSectionFlags = ELF::SHF_ALLOC;
473 if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
474 EHSectionFlags |= ELF::SHF_WRITE;
475
476 // ELF
477 BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
478 ELF::SHF_WRITE | ELF::SHF_ALLOC);
479
480 TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
481 ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
482
483 DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
484 ELF::SHF_WRITE | ELF::SHF_ALLOC);
485
486 ReadOnlySection =
487 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
488
489 TLSDataSection =
490 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
491 ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
492
493 TLSBSSSection = Ctx->getELFSection(
494 ".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
495
496 DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
497 ELF::SHF_ALLOC | ELF::SHF_WRITE);
498
499 MergeableConst4Section =
500 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
501 ELF::SHF_ALLOC | ELF::SHF_MERGE, 4, "");
502
503 MergeableConst8Section =
504 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
505 ELF::SHF_ALLOC | ELF::SHF_MERGE, 8, "");
506
507 MergeableConst16Section =
508 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
509 ELF::SHF_ALLOC | ELF::SHF_MERGE, 16, "");
510
511 MergeableConst32Section =
512 Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS,
513 ELF::SHF_ALLOC | ELF::SHF_MERGE, 32, "");
514
515 // Exception Handling Sections.
516
517 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
518 // it contains relocatable pointers. In PIC mode, this is probably a big
519 // runtime hit for C++ apps. Either the contents of the LSDA need to be
520 // adjusted or this should be a data section.
521 LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
522 ELF::SHF_ALLOC);
523
524 COFFDebugSymbolsSection = nullptr;
525 COFFDebugTypesSection = nullptr;
526
527 unsigned DebugSecType = ELF::SHT_PROGBITS;
528
529 // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
530 // to distinguish among sections contain DWARF and ECOFF debug formats.
531 // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
532 if (T.getArch() == Triple::mips || T.getArch() == Triple::mipsel ||
533 T.getArch() == Triple::mips64 || T.getArch() == Triple::mips64el)
534 DebugSecType = ELF::SHT_MIPS_DWARF;
535
536 // Debug Info Sections.
537 DwarfAbbrevSection =
538 Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);
539 DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0);
540 DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0);
Paul Robinson1f900292018-02-06 20:29:21 +0000541 DwarfLineStrSection =
542 Ctx->getELFSection(".debug_line_str", DebugSecType,
543 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000544 DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0);
545 DwarfPubNamesSection =
546 Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);
547 DwarfPubTypesSection =
548 Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);
549 DwarfGnuPubNamesSection =
550 Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);
551 DwarfGnuPubTypesSection =
552 Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);
553 DwarfStrSection =
554 Ctx->getELFSection(".debug_str", DebugSecType,
555 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
556 DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0);
557 DwarfARangesSection =
558 Ctx->getELFSection(".debug_aranges", DebugSecType, 0);
559 DwarfRangesSection =
560 Ctx->getELFSection(".debug_ranges", DebugSecType, 0);
561 DwarfMacinfoSection =
562 Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);
563
564 // DWARF5 Experimental Debug Info
565
566 // Accelerator Tables
Pavel Labath6088c232018-04-04 14:42:14 +0000567 DwarfDebugNamesSection =
568 Ctx->getELFSection(".debug_names", ELF::SHT_PROGBITS, 0);
Sean Eveson661e4fb2017-11-30 12:43:25 +0000569 DwarfAccelNamesSection =
570 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);
571 DwarfAccelObjCSection =
572 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);
573 DwarfAccelNamespaceSection =
574 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);
575 DwarfAccelTypesSection =
576 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);
577
578 // String Offset and Address Sections
579 DwarfStrOffSection =
580 Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);
581 DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);
582
583 // Fission Sections
584 DwarfInfoDWOSection =
585 Ctx->getELFSection(".debug_info.dwo", DebugSecType, 0);
586 DwarfTypesDWOSection =
587 Ctx->getELFSection(".debug_types.dwo", DebugSecType, 0);
588 DwarfAbbrevDWOSection =
589 Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, 0);
590 DwarfStrDWOSection =
591 Ctx->getELFSection(".debug_str.dwo", DebugSecType,
592 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
593 DwarfLineDWOSection =
594 Ctx->getELFSection(".debug_line.dwo", DebugSecType, 0);
595 DwarfLocDWOSection =
596 Ctx->getELFSection(".debug_loc.dwo", DebugSecType, 0);
597 DwarfStrOffDWOSection =
598 Ctx->getELFSection(".debug_str_offsets.dwo", DebugSecType, 0);
599
600 // DWP Sections
601 DwarfCUIndexSection =
602 Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);
603 DwarfTUIndexSection =
604 Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);
605
606 StackMapSection =
607 Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
608
609 FaultMapSection =
610 Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
611
612 EHFrameSection =
613 Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
Sean Evesona6bcd532017-11-30 13:05:14 +0000614
615 StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);
Sean Eveson661e4fb2017-11-30 12:43:25 +0000616}
617
618void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
619 EHFrameSection = Ctx->getCOFFSection(
620 ".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
621 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
622 SectionKind::getData());
623
624 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
625 // used to indicate to the linker that the text segment contains thumb instructions
626 // and to set the ISA selection bit for calls accordingly.
627 const bool IsThumb = T.getArch() == Triple::thumb;
628
629 CommDirectiveSupportsAlignment = true;
630
631 // COFF
632 BSSSection = Ctx->getCOFFSection(
633 ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
634 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
635 SectionKind::getBSS());
636 TextSection = Ctx->getCOFFSection(
637 ".text",
638 (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |
639 COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
640 COFF::IMAGE_SCN_MEM_READ,
641 SectionKind::getText());
642 DataSection = Ctx->getCOFFSection(
643 ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
644 COFF::IMAGE_SCN_MEM_WRITE,
645 SectionKind::getData());
646 ReadOnlySection = Ctx->getCOFFSection(
647 ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
648 SectionKind::getReadOnly());
649
650 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
651 // though it contains relocatable pointers. In PIC mode, this is probably a
652 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
653 // adjusted or this should be a data section.
654 if (T.getArch() == Triple::x86_64) {
655 // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
656 LSDASection = nullptr;
657 } else {
658 LSDASection = Ctx->getCOFFSection(".gcc_except_table",
659 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
660 COFF::IMAGE_SCN_MEM_READ,
661 SectionKind::getReadOnly());
662 }
663
664 // Debug info.
665 COFFDebugSymbolsSection =
666 Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
667 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
668 COFF::IMAGE_SCN_MEM_READ),
669 SectionKind::getMetadata());
670 COFFDebugTypesSection =
671 Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
672 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
673 COFF::IMAGE_SCN_MEM_READ),
674 SectionKind::getMetadata());
Zachary Turner048f8f92017-12-13 22:33:58 +0000675 COFFGlobalTypeHashesSection = Ctx->getCOFFSection(
676 ".debug$H",
677 (COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
678 COFF::IMAGE_SCN_MEM_READ),
679 SectionKind::getMetadata());
Sean Eveson661e4fb2017-11-30 12:43:25 +0000680
681 DwarfAbbrevSection = Ctx->getCOFFSection(
682 ".debug_abbrev",
683 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
684 COFF::IMAGE_SCN_MEM_READ,
685 SectionKind::getMetadata(), "section_abbrev");
686 DwarfInfoSection = Ctx->getCOFFSection(
687 ".debug_info",
688 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
689 COFF::IMAGE_SCN_MEM_READ,
690 SectionKind::getMetadata(), "section_info");
691 DwarfLineSection = Ctx->getCOFFSection(
692 ".debug_line",
693 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
694 COFF::IMAGE_SCN_MEM_READ,
695 SectionKind::getMetadata(), "section_line");
Paul Robinson1f900292018-02-06 20:29:21 +0000696 DwarfLineStrSection = Ctx->getCOFFSection(
697 ".debug_line_str",
698 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
699 COFF::IMAGE_SCN_MEM_READ,
700 SectionKind::getMetadata(), "section_line_str");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000701 DwarfFrameSection = Ctx->getCOFFSection(
702 ".debug_frame",
703 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
704 COFF::IMAGE_SCN_MEM_READ,
705 SectionKind::getMetadata());
706 DwarfPubNamesSection = Ctx->getCOFFSection(
707 ".debug_pubnames",
708 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
709 COFF::IMAGE_SCN_MEM_READ,
710 SectionKind::getMetadata());
711 DwarfPubTypesSection = Ctx->getCOFFSection(
712 ".debug_pubtypes",
713 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
714 COFF::IMAGE_SCN_MEM_READ,
715 SectionKind::getMetadata());
716 DwarfGnuPubNamesSection = Ctx->getCOFFSection(
717 ".debug_gnu_pubnames",
718 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
719 COFF::IMAGE_SCN_MEM_READ,
720 SectionKind::getMetadata());
721 DwarfGnuPubTypesSection = Ctx->getCOFFSection(
722 ".debug_gnu_pubtypes",
723 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
724 COFF::IMAGE_SCN_MEM_READ,
725 SectionKind::getMetadata());
726 DwarfStrSection = Ctx->getCOFFSection(
727 ".debug_str",
728 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
729 COFF::IMAGE_SCN_MEM_READ,
730 SectionKind::getMetadata(), "info_string");
731 DwarfStrOffSection = Ctx->getCOFFSection(
732 ".debug_str_offsets",
733 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
734 COFF::IMAGE_SCN_MEM_READ,
735 SectionKind::getMetadata(), "section_str_off");
736 DwarfLocSection = Ctx->getCOFFSection(
737 ".debug_loc",
738 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
739 COFF::IMAGE_SCN_MEM_READ,
740 SectionKind::getMetadata(), "section_debug_loc");
741 DwarfARangesSection = Ctx->getCOFFSection(
742 ".debug_aranges",
743 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
744 COFF::IMAGE_SCN_MEM_READ,
745 SectionKind::getMetadata());
746 DwarfRangesSection = Ctx->getCOFFSection(
747 ".debug_ranges",
748 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
749 COFF::IMAGE_SCN_MEM_READ,
750 SectionKind::getMetadata(), "debug_range");
751 DwarfMacinfoSection = Ctx->getCOFFSection(
752 ".debug_macinfo",
753 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
754 COFF::IMAGE_SCN_MEM_READ,
755 SectionKind::getMetadata(), "debug_macinfo");
756 DwarfInfoDWOSection = Ctx->getCOFFSection(
757 ".debug_info.dwo",
758 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
759 COFF::IMAGE_SCN_MEM_READ,
760 SectionKind::getMetadata(), "section_info_dwo");
761 DwarfTypesDWOSection = Ctx->getCOFFSection(
762 ".debug_types.dwo",
763 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
764 COFF::IMAGE_SCN_MEM_READ,
765 SectionKind::getMetadata(), "section_types_dwo");
766 DwarfAbbrevDWOSection = Ctx->getCOFFSection(
767 ".debug_abbrev.dwo",
768 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
769 COFF::IMAGE_SCN_MEM_READ,
770 SectionKind::getMetadata(), "section_abbrev_dwo");
771 DwarfStrDWOSection = Ctx->getCOFFSection(
772 ".debug_str.dwo",
773 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
774 COFF::IMAGE_SCN_MEM_READ,
775 SectionKind::getMetadata(), "skel_string");
776 DwarfLineDWOSection = Ctx->getCOFFSection(
777 ".debug_line.dwo",
778 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
779 COFF::IMAGE_SCN_MEM_READ,
780 SectionKind::getMetadata());
781 DwarfLocDWOSection = Ctx->getCOFFSection(
782 ".debug_loc.dwo",
783 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
784 COFF::IMAGE_SCN_MEM_READ,
785 SectionKind::getMetadata(), "skel_loc");
786 DwarfStrOffDWOSection = Ctx->getCOFFSection(
787 ".debug_str_offsets.dwo",
788 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
789 COFF::IMAGE_SCN_MEM_READ,
790 SectionKind::getMetadata(), "section_str_off_dwo");
791 DwarfAddrSection = Ctx->getCOFFSection(
792 ".debug_addr",
793 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
794 COFF::IMAGE_SCN_MEM_READ,
795 SectionKind::getMetadata(), "addr_sec");
796 DwarfCUIndexSection = Ctx->getCOFFSection(
797 ".debug_cu_index",
798 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
799 COFF::IMAGE_SCN_MEM_READ,
800 SectionKind::getMetadata());
801 DwarfTUIndexSection = Ctx->getCOFFSection(
802 ".debug_tu_index",
803 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
804 COFF::IMAGE_SCN_MEM_READ,
805 SectionKind::getMetadata());
Pavel Labath6088c232018-04-04 14:42:14 +0000806 DwarfDebugNamesSection = Ctx->getCOFFSection(
807 ".debug_names",
808 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
809 COFF::IMAGE_SCN_MEM_READ,
810 SectionKind::getMetadata(), "debug_names_begin");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000811 DwarfAccelNamesSection = Ctx->getCOFFSection(
812 ".apple_names",
813 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
814 COFF::IMAGE_SCN_MEM_READ,
815 SectionKind::getMetadata(), "names_begin");
816 DwarfAccelNamespaceSection = Ctx->getCOFFSection(
817 ".apple_namespaces",
818 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
819 COFF::IMAGE_SCN_MEM_READ,
820 SectionKind::getMetadata(), "namespac_begin");
821 DwarfAccelTypesSection = Ctx->getCOFFSection(
822 ".apple_types",
823 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
824 COFF::IMAGE_SCN_MEM_READ,
825 SectionKind::getMetadata(), "types_begin");
826 DwarfAccelObjCSection = Ctx->getCOFFSection(
827 ".apple_objc",
828 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
829 COFF::IMAGE_SCN_MEM_READ,
830 SectionKind::getMetadata(), "objc_begin");
831
832 DrectveSection = Ctx->getCOFFSection(
833 ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
834 SectionKind::getMetadata());
835
836 PDataSection = Ctx->getCOFFSection(
837 ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
838 SectionKind::getData());
839
840 XDataSection = Ctx->getCOFFSection(
841 ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
842 SectionKind::getData());
843
844 SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO,
845 SectionKind::getMetadata());
846
Adrian McCarthydb2736d2018-01-09 23:49:30 +0000847 GFIDsSection = Ctx->getCOFFSection(".gfids$y",
848 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
849 COFF::IMAGE_SCN_MEM_READ,
850 SectionKind::getMetadata());
851
Sean Eveson661e4fb2017-11-30 12:43:25 +0000852 TLSDataSection = Ctx->getCOFFSection(
853 ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
854 COFF::IMAGE_SCN_MEM_WRITE,
855 SectionKind::getData());
856
857 StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
858 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
859 COFF::IMAGE_SCN_MEM_READ,
860 SectionKind::getReadOnly());
861}
862
863void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
864 // TODO: Set the section types and flags.
865 TextSection = Ctx->getWasmSection(".text", SectionKind::getText());
866 DataSection = Ctx->getWasmSection(".data", SectionKind::getData());
867
868 // TODO: Set the section types and flags.
869 DwarfLineSection = Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());
Paul Robinson1f900292018-02-06 20:29:21 +0000870 DwarfLineStrSection =
871 Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata());
Sean Eveson661e4fb2017-11-30 12:43:25 +0000872 DwarfStrSection = Ctx->getWasmSection(".debug_str", SectionKind::getMetadata());
873 DwarfLocSection = Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());
874 DwarfAbbrevSection = Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata(), "section_abbrev");
875 DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());
876 DwarfRangesSection = Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata(), "debug_range");
877 DwarfMacinfoSection = Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata(), "debug_macinfo");
878 DwarfAddrSection = Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata());
879 DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
880 DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
881 DwarfInfoSection = Ctx->getWasmSection(".debug_info", SectionKind::getMetadata(), "section_info");
882 DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());
883 DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
884 DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
885
886 // TODO: Define more sections.
887}
888
889void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
890 MCContext &ctx,
891 bool LargeCodeModel) {
892 PositionIndependent = PIC;
893 Ctx = &ctx;
894
895 // Common.
896 CommDirectiveSupportsAlignment = true;
897 SupportsWeakOmittedEHFrame = true;
898 SupportsCompactUnwindWithoutEHFrame = false;
899 OmitDwarfIfHaveCompactUnwind = false;
900
901 PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
902 dwarf::DW_EH_PE_absptr;
903
904 CompactUnwindDwarfEHFrameOnly = 0;
905
906 EHFrameSection = nullptr; // Created on demand.
907 CompactUnwindSection = nullptr; // Used only by selected targets.
908 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
909 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
910 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
911 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
912
913 TT = TheTriple;
914
915 switch (TT.getObjectFormat()) {
916 case Triple::MachO:
917 Env = IsMachO;
918 initMachOMCObjectFileInfo(TT);
919 break;
920 case Triple::COFF:
921 if (!TT.isOSWindows())
922 report_fatal_error(
923 "Cannot initialize MC for non-Windows COFF object files.");
924
925 Env = IsCOFF;
926 initCOFFMCObjectFileInfo(TT);
927 break;
928 case Triple::ELF:
929 Env = IsELF;
930 initELFMCObjectFileInfo(TT, LargeCodeModel);
931 break;
932 case Triple::Wasm:
933 Env = IsWasm;
934 initWasmMCObjectFileInfo(TT);
935 break;
936 case Triple::UnknownObjectFormat:
937 report_fatal_error("Cannot initialize MC for unknown object file format.");
938 break;
939 }
940}
941
942MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
943 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
944 0, utostr(Hash));
945}