1 //===-- MObjectFileInfo.cpp - Object File Information ---------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/MC/MCObjectFileInfo.h"
11 #include "llvm/ADT/StringExtras.h"
12 #include "llvm/ADT/Triple.h"
13 #include "llvm/MC/MCContext.h"
14 #include "llvm/MC/MCSection.h"
15 #include "llvm/MC/MCSectionCOFF.h"
16 #include "llvm/MC/MCSectionELF.h"
17 #include "llvm/MC/MCSectionMachO.h"
20 void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
22 IsFunctionEHFrameSymbolPrivate = false;
23 SupportsWeakOmittedEHFrame = false;
25 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
26 | dwarf::DW_EH_PE_sdata4;
27 LSDAEncoding = FDEEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
28 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
29 dwarf::DW_EH_PE_sdata4;
31 // .comm doesn't support alignment before Leopard.
32 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
33 CommDirectiveSupportsAlignment = false;
36 = Ctx->getMachOSection("__TEXT", "__text",
37 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
38 SectionKind::getText());
40 = Ctx->getMachOSection("__DATA", "__data", 0,
41 SectionKind::getDataRel());
43 // BSSSection might not be expected initialized on msvc.
46 TLSDataSection // .tdata
47 = Ctx->getMachOSection("__DATA", "__thread_data",
48 MCSectionMachO::S_THREAD_LOCAL_REGULAR,
49 SectionKind::getDataRel());
50 TLSBSSSection // .tbss
51 = Ctx->getMachOSection("__DATA", "__thread_bss",
52 MCSectionMachO::S_THREAD_LOCAL_ZEROFILL,
53 SectionKind::getThreadBSS());
55 // TODO: Verify datarel below.
57 = Ctx->getMachOSection("__DATA", "__thread_vars",
58 MCSectionMachO::S_THREAD_LOCAL_VARIABLES,
59 SectionKind::getDataRel());
62 = Ctx->getMachOSection("__DATA", "__thread_init",
63 MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
64 SectionKind::getDataRel());
66 CStringSection // .cstring
67 = Ctx->getMachOSection("__TEXT", "__cstring",
68 MCSectionMachO::S_CSTRING_LITERALS,
69 SectionKind::getMergeable1ByteCString());
71 = Ctx->getMachOSection("__TEXT","__ustring", 0,
72 SectionKind::getMergeable2ByteCString());
73 FourByteConstantSection // .literal4
74 = Ctx->getMachOSection("__TEXT", "__literal4",
75 MCSectionMachO::S_4BYTE_LITERALS,
76 SectionKind::getMergeableConst4());
77 EightByteConstantSection // .literal8
78 = Ctx->getMachOSection("__TEXT", "__literal8",
79 MCSectionMachO::S_8BYTE_LITERALS,
80 SectionKind::getMergeableConst8());
82 // ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back
83 // to using it in -static mode.
84 SixteenByteConstantSection = 0;
85 if (RelocM != Reloc::Static &&
86 T.getArch() != Triple::x86_64 && T.getArch() != Triple::ppc64 &&
87 T.getArch() != Triple::ppc64le)
88 SixteenByteConstantSection = // .literal16
89 Ctx->getMachOSection("__TEXT", "__literal16",
90 MCSectionMachO::S_16BYTE_LITERALS,
91 SectionKind::getMergeableConst16());
93 ReadOnlySection // .const
94 = Ctx->getMachOSection("__TEXT", "__const", 0,
95 SectionKind::getReadOnly());
98 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
99 MCSectionMachO::S_COALESCED |
100 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
101 SectionKind::getText());
103 = Ctx->getMachOSection("__TEXT", "__const_coal",
104 MCSectionMachO::S_COALESCED,
105 SectionKind::getReadOnly());
106 ConstDataSection // .const_data
107 = Ctx->getMachOSection("__DATA", "__const", 0,
108 SectionKind::getReadOnlyWithRel());
110 = Ctx->getMachOSection("__DATA","__datacoal_nt",
111 MCSectionMachO::S_COALESCED,
112 SectionKind::getDataRel());
114 = Ctx->getMachOSection("__DATA","__common",
115 MCSectionMachO::S_ZEROFILL,
116 SectionKind::getBSS());
118 = Ctx->getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL,
119 SectionKind::getBSS());
122 LazySymbolPointerSection
123 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
124 MCSectionMachO::S_LAZY_SYMBOL_POINTERS,
125 SectionKind::getMetadata());
126 NonLazySymbolPointerSection
127 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
128 MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
129 SectionKind::getMetadata());
131 if (RelocM == Reloc::Static) {
133 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
134 SectionKind::getDataRel());
136 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
137 SectionKind::getDataRel());
140 = Ctx->getMachOSection("__DATA", "__mod_init_func",
141 MCSectionMachO::S_MOD_INIT_FUNC_POINTERS,
142 SectionKind::getDataRel());
144 = Ctx->getMachOSection("__DATA", "__mod_term_func",
145 MCSectionMachO::S_MOD_TERM_FUNC_POINTERS,
146 SectionKind::getDataRel());
149 // Exception Handling.
150 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
151 SectionKind::getReadOnlyWithRel());
153 COFFDebugSymbolsSection = 0;
155 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) {
156 CompactUnwindSection =
157 Ctx->getMachOSection("__LD", "__compact_unwind",
158 MCSectionMachO::S_ATTR_DEBUG,
159 SectionKind::getReadOnly());
161 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
162 CompactUnwindDwarfEHFrameOnly = 0x04000000;
165 // Debug Information.
166 DwarfAccelNamesSection =
167 Ctx->getMachOSection("__DWARF", "__apple_names",
168 MCSectionMachO::S_ATTR_DEBUG,
169 SectionKind::getMetadata());
170 DwarfAccelObjCSection =
171 Ctx->getMachOSection("__DWARF", "__apple_objc",
172 MCSectionMachO::S_ATTR_DEBUG,
173 SectionKind::getMetadata());
174 // 16 character section limit...
175 DwarfAccelNamespaceSection =
176 Ctx->getMachOSection("__DWARF", "__apple_namespac",
177 MCSectionMachO::S_ATTR_DEBUG,
178 SectionKind::getMetadata());
179 DwarfAccelTypesSection =
180 Ctx->getMachOSection("__DWARF", "__apple_types",
181 MCSectionMachO::S_ATTR_DEBUG,
182 SectionKind::getMetadata());
185 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
186 MCSectionMachO::S_ATTR_DEBUG,
187 SectionKind::getMetadata());
189 Ctx->getMachOSection("__DWARF", "__debug_info",
190 MCSectionMachO::S_ATTR_DEBUG,
191 SectionKind::getMetadata());
193 Ctx->getMachOSection("__DWARF", "__debug_line",
194 MCSectionMachO::S_ATTR_DEBUG,
195 SectionKind::getMetadata());
197 Ctx->getMachOSection("__DWARF", "__debug_frame",
198 MCSectionMachO::S_ATTR_DEBUG,
199 SectionKind::getMetadata());
200 DwarfPubNamesSection =
201 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
202 MCSectionMachO::S_ATTR_DEBUG,
203 SectionKind::getMetadata());
204 DwarfPubTypesSection =
205 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
206 MCSectionMachO::S_ATTR_DEBUG,
207 SectionKind::getMetadata());
208 DwarfGnuPubNamesSection =
209 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
210 MCSectionMachO::S_ATTR_DEBUG,
211 SectionKind::getMetadata());
212 DwarfGnuPubTypesSection =
213 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
214 MCSectionMachO::S_ATTR_DEBUG,
215 SectionKind::getMetadata());
217 Ctx->getMachOSection("__DWARF", "__debug_str",
218 MCSectionMachO::S_ATTR_DEBUG,
219 SectionKind::getMetadata());
221 Ctx->getMachOSection("__DWARF", "__debug_loc",
222 MCSectionMachO::S_ATTR_DEBUG,
223 SectionKind::getMetadata());
224 DwarfARangesSection =
225 Ctx->getMachOSection("__DWARF", "__debug_aranges",
226 MCSectionMachO::S_ATTR_DEBUG,
227 SectionKind::getMetadata());
229 Ctx->getMachOSection("__DWARF", "__debug_ranges",
230 MCSectionMachO::S_ATTR_DEBUG,
231 SectionKind::getMetadata());
232 DwarfMacroInfoSection =
233 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
234 MCSectionMachO::S_ATTR_DEBUG,
235 SectionKind::getMetadata());
236 DwarfDebugInlineSection =
237 Ctx->getMachOSection("__DWARF", "__debug_inlined",
238 MCSectionMachO::S_ATTR_DEBUG,
239 SectionKind::getMetadata());
241 Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
242 SectionKind::getMetadata());
244 TLSExtraDataSection = TLSTLVSection;
247 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
248 if (T.getArch() == Triple::mips ||
249 T.getArch() == Triple::mipsel)
250 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
251 else if (T.getArch() == Triple::mips64 ||
252 T.getArch() == Triple::mips64el)
253 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
255 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
257 if (T.getArch() == Triple::x86) {
258 PersonalityEncoding = (RelocM == Reloc::PIC_)
259 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
260 : dwarf::DW_EH_PE_absptr;
261 LSDAEncoding = (RelocM == Reloc::PIC_)
262 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
263 : dwarf::DW_EH_PE_absptr;
264 FDEEncoding = (RelocM == Reloc::PIC_)
265 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
266 : dwarf::DW_EH_PE_absptr;
267 TTypeEncoding = (RelocM == Reloc::PIC_)
268 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
269 : dwarf::DW_EH_PE_absptr;
270 } else if (T.getArch() == Triple::x86_64) {
271 if (RelocM == Reloc::PIC_) {
272 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
273 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
274 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
275 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
276 (CMModel == CodeModel::Small
277 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
278 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
279 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
280 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
281 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
283 PersonalityEncoding =
284 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
285 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
286 LSDAEncoding = (CMModel == CodeModel::Small)
287 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
288 FDEEncoding = dwarf::DW_EH_PE_udata4;
289 TTypeEncoding = (CMModel == CodeModel::Small)
290 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
292 } else if (T.getArch() == Triple::aarch64) {
293 // The small model guarantees static code/data size < 4GB, but not where it
294 // will be in memory. Most of these could end up >2GB away so even a signed
295 // pc-relative 32-bit address is insufficient, theoretically.
296 if (RelocM == Reloc::PIC_) {
297 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
298 dwarf::DW_EH_PE_sdata8;
299 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
300 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
301 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
302 dwarf::DW_EH_PE_sdata8;
304 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
305 LSDAEncoding = dwarf::DW_EH_PE_absptr;
306 FDEEncoding = dwarf::DW_EH_PE_udata4;
307 TTypeEncoding = dwarf::DW_EH_PE_absptr;
309 } else if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le) {
310 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
311 dwarf::DW_EH_PE_udata8;
312 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
313 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
314 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
315 dwarf::DW_EH_PE_udata8;
316 } else if (T.getArch() == Triple::sparc) {
317 if (RelocM == Reloc::PIC_) {
318 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
319 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
320 dwarf::DW_EH_PE_sdata4;
321 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
322 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
323 dwarf::DW_EH_PE_sdata4;
325 LSDAEncoding = dwarf::DW_EH_PE_absptr;
326 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
327 FDEEncoding = dwarf::DW_EH_PE_udata4;
328 TTypeEncoding = dwarf::DW_EH_PE_absptr;
330 } else if (T.getArch() == Triple::sparcv9) {
331 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
332 if (RelocM == Reloc::PIC_) {
333 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
334 dwarf::DW_EH_PE_sdata4;
335 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
336 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
337 dwarf::DW_EH_PE_sdata4;
339 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
340 FDEEncoding = dwarf::DW_EH_PE_udata4;
341 TTypeEncoding = dwarf::DW_EH_PE_absptr;
343 } else if (T.getArch() == Triple::systemz) {
344 // All currently-defined code models guarantee that 4-byte PC-relative
345 // values will be in range.
346 if (RelocM == Reloc::PIC_) {
347 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
348 dwarf::DW_EH_PE_sdata4;
349 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
350 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
351 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
352 dwarf::DW_EH_PE_sdata4;
354 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
355 LSDAEncoding = dwarf::DW_EH_PE_absptr;
356 FDEEncoding = dwarf::DW_EH_PE_absptr;
357 TTypeEncoding = dwarf::DW_EH_PE_absptr;
361 // Solaris requires different flags for .eh_frame to seemingly every other
363 EHSectionType = ELF::SHT_PROGBITS;
364 EHSectionFlags = ELF::SHF_ALLOC;
365 if (T.getOS() == Triple::Solaris) {
366 if (T.getArch() == Triple::x86_64)
367 EHSectionType = ELF::SHT_X86_64_UNWIND;
369 EHSectionFlags |= ELF::SHF_WRITE;
375 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
376 ELF::SHF_WRITE | ELF::SHF_ALLOC,
377 SectionKind::getBSS());
380 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
383 SectionKind::getText());
386 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
387 ELF::SHF_WRITE |ELF::SHF_ALLOC,
388 SectionKind::getDataRel());
391 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
393 SectionKind::getReadOnly());
396 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
397 ELF::SHF_ALLOC | ELF::SHF_TLS |
399 SectionKind::getThreadData());
402 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
403 ELF::SHF_ALLOC | ELF::SHF_TLS |
405 SectionKind::getThreadBSS());
408 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
409 ELF::SHF_ALLOC |ELF::SHF_WRITE,
410 SectionKind::getDataRel());
412 DataRelLocalSection =
413 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
414 ELF::SHF_ALLOC |ELF::SHF_WRITE,
415 SectionKind::getDataRelLocal());
418 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
419 ELF::SHF_ALLOC |ELF::SHF_WRITE,
420 SectionKind::getReadOnlyWithRel());
422 DataRelROLocalSection =
423 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
424 ELF::SHF_ALLOC |ELF::SHF_WRITE,
425 SectionKind::getReadOnlyWithRelLocal());
427 MergeableConst4Section =
428 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
429 ELF::SHF_ALLOC |ELF::SHF_MERGE,
430 SectionKind::getMergeableConst4());
432 MergeableConst8Section =
433 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
434 ELF::SHF_ALLOC |ELF::SHF_MERGE,
435 SectionKind::getMergeableConst8());
437 MergeableConst16Section =
438 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
439 ELF::SHF_ALLOC |ELF::SHF_MERGE,
440 SectionKind::getMergeableConst16());
443 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
444 ELF::SHF_ALLOC |ELF::SHF_WRITE,
445 SectionKind::getDataRel());
448 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
449 ELF::SHF_ALLOC |ELF::SHF_WRITE,
450 SectionKind::getDataRel());
452 // Exception Handling Sections.
454 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
455 // it contains relocatable pointers. In PIC mode, this is probably a big
456 // runtime hit for C++ apps. Either the contents of the LSDA need to be
457 // adjusted or this should be a data section.
459 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
461 SectionKind::getReadOnly());
463 COFFDebugSymbolsSection = 0;
465 // Debug Info Sections.
467 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
468 SectionKind::getMetadata());
470 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
471 SectionKind::getMetadata());
473 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
474 SectionKind::getMetadata());
476 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
477 SectionKind::getMetadata());
478 DwarfPubNamesSection =
479 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
480 SectionKind::getMetadata());
481 DwarfPubTypesSection =
482 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
483 SectionKind::getMetadata());
484 DwarfGnuPubNamesSection =
485 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
486 SectionKind::getMetadata());
487 DwarfGnuPubTypesSection =
488 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
489 SectionKind::getMetadata());
491 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
492 ELF::SHF_MERGE | ELF::SHF_STRINGS,
493 SectionKind::getMergeable1ByteCString());
495 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
496 SectionKind::getMetadata());
497 DwarfARangesSection =
498 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
499 SectionKind::getMetadata());
501 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
502 SectionKind::getMetadata());
503 DwarfMacroInfoSection =
504 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
505 SectionKind::getMetadata());
507 // DWARF5 Experimental Debug Info
509 // Accelerator Tables
510 DwarfAccelNamesSection =
511 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
512 SectionKind::getMetadata());
513 DwarfAccelObjCSection =
514 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
515 SectionKind::getMetadata());
516 DwarfAccelNamespaceSection =
517 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
518 SectionKind::getMetadata());
519 DwarfAccelTypesSection =
520 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
521 SectionKind::getMetadata());
524 DwarfInfoDWOSection =
525 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
526 SectionKind::getMetadata());
527 DwarfAbbrevDWOSection =
528 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
529 SectionKind::getMetadata());
531 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
532 ELF::SHF_MERGE | ELF::SHF_STRINGS,
533 SectionKind::getMergeable1ByteCString());
534 DwarfLineDWOSection =
535 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
536 SectionKind::getMetadata());
538 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
539 SectionKind::getMetadata());
540 DwarfStrOffDWOSection =
541 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
542 SectionKind::getMetadata());
544 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
545 SectionKind::getMetadata());
549 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
552 Ctx->getCOFFSection(".bss",
553 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
554 COFF::IMAGE_SCN_MEM_READ |
555 COFF::IMAGE_SCN_MEM_WRITE,
556 SectionKind::getBSS());
558 Ctx->getCOFFSection(".text",
559 COFF::IMAGE_SCN_CNT_CODE |
560 COFF::IMAGE_SCN_MEM_EXECUTE |
561 COFF::IMAGE_SCN_MEM_READ,
562 SectionKind::getText());
564 Ctx->getCOFFSection(".data",
565 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
566 COFF::IMAGE_SCN_MEM_READ |
567 COFF::IMAGE_SCN_MEM_WRITE,
568 SectionKind::getDataRel());
570 Ctx->getCOFFSection(".rdata",
571 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
572 COFF::IMAGE_SCN_MEM_READ,
573 SectionKind::getReadOnly());
574 if (T.getOS() == Triple::Win32) {
576 Ctx->getCOFFSection(".CRT$XCU",
577 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
578 COFF::IMAGE_SCN_MEM_READ,
579 SectionKind::getReadOnly());
582 Ctx->getCOFFSection(".ctors",
583 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
584 COFF::IMAGE_SCN_MEM_READ |
585 COFF::IMAGE_SCN_MEM_WRITE,
586 SectionKind::getDataRel());
590 if (T.getOS() == Triple::Win32) {
592 Ctx->getCOFFSection(".CRT$XTX",
593 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
594 COFF::IMAGE_SCN_MEM_READ,
595 SectionKind::getReadOnly());
598 Ctx->getCOFFSection(".dtors",
599 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
600 COFF::IMAGE_SCN_MEM_READ |
601 COFF::IMAGE_SCN_MEM_WRITE,
602 SectionKind::getDataRel());
605 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
606 // though it contains relocatable pointers. In PIC mode, this is probably a
607 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
608 // adjusted or this should be a data section.
610 Ctx->getCOFFSection(".gcc_except_table",
611 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
612 COFF::IMAGE_SCN_MEM_READ,
613 SectionKind::getReadOnly());
616 COFFDebugSymbolsSection =
617 Ctx->getCOFFSection(".debug$S",
618 COFF::IMAGE_SCN_MEM_DISCARDABLE |
619 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
620 COFF::IMAGE_SCN_MEM_READ,
621 SectionKind::getMetadata());
624 Ctx->getCOFFSection(".debug_abbrev",
625 COFF::IMAGE_SCN_MEM_DISCARDABLE |
626 COFF::IMAGE_SCN_MEM_READ,
627 SectionKind::getMetadata());
629 Ctx->getCOFFSection(".debug_info",
630 COFF::IMAGE_SCN_MEM_DISCARDABLE |
631 COFF::IMAGE_SCN_MEM_READ,
632 SectionKind::getMetadata());
634 Ctx->getCOFFSection(".debug_line",
635 COFF::IMAGE_SCN_MEM_DISCARDABLE |
636 COFF::IMAGE_SCN_MEM_READ,
637 SectionKind::getMetadata());
639 Ctx->getCOFFSection(".debug_frame",
640 COFF::IMAGE_SCN_MEM_DISCARDABLE |
641 COFF::IMAGE_SCN_MEM_READ,
642 SectionKind::getMetadata());
643 DwarfPubNamesSection =
644 Ctx->getCOFFSection(".debug_pubnames",
645 COFF::IMAGE_SCN_MEM_DISCARDABLE |
646 COFF::IMAGE_SCN_MEM_READ,
647 SectionKind::getMetadata());
648 DwarfPubTypesSection =
649 Ctx->getCOFFSection(".debug_pubtypes",
650 COFF::IMAGE_SCN_MEM_DISCARDABLE |
651 COFF::IMAGE_SCN_MEM_READ,
652 SectionKind::getMetadata());
653 DwarfGnuPubNamesSection =
654 Ctx->getCOFFSection(".debug_gnu_pubnames",
655 COFF::IMAGE_SCN_MEM_DISCARDABLE |
656 COFF::IMAGE_SCN_MEM_READ,
657 SectionKind::getMetadata());
658 DwarfGnuPubTypesSection =
659 Ctx->getCOFFSection(".debug_gnu_pubtypes",
660 COFF::IMAGE_SCN_MEM_DISCARDABLE |
661 COFF::IMAGE_SCN_MEM_READ,
662 SectionKind::getMetadata());
664 Ctx->getCOFFSection(".debug_str",
665 COFF::IMAGE_SCN_MEM_DISCARDABLE |
666 COFF::IMAGE_SCN_MEM_READ,
667 SectionKind::getMetadata());
669 Ctx->getCOFFSection(".debug_loc",
670 COFF::IMAGE_SCN_MEM_DISCARDABLE |
671 COFF::IMAGE_SCN_MEM_READ,
672 SectionKind::getMetadata());
673 DwarfARangesSection =
674 Ctx->getCOFFSection(".debug_aranges",
675 COFF::IMAGE_SCN_MEM_DISCARDABLE |
676 COFF::IMAGE_SCN_MEM_READ,
677 SectionKind::getMetadata());
679 Ctx->getCOFFSection(".debug_ranges",
680 COFF::IMAGE_SCN_MEM_DISCARDABLE |
681 COFF::IMAGE_SCN_MEM_READ,
682 SectionKind::getMetadata());
683 DwarfMacroInfoSection =
684 Ctx->getCOFFSection(".debug_macinfo",
685 COFF::IMAGE_SCN_MEM_DISCARDABLE |
686 COFF::IMAGE_SCN_MEM_READ,
687 SectionKind::getMetadata());
690 Ctx->getCOFFSection(".drectve",
691 COFF::IMAGE_SCN_LNK_INFO,
692 SectionKind::getMetadata());
695 Ctx->getCOFFSection(".pdata",
696 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
697 COFF::IMAGE_SCN_MEM_READ,
698 SectionKind::getDataRel());
701 Ctx->getCOFFSection(".xdata",
702 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
703 COFF::IMAGE_SCN_MEM_READ,
704 SectionKind::getDataRel());
706 Ctx->getCOFFSection(".tls$",
707 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
708 COFF::IMAGE_SCN_MEM_READ |
709 COFF::IMAGE_SCN_MEM_WRITE,
710 SectionKind::getDataRel());
713 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
721 CommDirectiveSupportsAlignment = true;
722 SupportsWeakOmittedEHFrame = true;
723 IsFunctionEHFrameSymbolPrivate = true;
725 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
726 TTypeEncoding = dwarf::DW_EH_PE_absptr;
728 CompactUnwindDwarfEHFrameOnly = 0;
730 EHFrameSection = 0; // Created on demand.
731 CompactUnwindSection = 0; // Used only by selected targets.
732 DwarfAccelNamesSection = 0; // Used only by selected targets.
733 DwarfAccelObjCSection = 0; // Used only by selected targets.
734 DwarfAccelNamespaceSection = 0; // Used only by selected targets.
735 DwarfAccelTypesSection = 0; // Used only by selected targets.
738 Triple::ArchType Arch = T.getArch();
739 // FIXME: Checking for Arch here to filter out bogus triples such as
740 // cellspu-apple-darwin. Perhaps we should fix in Triple?
741 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
742 Arch == Triple::arm || Arch == Triple::thumb ||
743 Arch == Triple::ppc || Arch == Triple::ppc64 ||
744 Arch == Triple::UnknownArch) &&
745 (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
747 InitMachOMCObjectFileInfo(T);
748 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
749 (T.getEnvironment() != Triple::ELF) &&
750 (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
751 T.getOS() == Triple::Win32)) {
753 InitCOFFMCObjectFileInfo(T);
756 InitELFMCObjectFileInfo(T);
760 const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
761 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
762 SectionKind::getMetadata(), 0, utostr(Hash));
766 MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
767 return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS,
768 ELF::SHF_GROUP, SectionKind::getMetadata(), 0,
772 void MCObjectFileInfo::InitEHFrameSection() {
775 Ctx->getMachOSection("__TEXT", "__eh_frame",
776 MCSectionMachO::S_COALESCED |
777 MCSectionMachO::S_ATTR_NO_TOC |
778 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
779 MCSectionMachO::S_ATTR_LIVE_SUPPORT,
780 SectionKind::getReadOnly());
781 else if (Env == IsELF)
783 Ctx->getELFSection(".eh_frame", EHSectionType,
785 SectionKind::getDataRel());
788 Ctx->getCOFFSection(".eh_frame",
789 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
790 COFF::IMAGE_SCN_MEM_READ |
791 COFF::IMAGE_SCN_MEM_WRITE,
792 SectionKind::getDataRel());