blob: 0d32ad40e806c47858a70b498d9106e40b79e23f [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) {
Jack Carter732f4bc2013-04-01 21:55:15 +0000226 if (T.getArch() != Triple::mips &&
227 T.getArch() != Triple::mipsel &&
228 T.getArch() != Triple::mips64 &&
229 T.getArch() != Triple::mips64el )
Rafael Espindola7a86ffb2013-03-15 05:51:57 +0000230 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
231
Evan Cheng203576a2011-07-20 19:50:42 +0000232 if (T.getArch() == Triple::x86) {
233 PersonalityEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach946227d2011-11-15 16:46:22 +0000234 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
235 : dwarf::DW_EH_PE_absptr;
Evan Cheng203576a2011-07-20 19:50:42 +0000236 LSDAEncoding = (RelocM == Reloc::PIC_)
237 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
238 : dwarf::DW_EH_PE_absptr;
Rafael Espindola7a86ffb2013-03-15 05:51:57 +0000239 FDEEncoding = (RelocM == Reloc::PIC_)
Evan Cheng203576a2011-07-20 19:50:42 +0000240 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
241 : dwarf::DW_EH_PE_absptr;
242 TTypeEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach946227d2011-11-15 16:46:22 +0000243 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
244 : dwarf::DW_EH_PE_absptr;
Evan Cheng203576a2011-07-20 19:50:42 +0000245 } else if (T.getArch() == Triple::x86_64) {
Evan Cheng203576a2011-07-20 19:50:42 +0000246 if (RelocM == Reloc::PIC_) {
247 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
248 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
249 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
250 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
251 (CMModel == CodeModel::Small
252 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
253 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
254 TTypeEncoding = 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 } else {
258 PersonalityEncoding =
259 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
260 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
261 LSDAEncoding = (CMModel == CodeModel::Small)
262 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
263 FDEEncoding = dwarf::DW_EH_PE_udata4;
264 TTypeEncoding = (CMModel == CodeModel::Small)
265 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
266 }
Tim Northover72062f52013-01-31 12:12:40 +0000267 } else if (T.getArch() == Triple::aarch64) {
Tim Northover72062f52013-01-31 12:12:40 +0000268 // The small model guarantees static code/data size < 4GB, but not where it
269 // will be in memory. Most of these could end up >2GB away so even a signed
270 // pc-relative 32-bit address is insufficient, theoretically.
271 if (RelocM == Reloc::PIC_) {
272 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
273 dwarf::DW_EH_PE_sdata8;
274 LSDAEncoding = dwarf::DW_EH_PE_pcrel | 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 dwarf::DW_EH_PE_sdata8;
278 } else {
279 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
280 LSDAEncoding = dwarf::DW_EH_PE_absptr;
281 FDEEncoding = dwarf::DW_EH_PE_udata4;
282 TTypeEncoding = dwarf::DW_EH_PE_absptr;
283 }
Adhemerval Zanella7b449882013-01-04 19:08:13 +0000284 } else if (T.getArch() == Triple::ppc64) {
Adhemerval Zanellaa1db5de2013-01-09 17:08:15 +0000285 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
286 dwarf::DW_EH_PE_udata8;
Adhemerval Zanellaa1db5de2013-01-09 17:08:15 +0000287 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
288 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
289 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
290 dwarf::DW_EH_PE_udata8;
Evan Cheng203576a2011-07-20 19:50:42 +0000291 }
292
David Chisnall4cbcee12012-02-17 17:31:15 +0000293 // Solaris requires different flags for .eh_frame to seemingly every other
294 // platform.
David Chisnallbce0de42012-04-10 11:44:33 +0000295 EHSectionType = ELF::SHT_PROGBITS;
David Chisnall4cbcee12012-02-17 17:31:15 +0000296 EHSectionFlags = ELF::SHF_ALLOC;
David Chisnallbce0de42012-04-10 11:44:33 +0000297 if (T.getOS() == Triple::Solaris) {
298 if (T.getArch() == Triple::x86_64)
299 EHSectionType = ELF::SHT_X86_64_UNWIND;
300 else
301 EHSectionFlags |= ELF::SHF_WRITE;
302 }
David Chisnall4cbcee12012-02-17 17:31:15 +0000303
304
Evan Chenge76a33b2011-07-20 05:58:47 +0000305 // ELF
306 BSSSection =
307 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
Anton Korobeynikov4a99f592012-01-25 22:24:19 +0000308 ELF::SHF_WRITE | ELF::SHF_ALLOC,
Evan Chenge76a33b2011-07-20 05:58:47 +0000309 SectionKind::getBSS());
310
311 TextSection =
312 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
313 ELF::SHF_EXECINSTR |
314 ELF::SHF_ALLOC,
315 SectionKind::getText());
316
317 DataSection =
318 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
319 ELF::SHF_WRITE |ELF::SHF_ALLOC,
320 SectionKind::getDataRel());
321
322 ReadOnlySection =
323 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
324 ELF::SHF_ALLOC,
325 SectionKind::getReadOnly());
326
327 TLSDataSection =
328 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
329 ELF::SHF_ALLOC | ELF::SHF_TLS |
330 ELF::SHF_WRITE,
331 SectionKind::getThreadData());
332
333 TLSBSSSection =
334 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
335 ELF::SHF_ALLOC | ELF::SHF_TLS |
336 ELF::SHF_WRITE,
337 SectionKind::getThreadBSS());
338
339 DataRelSection =
340 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
341 ELF::SHF_ALLOC |ELF::SHF_WRITE,
342 SectionKind::getDataRel());
343
344 DataRelLocalSection =
345 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
346 ELF::SHF_ALLOC |ELF::SHF_WRITE,
347 SectionKind::getDataRelLocal());
348
349 DataRelROSection =
350 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
351 ELF::SHF_ALLOC |ELF::SHF_WRITE,
352 SectionKind::getReadOnlyWithRel());
353
354 DataRelROLocalSection =
355 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
356 ELF::SHF_ALLOC |ELF::SHF_WRITE,
357 SectionKind::getReadOnlyWithRelLocal());
358
359 MergeableConst4Section =
360 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
361 ELF::SHF_ALLOC |ELF::SHF_MERGE,
362 SectionKind::getMergeableConst4());
363
364 MergeableConst8Section =
365 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
366 ELF::SHF_ALLOC |ELF::SHF_MERGE,
367 SectionKind::getMergeableConst8());
368
369 MergeableConst16Section =
370 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
371 ELF::SHF_ALLOC |ELF::SHF_MERGE,
372 SectionKind::getMergeableConst16());
373
374 StaticCtorSection =
375 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
376 ELF::SHF_ALLOC |ELF::SHF_WRITE,
377 SectionKind::getDataRel());
378
379 StaticDtorSection =
380 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
381 ELF::SHF_ALLOC |ELF::SHF_WRITE,
382 SectionKind::getDataRel());
383
384 // Exception Handling Sections.
385
386 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
387 // it contains relocatable pointers. In PIC mode, this is probably a big
388 // runtime hit for C++ apps. Either the contents of the LSDA need to be
389 // adjusted or this should be a data section.
390 LSDASection =
391 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
392 ELF::SHF_ALLOC,
393 SectionKind::getReadOnly());
394
395 // Debug Info Sections.
396 DwarfAbbrevSection =
397 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
398 SectionKind::getMetadata());
399 DwarfInfoSection =
400 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
401 SectionKind::getMetadata());
402 DwarfLineSection =
403 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
404 SectionKind::getMetadata());
405 DwarfFrameSection =
406 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
407 SectionKind::getMetadata());
Krzysztof Parzyszekc5ef7ee2013-02-12 18:00:14 +0000408 DwarfPubNamesSection =
409 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
410 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000411 DwarfPubTypesSection =
412 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
413 SectionKind::getMetadata());
414 DwarfStrSection =
Nick Lewycky5a86c5b2011-10-26 18:44:32 +0000415 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
416 ELF::SHF_MERGE | ELF::SHF_STRINGS,
417 SectionKind::getMergeable1ByteCString());
Evan Chenge76a33b2011-07-20 05:58:47 +0000418 DwarfLocSection =
419 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
420 SectionKind::getMetadata());
421 DwarfARangesSection =
422 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
423 SectionKind::getMetadata());
424 DwarfRangesSection =
425 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
426 SectionKind::getMetadata());
427 DwarfMacroInfoSection =
428 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
429 SectionKind::getMetadata());
Eric Christopherea1504d2012-11-28 02:49:34 +0000430
431 // DWARF5 Experimental Debug Info
432
433 // Accelerator Tables
Eric Christopher5b4461c2012-10-08 21:41:30 +0000434 DwarfAccelNamesSection =
435 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
436 SectionKind::getMetadata());
437 DwarfAccelObjCSection =
438 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
439 SectionKind::getMetadata());
440 DwarfAccelNamespaceSection =
441 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
442 SectionKind::getMetadata());
443 DwarfAccelTypesSection =
444 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
445 SectionKind::getMetadata());
Eric Christopher6acb5312012-11-28 02:49:38 +0000446
447 // Fission Sections
448 DwarfInfoDWOSection =
449 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
450 SectionKind::getMetadata());
Eric Christopher67587f42012-11-30 06:47:06 +0000451 DwarfAbbrevDWOSection =
452 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
453 SectionKind::getMetadata());
454 DwarfStrDWOSection =
455 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
456 ELF::SHF_MERGE | ELF::SHF_STRINGS,
457 SectionKind::getMergeable1ByteCString());
458 DwarfLineDWOSection =
459 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
460 SectionKind::getMetadata());
461 DwarfLocDWOSection =
462 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
463 SectionKind::getMetadata());
Eric Christopher60230ef2013-01-04 17:59:22 +0000464 DwarfStrOffDWOSection =
465 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
466 SectionKind::getMetadata());
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000467 DwarfAddrSection =
468 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
469 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000470}
471
472
473void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
474 // COFF
475 TextSection =
476 Ctx->getCOFFSection(".text",
477 COFF::IMAGE_SCN_CNT_CODE |
478 COFF::IMAGE_SCN_MEM_EXECUTE |
479 COFF::IMAGE_SCN_MEM_READ,
480 SectionKind::getText());
481 DataSection =
482 Ctx->getCOFFSection(".data",
483 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
484 COFF::IMAGE_SCN_MEM_READ |
485 COFF::IMAGE_SCN_MEM_WRITE,
486 SectionKind::getDataRel());
487 ReadOnlySection =
488 Ctx->getCOFFSection(".rdata",
489 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
490 COFF::IMAGE_SCN_MEM_READ,
491 SectionKind::getReadOnly());
Michael J. Spencer32d22ee2012-02-23 21:56:08 +0000492 if (T.getOS() == Triple::Win32) {
493 StaticCtorSection =
494 Ctx->getCOFFSection(".CRT$XCU",
495 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
496 COFF::IMAGE_SCN_MEM_READ,
497 SectionKind::getReadOnly());
498 } else {
499 StaticCtorSection =
500 Ctx->getCOFFSection(".ctors",
501 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
502 COFF::IMAGE_SCN_MEM_READ |
503 COFF::IMAGE_SCN_MEM_WRITE,
504 SectionKind::getDataRel());
505 }
506
507
Anton Korobeynikov371e17c2012-09-23 15:53:47 +0000508 if (T.getOS() == Triple::Win32) {
509 StaticDtorSection =
510 Ctx->getCOFFSection(".CRT$XTX",
511 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
512 COFF::IMAGE_SCN_MEM_READ,
513 SectionKind::getReadOnly());
514 } else {
515 StaticDtorSection =
516 Ctx->getCOFFSection(".dtors",
517 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
518 COFF::IMAGE_SCN_MEM_READ |
519 COFF::IMAGE_SCN_MEM_WRITE,
520 SectionKind::getDataRel());
521 }
Evan Chenge76a33b2011-07-20 05:58:47 +0000522
523 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
524 // though it contains relocatable pointers. In PIC mode, this is probably a
525 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
526 // adjusted or this should be a data section.
527 LSDASection =
528 Ctx->getCOFFSection(".gcc_except_table",
529 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
530 COFF::IMAGE_SCN_MEM_READ,
531 SectionKind::getReadOnly());
532
533 // Debug info.
534 DwarfAbbrevSection =
535 Ctx->getCOFFSection(".debug_abbrev",
536 COFF::IMAGE_SCN_MEM_DISCARDABLE |
537 COFF::IMAGE_SCN_MEM_READ,
538 SectionKind::getMetadata());
539 DwarfInfoSection =
540 Ctx->getCOFFSection(".debug_info",
541 COFF::IMAGE_SCN_MEM_DISCARDABLE |
542 COFF::IMAGE_SCN_MEM_READ,
543 SectionKind::getMetadata());
544 DwarfLineSection =
545 Ctx->getCOFFSection(".debug_line",
546 COFF::IMAGE_SCN_MEM_DISCARDABLE |
547 COFF::IMAGE_SCN_MEM_READ,
548 SectionKind::getMetadata());
549 DwarfFrameSection =
550 Ctx->getCOFFSection(".debug_frame",
551 COFF::IMAGE_SCN_MEM_DISCARDABLE |
552 COFF::IMAGE_SCN_MEM_READ,
553 SectionKind::getMetadata());
Krzysztof Parzyszekc5ef7ee2013-02-12 18:00:14 +0000554 DwarfPubNamesSection =
555 Ctx->getCOFFSection(".debug_pubnames",
556 COFF::IMAGE_SCN_MEM_DISCARDABLE |
557 COFF::IMAGE_SCN_MEM_READ,
558 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000559 DwarfPubTypesSection =
560 Ctx->getCOFFSection(".debug_pubtypes",
561 COFF::IMAGE_SCN_MEM_DISCARDABLE |
562 COFF::IMAGE_SCN_MEM_READ,
563 SectionKind::getMetadata());
564 DwarfStrSection =
565 Ctx->getCOFFSection(".debug_str",
566 COFF::IMAGE_SCN_MEM_DISCARDABLE |
567 COFF::IMAGE_SCN_MEM_READ,
568 SectionKind::getMetadata());
569 DwarfLocSection =
570 Ctx->getCOFFSection(".debug_loc",
571 COFF::IMAGE_SCN_MEM_DISCARDABLE |
572 COFF::IMAGE_SCN_MEM_READ,
573 SectionKind::getMetadata());
574 DwarfARangesSection =
575 Ctx->getCOFFSection(".debug_aranges",
576 COFF::IMAGE_SCN_MEM_DISCARDABLE |
577 COFF::IMAGE_SCN_MEM_READ,
578 SectionKind::getMetadata());
579 DwarfRangesSection =
580 Ctx->getCOFFSection(".debug_ranges",
581 COFF::IMAGE_SCN_MEM_DISCARDABLE |
582 COFF::IMAGE_SCN_MEM_READ,
583 SectionKind::getMetadata());
584 DwarfMacroInfoSection =
585 Ctx->getCOFFSection(".debug_macinfo",
586 COFF::IMAGE_SCN_MEM_DISCARDABLE |
587 COFF::IMAGE_SCN_MEM_READ,
588 SectionKind::getMetadata());
589
590 DrectveSection =
591 Ctx->getCOFFSection(".drectve",
592 COFF::IMAGE_SCN_LNK_INFO,
593 SectionKind::getMetadata());
594
595 PDataSection =
596 Ctx->getCOFFSection(".pdata",
597 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikov0a0e50c2012-08-08 12:46:46 +0000598 COFF::IMAGE_SCN_MEM_READ,
Evan Chenge76a33b2011-07-20 05:58:47 +0000599 SectionKind::getDataRel());
600
601 XDataSection =
602 Ctx->getCOFFSection(".xdata",
603 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikov0a0e50c2012-08-08 12:46:46 +0000604 COFF::IMAGE_SCN_MEM_READ,
Evan Chenge76a33b2011-07-20 05:58:47 +0000605 SectionKind::getDataRel());
Anton Korobeynikovd4a19b62012-02-11 17:26:53 +0000606 TLSDataSection =
607 Ctx->getCOFFSection(".tls$",
608 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
609 COFF::IMAGE_SCN_MEM_READ |
610 COFF::IMAGE_SCN_MEM_WRITE,
611 SectionKind::getDataRel());
Evan Chenge76a33b2011-07-20 05:58:47 +0000612}
613
614void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
Evan Cheng203576a2011-07-20 19:50:42 +0000615 CodeModel::Model cm,
Evan Chenge76a33b2011-07-20 05:58:47 +0000616 MCContext &ctx) {
617 RelocM = relocm;
Evan Cheng203576a2011-07-20 19:50:42 +0000618 CMModel = cm;
Evan Chenge76a33b2011-07-20 05:58:47 +0000619 Ctx = &ctx;
620
621 // Common.
622 CommDirectiveSupportsAlignment = true;
623 SupportsWeakOmittedEHFrame = true;
624 IsFunctionEHFrameSymbolPrivate = true;
Evan Cheng203576a2011-07-20 19:50:42 +0000625
626 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
627 TTypeEncoding = dwarf::DW_EH_PE_absptr;
628
Eric Christopher09ac3d82011-11-07 09:24:32 +0000629 EHFrameSection = 0; // Created on demand.
630 CompactUnwindSection = 0; // Used only by selected targets.
631 DwarfAccelNamesSection = 0; // Used only by selected targets.
632 DwarfAccelObjCSection = 0; // Used only by selected targets.
633 DwarfAccelNamespaceSection = 0; // Used only by selected targets.
634 DwarfAccelTypesSection = 0; // Used only by selected targets.
Evan Chenge76a33b2011-07-20 05:58:47 +0000635
636 Triple T(TT);
637 Triple::ArchType Arch = T.getArch();
638 // FIXME: Checking for Arch here to filter out bogus triples such as
639 // cellspu-apple-darwin. Perhaps we should fix in Triple?
640 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
641 Arch == Triple::arm || Arch == Triple::thumb ||
642 Arch == Triple::ppc || Arch == Triple::ppc64 ||
643 Arch == Triple::UnknownArch) &&
644 (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
645 Env = IsMachO;
646 InitMachOMCObjectFileInfo(T);
Evan Cheng36c62d32011-07-20 23:53:54 +0000647 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
Andrew Kaylor7bbd6e32012-10-02 18:38:34 +0000648 (T.getEnvironment() != Triple::ELF) &&
Evan Cheng36c62d32011-07-20 23:53:54 +0000649 (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
650 T.getOS() == Triple::Win32)) {
Evan Chenge76a33b2011-07-20 05:58:47 +0000651 Env = IsCOFF;
652 InitCOFFMCObjectFileInfo(T);
653 } else {
654 Env = IsELF;
655 InitELFMCObjectFileInfo(T);
656 }
657}
658
David Chisnall8bb51ef2012-02-17 16:51:02 +0000659void MCObjectFileInfo::InitEHFrameSection() {
660 if (Env == IsMachO)
661 EHFrameSection =
662 Ctx->getMachOSection("__TEXT", "__eh_frame",
663 MCSectionMachO::S_COALESCED |
664 MCSectionMachO::S_ATTR_NO_TOC |
665 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
666 MCSectionMachO::S_ATTR_LIVE_SUPPORT,
667 SectionKind::getReadOnly());
668 else if (Env == IsELF)
669 EHFrameSection =
David Chisnallbce0de42012-04-10 11:44:33 +0000670 Ctx->getELFSection(".eh_frame", EHSectionType,
David Chisnall4cbcee12012-02-17 17:31:15 +0000671 EHSectionFlags,
David Chisnall8bb51ef2012-02-17 16:51:02 +0000672 SectionKind::getDataRel());
673 else
674 EHFrameSection =
675 Ctx->getCOFFSection(".eh_frame",
676 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
677 COFF::IMAGE_SCN_MEM_READ |
678 COFF::IMAGE_SCN_MEM_WRITE,
679 SectionKind::getDataRel());
680}