blob: 96b62f19d9344430dea1a5599e50243ba3c7e98d [file] [log] [blame]
Evan Chenge76a33b2011-07-20 05:58:47 +00001//===-- MObjectFileInfo.cpp - Object File Information ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/MC/MCObjectFileInfo.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000011#include "llvm/ADT/Triple.h"
Evan Chenge76a33b2011-07-20 05:58:47 +000012#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"
Evan Chenge76a33b2011-07-20 05:58:47 +000017using namespace llvm;
18
19void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
20 // MachO
21 IsFunctionEHFrameSymbolPrivate = false;
22 SupportsWeakOmittedEHFrame = false;
23
Evan Cheng203576a2011-07-20 19:50:42 +000024 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;
29
Evan Chenge76a33b2011-07-20 05:58:47 +000030 // .comm doesn't support alignment before Leopard.
31 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
32 CommDirectiveSupportsAlignment = false;
33
34 TextSection // .text
35 = Ctx->getMachOSection("__TEXT", "__text",
36 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
37 SectionKind::getText());
38 DataSection // .data
39 = Ctx->getMachOSection("__DATA", "__data", 0,
40 SectionKind::getDataRel());
41
42 TLSDataSection // .tdata
43 = Ctx->getMachOSection("__DATA", "__thread_data",
44 MCSectionMachO::S_THREAD_LOCAL_REGULAR,
45 SectionKind::getDataRel());
46 TLSBSSSection // .tbss
47 = Ctx->getMachOSection("__DATA", "__thread_bss",
48 MCSectionMachO::S_THREAD_LOCAL_ZEROFILL,
49 SectionKind::getThreadBSS());
50
51 // TODO: Verify datarel below.
52 TLSTLVSection // .tlv
53 = Ctx->getMachOSection("__DATA", "__thread_vars",
54 MCSectionMachO::S_THREAD_LOCAL_VARIABLES,
55 SectionKind::getDataRel());
56
57 TLSThreadInitSection
58 = Ctx->getMachOSection("__DATA", "__thread_init",
Jim Grosbach946227d2011-11-15 16:46:22 +000059 MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
60 SectionKind::getDataRel());
Evan Chenge76a33b2011-07-20 05:58:47 +000061
62 CStringSection // .cstring
63 = Ctx->getMachOSection("__TEXT", "__cstring",
64 MCSectionMachO::S_CSTRING_LITERALS,
65 SectionKind::getMergeable1ByteCString());
66 UStringSection
67 = Ctx->getMachOSection("__TEXT","__ustring", 0,
68 SectionKind::getMergeable2ByteCString());
69 FourByteConstantSection // .literal4
70 = Ctx->getMachOSection("__TEXT", "__literal4",
71 MCSectionMachO::S_4BYTE_LITERALS,
72 SectionKind::getMergeableConst4());
73 EightByteConstantSection // .literal8
74 = Ctx->getMachOSection("__TEXT", "__literal8",
75 MCSectionMachO::S_8BYTE_LITERALS,
76 SectionKind::getMergeableConst8());
77
78 // ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back
79 // to using it in -static mode.
80 SixteenByteConstantSection = 0;
81 if (RelocM != Reloc::Static &&
82 T.getArch() != Triple::x86_64 && T.getArch() != Triple::ppc64)
83 SixteenByteConstantSection = // .literal16
84 Ctx->getMachOSection("__TEXT", "__literal16",
85 MCSectionMachO::S_16BYTE_LITERALS,
86 SectionKind::getMergeableConst16());
87
88 ReadOnlySection // .const
89 = Ctx->getMachOSection("__TEXT", "__const", 0,
90 SectionKind::getReadOnly());
91
92 TextCoalSection
93 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
94 MCSectionMachO::S_COALESCED |
95 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
96 SectionKind::getText());
97 ConstTextCoalSection
98 = Ctx->getMachOSection("__TEXT", "__const_coal",
99 MCSectionMachO::S_COALESCED,
100 SectionKind::getReadOnly());
101 ConstDataSection // .const_data
102 = Ctx->getMachOSection("__DATA", "__const", 0,
103 SectionKind::getReadOnlyWithRel());
104 DataCoalSection
105 = Ctx->getMachOSection("__DATA","__datacoal_nt",
106 MCSectionMachO::S_COALESCED,
107 SectionKind::getDataRel());
108 DataCommonSection
109 = Ctx->getMachOSection("__DATA","__common",
110 MCSectionMachO::S_ZEROFILL,
111 SectionKind::getBSS());
112 DataBSSSection
113 = Ctx->getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL,
114 SectionKind::getBSS());
115
116
117 LazySymbolPointerSection
118 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
119 MCSectionMachO::S_LAZY_SYMBOL_POINTERS,
120 SectionKind::getMetadata());
121 NonLazySymbolPointerSection
122 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
123 MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
124 SectionKind::getMetadata());
125
126 if (RelocM == Reloc::Static) {
127 StaticCtorSection
128 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
129 SectionKind::getDataRel());
130 StaticDtorSection
131 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
132 SectionKind::getDataRel());
133 } else {
134 StaticCtorSection
135 = Ctx->getMachOSection("__DATA", "__mod_init_func",
136 MCSectionMachO::S_MOD_INIT_FUNC_POINTERS,
137 SectionKind::getDataRel());
138 StaticDtorSection
139 = Ctx->getMachOSection("__DATA", "__mod_term_func",
140 MCSectionMachO::S_MOD_TERM_FUNC_POINTERS,
141 SectionKind::getDataRel());
142 }
143
144 // Exception Handling.
145 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
146 SectionKind::getReadOnlyWithRel());
147
Bill Wendling62c75ad2013-04-10 21:42:06 +0000148 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) {
Evan Chenge76a33b2011-07-20 05:58:47 +0000149 CompactUnwindSection =
150 Ctx->getMachOSection("__LD", "__compact_unwind",
151 MCSectionMachO::S_ATTR_DEBUG,
152 SectionKind::getReadOnly());
153
Bill Wendling62c75ad2013-04-10 21:42:06 +0000154 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
155 CompactUnwindDwarfEHFrameOnly = 0x04000000;
156 }
157
Evan Chenge76a33b2011-07-20 05:58:47 +0000158 // Debug Information.
Eric Christopher09ac3d82011-11-07 09:24:32 +0000159 DwarfAccelNamesSection =
160 Ctx->getMachOSection("__DWARF", "__apple_names",
161 MCSectionMachO::S_ATTR_DEBUG,
162 SectionKind::getMetadata());
163 DwarfAccelObjCSection =
164 Ctx->getMachOSection("__DWARF", "__apple_objc",
165 MCSectionMachO::S_ATTR_DEBUG,
166 SectionKind::getMetadata());
167 // 16 character section limit...
168 DwarfAccelNamespaceSection =
169 Ctx->getMachOSection("__DWARF", "__apple_namespac",
170 MCSectionMachO::S_ATTR_DEBUG,
171 SectionKind::getMetadata());
172 DwarfAccelTypesSection =
173 Ctx->getMachOSection("__DWARF", "__apple_types",
174 MCSectionMachO::S_ATTR_DEBUG,
175 SectionKind::getMetadata());
Jim Grosbach2684d9e2012-05-11 01:41:30 +0000176
Evan Chenge76a33b2011-07-20 05:58:47 +0000177 DwarfAbbrevSection =
178 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
179 MCSectionMachO::S_ATTR_DEBUG,
180 SectionKind::getMetadata());
181 DwarfInfoSection =
182 Ctx->getMachOSection("__DWARF", "__debug_info",
183 MCSectionMachO::S_ATTR_DEBUG,
184 SectionKind::getMetadata());
185 DwarfLineSection =
186 Ctx->getMachOSection("__DWARF", "__debug_line",
187 MCSectionMachO::S_ATTR_DEBUG,
188 SectionKind::getMetadata());
189 DwarfFrameSection =
190 Ctx->getMachOSection("__DWARF", "__debug_frame",
191 MCSectionMachO::S_ATTR_DEBUG,
192 SectionKind::getMetadata());
Krzysztof Parzyszekc5ef7ee2013-02-12 18:00:14 +0000193 DwarfPubNamesSection =
194 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
195 MCSectionMachO::S_ATTR_DEBUG,
196 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000197 DwarfPubTypesSection =
198 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
199 MCSectionMachO::S_ATTR_DEBUG,
200 SectionKind::getMetadata());
201 DwarfStrSection =
202 Ctx->getMachOSection("__DWARF", "__debug_str",
203 MCSectionMachO::S_ATTR_DEBUG,
204 SectionKind::getMetadata());
205 DwarfLocSection =
206 Ctx->getMachOSection("__DWARF", "__debug_loc",
207 MCSectionMachO::S_ATTR_DEBUG,
208 SectionKind::getMetadata());
209 DwarfARangesSection =
210 Ctx->getMachOSection("__DWARF", "__debug_aranges",
211 MCSectionMachO::S_ATTR_DEBUG,
212 SectionKind::getMetadata());
213 DwarfRangesSection =
214 Ctx->getMachOSection("__DWARF", "__debug_ranges",
215 MCSectionMachO::S_ATTR_DEBUG,
216 SectionKind::getMetadata());
217 DwarfMacroInfoSection =
218 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
219 MCSectionMachO::S_ATTR_DEBUG,
220 SectionKind::getMetadata());
221 DwarfDebugInlineSection =
222 Ctx->getMachOSection("__DWARF", "__debug_inlined",
223 MCSectionMachO::S_ATTR_DEBUG,
224 SectionKind::getMetadata());
225
226 TLSExtraDataSection = TLSTLVSection;
227}
228
229void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
Rafael Espindola04011e842013-04-03 03:13:19 +0000230 if (T.getArch() == Triple::mips ||
231 T.getArch() == Triple::mipsel)
232 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
233 else if (T.getArch() == Triple::mips64 ||
234 T.getArch() == Triple::mips64el)
235 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
236 else
Rafael Espindola7a86ffb2013-03-15 05:51:57 +0000237 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
238
Evan Cheng203576a2011-07-20 19:50:42 +0000239 if (T.getArch() == Triple::x86) {
240 PersonalityEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach946227d2011-11-15 16:46:22 +0000241 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
242 : dwarf::DW_EH_PE_absptr;
Evan Cheng203576a2011-07-20 19:50:42 +0000243 LSDAEncoding = (RelocM == Reloc::PIC_)
244 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
245 : dwarf::DW_EH_PE_absptr;
Rafael Espindola7a86ffb2013-03-15 05:51:57 +0000246 FDEEncoding = (RelocM == Reloc::PIC_)
Evan Cheng203576a2011-07-20 19:50:42 +0000247 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
248 : dwarf::DW_EH_PE_absptr;
249 TTypeEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach946227d2011-11-15 16:46:22 +0000250 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
251 : dwarf::DW_EH_PE_absptr;
Evan Cheng203576a2011-07-20 19:50:42 +0000252 } else if (T.getArch() == Triple::x86_64) {
Evan Cheng203576a2011-07-20 19:50:42 +0000253 if (RelocM == Reloc::PIC_) {
254 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
255 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
256 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
257 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
258 (CMModel == CodeModel::Small
259 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
260 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
261 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
262 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
263 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
264 } else {
265 PersonalityEncoding =
266 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
267 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
268 LSDAEncoding = (CMModel == CodeModel::Small)
269 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
270 FDEEncoding = dwarf::DW_EH_PE_udata4;
271 TTypeEncoding = (CMModel == CodeModel::Small)
272 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
273 }
Tim Northover72062f52013-01-31 12:12:40 +0000274 } else if (T.getArch() == Triple::aarch64) {
Tim Northover72062f52013-01-31 12:12:40 +0000275 // The small model guarantees static code/data size < 4GB, but not where it
276 // will be in memory. Most of these could end up >2GB away so even a signed
277 // pc-relative 32-bit address is insufficient, theoretically.
278 if (RelocM == Reloc::PIC_) {
279 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
280 dwarf::DW_EH_PE_sdata8;
281 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
282 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
283 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
284 dwarf::DW_EH_PE_sdata8;
285 } else {
286 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
287 LSDAEncoding = dwarf::DW_EH_PE_absptr;
288 FDEEncoding = dwarf::DW_EH_PE_udata4;
289 TTypeEncoding = dwarf::DW_EH_PE_absptr;
290 }
Adhemerval Zanella7b449882013-01-04 19:08:13 +0000291 } else if (T.getArch() == Triple::ppc64) {
Adhemerval Zanellaa1db5de2013-01-09 17:08:15 +0000292 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
293 dwarf::DW_EH_PE_udata8;
Adhemerval Zanellaa1db5de2013-01-09 17:08:15 +0000294 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
295 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
296 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
297 dwarf::DW_EH_PE_udata8;
Ulrich Weigande96e43f2013-05-06 16:11:12 +0000298 } else if (T.getArch() == Triple::systemz) {
299 // All currently-defined code models guarantee that 4-byte PC-relative
300 // values will be in range.
Ulrich Weigande5c8c242013-05-06 17:28:30 +0000301 if (RelocM == Reloc::PIC_) {
302 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
303 dwarf::DW_EH_PE_sdata4;
304 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
305 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
306 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
307 dwarf::DW_EH_PE_sdata4;
308 } else {
309 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
310 LSDAEncoding = dwarf::DW_EH_PE_absptr;
311 FDEEncoding = dwarf::DW_EH_PE_absptr;
312 TTypeEncoding = dwarf::DW_EH_PE_absptr;
313 }
Evan Cheng203576a2011-07-20 19:50:42 +0000314 }
315
David Chisnall4cbcee12012-02-17 17:31:15 +0000316 // Solaris requires different flags for .eh_frame to seemingly every other
317 // platform.
David Chisnallbce0de42012-04-10 11:44:33 +0000318 EHSectionType = ELF::SHT_PROGBITS;
David Chisnall4cbcee12012-02-17 17:31:15 +0000319 EHSectionFlags = ELF::SHF_ALLOC;
David Chisnallbce0de42012-04-10 11:44:33 +0000320 if (T.getOS() == Triple::Solaris) {
321 if (T.getArch() == Triple::x86_64)
322 EHSectionType = ELF::SHT_X86_64_UNWIND;
323 else
324 EHSectionFlags |= ELF::SHF_WRITE;
325 }
David Chisnall4cbcee12012-02-17 17:31:15 +0000326
327
Evan Chenge76a33b2011-07-20 05:58:47 +0000328 // ELF
329 BSSSection =
330 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
Anton Korobeynikov4a99f592012-01-25 22:24:19 +0000331 ELF::SHF_WRITE | ELF::SHF_ALLOC,
Evan Chenge76a33b2011-07-20 05:58:47 +0000332 SectionKind::getBSS());
333
334 TextSection =
335 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
336 ELF::SHF_EXECINSTR |
337 ELF::SHF_ALLOC,
338 SectionKind::getText());
339
340 DataSection =
341 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
342 ELF::SHF_WRITE |ELF::SHF_ALLOC,
343 SectionKind::getDataRel());
344
345 ReadOnlySection =
346 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
347 ELF::SHF_ALLOC,
348 SectionKind::getReadOnly());
349
350 TLSDataSection =
351 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
352 ELF::SHF_ALLOC | ELF::SHF_TLS |
353 ELF::SHF_WRITE,
354 SectionKind::getThreadData());
355
356 TLSBSSSection =
357 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
358 ELF::SHF_ALLOC | ELF::SHF_TLS |
359 ELF::SHF_WRITE,
360 SectionKind::getThreadBSS());
361
362 DataRelSection =
363 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
364 ELF::SHF_ALLOC |ELF::SHF_WRITE,
365 SectionKind::getDataRel());
366
367 DataRelLocalSection =
368 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
369 ELF::SHF_ALLOC |ELF::SHF_WRITE,
370 SectionKind::getDataRelLocal());
371
372 DataRelROSection =
373 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
374 ELF::SHF_ALLOC |ELF::SHF_WRITE,
375 SectionKind::getReadOnlyWithRel());
376
377 DataRelROLocalSection =
378 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
379 ELF::SHF_ALLOC |ELF::SHF_WRITE,
380 SectionKind::getReadOnlyWithRelLocal());
381
382 MergeableConst4Section =
383 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
384 ELF::SHF_ALLOC |ELF::SHF_MERGE,
385 SectionKind::getMergeableConst4());
386
387 MergeableConst8Section =
388 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
389 ELF::SHF_ALLOC |ELF::SHF_MERGE,
390 SectionKind::getMergeableConst8());
391
392 MergeableConst16Section =
393 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
394 ELF::SHF_ALLOC |ELF::SHF_MERGE,
395 SectionKind::getMergeableConst16());
396
397 StaticCtorSection =
398 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
399 ELF::SHF_ALLOC |ELF::SHF_WRITE,
400 SectionKind::getDataRel());
401
402 StaticDtorSection =
403 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
404 ELF::SHF_ALLOC |ELF::SHF_WRITE,
405 SectionKind::getDataRel());
406
407 // Exception Handling Sections.
408
409 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
410 // it contains relocatable pointers. In PIC mode, this is probably a big
411 // runtime hit for C++ apps. Either the contents of the LSDA need to be
412 // adjusted or this should be a data section.
413 LSDASection =
414 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
415 ELF::SHF_ALLOC,
416 SectionKind::getReadOnly());
417
418 // Debug Info Sections.
419 DwarfAbbrevSection =
420 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
421 SectionKind::getMetadata());
422 DwarfInfoSection =
423 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
424 SectionKind::getMetadata());
425 DwarfLineSection =
426 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
427 SectionKind::getMetadata());
428 DwarfFrameSection =
429 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
430 SectionKind::getMetadata());
Krzysztof Parzyszekc5ef7ee2013-02-12 18:00:14 +0000431 DwarfPubNamesSection =
432 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
433 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000434 DwarfPubTypesSection =
435 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
436 SectionKind::getMetadata());
437 DwarfStrSection =
Nick Lewycky5a86c5b2011-10-26 18:44:32 +0000438 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
439 ELF::SHF_MERGE | ELF::SHF_STRINGS,
440 SectionKind::getMergeable1ByteCString());
Evan Chenge76a33b2011-07-20 05:58:47 +0000441 DwarfLocSection =
442 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
443 SectionKind::getMetadata());
444 DwarfARangesSection =
445 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
446 SectionKind::getMetadata());
447 DwarfRangesSection =
448 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
449 SectionKind::getMetadata());
450 DwarfMacroInfoSection =
451 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
452 SectionKind::getMetadata());
Eric Christopherea1504d2012-11-28 02:49:34 +0000453
454 // DWARF5 Experimental Debug Info
455
456 // Accelerator Tables
Eric Christopher5b4461c2012-10-08 21:41:30 +0000457 DwarfAccelNamesSection =
458 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
459 SectionKind::getMetadata());
460 DwarfAccelObjCSection =
461 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
462 SectionKind::getMetadata());
463 DwarfAccelNamespaceSection =
464 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
465 SectionKind::getMetadata());
466 DwarfAccelTypesSection =
467 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
468 SectionKind::getMetadata());
Eric Christopher6acb5312012-11-28 02:49:38 +0000469
470 // Fission Sections
471 DwarfInfoDWOSection =
472 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
473 SectionKind::getMetadata());
Eric Christopher67587f42012-11-30 06:47:06 +0000474 DwarfAbbrevDWOSection =
475 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
476 SectionKind::getMetadata());
477 DwarfStrDWOSection =
478 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
479 ELF::SHF_MERGE | ELF::SHF_STRINGS,
480 SectionKind::getMergeable1ByteCString());
481 DwarfLineDWOSection =
482 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
483 SectionKind::getMetadata());
484 DwarfLocDWOSection =
485 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
486 SectionKind::getMetadata());
Eric Christopher60230ef2013-01-04 17:59:22 +0000487 DwarfStrOffDWOSection =
488 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
489 SectionKind::getMetadata());
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000490 DwarfAddrSection =
491 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
492 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000493}
494
495
496void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
497 // COFF
498 TextSection =
499 Ctx->getCOFFSection(".text",
500 COFF::IMAGE_SCN_CNT_CODE |
501 COFF::IMAGE_SCN_MEM_EXECUTE |
502 COFF::IMAGE_SCN_MEM_READ,
503 SectionKind::getText());
504 DataSection =
505 Ctx->getCOFFSection(".data",
506 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
507 COFF::IMAGE_SCN_MEM_READ |
508 COFF::IMAGE_SCN_MEM_WRITE,
509 SectionKind::getDataRel());
510 ReadOnlySection =
511 Ctx->getCOFFSection(".rdata",
512 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
513 COFF::IMAGE_SCN_MEM_READ,
514 SectionKind::getReadOnly());
Michael J. Spencer32d22ee2012-02-23 21:56:08 +0000515 if (T.getOS() == Triple::Win32) {
516 StaticCtorSection =
517 Ctx->getCOFFSection(".CRT$XCU",
518 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
519 COFF::IMAGE_SCN_MEM_READ,
520 SectionKind::getReadOnly());
521 } else {
522 StaticCtorSection =
523 Ctx->getCOFFSection(".ctors",
524 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
525 COFF::IMAGE_SCN_MEM_READ |
526 COFF::IMAGE_SCN_MEM_WRITE,
527 SectionKind::getDataRel());
528 }
529
530
Anton Korobeynikov371e17c2012-09-23 15:53:47 +0000531 if (T.getOS() == Triple::Win32) {
532 StaticDtorSection =
533 Ctx->getCOFFSection(".CRT$XTX",
534 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
535 COFF::IMAGE_SCN_MEM_READ,
536 SectionKind::getReadOnly());
537 } else {
538 StaticDtorSection =
539 Ctx->getCOFFSection(".dtors",
540 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
541 COFF::IMAGE_SCN_MEM_READ |
542 COFF::IMAGE_SCN_MEM_WRITE,
543 SectionKind::getDataRel());
544 }
Evan Chenge76a33b2011-07-20 05:58:47 +0000545
546 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
547 // though it contains relocatable pointers. In PIC mode, this is probably a
548 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
549 // adjusted or this should be a data section.
Kai Nacke113d32c2013-07-08 04:43:23 +0000550 LSDASection =
551 Ctx->getCOFFSection(".gcc_except_table",
552 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
553 COFF::IMAGE_SCN_MEM_READ,
554 SectionKind::getReadOnly());
Evan Chenge76a33b2011-07-20 05:58:47 +0000555
556 // Debug info.
557 DwarfAbbrevSection =
558 Ctx->getCOFFSection(".debug_abbrev",
559 COFF::IMAGE_SCN_MEM_DISCARDABLE |
560 COFF::IMAGE_SCN_MEM_READ,
561 SectionKind::getMetadata());
562 DwarfInfoSection =
563 Ctx->getCOFFSection(".debug_info",
564 COFF::IMAGE_SCN_MEM_DISCARDABLE |
565 COFF::IMAGE_SCN_MEM_READ,
566 SectionKind::getMetadata());
567 DwarfLineSection =
568 Ctx->getCOFFSection(".debug_line",
569 COFF::IMAGE_SCN_MEM_DISCARDABLE |
570 COFF::IMAGE_SCN_MEM_READ,
571 SectionKind::getMetadata());
572 DwarfFrameSection =
573 Ctx->getCOFFSection(".debug_frame",
574 COFF::IMAGE_SCN_MEM_DISCARDABLE |
575 COFF::IMAGE_SCN_MEM_READ,
576 SectionKind::getMetadata());
Krzysztof Parzyszekc5ef7ee2013-02-12 18:00:14 +0000577 DwarfPubNamesSection =
578 Ctx->getCOFFSection(".debug_pubnames",
579 COFF::IMAGE_SCN_MEM_DISCARDABLE |
580 COFF::IMAGE_SCN_MEM_READ,
581 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000582 DwarfPubTypesSection =
583 Ctx->getCOFFSection(".debug_pubtypes",
584 COFF::IMAGE_SCN_MEM_DISCARDABLE |
585 COFF::IMAGE_SCN_MEM_READ,
586 SectionKind::getMetadata());
587 DwarfStrSection =
588 Ctx->getCOFFSection(".debug_str",
589 COFF::IMAGE_SCN_MEM_DISCARDABLE |
590 COFF::IMAGE_SCN_MEM_READ,
591 SectionKind::getMetadata());
592 DwarfLocSection =
593 Ctx->getCOFFSection(".debug_loc",
594 COFF::IMAGE_SCN_MEM_DISCARDABLE |
595 COFF::IMAGE_SCN_MEM_READ,
596 SectionKind::getMetadata());
597 DwarfARangesSection =
598 Ctx->getCOFFSection(".debug_aranges",
599 COFF::IMAGE_SCN_MEM_DISCARDABLE |
600 COFF::IMAGE_SCN_MEM_READ,
601 SectionKind::getMetadata());
602 DwarfRangesSection =
603 Ctx->getCOFFSection(".debug_ranges",
604 COFF::IMAGE_SCN_MEM_DISCARDABLE |
605 COFF::IMAGE_SCN_MEM_READ,
606 SectionKind::getMetadata());
607 DwarfMacroInfoSection =
608 Ctx->getCOFFSection(".debug_macinfo",
609 COFF::IMAGE_SCN_MEM_DISCARDABLE |
610 COFF::IMAGE_SCN_MEM_READ,
611 SectionKind::getMetadata());
612
613 DrectveSection =
614 Ctx->getCOFFSection(".drectve",
615 COFF::IMAGE_SCN_LNK_INFO,
616 SectionKind::getMetadata());
617
618 PDataSection =
619 Ctx->getCOFFSection(".pdata",
620 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikov0a0e50c2012-08-08 12:46:46 +0000621 COFF::IMAGE_SCN_MEM_READ,
Evan Chenge76a33b2011-07-20 05:58:47 +0000622 SectionKind::getDataRel());
623
624 XDataSection =
625 Ctx->getCOFFSection(".xdata",
626 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikov0a0e50c2012-08-08 12:46:46 +0000627 COFF::IMAGE_SCN_MEM_READ,
Evan Chenge76a33b2011-07-20 05:58:47 +0000628 SectionKind::getDataRel());
Anton Korobeynikovd4a19b62012-02-11 17:26:53 +0000629 TLSDataSection =
630 Ctx->getCOFFSection(".tls$",
631 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
632 COFF::IMAGE_SCN_MEM_READ |
633 COFF::IMAGE_SCN_MEM_WRITE,
634 SectionKind::getDataRel());
Evan Chenge76a33b2011-07-20 05:58:47 +0000635}
636
637void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
Evan Cheng203576a2011-07-20 19:50:42 +0000638 CodeModel::Model cm,
Evan Chenge76a33b2011-07-20 05:58:47 +0000639 MCContext &ctx) {
640 RelocM = relocm;
Evan Cheng203576a2011-07-20 19:50:42 +0000641 CMModel = cm;
Evan Chenge76a33b2011-07-20 05:58:47 +0000642 Ctx = &ctx;
643
644 // Common.
645 CommDirectiveSupportsAlignment = true;
646 SupportsWeakOmittedEHFrame = true;
647 IsFunctionEHFrameSymbolPrivate = true;
Evan Cheng203576a2011-07-20 19:50:42 +0000648
649 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
650 TTypeEncoding = dwarf::DW_EH_PE_absptr;
651
Bill Wendling62c75ad2013-04-10 21:42:06 +0000652 CompactUnwindDwarfEHFrameOnly = 0;
653
Eric Christopher09ac3d82011-11-07 09:24:32 +0000654 EHFrameSection = 0; // Created on demand.
655 CompactUnwindSection = 0; // Used only by selected targets.
656 DwarfAccelNamesSection = 0; // Used only by selected targets.
657 DwarfAccelObjCSection = 0; // Used only by selected targets.
658 DwarfAccelNamespaceSection = 0; // Used only by selected targets.
659 DwarfAccelTypesSection = 0; // Used only by selected targets.
Evan Chenge76a33b2011-07-20 05:58:47 +0000660
661 Triple T(TT);
662 Triple::ArchType Arch = T.getArch();
663 // FIXME: Checking for Arch here to filter out bogus triples such as
664 // cellspu-apple-darwin. Perhaps we should fix in Triple?
665 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
666 Arch == Triple::arm || Arch == Triple::thumb ||
667 Arch == Triple::ppc || Arch == Triple::ppc64 ||
668 Arch == Triple::UnknownArch) &&
669 (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
670 Env = IsMachO;
671 InitMachOMCObjectFileInfo(T);
Evan Cheng36c62d32011-07-20 23:53:54 +0000672 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
Andrew Kaylor7bbd6e32012-10-02 18:38:34 +0000673 (T.getEnvironment() != Triple::ELF) &&
Evan Cheng36c62d32011-07-20 23:53:54 +0000674 (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
675 T.getOS() == Triple::Win32)) {
Evan Chenge76a33b2011-07-20 05:58:47 +0000676 Env = IsCOFF;
677 InitCOFFMCObjectFileInfo(T);
678 } else {
679 Env = IsELF;
680 InitELFMCObjectFileInfo(T);
681 }
682}
683
David Chisnall8bb51ef2012-02-17 16:51:02 +0000684void MCObjectFileInfo::InitEHFrameSection() {
685 if (Env == IsMachO)
686 EHFrameSection =
687 Ctx->getMachOSection("__TEXT", "__eh_frame",
688 MCSectionMachO::S_COALESCED |
689 MCSectionMachO::S_ATTR_NO_TOC |
690 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
691 MCSectionMachO::S_ATTR_LIVE_SUPPORT,
692 SectionKind::getReadOnly());
693 else if (Env == IsELF)
694 EHFrameSection =
David Chisnallbce0de42012-04-10 11:44:33 +0000695 Ctx->getELFSection(".eh_frame", EHSectionType,
David Chisnall4cbcee12012-02-17 17:31:15 +0000696 EHSectionFlags,
David Chisnall8bb51ef2012-02-17 16:51:02 +0000697 SectionKind::getDataRel());
698 else
699 EHFrameSection =
700 Ctx->getCOFFSection(".eh_frame",
701 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
702 COFF::IMAGE_SCN_MEM_READ |
703 COFF::IMAGE_SCN_MEM_WRITE,
704 SectionKind::getDataRel());
705}