blob: 819c00b180cbc76b7adc6f78f1060abf3b8e8f9b [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 &&
Bill Schmidtf38cc382013-07-26 01:35:43 +000082 T.getArch() != Triple::x86_64 && T.getArch() != Triple::ppc64 &&
83 T.getArch() != Triple::ppc64le)
Evan Chenge76a33b2011-07-20 05:58:47 +000084 SixteenByteConstantSection = // .literal16
85 Ctx->getMachOSection("__TEXT", "__literal16",
86 MCSectionMachO::S_16BYTE_LITERALS,
87 SectionKind::getMergeableConst16());
88
89 ReadOnlySection // .const
90 = Ctx->getMachOSection("__TEXT", "__const", 0,
91 SectionKind::getReadOnly());
92
93 TextCoalSection
94 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
95 MCSectionMachO::S_COALESCED |
96 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
97 SectionKind::getText());
98 ConstTextCoalSection
99 = Ctx->getMachOSection("__TEXT", "__const_coal",
100 MCSectionMachO::S_COALESCED,
101 SectionKind::getReadOnly());
102 ConstDataSection // .const_data
103 = Ctx->getMachOSection("__DATA", "__const", 0,
104 SectionKind::getReadOnlyWithRel());
105 DataCoalSection
106 = Ctx->getMachOSection("__DATA","__datacoal_nt",
107 MCSectionMachO::S_COALESCED,
108 SectionKind::getDataRel());
109 DataCommonSection
110 = Ctx->getMachOSection("__DATA","__common",
111 MCSectionMachO::S_ZEROFILL,
112 SectionKind::getBSS());
113 DataBSSSection
114 = Ctx->getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL,
115 SectionKind::getBSS());
116
117
118 LazySymbolPointerSection
119 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
120 MCSectionMachO::S_LAZY_SYMBOL_POINTERS,
121 SectionKind::getMetadata());
122 NonLazySymbolPointerSection
123 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
124 MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
125 SectionKind::getMetadata());
126
127 if (RelocM == Reloc::Static) {
128 StaticCtorSection
129 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
130 SectionKind::getDataRel());
131 StaticDtorSection
132 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
133 SectionKind::getDataRel());
134 } else {
135 StaticCtorSection
136 = Ctx->getMachOSection("__DATA", "__mod_init_func",
137 MCSectionMachO::S_MOD_INIT_FUNC_POINTERS,
138 SectionKind::getDataRel());
139 StaticDtorSection
140 = Ctx->getMachOSection("__DATA", "__mod_term_func",
141 MCSectionMachO::S_MOD_TERM_FUNC_POINTERS,
142 SectionKind::getDataRel());
143 }
144
145 // Exception Handling.
146 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
147 SectionKind::getReadOnlyWithRel());
148
Bill Wendling62c75ad2013-04-10 21:42:06 +0000149 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) {
Evan Chenge76a33b2011-07-20 05:58:47 +0000150 CompactUnwindSection =
151 Ctx->getMachOSection("__LD", "__compact_unwind",
152 MCSectionMachO::S_ATTR_DEBUG,
153 SectionKind::getReadOnly());
154
Bill Wendling62c75ad2013-04-10 21:42:06 +0000155 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
156 CompactUnwindDwarfEHFrameOnly = 0x04000000;
157 }
158
Evan Chenge76a33b2011-07-20 05:58:47 +0000159 // Debug Information.
Eric Christopher09ac3d82011-11-07 09:24:32 +0000160 DwarfAccelNamesSection =
161 Ctx->getMachOSection("__DWARF", "__apple_names",
162 MCSectionMachO::S_ATTR_DEBUG,
163 SectionKind::getMetadata());
164 DwarfAccelObjCSection =
165 Ctx->getMachOSection("__DWARF", "__apple_objc",
166 MCSectionMachO::S_ATTR_DEBUG,
167 SectionKind::getMetadata());
168 // 16 character section limit...
169 DwarfAccelNamespaceSection =
170 Ctx->getMachOSection("__DWARF", "__apple_namespac",
171 MCSectionMachO::S_ATTR_DEBUG,
172 SectionKind::getMetadata());
173 DwarfAccelTypesSection =
174 Ctx->getMachOSection("__DWARF", "__apple_types",
175 MCSectionMachO::S_ATTR_DEBUG,
176 SectionKind::getMetadata());
Jim Grosbach2684d9e2012-05-11 01:41:30 +0000177
Evan Chenge76a33b2011-07-20 05:58:47 +0000178 DwarfAbbrevSection =
179 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
180 MCSectionMachO::S_ATTR_DEBUG,
181 SectionKind::getMetadata());
182 DwarfInfoSection =
183 Ctx->getMachOSection("__DWARF", "__debug_info",
184 MCSectionMachO::S_ATTR_DEBUG,
185 SectionKind::getMetadata());
186 DwarfLineSection =
187 Ctx->getMachOSection("__DWARF", "__debug_line",
188 MCSectionMachO::S_ATTR_DEBUG,
189 SectionKind::getMetadata());
190 DwarfFrameSection =
191 Ctx->getMachOSection("__DWARF", "__debug_frame",
192 MCSectionMachO::S_ATTR_DEBUG,
193 SectionKind::getMetadata());
Krzysztof Parzyszekc5ef7ee2013-02-12 18:00:14 +0000194 DwarfPubNamesSection =
195 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
196 MCSectionMachO::S_ATTR_DEBUG,
197 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000198 DwarfPubTypesSection =
199 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
200 MCSectionMachO::S_ATTR_DEBUG,
201 SectionKind::getMetadata());
202 DwarfStrSection =
203 Ctx->getMachOSection("__DWARF", "__debug_str",
204 MCSectionMachO::S_ATTR_DEBUG,
205 SectionKind::getMetadata());
206 DwarfLocSection =
207 Ctx->getMachOSection("__DWARF", "__debug_loc",
208 MCSectionMachO::S_ATTR_DEBUG,
209 SectionKind::getMetadata());
210 DwarfARangesSection =
211 Ctx->getMachOSection("__DWARF", "__debug_aranges",
212 MCSectionMachO::S_ATTR_DEBUG,
213 SectionKind::getMetadata());
214 DwarfRangesSection =
215 Ctx->getMachOSection("__DWARF", "__debug_ranges",
216 MCSectionMachO::S_ATTR_DEBUG,
217 SectionKind::getMetadata());
218 DwarfMacroInfoSection =
219 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
220 MCSectionMachO::S_ATTR_DEBUG,
221 SectionKind::getMetadata());
222 DwarfDebugInlineSection =
223 Ctx->getMachOSection("__DWARF", "__debug_inlined",
224 MCSectionMachO::S_ATTR_DEBUG,
225 SectionKind::getMetadata());
226
227 TLSExtraDataSection = TLSTLVSection;
228}
229
230void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
Rafael Espindola04011e842013-04-03 03:13:19 +0000231 if (T.getArch() == Triple::mips ||
232 T.getArch() == Triple::mipsel)
233 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
234 else if (T.getArch() == Triple::mips64 ||
235 T.getArch() == Triple::mips64el)
236 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
237 else
Rafael Espindola7a86ffb2013-03-15 05:51:57 +0000238 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
239
Evan Cheng203576a2011-07-20 19:50:42 +0000240 if (T.getArch() == Triple::x86) {
241 PersonalityEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach946227d2011-11-15 16:46:22 +0000242 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
243 : dwarf::DW_EH_PE_absptr;
Evan Cheng203576a2011-07-20 19:50:42 +0000244 LSDAEncoding = (RelocM == Reloc::PIC_)
245 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
246 : dwarf::DW_EH_PE_absptr;
Rafael Espindola7a86ffb2013-03-15 05:51:57 +0000247 FDEEncoding = (RelocM == Reloc::PIC_)
Evan Cheng203576a2011-07-20 19:50:42 +0000248 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
249 : dwarf::DW_EH_PE_absptr;
250 TTypeEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach946227d2011-11-15 16:46:22 +0000251 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
252 : dwarf::DW_EH_PE_absptr;
Evan Cheng203576a2011-07-20 19:50:42 +0000253 } else if (T.getArch() == Triple::x86_64) {
Evan Cheng203576a2011-07-20 19:50:42 +0000254 if (RelocM == Reloc::PIC_) {
255 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
256 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
257 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
258 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
259 (CMModel == CodeModel::Small
260 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
261 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
262 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
263 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
264 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
265 } else {
266 PersonalityEncoding =
267 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
268 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
269 LSDAEncoding = (CMModel == CodeModel::Small)
270 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
271 FDEEncoding = dwarf::DW_EH_PE_udata4;
272 TTypeEncoding = (CMModel == CodeModel::Small)
273 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
274 }
Tim Northover72062f52013-01-31 12:12:40 +0000275 } else if (T.getArch() == Triple::aarch64) {
Tim Northover72062f52013-01-31 12:12:40 +0000276 // The small model guarantees static code/data size < 4GB, but not where it
277 // will be in memory. Most of these could end up >2GB away so even a signed
278 // pc-relative 32-bit address is insufficient, theoretically.
279 if (RelocM == Reloc::PIC_) {
280 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
281 dwarf::DW_EH_PE_sdata8;
282 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
283 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
284 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
285 dwarf::DW_EH_PE_sdata8;
286 } else {
287 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
288 LSDAEncoding = dwarf::DW_EH_PE_absptr;
289 FDEEncoding = dwarf::DW_EH_PE_udata4;
290 TTypeEncoding = dwarf::DW_EH_PE_absptr;
291 }
Bill Schmidtf38cc382013-07-26 01:35:43 +0000292 } else if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le) {
Adhemerval Zanellaa1db5de2013-01-09 17:08:15 +0000293 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
294 dwarf::DW_EH_PE_udata8;
Adhemerval Zanellaa1db5de2013-01-09 17:08:15 +0000295 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
296 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
297 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
298 dwarf::DW_EH_PE_udata8;
Ulrich Weigande96e43f2013-05-06 16:11:12 +0000299 } else if (T.getArch() == Triple::systemz) {
300 // All currently-defined code models guarantee that 4-byte PC-relative
301 // values will be in range.
Ulrich Weigande5c8c242013-05-06 17:28:30 +0000302 if (RelocM == Reloc::PIC_) {
303 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
304 dwarf::DW_EH_PE_sdata4;
305 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
306 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
307 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
308 dwarf::DW_EH_PE_sdata4;
309 } else {
310 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
311 LSDAEncoding = dwarf::DW_EH_PE_absptr;
312 FDEEncoding = dwarf::DW_EH_PE_absptr;
313 TTypeEncoding = dwarf::DW_EH_PE_absptr;
314 }
Evan Cheng203576a2011-07-20 19:50:42 +0000315 }
316
David Chisnall4cbcee12012-02-17 17:31:15 +0000317 // Solaris requires different flags for .eh_frame to seemingly every other
318 // platform.
David Chisnallbce0de42012-04-10 11:44:33 +0000319 EHSectionType = ELF::SHT_PROGBITS;
David Chisnall4cbcee12012-02-17 17:31:15 +0000320 EHSectionFlags = ELF::SHF_ALLOC;
David Chisnallbce0de42012-04-10 11:44:33 +0000321 if (T.getOS() == Triple::Solaris) {
322 if (T.getArch() == Triple::x86_64)
323 EHSectionType = ELF::SHT_X86_64_UNWIND;
324 else
325 EHSectionFlags |= ELF::SHF_WRITE;
326 }
David Chisnall4cbcee12012-02-17 17:31:15 +0000327
328
Evan Chenge76a33b2011-07-20 05:58:47 +0000329 // ELF
330 BSSSection =
331 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
Anton Korobeynikov4a99f592012-01-25 22:24:19 +0000332 ELF::SHF_WRITE | ELF::SHF_ALLOC,
Evan Chenge76a33b2011-07-20 05:58:47 +0000333 SectionKind::getBSS());
334
335 TextSection =
336 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
337 ELF::SHF_EXECINSTR |
338 ELF::SHF_ALLOC,
339 SectionKind::getText());
340
341 DataSection =
342 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
343 ELF::SHF_WRITE |ELF::SHF_ALLOC,
344 SectionKind::getDataRel());
345
346 ReadOnlySection =
347 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
348 ELF::SHF_ALLOC,
349 SectionKind::getReadOnly());
350
351 TLSDataSection =
352 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
353 ELF::SHF_ALLOC | ELF::SHF_TLS |
354 ELF::SHF_WRITE,
355 SectionKind::getThreadData());
356
357 TLSBSSSection =
358 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
359 ELF::SHF_ALLOC | ELF::SHF_TLS |
360 ELF::SHF_WRITE,
361 SectionKind::getThreadBSS());
362
363 DataRelSection =
364 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
365 ELF::SHF_ALLOC |ELF::SHF_WRITE,
366 SectionKind::getDataRel());
367
368 DataRelLocalSection =
369 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
370 ELF::SHF_ALLOC |ELF::SHF_WRITE,
371 SectionKind::getDataRelLocal());
372
373 DataRelROSection =
374 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
375 ELF::SHF_ALLOC |ELF::SHF_WRITE,
376 SectionKind::getReadOnlyWithRel());
377
378 DataRelROLocalSection =
379 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
380 ELF::SHF_ALLOC |ELF::SHF_WRITE,
381 SectionKind::getReadOnlyWithRelLocal());
382
383 MergeableConst4Section =
384 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
385 ELF::SHF_ALLOC |ELF::SHF_MERGE,
386 SectionKind::getMergeableConst4());
387
388 MergeableConst8Section =
389 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
390 ELF::SHF_ALLOC |ELF::SHF_MERGE,
391 SectionKind::getMergeableConst8());
392
393 MergeableConst16Section =
394 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
395 ELF::SHF_ALLOC |ELF::SHF_MERGE,
396 SectionKind::getMergeableConst16());
397
398 StaticCtorSection =
399 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
400 ELF::SHF_ALLOC |ELF::SHF_WRITE,
401 SectionKind::getDataRel());
402
403 StaticDtorSection =
404 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
405 ELF::SHF_ALLOC |ELF::SHF_WRITE,
406 SectionKind::getDataRel());
407
408 // Exception Handling Sections.
409
410 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
411 // it contains relocatable pointers. In PIC mode, this is probably a big
412 // runtime hit for C++ apps. Either the contents of the LSDA need to be
413 // adjusted or this should be a data section.
414 LSDASection =
415 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
416 ELF::SHF_ALLOC,
417 SectionKind::getReadOnly());
418
419 // Debug Info Sections.
420 DwarfAbbrevSection =
421 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
422 SectionKind::getMetadata());
423 DwarfInfoSection =
424 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
425 SectionKind::getMetadata());
426 DwarfLineSection =
427 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
428 SectionKind::getMetadata());
429 DwarfFrameSection =
430 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
431 SectionKind::getMetadata());
Krzysztof Parzyszekc5ef7ee2013-02-12 18:00:14 +0000432 DwarfPubNamesSection =
433 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
434 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000435 DwarfPubTypesSection =
436 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
437 SectionKind::getMetadata());
438 DwarfStrSection =
Nick Lewycky5a86c5b2011-10-26 18:44:32 +0000439 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
440 ELF::SHF_MERGE | ELF::SHF_STRINGS,
441 SectionKind::getMergeable1ByteCString());
Evan Chenge76a33b2011-07-20 05:58:47 +0000442 DwarfLocSection =
443 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
444 SectionKind::getMetadata());
445 DwarfARangesSection =
446 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
447 SectionKind::getMetadata());
448 DwarfRangesSection =
449 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
450 SectionKind::getMetadata());
451 DwarfMacroInfoSection =
452 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
453 SectionKind::getMetadata());
Eric Christopherea1504d2012-11-28 02:49:34 +0000454
455 // DWARF5 Experimental Debug Info
456
457 // Accelerator Tables
Eric Christopher5b4461c2012-10-08 21:41:30 +0000458 DwarfAccelNamesSection =
459 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
460 SectionKind::getMetadata());
461 DwarfAccelObjCSection =
462 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
463 SectionKind::getMetadata());
464 DwarfAccelNamespaceSection =
465 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
466 SectionKind::getMetadata());
467 DwarfAccelTypesSection =
468 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
469 SectionKind::getMetadata());
Eric Christopher6acb5312012-11-28 02:49:38 +0000470
471 // Fission Sections
472 DwarfInfoDWOSection =
473 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
474 SectionKind::getMetadata());
Eric Christopher67587f42012-11-30 06:47:06 +0000475 DwarfAbbrevDWOSection =
476 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
477 SectionKind::getMetadata());
478 DwarfStrDWOSection =
479 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
480 ELF::SHF_MERGE | ELF::SHF_STRINGS,
481 SectionKind::getMergeable1ByteCString());
482 DwarfLineDWOSection =
483 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
484 SectionKind::getMetadata());
485 DwarfLocDWOSection =
486 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
487 SectionKind::getMetadata());
Eric Christopher60230ef2013-01-04 17:59:22 +0000488 DwarfStrOffDWOSection =
489 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
490 SectionKind::getMetadata());
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000491 DwarfAddrSection =
492 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
493 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000494}
495
496
497void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
498 // COFF
David Majnemer6aa93152013-08-13 01:23:53 +0000499 BSSSection =
500 Ctx->getCOFFSection(".bss",
501 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
502 COFF::IMAGE_SCN_MEM_READ |
503 COFF::IMAGE_SCN_MEM_WRITE,
504 SectionKind::getBSS());
Evan Chenge76a33b2011-07-20 05:58:47 +0000505 TextSection =
506 Ctx->getCOFFSection(".text",
507 COFF::IMAGE_SCN_CNT_CODE |
508 COFF::IMAGE_SCN_MEM_EXECUTE |
509 COFF::IMAGE_SCN_MEM_READ,
510 SectionKind::getText());
511 DataSection =
512 Ctx->getCOFFSection(".data",
513 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
514 COFF::IMAGE_SCN_MEM_READ |
515 COFF::IMAGE_SCN_MEM_WRITE,
516 SectionKind::getDataRel());
517 ReadOnlySection =
518 Ctx->getCOFFSection(".rdata",
519 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
520 COFF::IMAGE_SCN_MEM_READ,
521 SectionKind::getReadOnly());
Michael J. Spencer32d22ee2012-02-23 21:56:08 +0000522 if (T.getOS() == Triple::Win32) {
523 StaticCtorSection =
524 Ctx->getCOFFSection(".CRT$XCU",
525 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
526 COFF::IMAGE_SCN_MEM_READ,
527 SectionKind::getReadOnly());
528 } else {
529 StaticCtorSection =
530 Ctx->getCOFFSection(".ctors",
531 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
532 COFF::IMAGE_SCN_MEM_READ |
533 COFF::IMAGE_SCN_MEM_WRITE,
534 SectionKind::getDataRel());
535 }
536
537
Anton Korobeynikov371e17c2012-09-23 15:53:47 +0000538 if (T.getOS() == Triple::Win32) {
539 StaticDtorSection =
540 Ctx->getCOFFSection(".CRT$XTX",
541 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
542 COFF::IMAGE_SCN_MEM_READ,
543 SectionKind::getReadOnly());
544 } else {
545 StaticDtorSection =
546 Ctx->getCOFFSection(".dtors",
547 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
548 COFF::IMAGE_SCN_MEM_READ |
549 COFF::IMAGE_SCN_MEM_WRITE,
550 SectionKind::getDataRel());
551 }
Evan Chenge76a33b2011-07-20 05:58:47 +0000552
553 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
554 // though it contains relocatable pointers. In PIC mode, this is probably a
555 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
556 // adjusted or this should be a data section.
Kai Nacke113d32c2013-07-08 04:43:23 +0000557 LSDASection =
558 Ctx->getCOFFSection(".gcc_except_table",
559 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
560 COFF::IMAGE_SCN_MEM_READ,
561 SectionKind::getReadOnly());
Evan Chenge76a33b2011-07-20 05:58:47 +0000562
563 // Debug info.
564 DwarfAbbrevSection =
565 Ctx->getCOFFSection(".debug_abbrev",
566 COFF::IMAGE_SCN_MEM_DISCARDABLE |
567 COFF::IMAGE_SCN_MEM_READ,
568 SectionKind::getMetadata());
569 DwarfInfoSection =
570 Ctx->getCOFFSection(".debug_info",
571 COFF::IMAGE_SCN_MEM_DISCARDABLE |
572 COFF::IMAGE_SCN_MEM_READ,
573 SectionKind::getMetadata());
574 DwarfLineSection =
575 Ctx->getCOFFSection(".debug_line",
576 COFF::IMAGE_SCN_MEM_DISCARDABLE |
577 COFF::IMAGE_SCN_MEM_READ,
578 SectionKind::getMetadata());
579 DwarfFrameSection =
580 Ctx->getCOFFSection(".debug_frame",
581 COFF::IMAGE_SCN_MEM_DISCARDABLE |
582 COFF::IMAGE_SCN_MEM_READ,
583 SectionKind::getMetadata());
Krzysztof Parzyszekc5ef7ee2013-02-12 18:00:14 +0000584 DwarfPubNamesSection =
585 Ctx->getCOFFSection(".debug_pubnames",
586 COFF::IMAGE_SCN_MEM_DISCARDABLE |
587 COFF::IMAGE_SCN_MEM_READ,
588 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000589 DwarfPubTypesSection =
590 Ctx->getCOFFSection(".debug_pubtypes",
591 COFF::IMAGE_SCN_MEM_DISCARDABLE |
592 COFF::IMAGE_SCN_MEM_READ,
593 SectionKind::getMetadata());
594 DwarfStrSection =
595 Ctx->getCOFFSection(".debug_str",
596 COFF::IMAGE_SCN_MEM_DISCARDABLE |
597 COFF::IMAGE_SCN_MEM_READ,
598 SectionKind::getMetadata());
599 DwarfLocSection =
600 Ctx->getCOFFSection(".debug_loc",
601 COFF::IMAGE_SCN_MEM_DISCARDABLE |
602 COFF::IMAGE_SCN_MEM_READ,
603 SectionKind::getMetadata());
604 DwarfARangesSection =
605 Ctx->getCOFFSection(".debug_aranges",
606 COFF::IMAGE_SCN_MEM_DISCARDABLE |
607 COFF::IMAGE_SCN_MEM_READ,
608 SectionKind::getMetadata());
609 DwarfRangesSection =
610 Ctx->getCOFFSection(".debug_ranges",
611 COFF::IMAGE_SCN_MEM_DISCARDABLE |
612 COFF::IMAGE_SCN_MEM_READ,
613 SectionKind::getMetadata());
614 DwarfMacroInfoSection =
615 Ctx->getCOFFSection(".debug_macinfo",
616 COFF::IMAGE_SCN_MEM_DISCARDABLE |
617 COFF::IMAGE_SCN_MEM_READ,
618 SectionKind::getMetadata());
619
620 DrectveSection =
621 Ctx->getCOFFSection(".drectve",
622 COFF::IMAGE_SCN_LNK_INFO,
623 SectionKind::getMetadata());
624
625 PDataSection =
626 Ctx->getCOFFSection(".pdata",
627 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikov0a0e50c2012-08-08 12:46:46 +0000628 COFF::IMAGE_SCN_MEM_READ,
Evan Chenge76a33b2011-07-20 05:58:47 +0000629 SectionKind::getDataRel());
630
631 XDataSection =
632 Ctx->getCOFFSection(".xdata",
633 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikov0a0e50c2012-08-08 12:46:46 +0000634 COFF::IMAGE_SCN_MEM_READ,
Evan Chenge76a33b2011-07-20 05:58:47 +0000635 SectionKind::getDataRel());
Anton Korobeynikovd4a19b62012-02-11 17:26:53 +0000636 TLSDataSection =
637 Ctx->getCOFFSection(".tls$",
638 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
639 COFF::IMAGE_SCN_MEM_READ |
640 COFF::IMAGE_SCN_MEM_WRITE,
641 SectionKind::getDataRel());
Evan Chenge76a33b2011-07-20 05:58:47 +0000642}
643
644void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
Evan Cheng203576a2011-07-20 19:50:42 +0000645 CodeModel::Model cm,
Evan Chenge76a33b2011-07-20 05:58:47 +0000646 MCContext &ctx) {
647 RelocM = relocm;
Evan Cheng203576a2011-07-20 19:50:42 +0000648 CMModel = cm;
Evan Chenge76a33b2011-07-20 05:58:47 +0000649 Ctx = &ctx;
650
651 // Common.
652 CommDirectiveSupportsAlignment = true;
653 SupportsWeakOmittedEHFrame = true;
654 IsFunctionEHFrameSymbolPrivate = true;
Evan Cheng203576a2011-07-20 19:50:42 +0000655
656 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
657 TTypeEncoding = dwarf::DW_EH_PE_absptr;
658
Bill Wendling62c75ad2013-04-10 21:42:06 +0000659 CompactUnwindDwarfEHFrameOnly = 0;
660
Eric Christopher09ac3d82011-11-07 09:24:32 +0000661 EHFrameSection = 0; // Created on demand.
662 CompactUnwindSection = 0; // Used only by selected targets.
663 DwarfAccelNamesSection = 0; // Used only by selected targets.
664 DwarfAccelObjCSection = 0; // Used only by selected targets.
665 DwarfAccelNamespaceSection = 0; // Used only by selected targets.
666 DwarfAccelTypesSection = 0; // Used only by selected targets.
Evan Chenge76a33b2011-07-20 05:58:47 +0000667
668 Triple T(TT);
669 Triple::ArchType Arch = T.getArch();
670 // FIXME: Checking for Arch here to filter out bogus triples such as
671 // cellspu-apple-darwin. Perhaps we should fix in Triple?
672 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
673 Arch == Triple::arm || Arch == Triple::thumb ||
674 Arch == Triple::ppc || Arch == Triple::ppc64 ||
675 Arch == Triple::UnknownArch) &&
676 (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
677 Env = IsMachO;
678 InitMachOMCObjectFileInfo(T);
Evan Cheng36c62d32011-07-20 23:53:54 +0000679 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
Andrew Kaylor7bbd6e32012-10-02 18:38:34 +0000680 (T.getEnvironment() != Triple::ELF) &&
Evan Cheng36c62d32011-07-20 23:53:54 +0000681 (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
682 T.getOS() == Triple::Win32)) {
Evan Chenge76a33b2011-07-20 05:58:47 +0000683 Env = IsCOFF;
684 InitCOFFMCObjectFileInfo(T);
685 } else {
686 Env = IsELF;
687 InitELFMCObjectFileInfo(T);
688 }
689}
690
David Chisnall8bb51ef2012-02-17 16:51:02 +0000691void MCObjectFileInfo::InitEHFrameSection() {
692 if (Env == IsMachO)
693 EHFrameSection =
694 Ctx->getMachOSection("__TEXT", "__eh_frame",
695 MCSectionMachO::S_COALESCED |
696 MCSectionMachO::S_ATTR_NO_TOC |
697 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
698 MCSectionMachO::S_ATTR_LIVE_SUPPORT,
699 SectionKind::getReadOnly());
700 else if (Env == IsELF)
701 EHFrameSection =
David Chisnallbce0de42012-04-10 11:44:33 +0000702 Ctx->getELFSection(".eh_frame", EHSectionType,
David Chisnall4cbcee12012-02-17 17:31:15 +0000703 EHSectionFlags,
David Chisnall8bb51ef2012-02-17 16:51:02 +0000704 SectionKind::getDataRel());
705 else
706 EHFrameSection =
707 Ctx->getCOFFSection(".eh_frame",
708 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
709 COFF::IMAGE_SCN_MEM_READ |
710 COFF::IMAGE_SCN_MEM_WRITE,
711 SectionKind::getDataRel());
712}