blob: a3045848b621b92d7abc38e7a988ca8ee7e3e433 [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());
Evan Chenge76a33b2011-07-20 05:58:47 +0000189 DwarfPubTypesSection =
190 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
191 MCSectionMachO::S_ATTR_DEBUG,
192 SectionKind::getMetadata());
193 DwarfStrSection =
194 Ctx->getMachOSection("__DWARF", "__debug_str",
195 MCSectionMachO::S_ATTR_DEBUG,
196 SectionKind::getMetadata());
197 DwarfLocSection =
198 Ctx->getMachOSection("__DWARF", "__debug_loc",
199 MCSectionMachO::S_ATTR_DEBUG,
200 SectionKind::getMetadata());
201 DwarfARangesSection =
202 Ctx->getMachOSection("__DWARF", "__debug_aranges",
203 MCSectionMachO::S_ATTR_DEBUG,
204 SectionKind::getMetadata());
205 DwarfRangesSection =
206 Ctx->getMachOSection("__DWARF", "__debug_ranges",
207 MCSectionMachO::S_ATTR_DEBUG,
208 SectionKind::getMetadata());
209 DwarfMacroInfoSection =
210 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
211 MCSectionMachO::S_ATTR_DEBUG,
212 SectionKind::getMetadata());
213 DwarfDebugInlineSection =
214 Ctx->getMachOSection("__DWARF", "__debug_inlined",
215 MCSectionMachO::S_ATTR_DEBUG,
216 SectionKind::getMetadata());
217
218 TLSExtraDataSection = TLSTLVSection;
219}
220
221void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
Evan Cheng203576a2011-07-20 19:50:42 +0000222 if (T.getArch() == Triple::x86) {
223 PersonalityEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach946227d2011-11-15 16:46:22 +0000224 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
225 : dwarf::DW_EH_PE_absptr;
Evan Cheng203576a2011-07-20 19:50:42 +0000226 LSDAEncoding = (RelocM == Reloc::PIC_)
227 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
228 : dwarf::DW_EH_PE_absptr;
229 FDEEncoding = FDECFIEncoding = (RelocM == Reloc::PIC_)
230 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
231 : dwarf::DW_EH_PE_absptr;
232 TTypeEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach946227d2011-11-15 16:46:22 +0000233 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
234 : dwarf::DW_EH_PE_absptr;
Evan Cheng203576a2011-07-20 19:50:42 +0000235 } else if (T.getArch() == Triple::x86_64) {
236 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
237
238 if (RelocM == Reloc::PIC_) {
239 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
240 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
241 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
242 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
243 (CMModel == CodeModel::Small
244 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
245 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
246 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
247 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
248 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
249 } else {
250 PersonalityEncoding =
251 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
252 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
253 LSDAEncoding = (CMModel == CodeModel::Small)
254 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
255 FDEEncoding = dwarf::DW_EH_PE_udata4;
256 TTypeEncoding = (CMModel == CodeModel::Small)
257 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
258 }
Adhemerval Zanella7b449882013-01-04 19:08:13 +0000259 } else if (T.getArch() == Triple::ppc64) {
Adhemerval Zanellaa1db5de2013-01-09 17:08:15 +0000260 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
261 dwarf::DW_EH_PE_udata8;
262 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
263 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
264 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
265 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
266 dwarf::DW_EH_PE_udata8;
Evan Cheng203576a2011-07-20 19:50:42 +0000267 }
268
David Chisnall4cbcee12012-02-17 17:31:15 +0000269 // Solaris requires different flags for .eh_frame to seemingly every other
270 // platform.
David Chisnallbce0de42012-04-10 11:44:33 +0000271 EHSectionType = ELF::SHT_PROGBITS;
David Chisnall4cbcee12012-02-17 17:31:15 +0000272 EHSectionFlags = ELF::SHF_ALLOC;
David Chisnallbce0de42012-04-10 11:44:33 +0000273 if (T.getOS() == Triple::Solaris) {
274 if (T.getArch() == Triple::x86_64)
275 EHSectionType = ELF::SHT_X86_64_UNWIND;
276 else
277 EHSectionFlags |= ELF::SHF_WRITE;
278 }
David Chisnall4cbcee12012-02-17 17:31:15 +0000279
280
Evan Chenge76a33b2011-07-20 05:58:47 +0000281 // ELF
282 BSSSection =
283 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
Anton Korobeynikov4a99f592012-01-25 22:24:19 +0000284 ELF::SHF_WRITE | ELF::SHF_ALLOC,
Evan Chenge76a33b2011-07-20 05:58:47 +0000285 SectionKind::getBSS());
286
287 TextSection =
288 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
289 ELF::SHF_EXECINSTR |
290 ELF::SHF_ALLOC,
291 SectionKind::getText());
292
293 DataSection =
294 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
295 ELF::SHF_WRITE |ELF::SHF_ALLOC,
296 SectionKind::getDataRel());
297
298 ReadOnlySection =
299 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
300 ELF::SHF_ALLOC,
301 SectionKind::getReadOnly());
302
303 TLSDataSection =
304 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
305 ELF::SHF_ALLOC | ELF::SHF_TLS |
306 ELF::SHF_WRITE,
307 SectionKind::getThreadData());
308
309 TLSBSSSection =
310 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
311 ELF::SHF_ALLOC | ELF::SHF_TLS |
312 ELF::SHF_WRITE,
313 SectionKind::getThreadBSS());
314
315 DataRelSection =
316 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
317 ELF::SHF_ALLOC |ELF::SHF_WRITE,
318 SectionKind::getDataRel());
319
320 DataRelLocalSection =
321 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
322 ELF::SHF_ALLOC |ELF::SHF_WRITE,
323 SectionKind::getDataRelLocal());
324
325 DataRelROSection =
326 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
327 ELF::SHF_ALLOC |ELF::SHF_WRITE,
328 SectionKind::getReadOnlyWithRel());
329
330 DataRelROLocalSection =
331 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
332 ELF::SHF_ALLOC |ELF::SHF_WRITE,
333 SectionKind::getReadOnlyWithRelLocal());
334
335 MergeableConst4Section =
336 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
337 ELF::SHF_ALLOC |ELF::SHF_MERGE,
338 SectionKind::getMergeableConst4());
339
340 MergeableConst8Section =
341 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
342 ELF::SHF_ALLOC |ELF::SHF_MERGE,
343 SectionKind::getMergeableConst8());
344
345 MergeableConst16Section =
346 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
347 ELF::SHF_ALLOC |ELF::SHF_MERGE,
348 SectionKind::getMergeableConst16());
349
350 StaticCtorSection =
351 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
352 ELF::SHF_ALLOC |ELF::SHF_WRITE,
353 SectionKind::getDataRel());
354
355 StaticDtorSection =
356 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
357 ELF::SHF_ALLOC |ELF::SHF_WRITE,
358 SectionKind::getDataRel());
359
360 // Exception Handling Sections.
361
362 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
363 // it contains relocatable pointers. In PIC mode, this is probably a big
364 // runtime hit for C++ apps. Either the contents of the LSDA need to be
365 // adjusted or this should be a data section.
366 LSDASection =
367 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
368 ELF::SHF_ALLOC,
369 SectionKind::getReadOnly());
370
371 // Debug Info Sections.
372 DwarfAbbrevSection =
373 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
374 SectionKind::getMetadata());
375 DwarfInfoSection =
376 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
377 SectionKind::getMetadata());
378 DwarfLineSection =
379 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
380 SectionKind::getMetadata());
381 DwarfFrameSection =
382 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
383 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000384 DwarfPubTypesSection =
385 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
386 SectionKind::getMetadata());
387 DwarfStrSection =
Nick Lewycky5a86c5b2011-10-26 18:44:32 +0000388 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
389 ELF::SHF_MERGE | ELF::SHF_STRINGS,
390 SectionKind::getMergeable1ByteCString());
Evan Chenge76a33b2011-07-20 05:58:47 +0000391 DwarfLocSection =
392 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
393 SectionKind::getMetadata());
394 DwarfARangesSection =
395 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
396 SectionKind::getMetadata());
397 DwarfRangesSection =
398 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
399 SectionKind::getMetadata());
400 DwarfMacroInfoSection =
401 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
402 SectionKind::getMetadata());
Eric Christopherea1504d2012-11-28 02:49:34 +0000403
404 // DWARF5 Experimental Debug Info
405
406 // Accelerator Tables
Eric Christopher5b4461c2012-10-08 21:41:30 +0000407 DwarfAccelNamesSection =
408 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
409 SectionKind::getMetadata());
410 DwarfAccelObjCSection =
411 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
412 SectionKind::getMetadata());
413 DwarfAccelNamespaceSection =
414 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
415 SectionKind::getMetadata());
416 DwarfAccelTypesSection =
417 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
418 SectionKind::getMetadata());
Eric Christopher6acb5312012-11-28 02:49:38 +0000419
420 // Fission Sections
421 DwarfInfoDWOSection =
422 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
423 SectionKind::getMetadata());
Eric Christopher67587f42012-11-30 06:47:06 +0000424 DwarfAbbrevDWOSection =
425 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
426 SectionKind::getMetadata());
427 DwarfStrDWOSection =
428 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
429 ELF::SHF_MERGE | ELF::SHF_STRINGS,
430 SectionKind::getMergeable1ByteCString());
431 DwarfLineDWOSection =
432 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
433 SectionKind::getMetadata());
434 DwarfLocDWOSection =
435 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
436 SectionKind::getMetadata());
Eric Christopher60230ef2013-01-04 17:59:22 +0000437 DwarfStrOffDWOSection =
438 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
439 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000440}
441
442
443void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
444 // COFF
445 TextSection =
446 Ctx->getCOFFSection(".text",
447 COFF::IMAGE_SCN_CNT_CODE |
448 COFF::IMAGE_SCN_MEM_EXECUTE |
449 COFF::IMAGE_SCN_MEM_READ,
450 SectionKind::getText());
451 DataSection =
452 Ctx->getCOFFSection(".data",
453 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
454 COFF::IMAGE_SCN_MEM_READ |
455 COFF::IMAGE_SCN_MEM_WRITE,
456 SectionKind::getDataRel());
457 ReadOnlySection =
458 Ctx->getCOFFSection(".rdata",
459 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
460 COFF::IMAGE_SCN_MEM_READ,
461 SectionKind::getReadOnly());
Michael J. Spencer32d22ee2012-02-23 21:56:08 +0000462 if (T.getOS() == Triple::Win32) {
463 StaticCtorSection =
464 Ctx->getCOFFSection(".CRT$XCU",
465 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
466 COFF::IMAGE_SCN_MEM_READ,
467 SectionKind::getReadOnly());
468 } else {
469 StaticCtorSection =
470 Ctx->getCOFFSection(".ctors",
471 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
472 COFF::IMAGE_SCN_MEM_READ |
473 COFF::IMAGE_SCN_MEM_WRITE,
474 SectionKind::getDataRel());
475 }
476
477
Anton Korobeynikov371e17c2012-09-23 15:53:47 +0000478 if (T.getOS() == Triple::Win32) {
479 StaticDtorSection =
480 Ctx->getCOFFSection(".CRT$XTX",
481 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
482 COFF::IMAGE_SCN_MEM_READ,
483 SectionKind::getReadOnly());
484 } else {
485 StaticDtorSection =
486 Ctx->getCOFFSection(".dtors",
487 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
488 COFF::IMAGE_SCN_MEM_READ |
489 COFF::IMAGE_SCN_MEM_WRITE,
490 SectionKind::getDataRel());
491 }
Evan Chenge76a33b2011-07-20 05:58:47 +0000492
493 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
494 // though it contains relocatable pointers. In PIC mode, this is probably a
495 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
496 // adjusted or this should be a data section.
497 LSDASection =
498 Ctx->getCOFFSection(".gcc_except_table",
499 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
500 COFF::IMAGE_SCN_MEM_READ,
501 SectionKind::getReadOnly());
502
503 // Debug info.
504 DwarfAbbrevSection =
505 Ctx->getCOFFSection(".debug_abbrev",
506 COFF::IMAGE_SCN_MEM_DISCARDABLE |
507 COFF::IMAGE_SCN_MEM_READ,
508 SectionKind::getMetadata());
509 DwarfInfoSection =
510 Ctx->getCOFFSection(".debug_info",
511 COFF::IMAGE_SCN_MEM_DISCARDABLE |
512 COFF::IMAGE_SCN_MEM_READ,
513 SectionKind::getMetadata());
514 DwarfLineSection =
515 Ctx->getCOFFSection(".debug_line",
516 COFF::IMAGE_SCN_MEM_DISCARDABLE |
517 COFF::IMAGE_SCN_MEM_READ,
518 SectionKind::getMetadata());
519 DwarfFrameSection =
520 Ctx->getCOFFSection(".debug_frame",
521 COFF::IMAGE_SCN_MEM_DISCARDABLE |
522 COFF::IMAGE_SCN_MEM_READ,
523 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000524 DwarfPubTypesSection =
525 Ctx->getCOFFSection(".debug_pubtypes",
526 COFF::IMAGE_SCN_MEM_DISCARDABLE |
527 COFF::IMAGE_SCN_MEM_READ,
528 SectionKind::getMetadata());
529 DwarfStrSection =
530 Ctx->getCOFFSection(".debug_str",
531 COFF::IMAGE_SCN_MEM_DISCARDABLE |
532 COFF::IMAGE_SCN_MEM_READ,
533 SectionKind::getMetadata());
534 DwarfLocSection =
535 Ctx->getCOFFSection(".debug_loc",
536 COFF::IMAGE_SCN_MEM_DISCARDABLE |
537 COFF::IMAGE_SCN_MEM_READ,
538 SectionKind::getMetadata());
539 DwarfARangesSection =
540 Ctx->getCOFFSection(".debug_aranges",
541 COFF::IMAGE_SCN_MEM_DISCARDABLE |
542 COFF::IMAGE_SCN_MEM_READ,
543 SectionKind::getMetadata());
544 DwarfRangesSection =
545 Ctx->getCOFFSection(".debug_ranges",
546 COFF::IMAGE_SCN_MEM_DISCARDABLE |
547 COFF::IMAGE_SCN_MEM_READ,
548 SectionKind::getMetadata());
549 DwarfMacroInfoSection =
550 Ctx->getCOFFSection(".debug_macinfo",
551 COFF::IMAGE_SCN_MEM_DISCARDABLE |
552 COFF::IMAGE_SCN_MEM_READ,
553 SectionKind::getMetadata());
554
555 DrectveSection =
556 Ctx->getCOFFSection(".drectve",
557 COFF::IMAGE_SCN_LNK_INFO,
558 SectionKind::getMetadata());
559
560 PDataSection =
561 Ctx->getCOFFSection(".pdata",
562 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikov0a0e50c2012-08-08 12:46:46 +0000563 COFF::IMAGE_SCN_MEM_READ,
Evan Chenge76a33b2011-07-20 05:58:47 +0000564 SectionKind::getDataRel());
565
566 XDataSection =
567 Ctx->getCOFFSection(".xdata",
568 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikov0a0e50c2012-08-08 12:46:46 +0000569 COFF::IMAGE_SCN_MEM_READ,
Evan Chenge76a33b2011-07-20 05:58:47 +0000570 SectionKind::getDataRel());
Anton Korobeynikovd4a19b62012-02-11 17:26:53 +0000571 TLSDataSection =
572 Ctx->getCOFFSection(".tls$",
573 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
574 COFF::IMAGE_SCN_MEM_READ |
575 COFF::IMAGE_SCN_MEM_WRITE,
576 SectionKind::getDataRel());
Evan Chenge76a33b2011-07-20 05:58:47 +0000577}
578
579void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
Evan Cheng203576a2011-07-20 19:50:42 +0000580 CodeModel::Model cm,
Evan Chenge76a33b2011-07-20 05:58:47 +0000581 MCContext &ctx) {
582 RelocM = relocm;
Evan Cheng203576a2011-07-20 19:50:42 +0000583 CMModel = cm;
Evan Chenge76a33b2011-07-20 05:58:47 +0000584 Ctx = &ctx;
585
586 // Common.
587 CommDirectiveSupportsAlignment = true;
588 SupportsWeakOmittedEHFrame = true;
589 IsFunctionEHFrameSymbolPrivate = true;
Evan Cheng203576a2011-07-20 19:50:42 +0000590
591 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
592 TTypeEncoding = dwarf::DW_EH_PE_absptr;
593
Eric Christopher09ac3d82011-11-07 09:24:32 +0000594 EHFrameSection = 0; // Created on demand.
595 CompactUnwindSection = 0; // Used only by selected targets.
596 DwarfAccelNamesSection = 0; // Used only by selected targets.
597 DwarfAccelObjCSection = 0; // Used only by selected targets.
598 DwarfAccelNamespaceSection = 0; // Used only by selected targets.
599 DwarfAccelTypesSection = 0; // Used only by selected targets.
Evan Chenge76a33b2011-07-20 05:58:47 +0000600
601 Triple T(TT);
602 Triple::ArchType Arch = T.getArch();
603 // FIXME: Checking for Arch here to filter out bogus triples such as
604 // cellspu-apple-darwin. Perhaps we should fix in Triple?
605 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
606 Arch == Triple::arm || Arch == Triple::thumb ||
607 Arch == Triple::ppc || Arch == Triple::ppc64 ||
608 Arch == Triple::UnknownArch) &&
609 (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
610 Env = IsMachO;
611 InitMachOMCObjectFileInfo(T);
Evan Cheng36c62d32011-07-20 23:53:54 +0000612 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
Andrew Kaylor7bbd6e32012-10-02 18:38:34 +0000613 (T.getEnvironment() != Triple::ELF) &&
Evan Cheng36c62d32011-07-20 23:53:54 +0000614 (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
615 T.getOS() == Triple::Win32)) {
Evan Chenge76a33b2011-07-20 05:58:47 +0000616 Env = IsCOFF;
617 InitCOFFMCObjectFileInfo(T);
618 } else {
619 Env = IsELF;
620 InitELFMCObjectFileInfo(T);
621 }
622}
623
David Chisnall8bb51ef2012-02-17 16:51:02 +0000624void MCObjectFileInfo::InitEHFrameSection() {
625 if (Env == IsMachO)
626 EHFrameSection =
627 Ctx->getMachOSection("__TEXT", "__eh_frame",
628 MCSectionMachO::S_COALESCED |
629 MCSectionMachO::S_ATTR_NO_TOC |
630 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
631 MCSectionMachO::S_ATTR_LIVE_SUPPORT,
632 SectionKind::getReadOnly());
633 else if (Env == IsELF)
634 EHFrameSection =
David Chisnallbce0de42012-04-10 11:44:33 +0000635 Ctx->getELFSection(".eh_frame", EHSectionType,
David Chisnall4cbcee12012-02-17 17:31:15 +0000636 EHSectionFlags,
David Chisnall8bb51ef2012-02-17 16:51:02 +0000637 SectionKind::getDataRel());
638 else
639 EHFrameSection =
640 Ctx->getCOFFSection(".eh_frame",
641 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
642 COFF::IMAGE_SCN_MEM_READ |
643 COFF::IMAGE_SCN_MEM_WRITE,
644 SectionKind::getDataRel());
645}