blob: 5d7a5f886324c5b4c48650725fa09581f8a01bf5 [file] [log] [blame]
Evan Cheng76792992011-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"
David Blaikiebc563272013-12-13 21:33:40 +000011#include "llvm/ADT/StringExtras.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000012#include "llvm/ADT/Triple.h"
Evan Cheng76792992011-07-20 05:58:47 +000013#include "llvm/MC/MCContext.h"
14#include "llvm/MC/MCSection.h"
15#include "llvm/MC/MCSectionCOFF.h"
16#include "llvm/MC/MCSectionELF.h"
17#include "llvm/MC/MCSectionMachO.h"
Evan Cheng76792992011-07-20 05:58:47 +000018using namespace llvm;
19
20void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
21 // MachO
22 IsFunctionEHFrameSymbolPrivate = false;
23 SupportsWeakOmittedEHFrame = false;
24
Evan Chengbbf3b0d2011-07-20 19:50:42 +000025 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
26 | dwarf::DW_EH_PE_sdata4;
27 LSDAEncoding = FDEEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
28 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
29 dwarf::DW_EH_PE_sdata4;
30
Evan Cheng76792992011-07-20 05:58:47 +000031 // .comm doesn't support alignment before Leopard.
32 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
33 CommDirectiveSupportsAlignment = false;
34
35 TextSection // .text
36 = Ctx->getMachOSection("__TEXT", "__text",
37 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
38 SectionKind::getText());
39 DataSection // .data
40 = Ctx->getMachOSection("__DATA", "__data", 0,
41 SectionKind::getDataRel());
42
NAKAMURA Takumi68fa6f92013-09-21 02:34:45 +000043 // BSSSection might not be expected initialized on msvc.
44 BSSSection = 0;
45
Evan Cheng76792992011-07-20 05:58:47 +000046 TLSDataSection // .tdata
47 = Ctx->getMachOSection("__DATA", "__thread_data",
48 MCSectionMachO::S_THREAD_LOCAL_REGULAR,
49 SectionKind::getDataRel());
50 TLSBSSSection // .tbss
51 = Ctx->getMachOSection("__DATA", "__thread_bss",
52 MCSectionMachO::S_THREAD_LOCAL_ZEROFILL,
53 SectionKind::getThreadBSS());
54
55 // TODO: Verify datarel below.
56 TLSTLVSection // .tlv
57 = Ctx->getMachOSection("__DATA", "__thread_vars",
58 MCSectionMachO::S_THREAD_LOCAL_VARIABLES,
59 SectionKind::getDataRel());
60
61 TLSThreadInitSection
62 = Ctx->getMachOSection("__DATA", "__thread_init",
Jim Grosbach0dde3492011-11-15 16:46:22 +000063 MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
64 SectionKind::getDataRel());
Evan Cheng76792992011-07-20 05:58:47 +000065
66 CStringSection // .cstring
67 = Ctx->getMachOSection("__TEXT", "__cstring",
68 MCSectionMachO::S_CSTRING_LITERALS,
69 SectionKind::getMergeable1ByteCString());
70 UStringSection
71 = Ctx->getMachOSection("__TEXT","__ustring", 0,
72 SectionKind::getMergeable2ByteCString());
73 FourByteConstantSection // .literal4
74 = Ctx->getMachOSection("__TEXT", "__literal4",
75 MCSectionMachO::S_4BYTE_LITERALS,
76 SectionKind::getMergeableConst4());
77 EightByteConstantSection // .literal8
78 = Ctx->getMachOSection("__TEXT", "__literal8",
79 MCSectionMachO::S_8BYTE_LITERALS,
80 SectionKind::getMergeableConst8());
81
82 // ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back
83 // to using it in -static mode.
84 SixteenByteConstantSection = 0;
85 if (RelocM != Reloc::Static &&
Bill Schmidt0a9170d2013-07-26 01:35:43 +000086 T.getArch() != Triple::x86_64 && T.getArch() != Triple::ppc64 &&
87 T.getArch() != Triple::ppc64le)
Evan Cheng76792992011-07-20 05:58:47 +000088 SixteenByteConstantSection = // .literal16
89 Ctx->getMachOSection("__TEXT", "__literal16",
90 MCSectionMachO::S_16BYTE_LITERALS,
91 SectionKind::getMergeableConst16());
92
93 ReadOnlySection // .const
94 = Ctx->getMachOSection("__TEXT", "__const", 0,
95 SectionKind::getReadOnly());
96
97 TextCoalSection
98 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
99 MCSectionMachO::S_COALESCED |
100 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
101 SectionKind::getText());
102 ConstTextCoalSection
103 = Ctx->getMachOSection("__TEXT", "__const_coal",
104 MCSectionMachO::S_COALESCED,
105 SectionKind::getReadOnly());
106 ConstDataSection // .const_data
107 = Ctx->getMachOSection("__DATA", "__const", 0,
108 SectionKind::getReadOnlyWithRel());
109 DataCoalSection
110 = Ctx->getMachOSection("__DATA","__datacoal_nt",
111 MCSectionMachO::S_COALESCED,
112 SectionKind::getDataRel());
113 DataCommonSection
114 = Ctx->getMachOSection("__DATA","__common",
115 MCSectionMachO::S_ZEROFILL,
116 SectionKind::getBSS());
117 DataBSSSection
118 = Ctx->getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL,
119 SectionKind::getBSS());
120
121
122 LazySymbolPointerSection
123 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
124 MCSectionMachO::S_LAZY_SYMBOL_POINTERS,
125 SectionKind::getMetadata());
126 NonLazySymbolPointerSection
127 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
128 MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
129 SectionKind::getMetadata());
130
131 if (RelocM == Reloc::Static) {
132 StaticCtorSection
133 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
134 SectionKind::getDataRel());
135 StaticDtorSection
136 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
137 SectionKind::getDataRel());
138 } else {
139 StaticCtorSection
140 = Ctx->getMachOSection("__DATA", "__mod_init_func",
141 MCSectionMachO::S_MOD_INIT_FUNC_POINTERS,
142 SectionKind::getDataRel());
143 StaticDtorSection
144 = Ctx->getMachOSection("__DATA", "__mod_term_func",
145 MCSectionMachO::S_MOD_TERM_FUNC_POINTERS,
146 SectionKind::getDataRel());
147 }
148
149 // Exception Handling.
150 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
151 SectionKind::getReadOnlyWithRel());
152
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000153 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) {
Evan Cheng76792992011-07-20 05:58:47 +0000154 CompactUnwindSection =
155 Ctx->getMachOSection("__LD", "__compact_unwind",
156 MCSectionMachO::S_ATTR_DEBUG,
157 SectionKind::getReadOnly());
158
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000159 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
160 CompactUnwindDwarfEHFrameOnly = 0x04000000;
161 }
162
Evan Cheng76792992011-07-20 05:58:47 +0000163 // Debug Information.
Eric Christopher4996c702011-11-07 09:24:32 +0000164 DwarfAccelNamesSection =
165 Ctx->getMachOSection("__DWARF", "__apple_names",
166 MCSectionMachO::S_ATTR_DEBUG,
167 SectionKind::getMetadata());
168 DwarfAccelObjCSection =
169 Ctx->getMachOSection("__DWARF", "__apple_objc",
170 MCSectionMachO::S_ATTR_DEBUG,
171 SectionKind::getMetadata());
172 // 16 character section limit...
173 DwarfAccelNamespaceSection =
174 Ctx->getMachOSection("__DWARF", "__apple_namespac",
175 MCSectionMachO::S_ATTR_DEBUG,
176 SectionKind::getMetadata());
177 DwarfAccelTypesSection =
178 Ctx->getMachOSection("__DWARF", "__apple_types",
179 MCSectionMachO::S_ATTR_DEBUG,
180 SectionKind::getMetadata());
Jim Grosbachdc1e36e2012-05-11 01:41:30 +0000181
Evan Cheng76792992011-07-20 05:58:47 +0000182 DwarfAbbrevSection =
183 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
184 MCSectionMachO::S_ATTR_DEBUG,
185 SectionKind::getMetadata());
186 DwarfInfoSection =
187 Ctx->getMachOSection("__DWARF", "__debug_info",
188 MCSectionMachO::S_ATTR_DEBUG,
189 SectionKind::getMetadata());
190 DwarfLineSection =
191 Ctx->getMachOSection("__DWARF", "__debug_line",
192 MCSectionMachO::S_ATTR_DEBUG,
193 SectionKind::getMetadata());
194 DwarfFrameSection =
195 Ctx->getMachOSection("__DWARF", "__debug_frame",
196 MCSectionMachO::S_ATTR_DEBUG,
197 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000198 DwarfPubNamesSection =
199 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
200 MCSectionMachO::S_ATTR_DEBUG,
201 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000202 DwarfPubTypesSection =
203 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
204 MCSectionMachO::S_ATTR_DEBUG,
205 SectionKind::getMetadata());
Eric Christopherb0e76942013-09-09 20:03:14 +0000206 DwarfGnuPubNamesSection =
207 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
208 MCSectionMachO::S_ATTR_DEBUG,
209 SectionKind::getMetadata());
210 DwarfGnuPubTypesSection =
211 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
212 MCSectionMachO::S_ATTR_DEBUG,
213 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000214 DwarfStrSection =
215 Ctx->getMachOSection("__DWARF", "__debug_str",
216 MCSectionMachO::S_ATTR_DEBUG,
217 SectionKind::getMetadata());
218 DwarfLocSection =
219 Ctx->getMachOSection("__DWARF", "__debug_loc",
220 MCSectionMachO::S_ATTR_DEBUG,
221 SectionKind::getMetadata());
222 DwarfARangesSection =
223 Ctx->getMachOSection("__DWARF", "__debug_aranges",
224 MCSectionMachO::S_ATTR_DEBUG,
225 SectionKind::getMetadata());
226 DwarfRangesSection =
227 Ctx->getMachOSection("__DWARF", "__debug_ranges",
228 MCSectionMachO::S_ATTR_DEBUG,
229 SectionKind::getMetadata());
230 DwarfMacroInfoSection =
231 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
232 MCSectionMachO::S_ATTR_DEBUG,
233 SectionKind::getMetadata());
234 DwarfDebugInlineSection =
235 Ctx->getMachOSection("__DWARF", "__debug_inlined",
236 MCSectionMachO::S_ATTR_DEBUG,
237 SectionKind::getMetadata());
Lang Hames30789772013-11-08 22:14:49 +0000238 StackMapSection =
239 Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
240 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000241
242 TLSExtraDataSection = TLSTLVSection;
243}
244
245void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
Rafael Espindolab9b7ae02013-04-03 03:13:19 +0000246 if (T.getArch() == Triple::mips ||
247 T.getArch() == Triple::mipsel)
248 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
249 else if (T.getArch() == Triple::mips64 ||
250 T.getArch() == Triple::mips64el)
251 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
252 else
Rafael Espindolaef9d3492013-03-15 05:51:57 +0000253 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
254
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000255 if (T.getArch() == Triple::x86) {
256 PersonalityEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach0dde3492011-11-15 16:46:22 +0000257 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
258 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000259 LSDAEncoding = (RelocM == Reloc::PIC_)
260 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
261 : dwarf::DW_EH_PE_absptr;
Rafael Espindolaef9d3492013-03-15 05:51:57 +0000262 FDEEncoding = (RelocM == Reloc::PIC_)
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000263 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
264 : dwarf::DW_EH_PE_absptr;
265 TTypeEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach0dde3492011-11-15 16:46:22 +0000266 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
267 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000268 } else if (T.getArch() == Triple::x86_64) {
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000269 if (RelocM == Reloc::PIC_) {
270 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
271 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
272 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
273 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
274 (CMModel == CodeModel::Small
275 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
276 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
277 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
278 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
279 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
280 } else {
281 PersonalityEncoding =
282 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
283 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
284 LSDAEncoding = (CMModel == CodeModel::Small)
285 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
286 FDEEncoding = dwarf::DW_EH_PE_udata4;
287 TTypeEncoding = (CMModel == CodeModel::Small)
288 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
289 }
Tim Northovere0e3aef2013-01-31 12:12:40 +0000290 } else if (T.getArch() == Triple::aarch64) {
Tim Northovere0e3aef2013-01-31 12:12:40 +0000291 // The small model guarantees static code/data size < 4GB, but not where it
292 // will be in memory. Most of these could end up >2GB away so even a signed
293 // pc-relative 32-bit address is insufficient, theoretically.
294 if (RelocM == Reloc::PIC_) {
295 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
296 dwarf::DW_EH_PE_sdata8;
297 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
298 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
299 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
300 dwarf::DW_EH_PE_sdata8;
301 } else {
302 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
303 LSDAEncoding = dwarf::DW_EH_PE_absptr;
304 FDEEncoding = dwarf::DW_EH_PE_udata4;
305 TTypeEncoding = dwarf::DW_EH_PE_absptr;
306 }
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000307 } else if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le) {
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000308 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
309 dwarf::DW_EH_PE_udata8;
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000310 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
311 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
312 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
313 dwarf::DW_EH_PE_udata8;
Ulrich Weigand0213e7f2013-05-06 16:11:12 +0000314 } else if (T.getArch() == Triple::systemz) {
315 // All currently-defined code models guarantee that 4-byte PC-relative
316 // values will be in range.
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000317 if (RelocM == Reloc::PIC_) {
318 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
319 dwarf::DW_EH_PE_sdata4;
320 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
321 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
322 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
323 dwarf::DW_EH_PE_sdata4;
324 } else {
325 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
326 LSDAEncoding = dwarf::DW_EH_PE_absptr;
327 FDEEncoding = dwarf::DW_EH_PE_absptr;
328 TTypeEncoding = dwarf::DW_EH_PE_absptr;
329 }
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000330 }
331
David Chisnall07f8d3e2012-02-17 17:31:15 +0000332 // Solaris requires different flags for .eh_frame to seemingly every other
333 // platform.
David Chisnallbbec8722012-04-10 11:44:33 +0000334 EHSectionType = ELF::SHT_PROGBITS;
David Chisnall07f8d3e2012-02-17 17:31:15 +0000335 EHSectionFlags = ELF::SHF_ALLOC;
David Chisnallbbec8722012-04-10 11:44:33 +0000336 if (T.getOS() == Triple::Solaris) {
337 if (T.getArch() == Triple::x86_64)
338 EHSectionType = ELF::SHT_X86_64_UNWIND;
339 else
340 EHSectionFlags |= ELF::SHF_WRITE;
341 }
David Chisnall07f8d3e2012-02-17 17:31:15 +0000342
343
Evan Cheng76792992011-07-20 05:58:47 +0000344 // ELF
345 BSSSection =
346 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
Anton Korobeynikov7722a2d2012-01-25 22:24:19 +0000347 ELF::SHF_WRITE | ELF::SHF_ALLOC,
Evan Cheng76792992011-07-20 05:58:47 +0000348 SectionKind::getBSS());
349
350 TextSection =
351 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
352 ELF::SHF_EXECINSTR |
353 ELF::SHF_ALLOC,
354 SectionKind::getText());
355
356 DataSection =
357 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
358 ELF::SHF_WRITE |ELF::SHF_ALLOC,
359 SectionKind::getDataRel());
360
361 ReadOnlySection =
362 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
363 ELF::SHF_ALLOC,
364 SectionKind::getReadOnly());
365
366 TLSDataSection =
367 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
368 ELF::SHF_ALLOC | ELF::SHF_TLS |
369 ELF::SHF_WRITE,
370 SectionKind::getThreadData());
371
372 TLSBSSSection =
373 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
374 ELF::SHF_ALLOC | ELF::SHF_TLS |
375 ELF::SHF_WRITE,
376 SectionKind::getThreadBSS());
377
378 DataRelSection =
379 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
380 ELF::SHF_ALLOC |ELF::SHF_WRITE,
381 SectionKind::getDataRel());
382
383 DataRelLocalSection =
384 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
385 ELF::SHF_ALLOC |ELF::SHF_WRITE,
386 SectionKind::getDataRelLocal());
387
388 DataRelROSection =
389 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
390 ELF::SHF_ALLOC |ELF::SHF_WRITE,
391 SectionKind::getReadOnlyWithRel());
392
393 DataRelROLocalSection =
394 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
395 ELF::SHF_ALLOC |ELF::SHF_WRITE,
396 SectionKind::getReadOnlyWithRelLocal());
397
398 MergeableConst4Section =
399 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
400 ELF::SHF_ALLOC |ELF::SHF_MERGE,
401 SectionKind::getMergeableConst4());
402
403 MergeableConst8Section =
404 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
405 ELF::SHF_ALLOC |ELF::SHF_MERGE,
406 SectionKind::getMergeableConst8());
407
408 MergeableConst16Section =
409 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
410 ELF::SHF_ALLOC |ELF::SHF_MERGE,
411 SectionKind::getMergeableConst16());
412
413 StaticCtorSection =
414 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
415 ELF::SHF_ALLOC |ELF::SHF_WRITE,
416 SectionKind::getDataRel());
417
418 StaticDtorSection =
419 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
420 ELF::SHF_ALLOC |ELF::SHF_WRITE,
421 SectionKind::getDataRel());
422
423 // Exception Handling Sections.
424
425 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
426 // it contains relocatable pointers. In PIC mode, this is probably a big
427 // runtime hit for C++ apps. Either the contents of the LSDA need to be
428 // adjusted or this should be a data section.
429 LSDASection =
430 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
431 ELF::SHF_ALLOC,
432 SectionKind::getReadOnly());
433
434 // Debug Info Sections.
435 DwarfAbbrevSection =
436 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
437 SectionKind::getMetadata());
438 DwarfInfoSection =
439 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
440 SectionKind::getMetadata());
441 DwarfLineSection =
442 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
443 SectionKind::getMetadata());
444 DwarfFrameSection =
445 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
446 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000447 DwarfPubNamesSection =
448 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
449 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000450 DwarfPubTypesSection =
451 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
452 SectionKind::getMetadata());
Eric Christopherb0e76942013-09-09 20:03:14 +0000453 DwarfGnuPubNamesSection =
454 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
455 SectionKind::getMetadata());
456 DwarfGnuPubTypesSection =
457 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
458 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000459 DwarfStrSection =
Nick Lewycky1a62d782011-10-26 18:44:32 +0000460 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
461 ELF::SHF_MERGE | ELF::SHF_STRINGS,
462 SectionKind::getMergeable1ByteCString());
Evan Cheng76792992011-07-20 05:58:47 +0000463 DwarfLocSection =
464 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
465 SectionKind::getMetadata());
466 DwarfARangesSection =
467 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
468 SectionKind::getMetadata());
469 DwarfRangesSection =
470 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
471 SectionKind::getMetadata());
472 DwarfMacroInfoSection =
473 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
474 SectionKind::getMetadata());
Eric Christopher27ed8ec2012-11-28 02:49:34 +0000475
476 // DWARF5 Experimental Debug Info
477
478 // Accelerator Tables
Eric Christophera0ad67d2012-10-08 21:41:30 +0000479 DwarfAccelNamesSection =
480 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
481 SectionKind::getMetadata());
482 DwarfAccelObjCSection =
483 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
484 SectionKind::getMetadata());
485 DwarfAccelNamespaceSection =
486 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
487 SectionKind::getMetadata());
488 DwarfAccelTypesSection =
489 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
490 SectionKind::getMetadata());
Eric Christopherc3b434b2012-11-28 02:49:38 +0000491
492 // Fission Sections
493 DwarfInfoDWOSection =
494 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
495 SectionKind::getMetadata());
Eric Christopher3c230092012-11-30 06:47:06 +0000496 DwarfAbbrevDWOSection =
497 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
498 SectionKind::getMetadata());
499 DwarfStrDWOSection =
500 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
501 ELF::SHF_MERGE | ELF::SHF_STRINGS,
502 SectionKind::getMergeable1ByteCString());
503 DwarfLineDWOSection =
504 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
505 SectionKind::getMetadata());
506 DwarfLocDWOSection =
507 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
508 SectionKind::getMetadata());
Eric Christopherc0fa8672013-01-04 17:59:22 +0000509 DwarfStrOffDWOSection =
510 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
511 SectionKind::getMetadata());
Eric Christopher962c9082013-01-15 23:56:56 +0000512 DwarfAddrSection =
513 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
514 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000515}
516
517
518void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
519 // COFF
David Majnemer3d96acb2013-08-13 01:23:53 +0000520 BSSSection =
521 Ctx->getCOFFSection(".bss",
522 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
523 COFF::IMAGE_SCN_MEM_READ |
524 COFF::IMAGE_SCN_MEM_WRITE,
525 SectionKind::getBSS());
Evan Cheng76792992011-07-20 05:58:47 +0000526 TextSection =
527 Ctx->getCOFFSection(".text",
528 COFF::IMAGE_SCN_CNT_CODE |
529 COFF::IMAGE_SCN_MEM_EXECUTE |
530 COFF::IMAGE_SCN_MEM_READ,
531 SectionKind::getText());
532 DataSection =
533 Ctx->getCOFFSection(".data",
534 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
535 COFF::IMAGE_SCN_MEM_READ |
536 COFF::IMAGE_SCN_MEM_WRITE,
537 SectionKind::getDataRel());
538 ReadOnlySection =
539 Ctx->getCOFFSection(".rdata",
540 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
541 COFF::IMAGE_SCN_MEM_READ,
542 SectionKind::getReadOnly());
Michael J. Spencerb560d072012-02-23 21:56:08 +0000543 if (T.getOS() == Triple::Win32) {
544 StaticCtorSection =
545 Ctx->getCOFFSection(".CRT$XCU",
546 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
547 COFF::IMAGE_SCN_MEM_READ,
548 SectionKind::getReadOnly());
549 } else {
550 StaticCtorSection =
551 Ctx->getCOFFSection(".ctors",
552 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
553 COFF::IMAGE_SCN_MEM_READ |
554 COFF::IMAGE_SCN_MEM_WRITE,
555 SectionKind::getDataRel());
556 }
557
558
Anton Korobeynikov37d73002012-09-23 15:53:47 +0000559 if (T.getOS() == Triple::Win32) {
560 StaticDtorSection =
561 Ctx->getCOFFSection(".CRT$XTX",
562 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
563 COFF::IMAGE_SCN_MEM_READ,
564 SectionKind::getReadOnly());
565 } else {
566 StaticDtorSection =
567 Ctx->getCOFFSection(".dtors",
568 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
569 COFF::IMAGE_SCN_MEM_READ |
570 COFF::IMAGE_SCN_MEM_WRITE,
571 SectionKind::getDataRel());
572 }
Evan Cheng76792992011-07-20 05:58:47 +0000573
574 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
575 // though it contains relocatable pointers. In PIC mode, this is probably a
576 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
577 // adjusted or this should be a data section.
Kai Nacke42097302013-07-08 04:43:23 +0000578 LSDASection =
579 Ctx->getCOFFSection(".gcc_except_table",
580 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
581 COFF::IMAGE_SCN_MEM_READ,
582 SectionKind::getReadOnly());
Evan Cheng76792992011-07-20 05:58:47 +0000583
584 // Debug info.
585 DwarfAbbrevSection =
586 Ctx->getCOFFSection(".debug_abbrev",
587 COFF::IMAGE_SCN_MEM_DISCARDABLE |
588 COFF::IMAGE_SCN_MEM_READ,
589 SectionKind::getMetadata());
590 DwarfInfoSection =
591 Ctx->getCOFFSection(".debug_info",
592 COFF::IMAGE_SCN_MEM_DISCARDABLE |
593 COFF::IMAGE_SCN_MEM_READ,
594 SectionKind::getMetadata());
595 DwarfLineSection =
596 Ctx->getCOFFSection(".debug_line",
597 COFF::IMAGE_SCN_MEM_DISCARDABLE |
598 COFF::IMAGE_SCN_MEM_READ,
599 SectionKind::getMetadata());
600 DwarfFrameSection =
601 Ctx->getCOFFSection(".debug_frame",
602 COFF::IMAGE_SCN_MEM_DISCARDABLE |
603 COFF::IMAGE_SCN_MEM_READ,
604 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000605 DwarfPubNamesSection =
606 Ctx->getCOFFSection(".debug_pubnames",
607 COFF::IMAGE_SCN_MEM_DISCARDABLE |
608 COFF::IMAGE_SCN_MEM_READ,
609 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000610 DwarfPubTypesSection =
611 Ctx->getCOFFSection(".debug_pubtypes",
612 COFF::IMAGE_SCN_MEM_DISCARDABLE |
613 COFF::IMAGE_SCN_MEM_READ,
614 SectionKind::getMetadata());
NAKAMURA Takumi0229e352013-09-10 06:01:56 +0000615 DwarfGnuPubNamesSection =
Eric Christopherb0e76942013-09-09 20:03:14 +0000616 Ctx->getCOFFSection(".debug_gnu_pubnames",
617 COFF::IMAGE_SCN_MEM_DISCARDABLE |
618 COFF::IMAGE_SCN_MEM_READ,
619 SectionKind::getMetadata());
NAKAMURA Takumi0229e352013-09-10 06:01:56 +0000620 DwarfGnuPubTypesSection =
Eric Christopherb0e76942013-09-09 20:03:14 +0000621 Ctx->getCOFFSection(".debug_gnu_pubtypes",
622 COFF::IMAGE_SCN_MEM_DISCARDABLE |
623 COFF::IMAGE_SCN_MEM_READ,
624 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000625 DwarfStrSection =
626 Ctx->getCOFFSection(".debug_str",
627 COFF::IMAGE_SCN_MEM_DISCARDABLE |
628 COFF::IMAGE_SCN_MEM_READ,
629 SectionKind::getMetadata());
630 DwarfLocSection =
631 Ctx->getCOFFSection(".debug_loc",
632 COFF::IMAGE_SCN_MEM_DISCARDABLE |
633 COFF::IMAGE_SCN_MEM_READ,
634 SectionKind::getMetadata());
635 DwarfARangesSection =
636 Ctx->getCOFFSection(".debug_aranges",
637 COFF::IMAGE_SCN_MEM_DISCARDABLE |
638 COFF::IMAGE_SCN_MEM_READ,
639 SectionKind::getMetadata());
640 DwarfRangesSection =
641 Ctx->getCOFFSection(".debug_ranges",
642 COFF::IMAGE_SCN_MEM_DISCARDABLE |
643 COFF::IMAGE_SCN_MEM_READ,
644 SectionKind::getMetadata());
645 DwarfMacroInfoSection =
646 Ctx->getCOFFSection(".debug_macinfo",
647 COFF::IMAGE_SCN_MEM_DISCARDABLE |
648 COFF::IMAGE_SCN_MEM_READ,
649 SectionKind::getMetadata());
650
651 DrectveSection =
652 Ctx->getCOFFSection(".drectve",
653 COFF::IMAGE_SCN_LNK_INFO,
654 SectionKind::getMetadata());
655
656 PDataSection =
657 Ctx->getCOFFSection(".pdata",
658 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikovcc8c5392012-08-08 12:46:46 +0000659 COFF::IMAGE_SCN_MEM_READ,
Evan Cheng76792992011-07-20 05:58:47 +0000660 SectionKind::getDataRel());
661
662 XDataSection =
663 Ctx->getCOFFSection(".xdata",
664 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikovcc8c5392012-08-08 12:46:46 +0000665 COFF::IMAGE_SCN_MEM_READ,
Evan Cheng76792992011-07-20 05:58:47 +0000666 SectionKind::getDataRel());
Anton Korobeynikovc6b40172012-02-11 17:26:53 +0000667 TLSDataSection =
668 Ctx->getCOFFSection(".tls$",
669 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
670 COFF::IMAGE_SCN_MEM_READ |
671 COFF::IMAGE_SCN_MEM_WRITE,
672 SectionKind::getDataRel());
Evan Cheng76792992011-07-20 05:58:47 +0000673}
674
675void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000676 CodeModel::Model cm,
Evan Cheng76792992011-07-20 05:58:47 +0000677 MCContext &ctx) {
678 RelocM = relocm;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000679 CMModel = cm;
Evan Cheng76792992011-07-20 05:58:47 +0000680 Ctx = &ctx;
681
682 // Common.
683 CommDirectiveSupportsAlignment = true;
684 SupportsWeakOmittedEHFrame = true;
685 IsFunctionEHFrameSymbolPrivate = true;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000686
687 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
688 TTypeEncoding = dwarf::DW_EH_PE_absptr;
689
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000690 CompactUnwindDwarfEHFrameOnly = 0;
691
Eric Christopher4996c702011-11-07 09:24:32 +0000692 EHFrameSection = 0; // Created on demand.
693 CompactUnwindSection = 0; // Used only by selected targets.
694 DwarfAccelNamesSection = 0; // Used only by selected targets.
695 DwarfAccelObjCSection = 0; // Used only by selected targets.
696 DwarfAccelNamespaceSection = 0; // Used only by selected targets.
697 DwarfAccelTypesSection = 0; // Used only by selected targets.
Evan Cheng76792992011-07-20 05:58:47 +0000698
699 Triple T(TT);
700 Triple::ArchType Arch = T.getArch();
701 // FIXME: Checking for Arch here to filter out bogus triples such as
702 // cellspu-apple-darwin. Perhaps we should fix in Triple?
703 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
704 Arch == Triple::arm || Arch == Triple::thumb ||
705 Arch == Triple::ppc || Arch == Triple::ppc64 ||
706 Arch == Triple::UnknownArch) &&
707 (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
708 Env = IsMachO;
709 InitMachOMCObjectFileInfo(T);
Evan Chengc3035d62011-07-20 23:53:54 +0000710 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
Andrew Kaylorfeb805f2012-10-02 18:38:34 +0000711 (T.getEnvironment() != Triple::ELF) &&
Evan Chengc3035d62011-07-20 23:53:54 +0000712 (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
713 T.getOS() == Triple::Win32)) {
Evan Cheng76792992011-07-20 05:58:47 +0000714 Env = IsCOFF;
715 InitCOFFMCObjectFileInfo(T);
716 } else {
717 Env = IsELF;
718 InitELFMCObjectFileInfo(T);
719 }
720}
721
David Blaikiebc563272013-12-13 21:33:40 +0000722const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
723 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
724 SectionKind::getMetadata(), 0, utostr(Hash));
725}
726
727const MCSection *
728MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
729 return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_GROUP, 0,
730 SectionKind::getMetadata(), 0, utostr(Hash));
731}
732
David Chisnall85dd3092012-02-17 16:51:02 +0000733void MCObjectFileInfo::InitEHFrameSection() {
734 if (Env == IsMachO)
735 EHFrameSection =
736 Ctx->getMachOSection("__TEXT", "__eh_frame",
737 MCSectionMachO::S_COALESCED |
738 MCSectionMachO::S_ATTR_NO_TOC |
739 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
740 MCSectionMachO::S_ATTR_LIVE_SUPPORT,
741 SectionKind::getReadOnly());
742 else if (Env == IsELF)
743 EHFrameSection =
David Chisnallbbec8722012-04-10 11:44:33 +0000744 Ctx->getELFSection(".eh_frame", EHSectionType,
David Chisnall07f8d3e2012-02-17 17:31:15 +0000745 EHSectionFlags,
David Chisnall85dd3092012-02-17 16:51:02 +0000746 SectionKind::getDataRel());
747 else
748 EHFrameSection =
749 Ctx->getCOFFSection(".eh_frame",
750 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
751 COFF::IMAGE_SCN_MEM_READ |
752 COFF::IMAGE_SCN_MEM_WRITE,
753 SectionKind::getDataRel());
754}