blob: d19e79ac64f9c2865b86b27cfb17779fd66b2b56 [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
148 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
149 CompactUnwindSection =
150 Ctx->getMachOSection("__LD", "__compact_unwind",
151 MCSectionMachO::S_ATTR_DEBUG,
152 SectionKind::getReadOnly());
153
154 // Debug Information.
Eric Christopher09ac3d82011-11-07 09:24:32 +0000155 DwarfAccelNamesSection =
156 Ctx->getMachOSection("__DWARF", "__apple_names",
157 MCSectionMachO::S_ATTR_DEBUG,
158 SectionKind::getMetadata());
159 DwarfAccelObjCSection =
160 Ctx->getMachOSection("__DWARF", "__apple_objc",
161 MCSectionMachO::S_ATTR_DEBUG,
162 SectionKind::getMetadata());
163 // 16 character section limit...
164 DwarfAccelNamespaceSection =
165 Ctx->getMachOSection("__DWARF", "__apple_namespac",
166 MCSectionMachO::S_ATTR_DEBUG,
167 SectionKind::getMetadata());
168 DwarfAccelTypesSection =
169 Ctx->getMachOSection("__DWARF", "__apple_types",
170 MCSectionMachO::S_ATTR_DEBUG,
171 SectionKind::getMetadata());
Jim Grosbach2684d9e2012-05-11 01:41:30 +0000172
Evan Chenge76a33b2011-07-20 05:58:47 +0000173 DwarfAbbrevSection =
174 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
175 MCSectionMachO::S_ATTR_DEBUG,
176 SectionKind::getMetadata());
177 DwarfInfoSection =
178 Ctx->getMachOSection("__DWARF", "__debug_info",
179 MCSectionMachO::S_ATTR_DEBUG,
180 SectionKind::getMetadata());
181 DwarfLineSection =
182 Ctx->getMachOSection("__DWARF", "__debug_line",
183 MCSectionMachO::S_ATTR_DEBUG,
184 SectionKind::getMetadata());
185 DwarfFrameSection =
186 Ctx->getMachOSection("__DWARF", "__debug_frame",
187 MCSectionMachO::S_ATTR_DEBUG,
188 SectionKind::getMetadata());
Krzysztof Parzyszekc5ef7ee2013-02-12 18:00:14 +0000189 DwarfPubNamesSection =
190 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
191 MCSectionMachO::S_ATTR_DEBUG,
192 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000193 DwarfPubTypesSection =
194 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
195 MCSectionMachO::S_ATTR_DEBUG,
196 SectionKind::getMetadata());
197 DwarfStrSection =
198 Ctx->getMachOSection("__DWARF", "__debug_str",
199 MCSectionMachO::S_ATTR_DEBUG,
200 SectionKind::getMetadata());
201 DwarfLocSection =
202 Ctx->getMachOSection("__DWARF", "__debug_loc",
203 MCSectionMachO::S_ATTR_DEBUG,
204 SectionKind::getMetadata());
205 DwarfARangesSection =
206 Ctx->getMachOSection("__DWARF", "__debug_aranges",
207 MCSectionMachO::S_ATTR_DEBUG,
208 SectionKind::getMetadata());
209 DwarfRangesSection =
210 Ctx->getMachOSection("__DWARF", "__debug_ranges",
211 MCSectionMachO::S_ATTR_DEBUG,
212 SectionKind::getMetadata());
213 DwarfMacroInfoSection =
214 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
215 MCSectionMachO::S_ATTR_DEBUG,
216 SectionKind::getMetadata());
217 DwarfDebugInlineSection =
218 Ctx->getMachOSection("__DWARF", "__debug_inlined",
219 MCSectionMachO::S_ATTR_DEBUG,
220 SectionKind::getMetadata());
221
222 TLSExtraDataSection = TLSTLVSection;
223}
224
225void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
Rafael Espindola04011e842013-04-03 03:13:19 +0000226 if (T.getArch() == Triple::mips ||
227 T.getArch() == Triple::mipsel)
228 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
229 else if (T.getArch() == Triple::mips64 ||
230 T.getArch() == Triple::mips64el)
231 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
232 else
Rafael Espindola7a86ffb2013-03-15 05:51:57 +0000233 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
234
Evan Cheng203576a2011-07-20 19:50:42 +0000235 if (T.getArch() == Triple::x86) {
236 PersonalityEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach946227d2011-11-15 16:46:22 +0000237 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
238 : dwarf::DW_EH_PE_absptr;
Evan Cheng203576a2011-07-20 19:50:42 +0000239 LSDAEncoding = (RelocM == Reloc::PIC_)
240 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
241 : dwarf::DW_EH_PE_absptr;
Rafael Espindola7a86ffb2013-03-15 05:51:57 +0000242 FDEEncoding = (RelocM == Reloc::PIC_)
Evan Cheng203576a2011-07-20 19:50:42 +0000243 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
244 : dwarf::DW_EH_PE_absptr;
245 TTypeEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach946227d2011-11-15 16:46:22 +0000246 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
247 : dwarf::DW_EH_PE_absptr;
Evan Cheng203576a2011-07-20 19:50:42 +0000248 } else if (T.getArch() == Triple::x86_64) {
Evan Cheng203576a2011-07-20 19:50:42 +0000249 if (RelocM == Reloc::PIC_) {
250 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
251 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
252 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
253 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
254 (CMModel == CodeModel::Small
255 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
256 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
257 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
258 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
259 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
260 } else {
261 PersonalityEncoding =
262 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
263 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
264 LSDAEncoding = (CMModel == CodeModel::Small)
265 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
266 FDEEncoding = dwarf::DW_EH_PE_udata4;
267 TTypeEncoding = (CMModel == CodeModel::Small)
268 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
269 }
Tim Northover72062f52013-01-31 12:12:40 +0000270 } else if (T.getArch() == Triple::aarch64) {
Tim Northover72062f52013-01-31 12:12:40 +0000271 // The small model guarantees static code/data size < 4GB, but not where it
272 // will be in memory. Most of these could end up >2GB away so even a signed
273 // pc-relative 32-bit address is insufficient, theoretically.
274 if (RelocM == Reloc::PIC_) {
275 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
276 dwarf::DW_EH_PE_sdata8;
277 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
278 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
279 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
280 dwarf::DW_EH_PE_sdata8;
281 } else {
282 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
283 LSDAEncoding = dwarf::DW_EH_PE_absptr;
284 FDEEncoding = dwarf::DW_EH_PE_udata4;
285 TTypeEncoding = dwarf::DW_EH_PE_absptr;
286 }
Adhemerval Zanella7b449882013-01-04 19:08:13 +0000287 } else if (T.getArch() == Triple::ppc64) {
Adhemerval Zanellaa1db5de2013-01-09 17:08:15 +0000288 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
289 dwarf::DW_EH_PE_udata8;
Adhemerval Zanellaa1db5de2013-01-09 17:08:15 +0000290 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
291 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
292 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
293 dwarf::DW_EH_PE_udata8;
Evan Cheng203576a2011-07-20 19:50:42 +0000294 }
295
David Chisnall4cbcee12012-02-17 17:31:15 +0000296 // Solaris requires different flags for .eh_frame to seemingly every other
297 // platform.
David Chisnallbce0de42012-04-10 11:44:33 +0000298 EHSectionType = ELF::SHT_PROGBITS;
David Chisnall4cbcee12012-02-17 17:31:15 +0000299 EHSectionFlags = ELF::SHF_ALLOC;
David Chisnallbce0de42012-04-10 11:44:33 +0000300 if (T.getOS() == Triple::Solaris) {
301 if (T.getArch() == Triple::x86_64)
302 EHSectionType = ELF::SHT_X86_64_UNWIND;
303 else
304 EHSectionFlags |= ELF::SHF_WRITE;
305 }
David Chisnall4cbcee12012-02-17 17:31:15 +0000306
307
Evan Chenge76a33b2011-07-20 05:58:47 +0000308 // ELF
309 BSSSection =
310 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
Anton Korobeynikov4a99f592012-01-25 22:24:19 +0000311 ELF::SHF_WRITE | ELF::SHF_ALLOC,
Evan Chenge76a33b2011-07-20 05:58:47 +0000312 SectionKind::getBSS());
313
314 TextSection =
315 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
316 ELF::SHF_EXECINSTR |
317 ELF::SHF_ALLOC,
318 SectionKind::getText());
319
320 DataSection =
321 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
322 ELF::SHF_WRITE |ELF::SHF_ALLOC,
323 SectionKind::getDataRel());
324
325 ReadOnlySection =
326 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
327 ELF::SHF_ALLOC,
328 SectionKind::getReadOnly());
329
330 TLSDataSection =
331 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
332 ELF::SHF_ALLOC | ELF::SHF_TLS |
333 ELF::SHF_WRITE,
334 SectionKind::getThreadData());
335
336 TLSBSSSection =
337 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
338 ELF::SHF_ALLOC | ELF::SHF_TLS |
339 ELF::SHF_WRITE,
340 SectionKind::getThreadBSS());
341
342 DataRelSection =
343 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
344 ELF::SHF_ALLOC |ELF::SHF_WRITE,
345 SectionKind::getDataRel());
346
347 DataRelLocalSection =
348 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
349 ELF::SHF_ALLOC |ELF::SHF_WRITE,
350 SectionKind::getDataRelLocal());
351
352 DataRelROSection =
353 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
354 ELF::SHF_ALLOC |ELF::SHF_WRITE,
355 SectionKind::getReadOnlyWithRel());
356
357 DataRelROLocalSection =
358 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
359 ELF::SHF_ALLOC |ELF::SHF_WRITE,
360 SectionKind::getReadOnlyWithRelLocal());
361
362 MergeableConst4Section =
363 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
364 ELF::SHF_ALLOC |ELF::SHF_MERGE,
365 SectionKind::getMergeableConst4());
366
367 MergeableConst8Section =
368 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
369 ELF::SHF_ALLOC |ELF::SHF_MERGE,
370 SectionKind::getMergeableConst8());
371
372 MergeableConst16Section =
373 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
374 ELF::SHF_ALLOC |ELF::SHF_MERGE,
375 SectionKind::getMergeableConst16());
376
377 StaticCtorSection =
378 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
379 ELF::SHF_ALLOC |ELF::SHF_WRITE,
380 SectionKind::getDataRel());
381
382 StaticDtorSection =
383 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
384 ELF::SHF_ALLOC |ELF::SHF_WRITE,
385 SectionKind::getDataRel());
386
387 // Exception Handling Sections.
388
389 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
390 // it contains relocatable pointers. In PIC mode, this is probably a big
391 // runtime hit for C++ apps. Either the contents of the LSDA need to be
392 // adjusted or this should be a data section.
393 LSDASection =
394 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
395 ELF::SHF_ALLOC,
396 SectionKind::getReadOnly());
397
398 // Debug Info Sections.
399 DwarfAbbrevSection =
400 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
401 SectionKind::getMetadata());
402 DwarfInfoSection =
403 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
404 SectionKind::getMetadata());
405 DwarfLineSection =
406 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
407 SectionKind::getMetadata());
408 DwarfFrameSection =
409 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
410 SectionKind::getMetadata());
Krzysztof Parzyszekc5ef7ee2013-02-12 18:00:14 +0000411 DwarfPubNamesSection =
412 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
413 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000414 DwarfPubTypesSection =
415 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
416 SectionKind::getMetadata());
417 DwarfStrSection =
Nick Lewycky5a86c5b2011-10-26 18:44:32 +0000418 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
419 ELF::SHF_MERGE | ELF::SHF_STRINGS,
420 SectionKind::getMergeable1ByteCString());
Evan Chenge76a33b2011-07-20 05:58:47 +0000421 DwarfLocSection =
422 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
423 SectionKind::getMetadata());
424 DwarfARangesSection =
425 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
426 SectionKind::getMetadata());
427 DwarfRangesSection =
428 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
429 SectionKind::getMetadata());
430 DwarfMacroInfoSection =
431 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
432 SectionKind::getMetadata());
Eric Christopherea1504d2012-11-28 02:49:34 +0000433
434 // DWARF5 Experimental Debug Info
435
436 // Accelerator Tables
Eric Christopher5b4461c2012-10-08 21:41:30 +0000437 DwarfAccelNamesSection =
438 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
439 SectionKind::getMetadata());
440 DwarfAccelObjCSection =
441 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
442 SectionKind::getMetadata());
443 DwarfAccelNamespaceSection =
444 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
445 SectionKind::getMetadata());
446 DwarfAccelTypesSection =
447 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
448 SectionKind::getMetadata());
Eric Christopher6acb5312012-11-28 02:49:38 +0000449
450 // Fission Sections
451 DwarfInfoDWOSection =
452 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
453 SectionKind::getMetadata());
Eric Christopher67587f42012-11-30 06:47:06 +0000454 DwarfAbbrevDWOSection =
455 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
456 SectionKind::getMetadata());
457 DwarfStrDWOSection =
458 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
459 ELF::SHF_MERGE | ELF::SHF_STRINGS,
460 SectionKind::getMergeable1ByteCString());
461 DwarfLineDWOSection =
462 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
463 SectionKind::getMetadata());
464 DwarfLocDWOSection =
465 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
466 SectionKind::getMetadata());
Eric Christopher60230ef2013-01-04 17:59:22 +0000467 DwarfStrOffDWOSection =
468 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
469 SectionKind::getMetadata());
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000470 DwarfAddrSection =
471 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
472 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000473}
474
475
476void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
477 // COFF
478 TextSection =
479 Ctx->getCOFFSection(".text",
480 COFF::IMAGE_SCN_CNT_CODE |
481 COFF::IMAGE_SCN_MEM_EXECUTE |
482 COFF::IMAGE_SCN_MEM_READ,
483 SectionKind::getText());
484 DataSection =
485 Ctx->getCOFFSection(".data",
486 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
487 COFF::IMAGE_SCN_MEM_READ |
488 COFF::IMAGE_SCN_MEM_WRITE,
489 SectionKind::getDataRel());
490 ReadOnlySection =
491 Ctx->getCOFFSection(".rdata",
492 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
493 COFF::IMAGE_SCN_MEM_READ,
494 SectionKind::getReadOnly());
Michael J. Spencer32d22ee2012-02-23 21:56:08 +0000495 if (T.getOS() == Triple::Win32) {
496 StaticCtorSection =
497 Ctx->getCOFFSection(".CRT$XCU",
498 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
499 COFF::IMAGE_SCN_MEM_READ,
500 SectionKind::getReadOnly());
501 } else {
502 StaticCtorSection =
503 Ctx->getCOFFSection(".ctors",
504 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
505 COFF::IMAGE_SCN_MEM_READ |
506 COFF::IMAGE_SCN_MEM_WRITE,
507 SectionKind::getDataRel());
508 }
509
510
Anton Korobeynikov371e17c2012-09-23 15:53:47 +0000511 if (T.getOS() == Triple::Win32) {
512 StaticDtorSection =
513 Ctx->getCOFFSection(".CRT$XTX",
514 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
515 COFF::IMAGE_SCN_MEM_READ,
516 SectionKind::getReadOnly());
517 } else {
518 StaticDtorSection =
519 Ctx->getCOFFSection(".dtors",
520 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
521 COFF::IMAGE_SCN_MEM_READ |
522 COFF::IMAGE_SCN_MEM_WRITE,
523 SectionKind::getDataRel());
524 }
Evan Chenge76a33b2011-07-20 05:58:47 +0000525
526 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
527 // though it contains relocatable pointers. In PIC mode, this is probably a
528 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
529 // adjusted or this should be a data section.
530 LSDASection =
531 Ctx->getCOFFSection(".gcc_except_table",
532 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
533 COFF::IMAGE_SCN_MEM_READ,
534 SectionKind::getReadOnly());
535
536 // Debug info.
537 DwarfAbbrevSection =
538 Ctx->getCOFFSection(".debug_abbrev",
539 COFF::IMAGE_SCN_MEM_DISCARDABLE |
540 COFF::IMAGE_SCN_MEM_READ,
541 SectionKind::getMetadata());
542 DwarfInfoSection =
543 Ctx->getCOFFSection(".debug_info",
544 COFF::IMAGE_SCN_MEM_DISCARDABLE |
545 COFF::IMAGE_SCN_MEM_READ,
546 SectionKind::getMetadata());
547 DwarfLineSection =
548 Ctx->getCOFFSection(".debug_line",
549 COFF::IMAGE_SCN_MEM_DISCARDABLE |
550 COFF::IMAGE_SCN_MEM_READ,
551 SectionKind::getMetadata());
552 DwarfFrameSection =
553 Ctx->getCOFFSection(".debug_frame",
554 COFF::IMAGE_SCN_MEM_DISCARDABLE |
555 COFF::IMAGE_SCN_MEM_READ,
556 SectionKind::getMetadata());
Krzysztof Parzyszekc5ef7ee2013-02-12 18:00:14 +0000557 DwarfPubNamesSection =
558 Ctx->getCOFFSection(".debug_pubnames",
559 COFF::IMAGE_SCN_MEM_DISCARDABLE |
560 COFF::IMAGE_SCN_MEM_READ,
561 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000562 DwarfPubTypesSection =
563 Ctx->getCOFFSection(".debug_pubtypes",
564 COFF::IMAGE_SCN_MEM_DISCARDABLE |
565 COFF::IMAGE_SCN_MEM_READ,
566 SectionKind::getMetadata());
567 DwarfStrSection =
568 Ctx->getCOFFSection(".debug_str",
569 COFF::IMAGE_SCN_MEM_DISCARDABLE |
570 COFF::IMAGE_SCN_MEM_READ,
571 SectionKind::getMetadata());
572 DwarfLocSection =
573 Ctx->getCOFFSection(".debug_loc",
574 COFF::IMAGE_SCN_MEM_DISCARDABLE |
575 COFF::IMAGE_SCN_MEM_READ,
576 SectionKind::getMetadata());
577 DwarfARangesSection =
578 Ctx->getCOFFSection(".debug_aranges",
579 COFF::IMAGE_SCN_MEM_DISCARDABLE |
580 COFF::IMAGE_SCN_MEM_READ,
581 SectionKind::getMetadata());
582 DwarfRangesSection =
583 Ctx->getCOFFSection(".debug_ranges",
584 COFF::IMAGE_SCN_MEM_DISCARDABLE |
585 COFF::IMAGE_SCN_MEM_READ,
586 SectionKind::getMetadata());
587 DwarfMacroInfoSection =
588 Ctx->getCOFFSection(".debug_macinfo",
589 COFF::IMAGE_SCN_MEM_DISCARDABLE |
590 COFF::IMAGE_SCN_MEM_READ,
591 SectionKind::getMetadata());
592
593 DrectveSection =
594 Ctx->getCOFFSection(".drectve",
595 COFF::IMAGE_SCN_LNK_INFO,
596 SectionKind::getMetadata());
597
598 PDataSection =
599 Ctx->getCOFFSection(".pdata",
600 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikov0a0e50c2012-08-08 12:46:46 +0000601 COFF::IMAGE_SCN_MEM_READ,
Evan Chenge76a33b2011-07-20 05:58:47 +0000602 SectionKind::getDataRel());
603
604 XDataSection =
605 Ctx->getCOFFSection(".xdata",
606 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikov0a0e50c2012-08-08 12:46:46 +0000607 COFF::IMAGE_SCN_MEM_READ,
Evan Chenge76a33b2011-07-20 05:58:47 +0000608 SectionKind::getDataRel());
Anton Korobeynikovd4a19b62012-02-11 17:26:53 +0000609 TLSDataSection =
610 Ctx->getCOFFSection(".tls$",
611 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
612 COFF::IMAGE_SCN_MEM_READ |
613 COFF::IMAGE_SCN_MEM_WRITE,
614 SectionKind::getDataRel());
Evan Chenge76a33b2011-07-20 05:58:47 +0000615}
616
617void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
Evan Cheng203576a2011-07-20 19:50:42 +0000618 CodeModel::Model cm,
Evan Chenge76a33b2011-07-20 05:58:47 +0000619 MCContext &ctx) {
620 RelocM = relocm;
Evan Cheng203576a2011-07-20 19:50:42 +0000621 CMModel = cm;
Evan Chenge76a33b2011-07-20 05:58:47 +0000622 Ctx = &ctx;
623
624 // Common.
625 CommDirectiveSupportsAlignment = true;
626 SupportsWeakOmittedEHFrame = true;
627 IsFunctionEHFrameSymbolPrivate = true;
Evan Cheng203576a2011-07-20 19:50:42 +0000628
629 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
630 TTypeEncoding = dwarf::DW_EH_PE_absptr;
631
Eric Christopher09ac3d82011-11-07 09:24:32 +0000632 EHFrameSection = 0; // Created on demand.
633 CompactUnwindSection = 0; // Used only by selected targets.
634 DwarfAccelNamesSection = 0; // Used only by selected targets.
635 DwarfAccelObjCSection = 0; // Used only by selected targets.
636 DwarfAccelNamespaceSection = 0; // Used only by selected targets.
637 DwarfAccelTypesSection = 0; // Used only by selected targets.
Evan Chenge76a33b2011-07-20 05:58:47 +0000638
639 Triple T(TT);
640 Triple::ArchType Arch = T.getArch();
641 // FIXME: Checking for Arch here to filter out bogus triples such as
642 // cellspu-apple-darwin. Perhaps we should fix in Triple?
643 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
644 Arch == Triple::arm || Arch == Triple::thumb ||
645 Arch == Triple::ppc || Arch == Triple::ppc64 ||
646 Arch == Triple::UnknownArch) &&
647 (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
648 Env = IsMachO;
649 InitMachOMCObjectFileInfo(T);
Evan Cheng36c62d32011-07-20 23:53:54 +0000650 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
Andrew Kaylor7bbd6e32012-10-02 18:38:34 +0000651 (T.getEnvironment() != Triple::ELF) &&
Evan Cheng36c62d32011-07-20 23:53:54 +0000652 (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
653 T.getOS() == Triple::Win32)) {
Evan Chenge76a33b2011-07-20 05:58:47 +0000654 Env = IsCOFF;
655 InitCOFFMCObjectFileInfo(T);
656 } else {
657 Env = IsELF;
658 InitELFMCObjectFileInfo(T);
659 }
660}
661
David Chisnall8bb51ef2012-02-17 16:51:02 +0000662void MCObjectFileInfo::InitEHFrameSection() {
663 if (Env == IsMachO)
664 EHFrameSection =
665 Ctx->getMachOSection("__TEXT", "__eh_frame",
666 MCSectionMachO::S_COALESCED |
667 MCSectionMachO::S_ATTR_NO_TOC |
668 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
669 MCSectionMachO::S_ATTR_LIVE_SUPPORT,
670 SectionKind::getReadOnly());
671 else if (Env == IsELF)
672 EHFrameSection =
David Chisnallbce0de42012-04-10 11:44:33 +0000673 Ctx->getELFSection(".eh_frame", EHSectionType,
David Chisnall4cbcee12012-02-17 17:31:15 +0000674 EHSectionFlags,
David Chisnall8bb51ef2012-02-17 16:51:02 +0000675 SectionKind::getDataRel());
676 else
677 EHFrameSection =
678 Ctx->getCOFFSection(".eh_frame",
679 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
680 COFF::IMAGE_SCN_MEM_READ |
681 COFF::IMAGE_SCN_MEM_WRITE,
682 SectionKind::getDataRel());
683}