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/MC/MCContext.h"
13 #include "llvm/MC/MCSection.h"
14 #include "llvm/MC/MCSectionCOFF.h"
15 #include "llvm/MC/MCSectionELF.h"
16 #include "llvm/MC/MCSectionMachO.h"
19 void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
21 IsFunctionEHFrameSymbolPrivate = false;
22 SupportsWeakOmittedEHFrame = false;
24 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
25 | dwarf::DW_EH_PE_sdata4;
26 LSDAEncoding = FDEEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
27 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
28 dwarf::DW_EH_PE_sdata4;
30 // .comm doesn't support alignment before Leopard.
31 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
32 CommDirectiveSupportsAlignment = false;
35 = Ctx->getMachOSection("__TEXT", "__text",
36 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
37 SectionKind::getText());
39 = Ctx->getMachOSection("__DATA", "__data", 0,
40 SectionKind::getDataRel());
42 // BSSSection might not be expected initialized on msvc.
45 TLSDataSection // .tdata
46 = Ctx->getMachOSection("__DATA", "__thread_data",
47 MCSectionMachO::S_THREAD_LOCAL_REGULAR,
48 SectionKind::getDataRel());
49 TLSBSSSection // .tbss
50 = Ctx->getMachOSection("__DATA", "__thread_bss",
51 MCSectionMachO::S_THREAD_LOCAL_ZEROFILL,
52 SectionKind::getThreadBSS());
54 // TODO: Verify datarel below.
56 = Ctx->getMachOSection("__DATA", "__thread_vars",
57 MCSectionMachO::S_THREAD_LOCAL_VARIABLES,
58 SectionKind::getDataRel());
61 = Ctx->getMachOSection("__DATA", "__thread_init",
62 MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
63 SectionKind::getDataRel());
65 CStringSection // .cstring
66 = Ctx->getMachOSection("__TEXT", "__cstring",
67 MCSectionMachO::S_CSTRING_LITERALS,
68 SectionKind::getMergeable1ByteCString());
70 = Ctx->getMachOSection("__TEXT","__ustring", 0,
71 SectionKind::getMergeable2ByteCString());
72 FourByteConstantSection // .literal4
73 = Ctx->getMachOSection("__TEXT", "__literal4",
74 MCSectionMachO::S_4BYTE_LITERALS,
75 SectionKind::getMergeableConst4());
76 EightByteConstantSection // .literal8
77 = Ctx->getMachOSection("__TEXT", "__literal8",
78 MCSectionMachO::S_8BYTE_LITERALS,
79 SectionKind::getMergeableConst8());
81 // ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back
82 // to using it in -static mode.
83 SixteenByteConstantSection = 0;
84 if (RelocM != Reloc::Static &&
85 T.getArch() != Triple::x86_64 && T.getArch() != Triple::ppc64 &&
86 T.getArch() != Triple::ppc64le)
87 SixteenByteConstantSection = // .literal16
88 Ctx->getMachOSection("__TEXT", "__literal16",
89 MCSectionMachO::S_16BYTE_LITERALS,
90 SectionKind::getMergeableConst16());
92 ReadOnlySection // .const
93 = Ctx->getMachOSection("__TEXT", "__const", 0,
94 SectionKind::getReadOnly());
97 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
98 MCSectionMachO::S_COALESCED |
99 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
100 SectionKind::getText());
102 = Ctx->getMachOSection("__TEXT", "__const_coal",
103 MCSectionMachO::S_COALESCED,
104 SectionKind::getReadOnly());
105 ConstDataSection // .const_data
106 = Ctx->getMachOSection("__DATA", "__const", 0,
107 SectionKind::getReadOnlyWithRel());
109 = Ctx->getMachOSection("__DATA","__datacoal_nt",
110 MCSectionMachO::S_COALESCED,
111 SectionKind::getDataRel());
113 = Ctx->getMachOSection("__DATA","__common",
114 MCSectionMachO::S_ZEROFILL,
115 SectionKind::getBSS());
117 = Ctx->getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL,
118 SectionKind::getBSS());
121 LazySymbolPointerSection
122 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
123 MCSectionMachO::S_LAZY_SYMBOL_POINTERS,
124 SectionKind::getMetadata());
125 NonLazySymbolPointerSection
126 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
127 MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
128 SectionKind::getMetadata());
130 if (RelocM == Reloc::Static) {
132 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
133 SectionKind::getDataRel());
135 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
136 SectionKind::getDataRel());
139 = Ctx->getMachOSection("__DATA", "__mod_init_func",
140 MCSectionMachO::S_MOD_INIT_FUNC_POINTERS,
141 SectionKind::getDataRel());
143 = Ctx->getMachOSection("__DATA", "__mod_term_func",
144 MCSectionMachO::S_MOD_TERM_FUNC_POINTERS,
145 SectionKind::getDataRel());
148 // Exception Handling.
149 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
150 SectionKind::getReadOnlyWithRel());
152 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) {
153 CompactUnwindSection =
154 Ctx->getMachOSection("__LD", "__compact_unwind",
155 MCSectionMachO::S_ATTR_DEBUG,
156 SectionKind::getReadOnly());
158 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
159 CompactUnwindDwarfEHFrameOnly = 0x04000000;
162 // Debug Information.
163 DwarfAccelNamesSection =
164 Ctx->getMachOSection("__DWARF", "__apple_names",
165 MCSectionMachO::S_ATTR_DEBUG,
166 SectionKind::getMetadata());
167 DwarfAccelObjCSection =
168 Ctx->getMachOSection("__DWARF", "__apple_objc",
169 MCSectionMachO::S_ATTR_DEBUG,
170 SectionKind::getMetadata());
171 // 16 character section limit...
172 DwarfAccelNamespaceSection =
173 Ctx->getMachOSection("__DWARF", "__apple_namespac",
174 MCSectionMachO::S_ATTR_DEBUG,
175 SectionKind::getMetadata());
176 DwarfAccelTypesSection =
177 Ctx->getMachOSection("__DWARF", "__apple_types",
178 MCSectionMachO::S_ATTR_DEBUG,
179 SectionKind::getMetadata());
182 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
183 MCSectionMachO::S_ATTR_DEBUG,
184 SectionKind::getMetadata());
186 Ctx->getMachOSection("__DWARF", "__debug_info",
187 MCSectionMachO::S_ATTR_DEBUG,
188 SectionKind::getMetadata());
190 Ctx->getMachOSection("__DWARF", "__debug_line",
191 MCSectionMachO::S_ATTR_DEBUG,
192 SectionKind::getMetadata());
194 Ctx->getMachOSection("__DWARF", "__debug_frame",
195 MCSectionMachO::S_ATTR_DEBUG,
196 SectionKind::getMetadata());
197 DwarfPubNamesSection =
198 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
199 MCSectionMachO::S_ATTR_DEBUG,
200 SectionKind::getMetadata());
201 DwarfPubTypesSection =
202 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
203 MCSectionMachO::S_ATTR_DEBUG,
204 SectionKind::getMetadata());
205 DwarfGnuPubNamesSection =
206 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
207 MCSectionMachO::S_ATTR_DEBUG,
208 SectionKind::getMetadata());
209 DwarfGnuPubTypesSection =
210 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
211 MCSectionMachO::S_ATTR_DEBUG,
212 SectionKind::getMetadata());
214 Ctx->getMachOSection("__DWARF", "__debug_str",
215 MCSectionMachO::S_ATTR_DEBUG,
216 SectionKind::getMetadata());
218 Ctx->getMachOSection("__DWARF", "__debug_loc",
219 MCSectionMachO::S_ATTR_DEBUG,
220 SectionKind::getMetadata());
221 DwarfARangesSection =
222 Ctx->getMachOSection("__DWARF", "__debug_aranges",
223 MCSectionMachO::S_ATTR_DEBUG,
224 SectionKind::getMetadata());
226 Ctx->getMachOSection("__DWARF", "__debug_ranges",
227 MCSectionMachO::S_ATTR_DEBUG,
228 SectionKind::getMetadata());
229 DwarfMacroInfoSection =
230 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
231 MCSectionMachO::S_ATTR_DEBUG,
232 SectionKind::getMetadata());
233 DwarfDebugInlineSection =
234 Ctx->getMachOSection("__DWARF", "__debug_inlined",
235 MCSectionMachO::S_ATTR_DEBUG,
236 SectionKind::getMetadata());
238 Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
239 SectionKind::getMetadata());
241 TLSExtraDataSection = TLSTLVSection;
244 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
245 if (T.getArch() == Triple::mips ||
246 T.getArch() == Triple::mipsel)
247 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
248 else if (T.getArch() == Triple::mips64 ||
249 T.getArch() == Triple::mips64el)
250 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
252 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
254 if (T.getArch() == Triple::x86) {
255 PersonalityEncoding = (RelocM == Reloc::PIC_)
256 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
257 : dwarf::DW_EH_PE_absptr;
258 LSDAEncoding = (RelocM == Reloc::PIC_)
259 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
260 : dwarf::DW_EH_PE_absptr;
261 FDEEncoding = (RelocM == Reloc::PIC_)
262 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
263 : dwarf::DW_EH_PE_absptr;
264 TTypeEncoding = (RelocM == Reloc::PIC_)
265 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
266 : dwarf::DW_EH_PE_absptr;
267 } else if (T.getArch() == Triple::x86_64) {
268 if (RelocM == Reloc::PIC_) {
269 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
270 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
271 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
272 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
273 (CMModel == CodeModel::Small
274 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
275 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
276 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
277 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
278 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
280 PersonalityEncoding =
281 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
282 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
283 LSDAEncoding = (CMModel == CodeModel::Small)
284 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
285 FDEEncoding = dwarf::DW_EH_PE_udata4;
286 TTypeEncoding = (CMModel == CodeModel::Small)
287 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
289 } else if (T.getArch() == Triple::aarch64) {
290 // The small model guarantees static code/data size < 4GB, but not where it
291 // will be in memory. Most of these could end up >2GB away so even a signed
292 // pc-relative 32-bit address is insufficient, theoretically.
293 if (RelocM == Reloc::PIC_) {
294 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
295 dwarf::DW_EH_PE_sdata8;
296 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
297 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
298 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
299 dwarf::DW_EH_PE_sdata8;
301 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
302 LSDAEncoding = dwarf::DW_EH_PE_absptr;
303 FDEEncoding = dwarf::DW_EH_PE_udata4;
304 TTypeEncoding = dwarf::DW_EH_PE_absptr;
306 } else if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le) {
307 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
308 dwarf::DW_EH_PE_udata8;
309 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
310 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
311 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
312 dwarf::DW_EH_PE_udata8;
313 } else if (T.getArch() == Triple::sparc) {
314 if (RelocM == Reloc::PIC_) {
315 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
316 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
317 dwarf::DW_EH_PE_sdata4;
318 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
319 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
320 dwarf::DW_EH_PE_sdata4;
322 LSDAEncoding = dwarf::DW_EH_PE_absptr;
323 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
324 FDEEncoding = dwarf::DW_EH_PE_udata4;
325 TTypeEncoding = dwarf::DW_EH_PE_absptr;
327 } else if (T.getArch() == Triple::sparcv9) {
328 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
329 if (RelocM == Reloc::PIC_) {
330 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
331 dwarf::DW_EH_PE_sdata4;
332 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
333 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
334 dwarf::DW_EH_PE_sdata4;
336 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
337 FDEEncoding = dwarf::DW_EH_PE_udata4;
338 TTypeEncoding = dwarf::DW_EH_PE_absptr;
340 } else if (T.getArch() == Triple::systemz) {
341 // All currently-defined code models guarantee that 4-byte PC-relative
342 // values will be in range.
343 if (RelocM == Reloc::PIC_) {
344 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
345 dwarf::DW_EH_PE_sdata4;
346 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
347 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
348 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
349 dwarf::DW_EH_PE_sdata4;
351 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
352 LSDAEncoding = dwarf::DW_EH_PE_absptr;
353 FDEEncoding = dwarf::DW_EH_PE_absptr;
354 TTypeEncoding = dwarf::DW_EH_PE_absptr;
358 // Solaris requires different flags for .eh_frame to seemingly every other
360 EHSectionType = ELF::SHT_PROGBITS;
361 EHSectionFlags = ELF::SHF_ALLOC;
362 if (T.getOS() == Triple::Solaris) {
363 if (T.getArch() == Triple::x86_64)
364 EHSectionType = ELF::SHT_X86_64_UNWIND;
366 EHSectionFlags |= ELF::SHF_WRITE;
372 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
373 ELF::SHF_WRITE | ELF::SHF_ALLOC,
374 SectionKind::getBSS());
377 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
380 SectionKind::getText());
383 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
384 ELF::SHF_WRITE |ELF::SHF_ALLOC,
385 SectionKind::getDataRel());
388 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
390 SectionKind::getReadOnly());
393 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
394 ELF::SHF_ALLOC | ELF::SHF_TLS |
396 SectionKind::getThreadData());
399 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
400 ELF::SHF_ALLOC | ELF::SHF_TLS |
402 SectionKind::getThreadBSS());
405 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
406 ELF::SHF_ALLOC |ELF::SHF_WRITE,
407 SectionKind::getDataRel());
409 DataRelLocalSection =
410 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
411 ELF::SHF_ALLOC |ELF::SHF_WRITE,
412 SectionKind::getDataRelLocal());
415 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
416 ELF::SHF_ALLOC |ELF::SHF_WRITE,
417 SectionKind::getReadOnlyWithRel());
419 DataRelROLocalSection =
420 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
421 ELF::SHF_ALLOC |ELF::SHF_WRITE,
422 SectionKind::getReadOnlyWithRelLocal());
424 MergeableConst4Section =
425 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
426 ELF::SHF_ALLOC |ELF::SHF_MERGE,
427 SectionKind::getMergeableConst4());
429 MergeableConst8Section =
430 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
431 ELF::SHF_ALLOC |ELF::SHF_MERGE,
432 SectionKind::getMergeableConst8());
434 MergeableConst16Section =
435 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
436 ELF::SHF_ALLOC |ELF::SHF_MERGE,
437 SectionKind::getMergeableConst16());
440 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
441 ELF::SHF_ALLOC |ELF::SHF_WRITE,
442 SectionKind::getDataRel());
445 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
446 ELF::SHF_ALLOC |ELF::SHF_WRITE,
447 SectionKind::getDataRel());
449 // Exception Handling Sections.
451 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
452 // it contains relocatable pointers. In PIC mode, this is probably a big
453 // runtime hit for C++ apps. Either the contents of the LSDA need to be
454 // adjusted or this should be a data section.
456 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
458 SectionKind::getReadOnly());
460 // Debug Info Sections.
462 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
463 SectionKind::getMetadata());
465 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
466 SectionKind::getMetadata());
468 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
469 SectionKind::getMetadata());
471 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
472 SectionKind::getMetadata());
473 DwarfPubNamesSection =
474 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
475 SectionKind::getMetadata());
476 DwarfPubTypesSection =
477 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
478 SectionKind::getMetadata());
479 DwarfGnuPubNamesSection =
480 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
481 SectionKind::getMetadata());
482 DwarfGnuPubTypesSection =
483 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
484 SectionKind::getMetadata());
486 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
487 ELF::SHF_MERGE | ELF::SHF_STRINGS,
488 SectionKind::getMergeable1ByteCString());
490 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
491 SectionKind::getMetadata());
492 DwarfARangesSection =
493 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
494 SectionKind::getMetadata());
496 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
497 SectionKind::getMetadata());
498 DwarfMacroInfoSection =
499 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
500 SectionKind::getMetadata());
502 // DWARF5 Experimental Debug Info
504 // Accelerator Tables
505 DwarfAccelNamesSection =
506 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
507 SectionKind::getMetadata());
508 DwarfAccelObjCSection =
509 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
510 SectionKind::getMetadata());
511 DwarfAccelNamespaceSection =
512 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
513 SectionKind::getMetadata());
514 DwarfAccelTypesSection =
515 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
516 SectionKind::getMetadata());
519 DwarfInfoDWOSection =
520 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
521 SectionKind::getMetadata());
522 DwarfAbbrevDWOSection =
523 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
524 SectionKind::getMetadata());
526 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
527 ELF::SHF_MERGE | ELF::SHF_STRINGS,
528 SectionKind::getMergeable1ByteCString());
529 DwarfLineDWOSection =
530 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
531 SectionKind::getMetadata());
533 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
534 SectionKind::getMetadata());
535 DwarfStrOffDWOSection =
536 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
537 SectionKind::getMetadata());
539 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
540 SectionKind::getMetadata());
544 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
547 Ctx->getCOFFSection(".bss",
548 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
549 COFF::IMAGE_SCN_MEM_READ |
550 COFF::IMAGE_SCN_MEM_WRITE,
551 SectionKind::getBSS());
553 Ctx->getCOFFSection(".text",
554 COFF::IMAGE_SCN_CNT_CODE |
555 COFF::IMAGE_SCN_MEM_EXECUTE |
556 COFF::IMAGE_SCN_MEM_READ,
557 SectionKind::getText());
559 Ctx->getCOFFSection(".data",
560 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
561 COFF::IMAGE_SCN_MEM_READ |
562 COFF::IMAGE_SCN_MEM_WRITE,
563 SectionKind::getDataRel());
565 Ctx->getCOFFSection(".rdata",
566 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
567 COFF::IMAGE_SCN_MEM_READ,
568 SectionKind::getReadOnly());
569 if (T.getOS() == Triple::Win32) {
571 Ctx->getCOFFSection(".CRT$XCU",
572 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
573 COFF::IMAGE_SCN_MEM_READ,
574 SectionKind::getReadOnly());
577 Ctx->getCOFFSection(".ctors",
578 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
579 COFF::IMAGE_SCN_MEM_READ |
580 COFF::IMAGE_SCN_MEM_WRITE,
581 SectionKind::getDataRel());
585 if (T.getOS() == Triple::Win32) {
587 Ctx->getCOFFSection(".CRT$XTX",
588 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
589 COFF::IMAGE_SCN_MEM_READ,
590 SectionKind::getReadOnly());
593 Ctx->getCOFFSection(".dtors",
594 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
595 COFF::IMAGE_SCN_MEM_READ |
596 COFF::IMAGE_SCN_MEM_WRITE,
597 SectionKind::getDataRel());
600 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
601 // though it contains relocatable pointers. In PIC mode, this is probably a
602 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
603 // adjusted or this should be a data section.
605 Ctx->getCOFFSection(".gcc_except_table",
606 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
607 COFF::IMAGE_SCN_MEM_READ,
608 SectionKind::getReadOnly());
612 Ctx->getCOFFSection(".debug_abbrev",
613 COFF::IMAGE_SCN_MEM_DISCARDABLE |
614 COFF::IMAGE_SCN_MEM_READ,
615 SectionKind::getMetadata());
617 Ctx->getCOFFSection(".debug_info",
618 COFF::IMAGE_SCN_MEM_DISCARDABLE |
619 COFF::IMAGE_SCN_MEM_READ,
620 SectionKind::getMetadata());
622 Ctx->getCOFFSection(".debug_line",
623 COFF::IMAGE_SCN_MEM_DISCARDABLE |
624 COFF::IMAGE_SCN_MEM_READ,
625 SectionKind::getMetadata());
627 Ctx->getCOFFSection(".debug_frame",
628 COFF::IMAGE_SCN_MEM_DISCARDABLE |
629 COFF::IMAGE_SCN_MEM_READ,
630 SectionKind::getMetadata());
631 DwarfPubNamesSection =
632 Ctx->getCOFFSection(".debug_pubnames",
633 COFF::IMAGE_SCN_MEM_DISCARDABLE |
634 COFF::IMAGE_SCN_MEM_READ,
635 SectionKind::getMetadata());
636 DwarfPubTypesSection =
637 Ctx->getCOFFSection(".debug_pubtypes",
638 COFF::IMAGE_SCN_MEM_DISCARDABLE |
639 COFF::IMAGE_SCN_MEM_READ,
640 SectionKind::getMetadata());
641 DwarfGnuPubNamesSection =
642 Ctx->getCOFFSection(".debug_gnu_pubnames",
643 COFF::IMAGE_SCN_MEM_DISCARDABLE |
644 COFF::IMAGE_SCN_MEM_READ,
645 SectionKind::getMetadata());
646 DwarfGnuPubTypesSection =
647 Ctx->getCOFFSection(".debug_gnu_pubtypes",
648 COFF::IMAGE_SCN_MEM_DISCARDABLE |
649 COFF::IMAGE_SCN_MEM_READ,
650 SectionKind::getMetadata());
652 Ctx->getCOFFSection(".debug_str",
653 COFF::IMAGE_SCN_MEM_DISCARDABLE |
654 COFF::IMAGE_SCN_MEM_READ,
655 SectionKind::getMetadata());
657 Ctx->getCOFFSection(".debug_loc",
658 COFF::IMAGE_SCN_MEM_DISCARDABLE |
659 COFF::IMAGE_SCN_MEM_READ,
660 SectionKind::getMetadata());
661 DwarfARangesSection =
662 Ctx->getCOFFSection(".debug_aranges",
663 COFF::IMAGE_SCN_MEM_DISCARDABLE |
664 COFF::IMAGE_SCN_MEM_READ,
665 SectionKind::getMetadata());
667 Ctx->getCOFFSection(".debug_ranges",
668 COFF::IMAGE_SCN_MEM_DISCARDABLE |
669 COFF::IMAGE_SCN_MEM_READ,
670 SectionKind::getMetadata());
671 DwarfMacroInfoSection =
672 Ctx->getCOFFSection(".debug_macinfo",
673 COFF::IMAGE_SCN_MEM_DISCARDABLE |
674 COFF::IMAGE_SCN_MEM_READ,
675 SectionKind::getMetadata());
678 Ctx->getCOFFSection(".drectve",
679 COFF::IMAGE_SCN_LNK_INFO,
680 SectionKind::getMetadata());
683 Ctx->getCOFFSection(".pdata",
684 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
685 COFF::IMAGE_SCN_MEM_READ,
686 SectionKind::getDataRel());
689 Ctx->getCOFFSection(".xdata",
690 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
691 COFF::IMAGE_SCN_MEM_READ,
692 SectionKind::getDataRel());
694 Ctx->getCOFFSection(".tls$",
695 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
696 COFF::IMAGE_SCN_MEM_READ |
697 COFF::IMAGE_SCN_MEM_WRITE,
698 SectionKind::getDataRel());
701 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
709 CommDirectiveSupportsAlignment = true;
710 SupportsWeakOmittedEHFrame = true;
711 IsFunctionEHFrameSymbolPrivate = true;
713 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
714 TTypeEncoding = dwarf::DW_EH_PE_absptr;
716 CompactUnwindDwarfEHFrameOnly = 0;
718 EHFrameSection = 0; // Created on demand.
719 CompactUnwindSection = 0; // Used only by selected targets.
720 DwarfAccelNamesSection = 0; // Used only by selected targets.
721 DwarfAccelObjCSection = 0; // Used only by selected targets.
722 DwarfAccelNamespaceSection = 0; // Used only by selected targets.
723 DwarfAccelTypesSection = 0; // Used only by selected targets.
726 Triple::ArchType Arch = T.getArch();
727 // FIXME: Checking for Arch here to filter out bogus triples such as
728 // cellspu-apple-darwin. Perhaps we should fix in Triple?
729 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
730 Arch == Triple::arm || Arch == Triple::thumb ||
731 Arch == Triple::ppc || Arch == Triple::ppc64 ||
732 Arch == Triple::UnknownArch) &&
733 (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
735 InitMachOMCObjectFileInfo(T);
736 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
737 (T.getEnvironment() != Triple::ELF) &&
738 (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
739 T.getOS() == Triple::Win32)) {
741 InitCOFFMCObjectFileInfo(T);
744 InitELFMCObjectFileInfo(T);
748 void MCObjectFileInfo::InitEHFrameSection() {
751 Ctx->getMachOSection("__TEXT", "__eh_frame",
752 MCSectionMachO::S_COALESCED |
753 MCSectionMachO::S_ATTR_NO_TOC |
754 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
755 MCSectionMachO::S_ATTR_LIVE_SUPPORT,
756 SectionKind::getReadOnly());
757 else if (Env == IsELF)
759 Ctx->getELFSection(".eh_frame", EHSectionType,
761 SectionKind::getDataRel());
764 Ctx->getCOFFSection(".eh_frame",
765 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
766 COFF::IMAGE_SCN_MEM_READ |
767 COFF::IMAGE_SCN_MEM_WRITE,
768 SectionKind::getDataRel());