blob: 79ebad15e670fa93d969f85c3b53b63207281235 [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;
Evan Cheng203576a2011-07-20 19:50:42 +0000298 }
299
David Chisnall4cbcee12012-02-17 17:31:15 +0000300 // Solaris requires different flags for .eh_frame to seemingly every other
301 // platform.
David Chisnallbce0de42012-04-10 11:44:33 +0000302 EHSectionType = ELF::SHT_PROGBITS;
David Chisnall4cbcee12012-02-17 17:31:15 +0000303 EHSectionFlags = ELF::SHF_ALLOC;
David Chisnallbce0de42012-04-10 11:44:33 +0000304 if (T.getOS() == Triple::Solaris) {
305 if (T.getArch() == Triple::x86_64)
306 EHSectionType = ELF::SHT_X86_64_UNWIND;
307 else
308 EHSectionFlags |= ELF::SHF_WRITE;
309 }
David Chisnall4cbcee12012-02-17 17:31:15 +0000310
311
Evan Chenge76a33b2011-07-20 05:58:47 +0000312 // ELF
313 BSSSection =
314 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
Anton Korobeynikov4a99f592012-01-25 22:24:19 +0000315 ELF::SHF_WRITE | ELF::SHF_ALLOC,
Evan Chenge76a33b2011-07-20 05:58:47 +0000316 SectionKind::getBSS());
317
318 TextSection =
319 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
320 ELF::SHF_EXECINSTR |
321 ELF::SHF_ALLOC,
322 SectionKind::getText());
323
324 DataSection =
325 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
326 ELF::SHF_WRITE |ELF::SHF_ALLOC,
327 SectionKind::getDataRel());
328
329 ReadOnlySection =
330 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
331 ELF::SHF_ALLOC,
332 SectionKind::getReadOnly());
333
334 TLSDataSection =
335 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
336 ELF::SHF_ALLOC | ELF::SHF_TLS |
337 ELF::SHF_WRITE,
338 SectionKind::getThreadData());
339
340 TLSBSSSection =
341 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
342 ELF::SHF_ALLOC | ELF::SHF_TLS |
343 ELF::SHF_WRITE,
344 SectionKind::getThreadBSS());
345
346 DataRelSection =
347 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
348 ELF::SHF_ALLOC |ELF::SHF_WRITE,
349 SectionKind::getDataRel());
350
351 DataRelLocalSection =
352 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
353 ELF::SHF_ALLOC |ELF::SHF_WRITE,
354 SectionKind::getDataRelLocal());
355
356 DataRelROSection =
357 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
358 ELF::SHF_ALLOC |ELF::SHF_WRITE,
359 SectionKind::getReadOnlyWithRel());
360
361 DataRelROLocalSection =
362 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
363 ELF::SHF_ALLOC |ELF::SHF_WRITE,
364 SectionKind::getReadOnlyWithRelLocal());
365
366 MergeableConst4Section =
367 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
368 ELF::SHF_ALLOC |ELF::SHF_MERGE,
369 SectionKind::getMergeableConst4());
370
371 MergeableConst8Section =
372 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
373 ELF::SHF_ALLOC |ELF::SHF_MERGE,
374 SectionKind::getMergeableConst8());
375
376 MergeableConst16Section =
377 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
378 ELF::SHF_ALLOC |ELF::SHF_MERGE,
379 SectionKind::getMergeableConst16());
380
381 StaticCtorSection =
382 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
383 ELF::SHF_ALLOC |ELF::SHF_WRITE,
384 SectionKind::getDataRel());
385
386 StaticDtorSection =
387 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
388 ELF::SHF_ALLOC |ELF::SHF_WRITE,
389 SectionKind::getDataRel());
390
391 // Exception Handling Sections.
392
393 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
394 // it contains relocatable pointers. In PIC mode, this is probably a big
395 // runtime hit for C++ apps. Either the contents of the LSDA need to be
396 // adjusted or this should be a data section.
397 LSDASection =
398 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
399 ELF::SHF_ALLOC,
400 SectionKind::getReadOnly());
401
402 // Debug Info Sections.
403 DwarfAbbrevSection =
404 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
405 SectionKind::getMetadata());
406 DwarfInfoSection =
407 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
408 SectionKind::getMetadata());
409 DwarfLineSection =
410 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
411 SectionKind::getMetadata());
412 DwarfFrameSection =
413 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
414 SectionKind::getMetadata());
Krzysztof Parzyszekc5ef7ee2013-02-12 18:00:14 +0000415 DwarfPubNamesSection =
416 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
417 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000418 DwarfPubTypesSection =
419 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
420 SectionKind::getMetadata());
421 DwarfStrSection =
Nick Lewycky5a86c5b2011-10-26 18:44:32 +0000422 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
423 ELF::SHF_MERGE | ELF::SHF_STRINGS,
424 SectionKind::getMergeable1ByteCString());
Evan Chenge76a33b2011-07-20 05:58:47 +0000425 DwarfLocSection =
426 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
427 SectionKind::getMetadata());
428 DwarfARangesSection =
429 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
430 SectionKind::getMetadata());
431 DwarfRangesSection =
432 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
433 SectionKind::getMetadata());
434 DwarfMacroInfoSection =
435 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
436 SectionKind::getMetadata());
Eric Christopherea1504d2012-11-28 02:49:34 +0000437
438 // DWARF5 Experimental Debug Info
439
440 // Accelerator Tables
Eric Christopher5b4461c2012-10-08 21:41:30 +0000441 DwarfAccelNamesSection =
442 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
443 SectionKind::getMetadata());
444 DwarfAccelObjCSection =
445 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
446 SectionKind::getMetadata());
447 DwarfAccelNamespaceSection =
448 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
449 SectionKind::getMetadata());
450 DwarfAccelTypesSection =
451 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
452 SectionKind::getMetadata());
Eric Christopher6acb5312012-11-28 02:49:38 +0000453
454 // Fission Sections
455 DwarfInfoDWOSection =
456 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
457 SectionKind::getMetadata());
Eric Christopher67587f42012-11-30 06:47:06 +0000458 DwarfAbbrevDWOSection =
459 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
460 SectionKind::getMetadata());
461 DwarfStrDWOSection =
462 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
463 ELF::SHF_MERGE | ELF::SHF_STRINGS,
464 SectionKind::getMergeable1ByteCString());
465 DwarfLineDWOSection =
466 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
467 SectionKind::getMetadata());
468 DwarfLocDWOSection =
469 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
470 SectionKind::getMetadata());
Eric Christopher60230ef2013-01-04 17:59:22 +0000471 DwarfStrOffDWOSection =
472 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
473 SectionKind::getMetadata());
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000474 DwarfAddrSection =
475 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
476 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000477}
478
479
480void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
481 // COFF
482 TextSection =
483 Ctx->getCOFFSection(".text",
484 COFF::IMAGE_SCN_CNT_CODE |
485 COFF::IMAGE_SCN_MEM_EXECUTE |
486 COFF::IMAGE_SCN_MEM_READ,
487 SectionKind::getText());
488 DataSection =
489 Ctx->getCOFFSection(".data",
490 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
491 COFF::IMAGE_SCN_MEM_READ |
492 COFF::IMAGE_SCN_MEM_WRITE,
493 SectionKind::getDataRel());
494 ReadOnlySection =
495 Ctx->getCOFFSection(".rdata",
496 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
497 COFF::IMAGE_SCN_MEM_READ,
498 SectionKind::getReadOnly());
Michael J. Spencer32d22ee2012-02-23 21:56:08 +0000499 if (T.getOS() == Triple::Win32) {
500 StaticCtorSection =
501 Ctx->getCOFFSection(".CRT$XCU",
502 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
503 COFF::IMAGE_SCN_MEM_READ,
504 SectionKind::getReadOnly());
505 } else {
506 StaticCtorSection =
507 Ctx->getCOFFSection(".ctors",
508 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
509 COFF::IMAGE_SCN_MEM_READ |
510 COFF::IMAGE_SCN_MEM_WRITE,
511 SectionKind::getDataRel());
512 }
513
514
Anton Korobeynikov371e17c2012-09-23 15:53:47 +0000515 if (T.getOS() == Triple::Win32) {
516 StaticDtorSection =
517 Ctx->getCOFFSection(".CRT$XTX",
518 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
519 COFF::IMAGE_SCN_MEM_READ,
520 SectionKind::getReadOnly());
521 } else {
522 StaticDtorSection =
523 Ctx->getCOFFSection(".dtors",
524 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
525 COFF::IMAGE_SCN_MEM_READ |
526 COFF::IMAGE_SCN_MEM_WRITE,
527 SectionKind::getDataRel());
528 }
Evan Chenge76a33b2011-07-20 05:58:47 +0000529
530 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
531 // though it contains relocatable pointers. In PIC mode, this is probably a
532 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
533 // adjusted or this should be a data section.
534 LSDASection =
535 Ctx->getCOFFSection(".gcc_except_table",
536 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
537 COFF::IMAGE_SCN_MEM_READ,
538 SectionKind::getReadOnly());
539
540 // Debug info.
541 DwarfAbbrevSection =
542 Ctx->getCOFFSection(".debug_abbrev",
543 COFF::IMAGE_SCN_MEM_DISCARDABLE |
544 COFF::IMAGE_SCN_MEM_READ,
545 SectionKind::getMetadata());
546 DwarfInfoSection =
547 Ctx->getCOFFSection(".debug_info",
548 COFF::IMAGE_SCN_MEM_DISCARDABLE |
549 COFF::IMAGE_SCN_MEM_READ,
550 SectionKind::getMetadata());
551 DwarfLineSection =
552 Ctx->getCOFFSection(".debug_line",
553 COFF::IMAGE_SCN_MEM_DISCARDABLE |
554 COFF::IMAGE_SCN_MEM_READ,
555 SectionKind::getMetadata());
556 DwarfFrameSection =
557 Ctx->getCOFFSection(".debug_frame",
558 COFF::IMAGE_SCN_MEM_DISCARDABLE |
559 COFF::IMAGE_SCN_MEM_READ,
560 SectionKind::getMetadata());
Krzysztof Parzyszekc5ef7ee2013-02-12 18:00:14 +0000561 DwarfPubNamesSection =
562 Ctx->getCOFFSection(".debug_pubnames",
563 COFF::IMAGE_SCN_MEM_DISCARDABLE |
564 COFF::IMAGE_SCN_MEM_READ,
565 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000566 DwarfPubTypesSection =
567 Ctx->getCOFFSection(".debug_pubtypes",
568 COFF::IMAGE_SCN_MEM_DISCARDABLE |
569 COFF::IMAGE_SCN_MEM_READ,
570 SectionKind::getMetadata());
571 DwarfStrSection =
572 Ctx->getCOFFSection(".debug_str",
573 COFF::IMAGE_SCN_MEM_DISCARDABLE |
574 COFF::IMAGE_SCN_MEM_READ,
575 SectionKind::getMetadata());
576 DwarfLocSection =
577 Ctx->getCOFFSection(".debug_loc",
578 COFF::IMAGE_SCN_MEM_DISCARDABLE |
579 COFF::IMAGE_SCN_MEM_READ,
580 SectionKind::getMetadata());
581 DwarfARangesSection =
582 Ctx->getCOFFSection(".debug_aranges",
583 COFF::IMAGE_SCN_MEM_DISCARDABLE |
584 COFF::IMAGE_SCN_MEM_READ,
585 SectionKind::getMetadata());
586 DwarfRangesSection =
587 Ctx->getCOFFSection(".debug_ranges",
588 COFF::IMAGE_SCN_MEM_DISCARDABLE |
589 COFF::IMAGE_SCN_MEM_READ,
590 SectionKind::getMetadata());
591 DwarfMacroInfoSection =
592 Ctx->getCOFFSection(".debug_macinfo",
593 COFF::IMAGE_SCN_MEM_DISCARDABLE |
594 COFF::IMAGE_SCN_MEM_READ,
595 SectionKind::getMetadata());
596
597 DrectveSection =
598 Ctx->getCOFFSection(".drectve",
599 COFF::IMAGE_SCN_LNK_INFO,
600 SectionKind::getMetadata());
601
602 PDataSection =
603 Ctx->getCOFFSection(".pdata",
604 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikov0a0e50c2012-08-08 12:46:46 +0000605 COFF::IMAGE_SCN_MEM_READ,
Evan Chenge76a33b2011-07-20 05:58:47 +0000606 SectionKind::getDataRel());
607
608 XDataSection =
609 Ctx->getCOFFSection(".xdata",
610 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikov0a0e50c2012-08-08 12:46:46 +0000611 COFF::IMAGE_SCN_MEM_READ,
Evan Chenge76a33b2011-07-20 05:58:47 +0000612 SectionKind::getDataRel());
Anton Korobeynikovd4a19b62012-02-11 17:26:53 +0000613 TLSDataSection =
614 Ctx->getCOFFSection(".tls$",
615 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
616 COFF::IMAGE_SCN_MEM_READ |
617 COFF::IMAGE_SCN_MEM_WRITE,
618 SectionKind::getDataRel());
Evan Chenge76a33b2011-07-20 05:58:47 +0000619}
620
621void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
Evan Cheng203576a2011-07-20 19:50:42 +0000622 CodeModel::Model cm,
Evan Chenge76a33b2011-07-20 05:58:47 +0000623 MCContext &ctx) {
624 RelocM = relocm;
Evan Cheng203576a2011-07-20 19:50:42 +0000625 CMModel = cm;
Evan Chenge76a33b2011-07-20 05:58:47 +0000626 Ctx = &ctx;
627
628 // Common.
629 CommDirectiveSupportsAlignment = true;
630 SupportsWeakOmittedEHFrame = true;
631 IsFunctionEHFrameSymbolPrivate = true;
Evan Cheng203576a2011-07-20 19:50:42 +0000632
633 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
634 TTypeEncoding = dwarf::DW_EH_PE_absptr;
635
Bill Wendling62c75ad2013-04-10 21:42:06 +0000636 CompactUnwindDwarfEHFrameOnly = 0;
637
Eric Christopher09ac3d82011-11-07 09:24:32 +0000638 EHFrameSection = 0; // Created on demand.
639 CompactUnwindSection = 0; // Used only by selected targets.
640 DwarfAccelNamesSection = 0; // Used only by selected targets.
641 DwarfAccelObjCSection = 0; // Used only by selected targets.
642 DwarfAccelNamespaceSection = 0; // Used only by selected targets.
643 DwarfAccelTypesSection = 0; // Used only by selected targets.
Evan Chenge76a33b2011-07-20 05:58:47 +0000644
645 Triple T(TT);
646 Triple::ArchType Arch = T.getArch();
647 // FIXME: Checking for Arch here to filter out bogus triples such as
648 // cellspu-apple-darwin. Perhaps we should fix in Triple?
649 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
650 Arch == Triple::arm || Arch == Triple::thumb ||
651 Arch == Triple::ppc || Arch == Triple::ppc64 ||
652 Arch == Triple::UnknownArch) &&
653 (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
654 Env = IsMachO;
655 InitMachOMCObjectFileInfo(T);
Evan Cheng36c62d32011-07-20 23:53:54 +0000656 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
Andrew Kaylor7bbd6e32012-10-02 18:38:34 +0000657 (T.getEnvironment() != Triple::ELF) &&
Evan Cheng36c62d32011-07-20 23:53:54 +0000658 (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
659 T.getOS() == Triple::Win32)) {
Evan Chenge76a33b2011-07-20 05:58:47 +0000660 Env = IsCOFF;
661 InitCOFFMCObjectFileInfo(T);
662 } else {
663 Env = IsELF;
664 InitELFMCObjectFileInfo(T);
665 }
666}
667
David Chisnall8bb51ef2012-02-17 16:51:02 +0000668void MCObjectFileInfo::InitEHFrameSection() {
669 if (Env == IsMachO)
670 EHFrameSection =
671 Ctx->getMachOSection("__TEXT", "__eh_frame",
672 MCSectionMachO::S_COALESCED |
673 MCSectionMachO::S_ATTR_NO_TOC |
674 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
675 MCSectionMachO::S_ATTR_LIVE_SUPPORT,
676 SectionKind::getReadOnly());
677 else if (Env == IsELF)
678 EHFrameSection =
David Chisnallbce0de42012-04-10 11:44:33 +0000679 Ctx->getELFSection(".eh_frame", EHSectionType,
David Chisnall4cbcee12012-02-17 17:31:15 +0000680 EHSectionFlags,
David Chisnall8bb51ef2012-02-17 16:51:02 +0000681 SectionKind::getDataRel());
682 else
683 EHFrameSection =
684 Ctx->getCOFFSection(".eh_frame",
685 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
686 COFF::IMAGE_SCN_MEM_READ |
687 COFF::IMAGE_SCN_MEM_WRITE,
688 SectionKind::getDataRel());
689}