blob: 56c6d89c69f8e439cfa973c25f5119ae6b4bc33c [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.
Alexander Richardson85e200e2018-06-25 16:49:20 +0000532 if (T.isMIPS())
Sean Eveson661e4fb2017-11-30 12:43:25 +0000533 DebugSecType = ELF::SHT_MIPS_DWARF;
534
535 // Debug Info Sections.
536 DwarfAbbrevSection =
537 Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);
538 DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0);
539 DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0);
Paul Robinson1f900292018-02-06 20:29:21 +0000540 DwarfLineStrSection =
541 Ctx->getELFSection(".debug_line_str", DebugSecType,
542 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000543 DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0);
544 DwarfPubNamesSection =
545 Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);
546 DwarfPubTypesSection =
547 Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);
548 DwarfGnuPubNamesSection =
549 Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);
550 DwarfGnuPubTypesSection =
551 Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);
552 DwarfStrSection =
553 Ctx->getELFSection(".debug_str", DebugSecType,
554 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
555 DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0);
556 DwarfARangesSection =
557 Ctx->getELFSection(".debug_aranges", DebugSecType, 0);
558 DwarfRangesSection =
559 Ctx->getELFSection(".debug_ranges", DebugSecType, 0);
560 DwarfMacinfoSection =
561 Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);
562
563 // DWARF5 Experimental Debug Info
564
565 // Accelerator Tables
Pavel Labath6088c232018-04-04 14:42:14 +0000566 DwarfDebugNamesSection =
567 Ctx->getELFSection(".debug_names", ELF::SHT_PROGBITS, 0);
Sean Eveson661e4fb2017-11-30 12:43:25 +0000568 DwarfAccelNamesSection =
569 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);
570 DwarfAccelObjCSection =
571 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);
572 DwarfAccelNamespaceSection =
573 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);
574 DwarfAccelTypesSection =
575 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);
576
577 // String Offset and Address Sections
578 DwarfStrOffSection =
579 Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);
580 DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);
581
582 // Fission Sections
583 DwarfInfoDWOSection =
584 Ctx->getELFSection(".debug_info.dwo", DebugSecType, 0);
585 DwarfTypesDWOSection =
586 Ctx->getELFSection(".debug_types.dwo", DebugSecType, 0);
587 DwarfAbbrevDWOSection =
588 Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, 0);
589 DwarfStrDWOSection =
590 Ctx->getELFSection(".debug_str.dwo", DebugSecType,
591 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
592 DwarfLineDWOSection =
593 Ctx->getELFSection(".debug_line.dwo", DebugSecType, 0);
594 DwarfLocDWOSection =
595 Ctx->getELFSection(".debug_loc.dwo", DebugSecType, 0);
596 DwarfStrOffDWOSection =
597 Ctx->getELFSection(".debug_str_offsets.dwo", DebugSecType, 0);
598
599 // DWP Sections
600 DwarfCUIndexSection =
601 Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);
602 DwarfTUIndexSection =
603 Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);
604
605 StackMapSection =
606 Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
607
608 FaultMapSection =
609 Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
610
611 EHFrameSection =
612 Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
Sean Evesona6bcd532017-11-30 13:05:14 +0000613
614 StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);
Sean Eveson661e4fb2017-11-30 12:43:25 +0000615}
616
617void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
618 EHFrameSection = Ctx->getCOFFSection(
619 ".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
620 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
621 SectionKind::getData());
622
623 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
624 // used to indicate to the linker that the text segment contains thumb instructions
625 // and to set the ISA selection bit for calls accordingly.
626 const bool IsThumb = T.getArch() == Triple::thumb;
627
628 CommDirectiveSupportsAlignment = true;
629
630 // COFF
631 BSSSection = Ctx->getCOFFSection(
632 ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
633 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
634 SectionKind::getBSS());
635 TextSection = Ctx->getCOFFSection(
636 ".text",
637 (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |
638 COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
639 COFF::IMAGE_SCN_MEM_READ,
640 SectionKind::getText());
641 DataSection = Ctx->getCOFFSection(
642 ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
643 COFF::IMAGE_SCN_MEM_WRITE,
644 SectionKind::getData());
645 ReadOnlySection = Ctx->getCOFFSection(
646 ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
647 SectionKind::getReadOnly());
648
649 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
650 // though it contains relocatable pointers. In PIC mode, this is probably a
651 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
652 // adjusted or this should be a data section.
653 if (T.getArch() == Triple::x86_64) {
654 // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
655 LSDASection = nullptr;
656 } else {
657 LSDASection = Ctx->getCOFFSection(".gcc_except_table",
658 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
659 COFF::IMAGE_SCN_MEM_READ,
660 SectionKind::getReadOnly());
661 }
662
663 // Debug info.
664 COFFDebugSymbolsSection =
665 Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
666 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
667 COFF::IMAGE_SCN_MEM_READ),
668 SectionKind::getMetadata());
669 COFFDebugTypesSection =
670 Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
671 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
672 COFF::IMAGE_SCN_MEM_READ),
673 SectionKind::getMetadata());
Zachary Turner048f8f92017-12-13 22:33:58 +0000674 COFFGlobalTypeHashesSection = Ctx->getCOFFSection(
675 ".debug$H",
676 (COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
677 COFF::IMAGE_SCN_MEM_READ),
678 SectionKind::getMetadata());
Sean Eveson661e4fb2017-11-30 12:43:25 +0000679
680 DwarfAbbrevSection = Ctx->getCOFFSection(
681 ".debug_abbrev",
682 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
683 COFF::IMAGE_SCN_MEM_READ,
684 SectionKind::getMetadata(), "section_abbrev");
685 DwarfInfoSection = Ctx->getCOFFSection(
686 ".debug_info",
687 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
688 COFF::IMAGE_SCN_MEM_READ,
689 SectionKind::getMetadata(), "section_info");
690 DwarfLineSection = Ctx->getCOFFSection(
691 ".debug_line",
692 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
693 COFF::IMAGE_SCN_MEM_READ,
694 SectionKind::getMetadata(), "section_line");
Paul Robinson1f900292018-02-06 20:29:21 +0000695 DwarfLineStrSection = Ctx->getCOFFSection(
696 ".debug_line_str",
697 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
698 COFF::IMAGE_SCN_MEM_READ,
699 SectionKind::getMetadata(), "section_line_str");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000700 DwarfFrameSection = Ctx->getCOFFSection(
701 ".debug_frame",
702 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
703 COFF::IMAGE_SCN_MEM_READ,
704 SectionKind::getMetadata());
705 DwarfPubNamesSection = Ctx->getCOFFSection(
706 ".debug_pubnames",
707 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
708 COFF::IMAGE_SCN_MEM_READ,
709 SectionKind::getMetadata());
710 DwarfPubTypesSection = Ctx->getCOFFSection(
711 ".debug_pubtypes",
712 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
713 COFF::IMAGE_SCN_MEM_READ,
714 SectionKind::getMetadata());
715 DwarfGnuPubNamesSection = Ctx->getCOFFSection(
716 ".debug_gnu_pubnames",
717 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
718 COFF::IMAGE_SCN_MEM_READ,
719 SectionKind::getMetadata());
720 DwarfGnuPubTypesSection = Ctx->getCOFFSection(
721 ".debug_gnu_pubtypes",
722 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
723 COFF::IMAGE_SCN_MEM_READ,
724 SectionKind::getMetadata());
725 DwarfStrSection = Ctx->getCOFFSection(
726 ".debug_str",
727 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
728 COFF::IMAGE_SCN_MEM_READ,
729 SectionKind::getMetadata(), "info_string");
730 DwarfStrOffSection = Ctx->getCOFFSection(
731 ".debug_str_offsets",
732 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
733 COFF::IMAGE_SCN_MEM_READ,
734 SectionKind::getMetadata(), "section_str_off");
735 DwarfLocSection = Ctx->getCOFFSection(
736 ".debug_loc",
737 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
738 COFF::IMAGE_SCN_MEM_READ,
739 SectionKind::getMetadata(), "section_debug_loc");
740 DwarfARangesSection = Ctx->getCOFFSection(
741 ".debug_aranges",
742 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
743 COFF::IMAGE_SCN_MEM_READ,
744 SectionKind::getMetadata());
745 DwarfRangesSection = Ctx->getCOFFSection(
746 ".debug_ranges",
747 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
748 COFF::IMAGE_SCN_MEM_READ,
749 SectionKind::getMetadata(), "debug_range");
750 DwarfMacinfoSection = Ctx->getCOFFSection(
751 ".debug_macinfo",
752 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
753 COFF::IMAGE_SCN_MEM_READ,
754 SectionKind::getMetadata(), "debug_macinfo");
755 DwarfInfoDWOSection = Ctx->getCOFFSection(
756 ".debug_info.dwo",
757 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
758 COFF::IMAGE_SCN_MEM_READ,
759 SectionKind::getMetadata(), "section_info_dwo");
760 DwarfTypesDWOSection = Ctx->getCOFFSection(
761 ".debug_types.dwo",
762 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
763 COFF::IMAGE_SCN_MEM_READ,
764 SectionKind::getMetadata(), "section_types_dwo");
765 DwarfAbbrevDWOSection = Ctx->getCOFFSection(
766 ".debug_abbrev.dwo",
767 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
768 COFF::IMAGE_SCN_MEM_READ,
769 SectionKind::getMetadata(), "section_abbrev_dwo");
770 DwarfStrDWOSection = Ctx->getCOFFSection(
771 ".debug_str.dwo",
772 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
773 COFF::IMAGE_SCN_MEM_READ,
774 SectionKind::getMetadata(), "skel_string");
775 DwarfLineDWOSection = Ctx->getCOFFSection(
776 ".debug_line.dwo",
777 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
778 COFF::IMAGE_SCN_MEM_READ,
779 SectionKind::getMetadata());
780 DwarfLocDWOSection = Ctx->getCOFFSection(
781 ".debug_loc.dwo",
782 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
783 COFF::IMAGE_SCN_MEM_READ,
784 SectionKind::getMetadata(), "skel_loc");
785 DwarfStrOffDWOSection = Ctx->getCOFFSection(
786 ".debug_str_offsets.dwo",
787 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
788 COFF::IMAGE_SCN_MEM_READ,
789 SectionKind::getMetadata(), "section_str_off_dwo");
790 DwarfAddrSection = Ctx->getCOFFSection(
791 ".debug_addr",
792 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
793 COFF::IMAGE_SCN_MEM_READ,
794 SectionKind::getMetadata(), "addr_sec");
795 DwarfCUIndexSection = Ctx->getCOFFSection(
796 ".debug_cu_index",
797 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
798 COFF::IMAGE_SCN_MEM_READ,
799 SectionKind::getMetadata());
800 DwarfTUIndexSection = Ctx->getCOFFSection(
801 ".debug_tu_index",
802 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
803 COFF::IMAGE_SCN_MEM_READ,
804 SectionKind::getMetadata());
Pavel Labath6088c232018-04-04 14:42:14 +0000805 DwarfDebugNamesSection = Ctx->getCOFFSection(
806 ".debug_names",
807 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
808 COFF::IMAGE_SCN_MEM_READ,
809 SectionKind::getMetadata(), "debug_names_begin");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000810 DwarfAccelNamesSection = Ctx->getCOFFSection(
811 ".apple_names",
812 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
813 COFF::IMAGE_SCN_MEM_READ,
814 SectionKind::getMetadata(), "names_begin");
815 DwarfAccelNamespaceSection = Ctx->getCOFFSection(
816 ".apple_namespaces",
817 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
818 COFF::IMAGE_SCN_MEM_READ,
819 SectionKind::getMetadata(), "namespac_begin");
820 DwarfAccelTypesSection = Ctx->getCOFFSection(
821 ".apple_types",
822 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
823 COFF::IMAGE_SCN_MEM_READ,
824 SectionKind::getMetadata(), "types_begin");
825 DwarfAccelObjCSection = Ctx->getCOFFSection(
826 ".apple_objc",
827 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
828 COFF::IMAGE_SCN_MEM_READ,
829 SectionKind::getMetadata(), "objc_begin");
830
831 DrectveSection = Ctx->getCOFFSection(
832 ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
833 SectionKind::getMetadata());
834
835 PDataSection = Ctx->getCOFFSection(
836 ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
837 SectionKind::getData());
838
839 XDataSection = Ctx->getCOFFSection(
840 ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
841 SectionKind::getData());
842
843 SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO,
844 SectionKind::getMetadata());
845
Adrian McCarthydb2736d2018-01-09 23:49:30 +0000846 GFIDsSection = Ctx->getCOFFSection(".gfids$y",
847 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
848 COFF::IMAGE_SCN_MEM_READ,
849 SectionKind::getMetadata());
850
Sean Eveson661e4fb2017-11-30 12:43:25 +0000851 TLSDataSection = Ctx->getCOFFSection(
852 ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
853 COFF::IMAGE_SCN_MEM_WRITE,
854 SectionKind::getData());
855
856 StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
857 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
858 COFF::IMAGE_SCN_MEM_READ,
859 SectionKind::getReadOnly());
860}
861
862void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
Sean Eveson661e4fb2017-11-30 12:43:25 +0000863 TextSection = Ctx->getWasmSection(".text", SectionKind::getText());
864 DataSection = Ctx->getWasmSection(".data", SectionKind::getData());
865
Sam Cleggb210c642018-05-10 17:38:35 +0000866 DwarfLineSection =
867 Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());
Paul Robinson1f900292018-02-06 20:29:21 +0000868 DwarfLineStrSection =
869 Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata());
Sam Cleggb210c642018-05-10 17:38:35 +0000870 DwarfStrSection =
871 Ctx->getWasmSection(".debug_str", SectionKind::getMetadata());
872 DwarfLocSection =
873 Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());
874 DwarfAbbrevSection =
875 Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata());
Sean Eveson661e4fb2017-11-30 12:43:25 +0000876 DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());
Sam Cleggb210c642018-05-10 17:38:35 +0000877 DwarfRangesSection =
878 Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata());
879 DwarfMacinfoSection =
880 Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata());
Sean Eveson661e4fb2017-11-30 12:43:25 +0000881 DwarfAddrSection = Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata());
882 DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
883 DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
Sam Cleggb210c642018-05-10 17:38:35 +0000884 DwarfInfoSection =
885 Ctx->getWasmSection(".debug_info", SectionKind::getMetadata());
Sean Eveson661e4fb2017-11-30 12:43:25 +0000886 DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());
887 DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
888 DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
889
890 // TODO: Define more sections.
891}
892
893void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
894 MCContext &ctx,
895 bool LargeCodeModel) {
896 PositionIndependent = PIC;
897 Ctx = &ctx;
898
899 // Common.
900 CommDirectiveSupportsAlignment = true;
901 SupportsWeakOmittedEHFrame = true;
902 SupportsCompactUnwindWithoutEHFrame = false;
903 OmitDwarfIfHaveCompactUnwind = false;
904
905 PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
906 dwarf::DW_EH_PE_absptr;
907
908 CompactUnwindDwarfEHFrameOnly = 0;
909
910 EHFrameSection = nullptr; // Created on demand.
911 CompactUnwindSection = nullptr; // Used only by selected targets.
912 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
913 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
914 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
915 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
916
917 TT = TheTriple;
918
919 switch (TT.getObjectFormat()) {
920 case Triple::MachO:
921 Env = IsMachO;
922 initMachOMCObjectFileInfo(TT);
923 break;
924 case Triple::COFF:
925 if (!TT.isOSWindows())
926 report_fatal_error(
927 "Cannot initialize MC for non-Windows COFF object files.");
928
929 Env = IsCOFF;
930 initCOFFMCObjectFileInfo(TT);
931 break;
932 case Triple::ELF:
933 Env = IsELF;
934 initELFMCObjectFileInfo(TT, LargeCodeModel);
935 break;
936 case Triple::Wasm:
937 Env = IsWasm;
938 initWasmMCObjectFileInfo(TT);
939 break;
940 case Triple::UnknownObjectFormat:
941 report_fatal_error("Cannot initialize MC for unknown object file format.");
942 break;
943 }
944}
945
946MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
947 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
948 0, utostr(Hash));
949}
George Rimardcf59c52018-06-22 10:53:47 +0000950
951MCSection *
952MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const {
953 if (Env != IsELF)
954 return StackSizesSection;
955
956 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
957 unsigned Flags = ELF::SHF_LINK_ORDER;
958 StringRef GroupName;
959 if (const MCSymbol *Group = ElfSec.getGroup()) {
960 GroupName = Group->getName();
961 Flags |= ELF::SHF_GROUP;
962 }
963
964 const MCSymbol *Link = TextSec.getBeginSymbol();
965 auto It = StackSizesUniquing.insert({Link, StackSizesUniquing.size()});
966 unsigned UniqueID = It.first->second;
967
968 return Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, Flags, 0,
969 GroupName, UniqueID, cast<MCSymbolELF>(Link));
970}