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 SixteenByteConstantSection // .literal16
83 = Ctx->getMachOSection("__TEXT", "__literal16",
84 MCSectionMachO::S_16BYTE_LITERALS,
85 SectionKind::getMergeableConst16());
87 ReadOnlySection // .const
88 = Ctx->getMachOSection("__TEXT", "__const", 0,
89 SectionKind::getReadOnly());
92 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
93 MCSectionMachO::S_COALESCED |
94 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
95 SectionKind::getText());
97 = Ctx->getMachOSection("__TEXT", "__const_coal",
98 MCSectionMachO::S_COALESCED,
99 SectionKind::getReadOnly());
100 ConstDataSection // .const_data
101 = Ctx->getMachOSection("__DATA", "__const", 0,
102 SectionKind::getReadOnlyWithRel());
104 = Ctx->getMachOSection("__DATA","__datacoal_nt",
105 MCSectionMachO::S_COALESCED,
106 SectionKind::getDataRel());
108 = Ctx->getMachOSection("__DATA","__common",
109 MCSectionMachO::S_ZEROFILL,
110 SectionKind::getBSS());
112 = Ctx->getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL,
113 SectionKind::getBSS());
116 LazySymbolPointerSection
117 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
118 MCSectionMachO::S_LAZY_SYMBOL_POINTERS,
119 SectionKind::getMetadata());
120 NonLazySymbolPointerSection
121 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
122 MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
123 SectionKind::getMetadata());
125 if (RelocM == Reloc::Static) {
127 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
128 SectionKind::getDataRel());
130 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
131 SectionKind::getDataRel());
134 = Ctx->getMachOSection("__DATA", "__mod_init_func",
135 MCSectionMachO::S_MOD_INIT_FUNC_POINTERS,
136 SectionKind::getDataRel());
138 = Ctx->getMachOSection("__DATA", "__mod_term_func",
139 MCSectionMachO::S_MOD_TERM_FUNC_POINTERS,
140 SectionKind::getDataRel());
143 // Exception Handling.
144 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
145 SectionKind::getReadOnlyWithRel());
147 COFFDebugSymbolsSection = 0;
149 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) {
150 CompactUnwindSection =
151 Ctx->getMachOSection("__LD", "__compact_unwind",
152 MCSectionMachO::S_ATTR_DEBUG,
153 SectionKind::getReadOnly());
155 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
156 CompactUnwindDwarfEHFrameOnly = 0x04000000;
159 // Debug Information.
160 DwarfAccelNamesSection =
161 Ctx->getMachOSection("__DWARF", "__apple_names",
162 MCSectionMachO::S_ATTR_DEBUG,
163 SectionKind::getMetadata());
164 DwarfAccelObjCSection =
165 Ctx->getMachOSection("__DWARF", "__apple_objc",
166 MCSectionMachO::S_ATTR_DEBUG,
167 SectionKind::getMetadata());
168 // 16 character section limit...
169 DwarfAccelNamespaceSection =
170 Ctx->getMachOSection("__DWARF", "__apple_namespac",
171 MCSectionMachO::S_ATTR_DEBUG,
172 SectionKind::getMetadata());
173 DwarfAccelTypesSection =
174 Ctx->getMachOSection("__DWARF", "__apple_types",
175 MCSectionMachO::S_ATTR_DEBUG,
176 SectionKind::getMetadata());
179 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
180 MCSectionMachO::S_ATTR_DEBUG,
181 SectionKind::getMetadata());
183 Ctx->getMachOSection("__DWARF", "__debug_info",
184 MCSectionMachO::S_ATTR_DEBUG,
185 SectionKind::getMetadata());
187 Ctx->getMachOSection("__DWARF", "__debug_line",
188 MCSectionMachO::S_ATTR_DEBUG,
189 SectionKind::getMetadata());
191 Ctx->getMachOSection("__DWARF", "__debug_frame",
192 MCSectionMachO::S_ATTR_DEBUG,
193 SectionKind::getMetadata());
194 DwarfPubNamesSection =
195 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
196 MCSectionMachO::S_ATTR_DEBUG,
197 SectionKind::getMetadata());
198 DwarfPubTypesSection =
199 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
200 MCSectionMachO::S_ATTR_DEBUG,
201 SectionKind::getMetadata());
202 DwarfGnuPubNamesSection =
203 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
204 MCSectionMachO::S_ATTR_DEBUG,
205 SectionKind::getMetadata());
206 DwarfGnuPubTypesSection =
207 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
208 MCSectionMachO::S_ATTR_DEBUG,
209 SectionKind::getMetadata());
211 Ctx->getMachOSection("__DWARF", "__debug_str",
212 MCSectionMachO::S_ATTR_DEBUG,
213 SectionKind::getMetadata());
215 Ctx->getMachOSection("__DWARF", "__debug_loc",
216 MCSectionMachO::S_ATTR_DEBUG,
217 SectionKind::getMetadata());
218 DwarfARangesSection =
219 Ctx->getMachOSection("__DWARF", "__debug_aranges",
220 MCSectionMachO::S_ATTR_DEBUG,
221 SectionKind::getMetadata());
223 Ctx->getMachOSection("__DWARF", "__debug_ranges",
224 MCSectionMachO::S_ATTR_DEBUG,
225 SectionKind::getMetadata());
226 DwarfMacroInfoSection =
227 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
228 MCSectionMachO::S_ATTR_DEBUG,
229 SectionKind::getMetadata());
230 DwarfDebugInlineSection =
231 Ctx->getMachOSection("__DWARF", "__debug_inlined",
232 MCSectionMachO::S_ATTR_DEBUG,
233 SectionKind::getMetadata());
235 Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
236 SectionKind::getMetadata());
238 TLSExtraDataSection = TLSTLVSection;
241 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
242 if (T.getArch() == Triple::mips ||
243 T.getArch() == Triple::mipsel)
244 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
245 else if (T.getArch() == Triple::mips64 ||
246 T.getArch() == Triple::mips64el)
247 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
249 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
251 if (T.getArch() == Triple::x86) {
252 PersonalityEncoding = (RelocM == Reloc::PIC_)
253 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
254 : dwarf::DW_EH_PE_absptr;
255 LSDAEncoding = (RelocM == Reloc::PIC_)
256 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
257 : dwarf::DW_EH_PE_absptr;
258 FDEEncoding = (RelocM == Reloc::PIC_)
259 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
260 : dwarf::DW_EH_PE_absptr;
261 TTypeEncoding = (RelocM == Reloc::PIC_)
262 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
263 : dwarf::DW_EH_PE_absptr;
264 } else if (T.getArch() == Triple::x86_64) {
265 if (RelocM == Reloc::PIC_) {
266 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
267 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
268 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
269 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
270 (CMModel == CodeModel::Small
271 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
272 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
273 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
274 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
275 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
277 PersonalityEncoding =
278 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
279 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
280 LSDAEncoding = (CMModel == CodeModel::Small)
281 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
282 FDEEncoding = dwarf::DW_EH_PE_udata4;
283 TTypeEncoding = (CMModel == CodeModel::Small)
284 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
286 } else if (T.getArch() == Triple::aarch64) {
287 // The small model guarantees static code/data size < 4GB, but not where it
288 // will be in memory. Most of these could end up >2GB away so even a signed
289 // pc-relative 32-bit address is insufficient, theoretically.
290 if (RelocM == Reloc::PIC_) {
291 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
292 dwarf::DW_EH_PE_sdata8;
293 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
294 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
295 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
296 dwarf::DW_EH_PE_sdata8;
298 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
299 LSDAEncoding = dwarf::DW_EH_PE_absptr;
300 FDEEncoding = dwarf::DW_EH_PE_udata4;
301 TTypeEncoding = dwarf::DW_EH_PE_absptr;
303 } else if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le) {
304 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
305 dwarf::DW_EH_PE_udata8;
306 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
307 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
308 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
309 dwarf::DW_EH_PE_udata8;
310 } else if (T.getArch() == Triple::sparc) {
311 if (RelocM == Reloc::PIC_) {
312 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
313 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
314 dwarf::DW_EH_PE_sdata4;
315 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
316 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
317 dwarf::DW_EH_PE_sdata4;
319 LSDAEncoding = dwarf::DW_EH_PE_absptr;
320 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
321 FDEEncoding = dwarf::DW_EH_PE_udata4;
322 TTypeEncoding = dwarf::DW_EH_PE_absptr;
324 } else if (T.getArch() == Triple::sparcv9) {
325 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
326 if (RelocM == Reloc::PIC_) {
327 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
328 dwarf::DW_EH_PE_sdata4;
329 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
330 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
331 dwarf::DW_EH_PE_sdata4;
333 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
334 FDEEncoding = dwarf::DW_EH_PE_udata4;
335 TTypeEncoding = dwarf::DW_EH_PE_absptr;
337 } else if (T.getArch() == Triple::systemz) {
338 // All currently-defined code models guarantee that 4-byte PC-relative
339 // values will be in range.
340 if (RelocM == Reloc::PIC_) {
341 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
342 dwarf::DW_EH_PE_sdata4;
343 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
344 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
345 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
346 dwarf::DW_EH_PE_sdata4;
348 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
349 LSDAEncoding = dwarf::DW_EH_PE_absptr;
350 FDEEncoding = dwarf::DW_EH_PE_absptr;
351 TTypeEncoding = dwarf::DW_EH_PE_absptr;
355 // Solaris requires different flags for .eh_frame to seemingly every other
357 EHSectionType = ELF::SHT_PROGBITS;
358 EHSectionFlags = ELF::SHF_ALLOC;
359 if (T.getOS() == Triple::Solaris) {
360 if (T.getArch() == Triple::x86_64)
361 EHSectionType = ELF::SHT_X86_64_UNWIND;
363 EHSectionFlags |= ELF::SHF_WRITE;
369 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
370 ELF::SHF_WRITE | ELF::SHF_ALLOC,
371 SectionKind::getBSS());
374 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
377 SectionKind::getText());
380 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
381 ELF::SHF_WRITE |ELF::SHF_ALLOC,
382 SectionKind::getDataRel());
385 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
387 SectionKind::getReadOnly());
390 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
391 ELF::SHF_ALLOC | ELF::SHF_TLS |
393 SectionKind::getThreadData());
396 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
397 ELF::SHF_ALLOC | ELF::SHF_TLS |
399 SectionKind::getThreadBSS());
402 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
403 ELF::SHF_ALLOC |ELF::SHF_WRITE,
404 SectionKind::getDataRel());
406 DataRelLocalSection =
407 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
408 ELF::SHF_ALLOC |ELF::SHF_WRITE,
409 SectionKind::getDataRelLocal());
412 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
413 ELF::SHF_ALLOC |ELF::SHF_WRITE,
414 SectionKind::getReadOnlyWithRel());
416 DataRelROLocalSection =
417 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
418 ELF::SHF_ALLOC |ELF::SHF_WRITE,
419 SectionKind::getReadOnlyWithRelLocal());
421 MergeableConst4Section =
422 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
423 ELF::SHF_ALLOC |ELF::SHF_MERGE,
424 SectionKind::getMergeableConst4());
426 MergeableConst8Section =
427 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
428 ELF::SHF_ALLOC |ELF::SHF_MERGE,
429 SectionKind::getMergeableConst8());
431 MergeableConst16Section =
432 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
433 ELF::SHF_ALLOC |ELF::SHF_MERGE,
434 SectionKind::getMergeableConst16());
437 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
438 ELF::SHF_ALLOC |ELF::SHF_WRITE,
439 SectionKind::getDataRel());
442 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
443 ELF::SHF_ALLOC |ELF::SHF_WRITE,
444 SectionKind::getDataRel());
446 // Exception Handling Sections.
448 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
449 // it contains relocatable pointers. In PIC mode, this is probably a big
450 // runtime hit for C++ apps. Either the contents of the LSDA need to be
451 // adjusted or this should be a data section.
453 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
455 SectionKind::getReadOnly());
457 COFFDebugSymbolsSection = 0;
459 // Debug Info Sections.
461 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
462 SectionKind::getMetadata());
464 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
465 SectionKind::getMetadata());
467 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
468 SectionKind::getMetadata());
470 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
471 SectionKind::getMetadata());
472 DwarfPubNamesSection =
473 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
474 SectionKind::getMetadata());
475 DwarfPubTypesSection =
476 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
477 SectionKind::getMetadata());
478 DwarfGnuPubNamesSection =
479 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
480 SectionKind::getMetadata());
481 DwarfGnuPubTypesSection =
482 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
483 SectionKind::getMetadata());
485 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
486 ELF::SHF_MERGE | ELF::SHF_STRINGS,
487 SectionKind::getMergeable1ByteCString());
489 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
490 SectionKind::getMetadata());
491 DwarfARangesSection =
492 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
493 SectionKind::getMetadata());
495 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
496 SectionKind::getMetadata());
497 DwarfMacroInfoSection =
498 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
499 SectionKind::getMetadata());
501 // DWARF5 Experimental Debug Info
503 // Accelerator Tables
504 DwarfAccelNamesSection =
505 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
506 SectionKind::getMetadata());
507 DwarfAccelObjCSection =
508 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
509 SectionKind::getMetadata());
510 DwarfAccelNamespaceSection =
511 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
512 SectionKind::getMetadata());
513 DwarfAccelTypesSection =
514 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
515 SectionKind::getMetadata());
518 DwarfInfoDWOSection =
519 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
520 SectionKind::getMetadata());
521 DwarfAbbrevDWOSection =
522 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
523 SectionKind::getMetadata());
525 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
526 ELF::SHF_MERGE | ELF::SHF_STRINGS,
527 SectionKind::getMergeable1ByteCString());
528 DwarfLineDWOSection =
529 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
530 SectionKind::getMetadata());
532 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
533 SectionKind::getMetadata());
534 DwarfStrOffDWOSection =
535 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
536 SectionKind::getMetadata());
538 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
539 SectionKind::getMetadata());
543 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
546 Ctx->getCOFFSection(".bss",
547 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
548 COFF::IMAGE_SCN_MEM_READ |
549 COFF::IMAGE_SCN_MEM_WRITE,
550 SectionKind::getBSS());
552 Ctx->getCOFFSection(".text",
553 COFF::IMAGE_SCN_CNT_CODE |
554 COFF::IMAGE_SCN_MEM_EXECUTE |
555 COFF::IMAGE_SCN_MEM_READ,
556 SectionKind::getText());
558 Ctx->getCOFFSection(".data",
559 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
560 COFF::IMAGE_SCN_MEM_READ |
561 COFF::IMAGE_SCN_MEM_WRITE,
562 SectionKind::getDataRel());
564 Ctx->getCOFFSection(".rdata",
565 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
566 COFF::IMAGE_SCN_MEM_READ,
567 SectionKind::getReadOnly());
568 if (T.getOS() == Triple::Win32) {
570 Ctx->getCOFFSection(".CRT$XCU",
571 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
572 COFF::IMAGE_SCN_MEM_READ,
573 SectionKind::getReadOnly());
576 Ctx->getCOFFSection(".ctors",
577 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
578 COFF::IMAGE_SCN_MEM_READ |
579 COFF::IMAGE_SCN_MEM_WRITE,
580 SectionKind::getDataRel());
584 if (T.getOS() == Triple::Win32) {
586 Ctx->getCOFFSection(".CRT$XTX",
587 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
588 COFF::IMAGE_SCN_MEM_READ,
589 SectionKind::getReadOnly());
592 Ctx->getCOFFSection(".dtors",
593 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
594 COFF::IMAGE_SCN_MEM_READ |
595 COFF::IMAGE_SCN_MEM_WRITE,
596 SectionKind::getDataRel());
599 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
600 // though it contains relocatable pointers. In PIC mode, this is probably a
601 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
602 // adjusted or this should be a data section.
604 Ctx->getCOFFSection(".gcc_except_table",
605 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
606 COFF::IMAGE_SCN_MEM_READ,
607 SectionKind::getReadOnly());
610 COFFDebugSymbolsSection =
611 Ctx->getCOFFSection(".debug$S",
612 COFF::IMAGE_SCN_MEM_DISCARDABLE |
613 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
614 COFF::IMAGE_SCN_MEM_READ,
615 SectionKind::getMetadata());
618 Ctx->getCOFFSection(".debug_abbrev",
619 COFF::IMAGE_SCN_MEM_DISCARDABLE |
620 COFF::IMAGE_SCN_MEM_READ,
621 SectionKind::getMetadata());
623 Ctx->getCOFFSection(".debug_info",
624 COFF::IMAGE_SCN_MEM_DISCARDABLE |
625 COFF::IMAGE_SCN_MEM_READ,
626 SectionKind::getMetadata());
628 Ctx->getCOFFSection(".debug_line",
629 COFF::IMAGE_SCN_MEM_DISCARDABLE |
630 COFF::IMAGE_SCN_MEM_READ,
631 SectionKind::getMetadata());
633 Ctx->getCOFFSection(".debug_frame",
634 COFF::IMAGE_SCN_MEM_DISCARDABLE |
635 COFF::IMAGE_SCN_MEM_READ,
636 SectionKind::getMetadata());
637 DwarfPubNamesSection =
638 Ctx->getCOFFSection(".debug_pubnames",
639 COFF::IMAGE_SCN_MEM_DISCARDABLE |
640 COFF::IMAGE_SCN_MEM_READ,
641 SectionKind::getMetadata());
642 DwarfPubTypesSection =
643 Ctx->getCOFFSection(".debug_pubtypes",
644 COFF::IMAGE_SCN_MEM_DISCARDABLE |
645 COFF::IMAGE_SCN_MEM_READ,
646 SectionKind::getMetadata());
647 DwarfGnuPubNamesSection =
648 Ctx->getCOFFSection(".debug_gnu_pubnames",
649 COFF::IMAGE_SCN_MEM_DISCARDABLE |
650 COFF::IMAGE_SCN_MEM_READ,
651 SectionKind::getMetadata());
652 DwarfGnuPubTypesSection =
653 Ctx->getCOFFSection(".debug_gnu_pubtypes",
654 COFF::IMAGE_SCN_MEM_DISCARDABLE |
655 COFF::IMAGE_SCN_MEM_READ,
656 SectionKind::getMetadata());
658 Ctx->getCOFFSection(".debug_str",
659 COFF::IMAGE_SCN_MEM_DISCARDABLE |
660 COFF::IMAGE_SCN_MEM_READ,
661 SectionKind::getMetadata());
663 Ctx->getCOFFSection(".debug_loc",
664 COFF::IMAGE_SCN_MEM_DISCARDABLE |
665 COFF::IMAGE_SCN_MEM_READ,
666 SectionKind::getMetadata());
667 DwarfARangesSection =
668 Ctx->getCOFFSection(".debug_aranges",
669 COFF::IMAGE_SCN_MEM_DISCARDABLE |
670 COFF::IMAGE_SCN_MEM_READ,
671 SectionKind::getMetadata());
673 Ctx->getCOFFSection(".debug_ranges",
674 COFF::IMAGE_SCN_MEM_DISCARDABLE |
675 COFF::IMAGE_SCN_MEM_READ,
676 SectionKind::getMetadata());
677 DwarfMacroInfoSection =
678 Ctx->getCOFFSection(".debug_macinfo",
679 COFF::IMAGE_SCN_MEM_DISCARDABLE |
680 COFF::IMAGE_SCN_MEM_READ,
681 SectionKind::getMetadata());
684 Ctx->getCOFFSection(".drectve",
685 COFF::IMAGE_SCN_LNK_INFO,
686 SectionKind::getMetadata());
689 Ctx->getCOFFSection(".pdata",
690 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
691 COFF::IMAGE_SCN_MEM_READ,
692 SectionKind::getDataRel());
695 Ctx->getCOFFSection(".xdata",
696 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
697 COFF::IMAGE_SCN_MEM_READ,
698 SectionKind::getDataRel());
700 Ctx->getCOFFSection(".tls$",
701 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
702 COFF::IMAGE_SCN_MEM_READ |
703 COFF::IMAGE_SCN_MEM_WRITE,
704 SectionKind::getDataRel());
707 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
715 CommDirectiveSupportsAlignment = true;
716 SupportsWeakOmittedEHFrame = true;
717 IsFunctionEHFrameSymbolPrivate = true;
719 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
720 TTypeEncoding = dwarf::DW_EH_PE_absptr;
722 CompactUnwindDwarfEHFrameOnly = 0;
724 EHFrameSection = 0; // Created on demand.
725 CompactUnwindSection = 0; // Used only by selected targets.
726 DwarfAccelNamesSection = 0; // Used only by selected targets.
727 DwarfAccelObjCSection = 0; // Used only by selected targets.
728 DwarfAccelNamespaceSection = 0; // Used only by selected targets.
729 DwarfAccelTypesSection = 0; // Used only by selected targets.
732 Triple::ArchType Arch = T.getArch();
733 // FIXME: Checking for Arch here to filter out bogus triples such as
734 // cellspu-apple-darwin. Perhaps we should fix in Triple?
735 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
736 Arch == Triple::arm || Arch == Triple::thumb ||
737 Arch == Triple::ppc || Arch == Triple::ppc64 ||
738 Arch == Triple::UnknownArch) &&
739 (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
741 InitMachOMCObjectFileInfo(T);
742 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
743 (T.getEnvironment() != Triple::ELF) &&
744 (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
745 T.getOS() == Triple::Win32)) {
747 InitCOFFMCObjectFileInfo(T);
750 InitELFMCObjectFileInfo(T);
754 const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
755 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
756 SectionKind::getMetadata(), 0, utostr(Hash));
760 MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
761 return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS,
762 ELF::SHF_GROUP, SectionKind::getMetadata(), 0,
766 void MCObjectFileInfo::InitEHFrameSection() {
769 Ctx->getMachOSection("__TEXT", "__eh_frame",
770 MCSectionMachO::S_COALESCED |
771 MCSectionMachO::S_ATTR_NO_TOC |
772 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
773 MCSectionMachO::S_ATTR_LIVE_SUPPORT,
774 SectionKind::getReadOnly());
775 else if (Env == IsELF)
777 Ctx->getELFSection(".eh_frame", EHSectionType,
779 SectionKind::getDataRel());
782 Ctx->getCOFFSection(".eh_frame",
783 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
784 COFF::IMAGE_SCN_MEM_READ |
785 COFF::IMAGE_SCN_MEM_WRITE,
786 SectionKind::getDataRel());