blob: 8ef4a0a6d7b14351033fcabe281c9e1395638b60 [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
NAKAMURA Takumi023d90e2013-09-21 02:34:45 +000042 // BSSSection might not be expected initialized on msvc.
43 BSSSection = 0;
44
Evan Chenge76a33b2011-07-20 05:58:47 +000045 TLSDataSection // .tdata
46 = Ctx->getMachOSection("__DATA", "__thread_data",
47 MCSectionMachO::S_THREAD_LOCAL_REGULAR,
48 SectionKind::getDataRel());
49 TLSBSSSection // .tbss
50 = Ctx->getMachOSection("__DATA", "__thread_bss",
51 MCSectionMachO::S_THREAD_LOCAL_ZEROFILL,
52 SectionKind::getThreadBSS());
53
54 // TODO: Verify datarel below.
55 TLSTLVSection // .tlv
56 = Ctx->getMachOSection("__DATA", "__thread_vars",
57 MCSectionMachO::S_THREAD_LOCAL_VARIABLES,
58 SectionKind::getDataRel());
59
60 TLSThreadInitSection
61 = Ctx->getMachOSection("__DATA", "__thread_init",
Jim Grosbach946227d2011-11-15 16:46:22 +000062 MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
63 SectionKind::getDataRel());
Evan Chenge76a33b2011-07-20 05:58:47 +000064
65 CStringSection // .cstring
66 = Ctx->getMachOSection("__TEXT", "__cstring",
67 MCSectionMachO::S_CSTRING_LITERALS,
68 SectionKind::getMergeable1ByteCString());
69 UStringSection
70 = Ctx->getMachOSection("__TEXT","__ustring", 0,
71 SectionKind::getMergeable2ByteCString());
72 FourByteConstantSection // .literal4
73 = Ctx->getMachOSection("__TEXT", "__literal4",
74 MCSectionMachO::S_4BYTE_LITERALS,
75 SectionKind::getMergeableConst4());
76 EightByteConstantSection // .literal8
77 = Ctx->getMachOSection("__TEXT", "__literal8",
78 MCSectionMachO::S_8BYTE_LITERALS,
79 SectionKind::getMergeableConst8());
80
81 // ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back
82 // to using it in -static mode.
83 SixteenByteConstantSection = 0;
84 if (RelocM != Reloc::Static &&
Bill Schmidtf38cc382013-07-26 01:35:43 +000085 T.getArch() != Triple::x86_64 && T.getArch() != Triple::ppc64 &&
86 T.getArch() != Triple::ppc64le)
Evan Chenge76a33b2011-07-20 05:58:47 +000087 SixteenByteConstantSection = // .literal16
88 Ctx->getMachOSection("__TEXT", "__literal16",
89 MCSectionMachO::S_16BYTE_LITERALS,
90 SectionKind::getMergeableConst16());
91
92 ReadOnlySection // .const
93 = Ctx->getMachOSection("__TEXT", "__const", 0,
94 SectionKind::getReadOnly());
95
96 TextCoalSection
97 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
98 MCSectionMachO::S_COALESCED |
99 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
100 SectionKind::getText());
101 ConstTextCoalSection
102 = Ctx->getMachOSection("__TEXT", "__const_coal",
103 MCSectionMachO::S_COALESCED,
104 SectionKind::getReadOnly());
105 ConstDataSection // .const_data
106 = Ctx->getMachOSection("__DATA", "__const", 0,
107 SectionKind::getReadOnlyWithRel());
108 DataCoalSection
109 = Ctx->getMachOSection("__DATA","__datacoal_nt",
110 MCSectionMachO::S_COALESCED,
111 SectionKind::getDataRel());
112 DataCommonSection
113 = Ctx->getMachOSection("__DATA","__common",
114 MCSectionMachO::S_ZEROFILL,
115 SectionKind::getBSS());
116 DataBSSSection
117 = Ctx->getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL,
118 SectionKind::getBSS());
119
120
121 LazySymbolPointerSection
122 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
123 MCSectionMachO::S_LAZY_SYMBOL_POINTERS,
124 SectionKind::getMetadata());
125 NonLazySymbolPointerSection
126 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
127 MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
128 SectionKind::getMetadata());
129
130 if (RelocM == Reloc::Static) {
131 StaticCtorSection
132 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
133 SectionKind::getDataRel());
134 StaticDtorSection
135 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
136 SectionKind::getDataRel());
137 } else {
138 StaticCtorSection
139 = Ctx->getMachOSection("__DATA", "__mod_init_func",
140 MCSectionMachO::S_MOD_INIT_FUNC_POINTERS,
141 SectionKind::getDataRel());
142 StaticDtorSection
143 = Ctx->getMachOSection("__DATA", "__mod_term_func",
144 MCSectionMachO::S_MOD_TERM_FUNC_POINTERS,
145 SectionKind::getDataRel());
146 }
147
148 // Exception Handling.
149 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
150 SectionKind::getReadOnlyWithRel());
151
Bill Wendling62c75ad2013-04-10 21:42:06 +0000152 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) {
Evan Chenge76a33b2011-07-20 05:58:47 +0000153 CompactUnwindSection =
154 Ctx->getMachOSection("__LD", "__compact_unwind",
155 MCSectionMachO::S_ATTR_DEBUG,
156 SectionKind::getReadOnly());
157
Bill Wendling62c75ad2013-04-10 21:42:06 +0000158 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
159 CompactUnwindDwarfEHFrameOnly = 0x04000000;
160 }
161
Evan Chenge76a33b2011-07-20 05:58:47 +0000162 // Debug Information.
Eric Christopher09ac3d82011-11-07 09:24:32 +0000163 DwarfAccelNamesSection =
164 Ctx->getMachOSection("__DWARF", "__apple_names",
165 MCSectionMachO::S_ATTR_DEBUG,
166 SectionKind::getMetadata());
167 DwarfAccelObjCSection =
168 Ctx->getMachOSection("__DWARF", "__apple_objc",
169 MCSectionMachO::S_ATTR_DEBUG,
170 SectionKind::getMetadata());
171 // 16 character section limit...
172 DwarfAccelNamespaceSection =
173 Ctx->getMachOSection("__DWARF", "__apple_namespac",
174 MCSectionMachO::S_ATTR_DEBUG,
175 SectionKind::getMetadata());
176 DwarfAccelTypesSection =
177 Ctx->getMachOSection("__DWARF", "__apple_types",
178 MCSectionMachO::S_ATTR_DEBUG,
179 SectionKind::getMetadata());
Jim Grosbach2684d9e2012-05-11 01:41:30 +0000180
Evan Chenge76a33b2011-07-20 05:58:47 +0000181 DwarfAbbrevSection =
182 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
183 MCSectionMachO::S_ATTR_DEBUG,
184 SectionKind::getMetadata());
185 DwarfInfoSection =
186 Ctx->getMachOSection("__DWARF", "__debug_info",
187 MCSectionMachO::S_ATTR_DEBUG,
188 SectionKind::getMetadata());
189 DwarfLineSection =
190 Ctx->getMachOSection("__DWARF", "__debug_line",
191 MCSectionMachO::S_ATTR_DEBUG,
192 SectionKind::getMetadata());
193 DwarfFrameSection =
194 Ctx->getMachOSection("__DWARF", "__debug_frame",
195 MCSectionMachO::S_ATTR_DEBUG,
196 SectionKind::getMetadata());
Krzysztof Parzyszekc5ef7ee2013-02-12 18:00:14 +0000197 DwarfPubNamesSection =
198 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
199 MCSectionMachO::S_ATTR_DEBUG,
200 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000201 DwarfPubTypesSection =
202 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
203 MCSectionMachO::S_ATTR_DEBUG,
204 SectionKind::getMetadata());
Eric Christopher328a2042013-09-09 20:03:14 +0000205 DwarfGnuPubNamesSection =
206 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
207 MCSectionMachO::S_ATTR_DEBUG,
208 SectionKind::getMetadata());
209 DwarfGnuPubTypesSection =
210 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
211 MCSectionMachO::S_ATTR_DEBUG,
212 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000213 DwarfStrSection =
214 Ctx->getMachOSection("__DWARF", "__debug_str",
215 MCSectionMachO::S_ATTR_DEBUG,
216 SectionKind::getMetadata());
217 DwarfLocSection =
218 Ctx->getMachOSection("__DWARF", "__debug_loc",
219 MCSectionMachO::S_ATTR_DEBUG,
220 SectionKind::getMetadata());
221 DwarfARangesSection =
222 Ctx->getMachOSection("__DWARF", "__debug_aranges",
223 MCSectionMachO::S_ATTR_DEBUG,
224 SectionKind::getMetadata());
225 DwarfRangesSection =
226 Ctx->getMachOSection("__DWARF", "__debug_ranges",
227 MCSectionMachO::S_ATTR_DEBUG,
228 SectionKind::getMetadata());
229 DwarfMacroInfoSection =
230 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
231 MCSectionMachO::S_ATTR_DEBUG,
232 SectionKind::getMetadata());
233 DwarfDebugInlineSection =
234 Ctx->getMachOSection("__DWARF", "__debug_inlined",
235 MCSectionMachO::S_ATTR_DEBUG,
236 SectionKind::getMetadata());
Lang Hamesc87e4382013-11-08 22:14:49 +0000237 StackMapSection =
238 Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
239 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000240
241 TLSExtraDataSection = TLSTLVSection;
242}
243
244void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
Rafael Espindola04011e842013-04-03 03:13:19 +0000245 if (T.getArch() == Triple::mips ||
246 T.getArch() == Triple::mipsel)
247 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
248 else if (T.getArch() == Triple::mips64 ||
249 T.getArch() == Triple::mips64el)
250 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
251 else
Rafael Espindola7a86ffb2013-03-15 05:51:57 +0000252 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
253
Evan Cheng203576a2011-07-20 19:50:42 +0000254 if (T.getArch() == Triple::x86) {
255 PersonalityEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach946227d2011-11-15 16:46:22 +0000256 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
257 : dwarf::DW_EH_PE_absptr;
Evan Cheng203576a2011-07-20 19:50:42 +0000258 LSDAEncoding = (RelocM == Reloc::PIC_)
259 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
260 : dwarf::DW_EH_PE_absptr;
Rafael Espindola7a86ffb2013-03-15 05:51:57 +0000261 FDEEncoding = (RelocM == Reloc::PIC_)
Evan Cheng203576a2011-07-20 19:50:42 +0000262 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
263 : dwarf::DW_EH_PE_absptr;
264 TTypeEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach946227d2011-11-15 16:46:22 +0000265 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
266 : dwarf::DW_EH_PE_absptr;
Evan Cheng203576a2011-07-20 19:50:42 +0000267 } else if (T.getArch() == Triple::x86_64) {
Evan Cheng203576a2011-07-20 19:50:42 +0000268 if (RelocM == Reloc::PIC_) {
269 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
270 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
271 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
272 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
273 (CMModel == CodeModel::Small
274 ? dwarf::DW_EH_PE_sdata4 : 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 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
278 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
279 } else {
280 PersonalityEncoding =
281 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
282 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
283 LSDAEncoding = (CMModel == CodeModel::Small)
284 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
285 FDEEncoding = dwarf::DW_EH_PE_udata4;
286 TTypeEncoding = (CMModel == CodeModel::Small)
287 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
288 }
Tim Northover72062f52013-01-31 12:12:40 +0000289 } else if (T.getArch() == Triple::aarch64) {
Tim Northover72062f52013-01-31 12:12:40 +0000290 // The small model guarantees static code/data size < 4GB, but not where it
291 // will be in memory. Most of these could end up >2GB away so even a signed
292 // pc-relative 32-bit address is insufficient, theoretically.
293 if (RelocM == Reloc::PIC_) {
294 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
295 dwarf::DW_EH_PE_sdata8;
296 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
297 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
298 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
299 dwarf::DW_EH_PE_sdata8;
300 } else {
301 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
302 LSDAEncoding = dwarf::DW_EH_PE_absptr;
303 FDEEncoding = dwarf::DW_EH_PE_udata4;
304 TTypeEncoding = dwarf::DW_EH_PE_absptr;
305 }
Bill Schmidtf38cc382013-07-26 01:35:43 +0000306 } else if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le) {
Adhemerval Zanellaa1db5de2013-01-09 17:08:15 +0000307 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
308 dwarf::DW_EH_PE_udata8;
Adhemerval Zanellaa1db5de2013-01-09 17:08:15 +0000309 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
310 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
311 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
312 dwarf::DW_EH_PE_udata8;
Ulrich Weigande96e43f2013-05-06 16:11:12 +0000313 } else if (T.getArch() == Triple::systemz) {
314 // All currently-defined code models guarantee that 4-byte PC-relative
315 // values will be in range.
Ulrich Weigande5c8c242013-05-06 17:28:30 +0000316 if (RelocM == Reloc::PIC_) {
317 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
318 dwarf::DW_EH_PE_sdata4;
319 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
320 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
321 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
322 dwarf::DW_EH_PE_sdata4;
323 } else {
324 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
325 LSDAEncoding = dwarf::DW_EH_PE_absptr;
326 FDEEncoding = dwarf::DW_EH_PE_absptr;
327 TTypeEncoding = dwarf::DW_EH_PE_absptr;
328 }
Evan Cheng203576a2011-07-20 19:50:42 +0000329 }
330
David Chisnall4cbcee12012-02-17 17:31:15 +0000331 // Solaris requires different flags for .eh_frame to seemingly every other
332 // platform.
David Chisnallbce0de42012-04-10 11:44:33 +0000333 EHSectionType = ELF::SHT_PROGBITS;
David Chisnall4cbcee12012-02-17 17:31:15 +0000334 EHSectionFlags = ELF::SHF_ALLOC;
David Chisnallbce0de42012-04-10 11:44:33 +0000335 if (T.getOS() == Triple::Solaris) {
336 if (T.getArch() == Triple::x86_64)
337 EHSectionType = ELF::SHT_X86_64_UNWIND;
338 else
339 EHSectionFlags |= ELF::SHF_WRITE;
340 }
David Chisnall4cbcee12012-02-17 17:31:15 +0000341
342
Evan Chenge76a33b2011-07-20 05:58:47 +0000343 // ELF
344 BSSSection =
345 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
Anton Korobeynikov4a99f592012-01-25 22:24:19 +0000346 ELF::SHF_WRITE | ELF::SHF_ALLOC,
Evan Chenge76a33b2011-07-20 05:58:47 +0000347 SectionKind::getBSS());
348
349 TextSection =
350 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
351 ELF::SHF_EXECINSTR |
352 ELF::SHF_ALLOC,
353 SectionKind::getText());
354
355 DataSection =
356 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
357 ELF::SHF_WRITE |ELF::SHF_ALLOC,
358 SectionKind::getDataRel());
359
360 ReadOnlySection =
361 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
362 ELF::SHF_ALLOC,
363 SectionKind::getReadOnly());
364
365 TLSDataSection =
366 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
367 ELF::SHF_ALLOC | ELF::SHF_TLS |
368 ELF::SHF_WRITE,
369 SectionKind::getThreadData());
370
371 TLSBSSSection =
372 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
373 ELF::SHF_ALLOC | ELF::SHF_TLS |
374 ELF::SHF_WRITE,
375 SectionKind::getThreadBSS());
376
377 DataRelSection =
378 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
379 ELF::SHF_ALLOC |ELF::SHF_WRITE,
380 SectionKind::getDataRel());
381
382 DataRelLocalSection =
383 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
384 ELF::SHF_ALLOC |ELF::SHF_WRITE,
385 SectionKind::getDataRelLocal());
386
387 DataRelROSection =
388 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
389 ELF::SHF_ALLOC |ELF::SHF_WRITE,
390 SectionKind::getReadOnlyWithRel());
391
392 DataRelROLocalSection =
393 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
394 ELF::SHF_ALLOC |ELF::SHF_WRITE,
395 SectionKind::getReadOnlyWithRelLocal());
396
397 MergeableConst4Section =
398 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
399 ELF::SHF_ALLOC |ELF::SHF_MERGE,
400 SectionKind::getMergeableConst4());
401
402 MergeableConst8Section =
403 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
404 ELF::SHF_ALLOC |ELF::SHF_MERGE,
405 SectionKind::getMergeableConst8());
406
407 MergeableConst16Section =
408 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
409 ELF::SHF_ALLOC |ELF::SHF_MERGE,
410 SectionKind::getMergeableConst16());
411
412 StaticCtorSection =
413 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
414 ELF::SHF_ALLOC |ELF::SHF_WRITE,
415 SectionKind::getDataRel());
416
417 StaticDtorSection =
418 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
419 ELF::SHF_ALLOC |ELF::SHF_WRITE,
420 SectionKind::getDataRel());
421
422 // Exception Handling Sections.
423
424 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
425 // it contains relocatable pointers. In PIC mode, this is probably a big
426 // runtime hit for C++ apps. Either the contents of the LSDA need to be
427 // adjusted or this should be a data section.
428 LSDASection =
429 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
430 ELF::SHF_ALLOC,
431 SectionKind::getReadOnly());
432
433 // Debug Info Sections.
434 DwarfAbbrevSection =
435 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
436 SectionKind::getMetadata());
437 DwarfInfoSection =
438 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
439 SectionKind::getMetadata());
440 DwarfLineSection =
441 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
442 SectionKind::getMetadata());
443 DwarfFrameSection =
444 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
445 SectionKind::getMetadata());
Krzysztof Parzyszekc5ef7ee2013-02-12 18:00:14 +0000446 DwarfPubNamesSection =
447 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
448 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000449 DwarfPubTypesSection =
450 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
451 SectionKind::getMetadata());
Eric Christopher328a2042013-09-09 20:03:14 +0000452 DwarfGnuPubNamesSection =
453 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
454 SectionKind::getMetadata());
455 DwarfGnuPubTypesSection =
456 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
457 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000458 DwarfStrSection =
Nick Lewycky5a86c5b2011-10-26 18:44:32 +0000459 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
460 ELF::SHF_MERGE | ELF::SHF_STRINGS,
461 SectionKind::getMergeable1ByteCString());
Evan Chenge76a33b2011-07-20 05:58:47 +0000462 DwarfLocSection =
463 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
464 SectionKind::getMetadata());
465 DwarfARangesSection =
466 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
467 SectionKind::getMetadata());
468 DwarfRangesSection =
469 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
470 SectionKind::getMetadata());
471 DwarfMacroInfoSection =
472 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
473 SectionKind::getMetadata());
Eric Christopherea1504d2012-11-28 02:49:34 +0000474
475 // DWARF5 Experimental Debug Info
476
477 // Accelerator Tables
Eric Christopher5b4461c2012-10-08 21:41:30 +0000478 DwarfAccelNamesSection =
479 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
480 SectionKind::getMetadata());
481 DwarfAccelObjCSection =
482 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
483 SectionKind::getMetadata());
484 DwarfAccelNamespaceSection =
485 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
486 SectionKind::getMetadata());
487 DwarfAccelTypesSection =
488 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
489 SectionKind::getMetadata());
Eric Christopher6acb5312012-11-28 02:49:38 +0000490
491 // Fission Sections
492 DwarfInfoDWOSection =
493 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
494 SectionKind::getMetadata());
Eric Christopher67587f42012-11-30 06:47:06 +0000495 DwarfAbbrevDWOSection =
496 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
497 SectionKind::getMetadata());
498 DwarfStrDWOSection =
499 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
500 ELF::SHF_MERGE | ELF::SHF_STRINGS,
501 SectionKind::getMergeable1ByteCString());
502 DwarfLineDWOSection =
503 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
504 SectionKind::getMetadata());
505 DwarfLocDWOSection =
506 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
507 SectionKind::getMetadata());
Eric Christopher60230ef2013-01-04 17:59:22 +0000508 DwarfStrOffDWOSection =
509 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
510 SectionKind::getMetadata());
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000511 DwarfAddrSection =
512 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
513 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000514}
515
516
517void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
518 // COFF
David Majnemer6aa93152013-08-13 01:23:53 +0000519 BSSSection =
520 Ctx->getCOFFSection(".bss",
521 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
522 COFF::IMAGE_SCN_MEM_READ |
523 COFF::IMAGE_SCN_MEM_WRITE,
524 SectionKind::getBSS());
Evan Chenge76a33b2011-07-20 05:58:47 +0000525 TextSection =
526 Ctx->getCOFFSection(".text",
527 COFF::IMAGE_SCN_CNT_CODE |
528 COFF::IMAGE_SCN_MEM_EXECUTE |
529 COFF::IMAGE_SCN_MEM_READ,
530 SectionKind::getText());
531 DataSection =
532 Ctx->getCOFFSection(".data",
533 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
534 COFF::IMAGE_SCN_MEM_READ |
535 COFF::IMAGE_SCN_MEM_WRITE,
536 SectionKind::getDataRel());
537 ReadOnlySection =
538 Ctx->getCOFFSection(".rdata",
539 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
540 COFF::IMAGE_SCN_MEM_READ,
541 SectionKind::getReadOnly());
Michael J. Spencer32d22ee2012-02-23 21:56:08 +0000542 if (T.getOS() == Triple::Win32) {
543 StaticCtorSection =
544 Ctx->getCOFFSection(".CRT$XCU",
545 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
546 COFF::IMAGE_SCN_MEM_READ,
547 SectionKind::getReadOnly());
548 } else {
549 StaticCtorSection =
550 Ctx->getCOFFSection(".ctors",
551 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
552 COFF::IMAGE_SCN_MEM_READ |
553 COFF::IMAGE_SCN_MEM_WRITE,
554 SectionKind::getDataRel());
555 }
556
557
Anton Korobeynikov371e17c2012-09-23 15:53:47 +0000558 if (T.getOS() == Triple::Win32) {
559 StaticDtorSection =
560 Ctx->getCOFFSection(".CRT$XTX",
561 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
562 COFF::IMAGE_SCN_MEM_READ,
563 SectionKind::getReadOnly());
564 } else {
565 StaticDtorSection =
566 Ctx->getCOFFSection(".dtors",
567 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
568 COFF::IMAGE_SCN_MEM_READ |
569 COFF::IMAGE_SCN_MEM_WRITE,
570 SectionKind::getDataRel());
571 }
Evan Chenge76a33b2011-07-20 05:58:47 +0000572
573 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
574 // though it contains relocatable pointers. In PIC mode, this is probably a
575 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
576 // adjusted or this should be a data section.
Kai Nacke113d32c2013-07-08 04:43:23 +0000577 LSDASection =
578 Ctx->getCOFFSection(".gcc_except_table",
579 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
580 COFF::IMAGE_SCN_MEM_READ,
581 SectionKind::getReadOnly());
Evan Chenge76a33b2011-07-20 05:58:47 +0000582
583 // Debug info.
584 DwarfAbbrevSection =
585 Ctx->getCOFFSection(".debug_abbrev",
586 COFF::IMAGE_SCN_MEM_DISCARDABLE |
587 COFF::IMAGE_SCN_MEM_READ,
588 SectionKind::getMetadata());
589 DwarfInfoSection =
590 Ctx->getCOFFSection(".debug_info",
591 COFF::IMAGE_SCN_MEM_DISCARDABLE |
592 COFF::IMAGE_SCN_MEM_READ,
593 SectionKind::getMetadata());
594 DwarfLineSection =
595 Ctx->getCOFFSection(".debug_line",
596 COFF::IMAGE_SCN_MEM_DISCARDABLE |
597 COFF::IMAGE_SCN_MEM_READ,
598 SectionKind::getMetadata());
599 DwarfFrameSection =
600 Ctx->getCOFFSection(".debug_frame",
601 COFF::IMAGE_SCN_MEM_DISCARDABLE |
602 COFF::IMAGE_SCN_MEM_READ,
603 SectionKind::getMetadata());
Krzysztof Parzyszekc5ef7ee2013-02-12 18:00:14 +0000604 DwarfPubNamesSection =
605 Ctx->getCOFFSection(".debug_pubnames",
606 COFF::IMAGE_SCN_MEM_DISCARDABLE |
607 COFF::IMAGE_SCN_MEM_READ,
608 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000609 DwarfPubTypesSection =
610 Ctx->getCOFFSection(".debug_pubtypes",
611 COFF::IMAGE_SCN_MEM_DISCARDABLE |
612 COFF::IMAGE_SCN_MEM_READ,
613 SectionKind::getMetadata());
NAKAMURA Takumic3c9b9b2013-09-10 06:01:56 +0000614 DwarfGnuPubNamesSection =
Eric Christopher328a2042013-09-09 20:03:14 +0000615 Ctx->getCOFFSection(".debug_gnu_pubnames",
616 COFF::IMAGE_SCN_MEM_DISCARDABLE |
617 COFF::IMAGE_SCN_MEM_READ,
618 SectionKind::getMetadata());
NAKAMURA Takumic3c9b9b2013-09-10 06:01:56 +0000619 DwarfGnuPubTypesSection =
Eric Christopher328a2042013-09-09 20:03:14 +0000620 Ctx->getCOFFSection(".debug_gnu_pubtypes",
621 COFF::IMAGE_SCN_MEM_DISCARDABLE |
622 COFF::IMAGE_SCN_MEM_READ,
623 SectionKind::getMetadata());
Evan Chenge76a33b2011-07-20 05:58:47 +0000624 DwarfStrSection =
625 Ctx->getCOFFSection(".debug_str",
626 COFF::IMAGE_SCN_MEM_DISCARDABLE |
627 COFF::IMAGE_SCN_MEM_READ,
628 SectionKind::getMetadata());
629 DwarfLocSection =
630 Ctx->getCOFFSection(".debug_loc",
631 COFF::IMAGE_SCN_MEM_DISCARDABLE |
632 COFF::IMAGE_SCN_MEM_READ,
633 SectionKind::getMetadata());
634 DwarfARangesSection =
635 Ctx->getCOFFSection(".debug_aranges",
636 COFF::IMAGE_SCN_MEM_DISCARDABLE |
637 COFF::IMAGE_SCN_MEM_READ,
638 SectionKind::getMetadata());
639 DwarfRangesSection =
640 Ctx->getCOFFSection(".debug_ranges",
641 COFF::IMAGE_SCN_MEM_DISCARDABLE |
642 COFF::IMAGE_SCN_MEM_READ,
643 SectionKind::getMetadata());
644 DwarfMacroInfoSection =
645 Ctx->getCOFFSection(".debug_macinfo",
646 COFF::IMAGE_SCN_MEM_DISCARDABLE |
647 COFF::IMAGE_SCN_MEM_READ,
648 SectionKind::getMetadata());
649
650 DrectveSection =
651 Ctx->getCOFFSection(".drectve",
652 COFF::IMAGE_SCN_LNK_INFO,
653 SectionKind::getMetadata());
654
655 PDataSection =
656 Ctx->getCOFFSection(".pdata",
657 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikov0a0e50c2012-08-08 12:46:46 +0000658 COFF::IMAGE_SCN_MEM_READ,
Evan Chenge76a33b2011-07-20 05:58:47 +0000659 SectionKind::getDataRel());
660
661 XDataSection =
662 Ctx->getCOFFSection(".xdata",
663 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikov0a0e50c2012-08-08 12:46:46 +0000664 COFF::IMAGE_SCN_MEM_READ,
Evan Chenge76a33b2011-07-20 05:58:47 +0000665 SectionKind::getDataRel());
Anton Korobeynikovd4a19b62012-02-11 17:26:53 +0000666 TLSDataSection =
667 Ctx->getCOFFSection(".tls$",
668 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
669 COFF::IMAGE_SCN_MEM_READ |
670 COFF::IMAGE_SCN_MEM_WRITE,
671 SectionKind::getDataRel());
Evan Chenge76a33b2011-07-20 05:58:47 +0000672}
673
674void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
Evan Cheng203576a2011-07-20 19:50:42 +0000675 CodeModel::Model cm,
Evan Chenge76a33b2011-07-20 05:58:47 +0000676 MCContext &ctx) {
677 RelocM = relocm;
Evan Cheng203576a2011-07-20 19:50:42 +0000678 CMModel = cm;
Evan Chenge76a33b2011-07-20 05:58:47 +0000679 Ctx = &ctx;
680
681 // Common.
682 CommDirectiveSupportsAlignment = true;
683 SupportsWeakOmittedEHFrame = true;
684 IsFunctionEHFrameSymbolPrivate = true;
Evan Cheng203576a2011-07-20 19:50:42 +0000685
686 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
687 TTypeEncoding = dwarf::DW_EH_PE_absptr;
688
Bill Wendling62c75ad2013-04-10 21:42:06 +0000689 CompactUnwindDwarfEHFrameOnly = 0;
690
Eric Christopher09ac3d82011-11-07 09:24:32 +0000691 EHFrameSection = 0; // Created on demand.
692 CompactUnwindSection = 0; // Used only by selected targets.
693 DwarfAccelNamesSection = 0; // Used only by selected targets.
694 DwarfAccelObjCSection = 0; // Used only by selected targets.
695 DwarfAccelNamespaceSection = 0; // Used only by selected targets.
696 DwarfAccelTypesSection = 0; // Used only by selected targets.
Evan Chenge76a33b2011-07-20 05:58:47 +0000697
698 Triple T(TT);
699 Triple::ArchType Arch = T.getArch();
700 // FIXME: Checking for Arch here to filter out bogus triples such as
701 // cellspu-apple-darwin. Perhaps we should fix in Triple?
702 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
703 Arch == Triple::arm || Arch == Triple::thumb ||
704 Arch == Triple::ppc || Arch == Triple::ppc64 ||
705 Arch == Triple::UnknownArch) &&
706 (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
707 Env = IsMachO;
708 InitMachOMCObjectFileInfo(T);
Evan Cheng36c62d32011-07-20 23:53:54 +0000709 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
Andrew Kaylor7bbd6e32012-10-02 18:38:34 +0000710 (T.getEnvironment() != Triple::ELF) &&
Evan Cheng36c62d32011-07-20 23:53:54 +0000711 (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
712 T.getOS() == Triple::Win32)) {
Evan Chenge76a33b2011-07-20 05:58:47 +0000713 Env = IsCOFF;
714 InitCOFFMCObjectFileInfo(T);
715 } else {
716 Env = IsELF;
717 InitELFMCObjectFileInfo(T);
718 }
719}
720
David Chisnall8bb51ef2012-02-17 16:51:02 +0000721void MCObjectFileInfo::InitEHFrameSection() {
722 if (Env == IsMachO)
723 EHFrameSection =
724 Ctx->getMachOSection("__TEXT", "__eh_frame",
725 MCSectionMachO::S_COALESCED |
726 MCSectionMachO::S_ATTR_NO_TOC |
727 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
728 MCSectionMachO::S_ATTR_LIVE_SUPPORT,
729 SectionKind::getReadOnly());
730 else if (Env == IsELF)
731 EHFrameSection =
David Chisnallbce0de42012-04-10 11:44:33 +0000732 Ctx->getELFSection(".eh_frame", EHSectionType,
David Chisnall4cbcee12012-02-17 17:31:15 +0000733 EHSectionFlags,
David Chisnall8bb51ef2012-02-17 16:51:02 +0000734 SectionKind::getDataRel());
735 else
736 EHFrameSection =
737 Ctx->getCOFFSection(".eh_frame",
738 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
739 COFF::IMAGE_SCN_MEM_READ |
740 COFF::IMAGE_SCN_MEM_WRITE,
741 SectionKind::getDataRel());
742}