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/Triple.h"
12 #include "llvm/ADT/StringExtras.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 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) {
154 CompactUnwindSection =
155 Ctx->getMachOSection("__LD", "__compact_unwind",
156 MCSectionMachO::S_ATTR_DEBUG,
157 SectionKind::getReadOnly());
159 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
160 CompactUnwindDwarfEHFrameOnly = 0x04000000;
163 // Debug Information.
164 DwarfAccelNamesSection =
165 Ctx->getMachOSection("__DWARF", "__apple_names",
166 MCSectionMachO::S_ATTR_DEBUG,
167 SectionKind::getMetadata());
168 DwarfAccelObjCSection =
169 Ctx->getMachOSection("__DWARF", "__apple_objc",
170 MCSectionMachO::S_ATTR_DEBUG,
171 SectionKind::getMetadata());
172 // 16 character section limit...
173 DwarfAccelNamespaceSection =
174 Ctx->getMachOSection("__DWARF", "__apple_namespac",
175 MCSectionMachO::S_ATTR_DEBUG,
176 SectionKind::getMetadata());
177 DwarfAccelTypesSection =
178 Ctx->getMachOSection("__DWARF", "__apple_types",
179 MCSectionMachO::S_ATTR_DEBUG,
180 SectionKind::getMetadata());
183 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
184 MCSectionMachO::S_ATTR_DEBUG,
185 SectionKind::getMetadata());
187 Ctx->getMachOSection("__DWARF", "__debug_info",
188 MCSectionMachO::S_ATTR_DEBUG,
189 SectionKind::getMetadata());
191 Ctx->getMachOSection("__DWARF", "__debug_line",
192 MCSectionMachO::S_ATTR_DEBUG,
193 SectionKind::getMetadata());
195 Ctx->getMachOSection("__DWARF", "__debug_frame",
196 MCSectionMachO::S_ATTR_DEBUG,
197 SectionKind::getMetadata());
198 DwarfPubNamesSection =
199 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
200 MCSectionMachO::S_ATTR_DEBUG,
201 SectionKind::getMetadata());
202 DwarfPubTypesSection =
203 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
204 MCSectionMachO::S_ATTR_DEBUG,
205 SectionKind::getMetadata());
206 DwarfGnuPubNamesSection =
207 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
208 MCSectionMachO::S_ATTR_DEBUG,
209 SectionKind::getMetadata());
210 DwarfGnuPubTypesSection =
211 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
212 MCSectionMachO::S_ATTR_DEBUG,
213 SectionKind::getMetadata());
215 Ctx->getMachOSection("__DWARF", "__debug_str",
216 MCSectionMachO::S_ATTR_DEBUG,
217 SectionKind::getMetadata());
219 Ctx->getMachOSection("__DWARF", "__debug_loc",
220 MCSectionMachO::S_ATTR_DEBUG,
221 SectionKind::getMetadata());
222 DwarfARangesSection =
223 Ctx->getMachOSection("__DWARF", "__debug_aranges",
224 MCSectionMachO::S_ATTR_DEBUG,
225 SectionKind::getMetadata());
227 Ctx->getMachOSection("__DWARF", "__debug_ranges",
228 MCSectionMachO::S_ATTR_DEBUG,
229 SectionKind::getMetadata());
230 DwarfMacroInfoSection =
231 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
232 MCSectionMachO::S_ATTR_DEBUG,
233 SectionKind::getMetadata());
234 DwarfDebugInlineSection =
235 Ctx->getMachOSection("__DWARF", "__debug_inlined",
236 MCSectionMachO::S_ATTR_DEBUG,
237 SectionKind::getMetadata());
239 Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
240 SectionKind::getMetadata());
242 TLSExtraDataSection = TLSTLVSection;
245 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
246 if (T.getArch() == Triple::mips ||
247 T.getArch() == Triple::mipsel)
248 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
249 else if (T.getArch() == Triple::mips64 ||
250 T.getArch() == Triple::mips64el)
251 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
253 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
255 if (T.getArch() == Triple::x86) {
256 PersonalityEncoding = (RelocM == Reloc::PIC_)
257 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
258 : dwarf::DW_EH_PE_absptr;
259 LSDAEncoding = (RelocM == Reloc::PIC_)
260 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
261 : dwarf::DW_EH_PE_absptr;
262 FDEEncoding = (RelocM == Reloc::PIC_)
263 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
264 : dwarf::DW_EH_PE_absptr;
265 TTypeEncoding = (RelocM == Reloc::PIC_)
266 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
267 : dwarf::DW_EH_PE_absptr;
268 } else if (T.getArch() == Triple::x86_64) {
269 if (RelocM == Reloc::PIC_) {
270 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
271 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
272 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
273 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
274 (CMModel == CodeModel::Small
275 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
276 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
277 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
278 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
279 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
281 PersonalityEncoding =
282 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
283 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
284 LSDAEncoding = (CMModel == CodeModel::Small)
285 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
286 FDEEncoding = dwarf::DW_EH_PE_udata4;
287 TTypeEncoding = (CMModel == CodeModel::Small)
288 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
290 } else if (T.getArch() == Triple::aarch64) {
291 // The small model guarantees static code/data size < 4GB, but not where it
292 // will be in memory. Most of these could end up >2GB away so even a signed
293 // pc-relative 32-bit address is insufficient, theoretically.
294 if (RelocM == Reloc::PIC_) {
295 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
296 dwarf::DW_EH_PE_sdata8;
297 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
298 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
299 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
300 dwarf::DW_EH_PE_sdata8;
302 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
303 LSDAEncoding = dwarf::DW_EH_PE_absptr;
304 FDEEncoding = dwarf::DW_EH_PE_udata4;
305 TTypeEncoding = dwarf::DW_EH_PE_absptr;
307 } else if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le) {
308 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
309 dwarf::DW_EH_PE_udata8;
310 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
311 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
312 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
313 dwarf::DW_EH_PE_udata8;
314 } else if (T.getArch() == Triple::systemz) {
315 // All currently-defined code models guarantee that 4-byte PC-relative
316 // values will be in range.
317 if (RelocM == Reloc::PIC_) {
318 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
319 dwarf::DW_EH_PE_sdata4;
320 LSDAEncoding = dwarf::DW_EH_PE_pcrel | 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 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
326 LSDAEncoding = dwarf::DW_EH_PE_absptr;
327 FDEEncoding = dwarf::DW_EH_PE_absptr;
328 TTypeEncoding = dwarf::DW_EH_PE_absptr;
332 // Solaris requires different flags for .eh_frame to seemingly every other
334 EHSectionType = ELF::SHT_PROGBITS;
335 EHSectionFlags = ELF::SHF_ALLOC;
336 if (T.getOS() == Triple::Solaris) {
337 if (T.getArch() == Triple::x86_64)
338 EHSectionType = ELF::SHT_X86_64_UNWIND;
340 EHSectionFlags |= ELF::SHF_WRITE;
346 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
347 ELF::SHF_WRITE | ELF::SHF_ALLOC,
348 SectionKind::getBSS());
351 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
354 SectionKind::getText());
357 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
358 ELF::SHF_WRITE |ELF::SHF_ALLOC,
359 SectionKind::getDataRel());
362 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
364 SectionKind::getReadOnly());
367 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
368 ELF::SHF_ALLOC | ELF::SHF_TLS |
370 SectionKind::getThreadData());
373 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
374 ELF::SHF_ALLOC | ELF::SHF_TLS |
376 SectionKind::getThreadBSS());
379 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
380 ELF::SHF_ALLOC |ELF::SHF_WRITE,
381 SectionKind::getDataRel());
383 DataRelLocalSection =
384 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
385 ELF::SHF_ALLOC |ELF::SHF_WRITE,
386 SectionKind::getDataRelLocal());
389 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
390 ELF::SHF_ALLOC |ELF::SHF_WRITE,
391 SectionKind::getReadOnlyWithRel());
393 DataRelROLocalSection =
394 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
395 ELF::SHF_ALLOC |ELF::SHF_WRITE,
396 SectionKind::getReadOnlyWithRelLocal());
398 MergeableConst4Section =
399 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
400 ELF::SHF_ALLOC |ELF::SHF_MERGE,
401 SectionKind::getMergeableConst4());
403 MergeableConst8Section =
404 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
405 ELF::SHF_ALLOC |ELF::SHF_MERGE,
406 SectionKind::getMergeableConst8());
408 MergeableConst16Section =
409 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
410 ELF::SHF_ALLOC |ELF::SHF_MERGE,
411 SectionKind::getMergeableConst16());
414 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
415 ELF::SHF_ALLOC |ELF::SHF_WRITE,
416 SectionKind::getDataRel());
419 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
420 ELF::SHF_ALLOC |ELF::SHF_WRITE,
421 SectionKind::getDataRel());
423 // Exception Handling Sections.
425 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
426 // it contains relocatable pointers. In PIC mode, this is probably a big
427 // runtime hit for C++ apps. Either the contents of the LSDA need to be
428 // adjusted or this should be a data section.
430 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
432 SectionKind::getReadOnly());
434 // Debug Info Sections.
436 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
437 SectionKind::getMetadata());
439 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
440 SectionKind::getMetadata());
442 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
443 SectionKind::getMetadata());
445 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
446 SectionKind::getMetadata());
447 DwarfPubNamesSection =
448 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
449 SectionKind::getMetadata());
450 DwarfPubTypesSection =
451 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
452 SectionKind::getMetadata());
453 DwarfGnuPubNamesSection =
454 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
455 SectionKind::getMetadata());
456 DwarfGnuPubTypesSection =
457 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
458 SectionKind::getMetadata());
460 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
461 ELF::SHF_MERGE | ELF::SHF_STRINGS,
462 SectionKind::getMergeable1ByteCString());
464 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
465 SectionKind::getMetadata());
466 DwarfARangesSection =
467 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
468 SectionKind::getMetadata());
470 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
471 SectionKind::getMetadata());
472 DwarfMacroInfoSection =
473 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
474 SectionKind::getMetadata());
476 // DWARF5 Experimental Debug Info
478 // Accelerator Tables
479 DwarfAccelNamesSection =
480 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
481 SectionKind::getMetadata());
482 DwarfAccelObjCSection =
483 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
484 SectionKind::getMetadata());
485 DwarfAccelNamespaceSection =
486 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
487 SectionKind::getMetadata());
488 DwarfAccelTypesSection =
489 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
490 SectionKind::getMetadata());
493 DwarfInfoDWOSection =
494 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
495 SectionKind::getMetadata());
496 DwarfAbbrevDWOSection =
497 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
498 SectionKind::getMetadata());
500 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
501 ELF::SHF_MERGE | ELF::SHF_STRINGS,
502 SectionKind::getMergeable1ByteCString());
503 DwarfLineDWOSection =
504 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
505 SectionKind::getMetadata());
507 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
508 SectionKind::getMetadata());
509 DwarfStrOffDWOSection =
510 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
511 SectionKind::getMetadata());
513 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
514 SectionKind::getMetadata());
518 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
521 Ctx->getCOFFSection(".bss",
522 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
523 COFF::IMAGE_SCN_MEM_READ |
524 COFF::IMAGE_SCN_MEM_WRITE,
525 SectionKind::getBSS());
527 Ctx->getCOFFSection(".text",
528 COFF::IMAGE_SCN_CNT_CODE |
529 COFF::IMAGE_SCN_MEM_EXECUTE |
530 COFF::IMAGE_SCN_MEM_READ,
531 SectionKind::getText());
533 Ctx->getCOFFSection(".data",
534 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
535 COFF::IMAGE_SCN_MEM_READ |
536 COFF::IMAGE_SCN_MEM_WRITE,
537 SectionKind::getDataRel());
539 Ctx->getCOFFSection(".rdata",
540 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
541 COFF::IMAGE_SCN_MEM_READ,
542 SectionKind::getReadOnly());
543 if (T.getOS() == Triple::Win32) {
545 Ctx->getCOFFSection(".CRT$XCU",
546 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
547 COFF::IMAGE_SCN_MEM_READ,
548 SectionKind::getReadOnly());
551 Ctx->getCOFFSection(".ctors",
552 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
553 COFF::IMAGE_SCN_MEM_READ |
554 COFF::IMAGE_SCN_MEM_WRITE,
555 SectionKind::getDataRel());
559 if (T.getOS() == Triple::Win32) {
561 Ctx->getCOFFSection(".CRT$XTX",
562 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
563 COFF::IMAGE_SCN_MEM_READ,
564 SectionKind::getReadOnly());
567 Ctx->getCOFFSection(".dtors",
568 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
569 COFF::IMAGE_SCN_MEM_READ |
570 COFF::IMAGE_SCN_MEM_WRITE,
571 SectionKind::getDataRel());
574 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
575 // though it contains relocatable pointers. In PIC mode, this is probably a
576 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
577 // adjusted or this should be a data section.
579 Ctx->getCOFFSection(".gcc_except_table",
580 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
581 COFF::IMAGE_SCN_MEM_READ,
582 SectionKind::getReadOnly());
586 Ctx->getCOFFSection(".debug_abbrev",
587 COFF::IMAGE_SCN_MEM_DISCARDABLE |
588 COFF::IMAGE_SCN_MEM_READ,
589 SectionKind::getMetadata());
591 Ctx->getCOFFSection(".debug_info",
592 COFF::IMAGE_SCN_MEM_DISCARDABLE |
593 COFF::IMAGE_SCN_MEM_READ,
594 SectionKind::getMetadata());
596 Ctx->getCOFFSection(".debug_line",
597 COFF::IMAGE_SCN_MEM_DISCARDABLE |
598 COFF::IMAGE_SCN_MEM_READ,
599 SectionKind::getMetadata());
601 Ctx->getCOFFSection(".debug_frame",
602 COFF::IMAGE_SCN_MEM_DISCARDABLE |
603 COFF::IMAGE_SCN_MEM_READ,
604 SectionKind::getMetadata());
605 DwarfPubNamesSection =
606 Ctx->getCOFFSection(".debug_pubnames",
607 COFF::IMAGE_SCN_MEM_DISCARDABLE |
608 COFF::IMAGE_SCN_MEM_READ,
609 SectionKind::getMetadata());
610 DwarfPubTypesSection =
611 Ctx->getCOFFSection(".debug_pubtypes",
612 COFF::IMAGE_SCN_MEM_DISCARDABLE |
613 COFF::IMAGE_SCN_MEM_READ,
614 SectionKind::getMetadata());
615 DwarfGnuPubNamesSection =
616 Ctx->getCOFFSection(".debug_gnu_pubnames",
617 COFF::IMAGE_SCN_MEM_DISCARDABLE |
618 COFF::IMAGE_SCN_MEM_READ,
619 SectionKind::getMetadata());
620 DwarfGnuPubTypesSection =
621 Ctx->getCOFFSection(".debug_gnu_pubtypes",
622 COFF::IMAGE_SCN_MEM_DISCARDABLE |
623 COFF::IMAGE_SCN_MEM_READ,
624 SectionKind::getMetadata());
626 Ctx->getCOFFSection(".debug_str",
627 COFF::IMAGE_SCN_MEM_DISCARDABLE |
628 COFF::IMAGE_SCN_MEM_READ,
629 SectionKind::getMetadata());
631 Ctx->getCOFFSection(".debug_loc",
632 COFF::IMAGE_SCN_MEM_DISCARDABLE |
633 COFF::IMAGE_SCN_MEM_READ,
634 SectionKind::getMetadata());
635 DwarfARangesSection =
636 Ctx->getCOFFSection(".debug_aranges",
637 COFF::IMAGE_SCN_MEM_DISCARDABLE |
638 COFF::IMAGE_SCN_MEM_READ,
639 SectionKind::getMetadata());
641 Ctx->getCOFFSection(".debug_ranges",
642 COFF::IMAGE_SCN_MEM_DISCARDABLE |
643 COFF::IMAGE_SCN_MEM_READ,
644 SectionKind::getMetadata());
645 DwarfMacroInfoSection =
646 Ctx->getCOFFSection(".debug_macinfo",
647 COFF::IMAGE_SCN_MEM_DISCARDABLE |
648 COFF::IMAGE_SCN_MEM_READ,
649 SectionKind::getMetadata());
652 Ctx->getCOFFSection(".drectve",
653 COFF::IMAGE_SCN_LNK_INFO,
654 SectionKind::getMetadata());
657 Ctx->getCOFFSection(".pdata",
658 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
659 COFF::IMAGE_SCN_MEM_READ,
660 SectionKind::getDataRel());
663 Ctx->getCOFFSection(".xdata",
664 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
665 COFF::IMAGE_SCN_MEM_READ,
666 SectionKind::getDataRel());
668 Ctx->getCOFFSection(".tls$",
669 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
670 COFF::IMAGE_SCN_MEM_READ |
671 COFF::IMAGE_SCN_MEM_WRITE,
672 SectionKind::getDataRel());
675 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
683 CommDirectiveSupportsAlignment = true;
684 SupportsWeakOmittedEHFrame = true;
685 IsFunctionEHFrameSymbolPrivate = true;
687 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
688 TTypeEncoding = dwarf::DW_EH_PE_absptr;
690 CompactUnwindDwarfEHFrameOnly = 0;
692 EHFrameSection = 0; // Created on demand.
693 CompactUnwindSection = 0; // Used only by selected targets.
694 DwarfAccelNamesSection = 0; // Used only by selected targets.
695 DwarfAccelObjCSection = 0; // Used only by selected targets.
696 DwarfAccelNamespaceSection = 0; // Used only by selected targets.
697 DwarfAccelTypesSection = 0; // Used only by selected targets.
700 Triple::ArchType Arch = T.getArch();
701 // FIXME: Checking for Arch here to filter out bogus triples such as
702 // cellspu-apple-darwin. Perhaps we should fix in Triple?
703 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
704 Arch == Triple::arm || Arch == Triple::thumb ||
705 Arch == Triple::ppc || Arch == Triple::ppc64 ||
706 Arch == Triple::UnknownArch) &&
707 (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
709 InitMachOMCObjectFileInfo(T);
710 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
711 (T.getEnvironment() != Triple::ELF) &&
712 (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
713 T.getOS() == Triple::Win32)) {
715 InitCOFFMCObjectFileInfo(T);
718 InitELFMCObjectFileInfo(T);
722 const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
723 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
724 SectionKind::getMetadata(), 0, utostr(Hash));
728 MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
729 return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_GROUP, 0,
730 SectionKind::getMetadata(), 0, utostr(Hash));
733 void MCObjectFileInfo::InitEHFrameSection() {
736 Ctx->getMachOSection("__TEXT", "__eh_frame",
737 MCSectionMachO::S_COALESCED |
738 MCSectionMachO::S_ATTR_NO_TOC |
739 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
740 MCSectionMachO::S_ATTR_LIVE_SUPPORT,
741 SectionKind::getReadOnly());
742 else if (Env == IsELF)
744 Ctx->getELFSection(".eh_frame", EHSectionType,
746 SectionKind::getDataRel());
749 Ctx->getCOFFSection(".eh_frame",
750 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
751 COFF::IMAGE_SCN_MEM_READ |
752 COFF::IMAGE_SCN_MEM_WRITE,
753 SectionKind::getDataRel());