blob: 702ec6e421d0ac6990460fdc41fa6f823f843235 [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;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000314 } else if (T.getArch() == Triple::sparc) {
315 if (RelocM == Reloc::PIC_) {
316 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
317 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
318 dwarf::DW_EH_PE_sdata4;
319 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
320 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
321 dwarf::DW_EH_PE_sdata4;
322 } else {
323 LSDAEncoding = dwarf::DW_EH_PE_absptr;
324 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
325 FDEEncoding = dwarf::DW_EH_PE_udata4;
326 TTypeEncoding = dwarf::DW_EH_PE_absptr;
327 }
328 } else if (T.getArch() == Triple::sparcv9) {
329 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
330 if (RelocM == Reloc::PIC_) {
331 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
332 dwarf::DW_EH_PE_sdata4;
333 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
334 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
335 dwarf::DW_EH_PE_sdata4;
336 } else {
337 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
338 FDEEncoding = dwarf::DW_EH_PE_udata4;
339 TTypeEncoding = dwarf::DW_EH_PE_absptr;
340 }
Ulrich Weigand0213e7f2013-05-06 16:11:12 +0000341 } else if (T.getArch() == Triple::systemz) {
342 // All currently-defined code models guarantee that 4-byte PC-relative
343 // values will be in range.
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000344 if (RelocM == Reloc::PIC_) {
345 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
346 dwarf::DW_EH_PE_sdata4;
347 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
348 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
349 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
350 dwarf::DW_EH_PE_sdata4;
351 } else {
352 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
353 LSDAEncoding = dwarf::DW_EH_PE_absptr;
354 FDEEncoding = dwarf::DW_EH_PE_absptr;
355 TTypeEncoding = dwarf::DW_EH_PE_absptr;
356 }
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000357 }
358
David Chisnall07f8d3e2012-02-17 17:31:15 +0000359 // Solaris requires different flags for .eh_frame to seemingly every other
360 // platform.
David Chisnallbbec8722012-04-10 11:44:33 +0000361 EHSectionType = ELF::SHT_PROGBITS;
David Chisnall07f8d3e2012-02-17 17:31:15 +0000362 EHSectionFlags = ELF::SHF_ALLOC;
David Chisnallbbec8722012-04-10 11:44:33 +0000363 if (T.getOS() == Triple::Solaris) {
364 if (T.getArch() == Triple::x86_64)
365 EHSectionType = ELF::SHT_X86_64_UNWIND;
366 else
367 EHSectionFlags |= ELF::SHF_WRITE;
368 }
David Chisnall07f8d3e2012-02-17 17:31:15 +0000369
370
Evan Cheng76792992011-07-20 05:58:47 +0000371 // ELF
372 BSSSection =
373 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
Anton Korobeynikov7722a2d2012-01-25 22:24:19 +0000374 ELF::SHF_WRITE | ELF::SHF_ALLOC,
Evan Cheng76792992011-07-20 05:58:47 +0000375 SectionKind::getBSS());
376
377 TextSection =
378 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
379 ELF::SHF_EXECINSTR |
380 ELF::SHF_ALLOC,
381 SectionKind::getText());
382
383 DataSection =
384 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
385 ELF::SHF_WRITE |ELF::SHF_ALLOC,
386 SectionKind::getDataRel());
387
388 ReadOnlySection =
389 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
390 ELF::SHF_ALLOC,
391 SectionKind::getReadOnly());
392
393 TLSDataSection =
394 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
395 ELF::SHF_ALLOC | ELF::SHF_TLS |
396 ELF::SHF_WRITE,
397 SectionKind::getThreadData());
398
399 TLSBSSSection =
400 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
401 ELF::SHF_ALLOC | ELF::SHF_TLS |
402 ELF::SHF_WRITE,
403 SectionKind::getThreadBSS());
404
405 DataRelSection =
406 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
407 ELF::SHF_ALLOC |ELF::SHF_WRITE,
408 SectionKind::getDataRel());
409
410 DataRelLocalSection =
411 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
412 ELF::SHF_ALLOC |ELF::SHF_WRITE,
413 SectionKind::getDataRelLocal());
414
415 DataRelROSection =
416 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
417 ELF::SHF_ALLOC |ELF::SHF_WRITE,
418 SectionKind::getReadOnlyWithRel());
419
420 DataRelROLocalSection =
421 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
422 ELF::SHF_ALLOC |ELF::SHF_WRITE,
423 SectionKind::getReadOnlyWithRelLocal());
424
425 MergeableConst4Section =
426 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
427 ELF::SHF_ALLOC |ELF::SHF_MERGE,
428 SectionKind::getMergeableConst4());
429
430 MergeableConst8Section =
431 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
432 ELF::SHF_ALLOC |ELF::SHF_MERGE,
433 SectionKind::getMergeableConst8());
434
435 MergeableConst16Section =
436 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
437 ELF::SHF_ALLOC |ELF::SHF_MERGE,
438 SectionKind::getMergeableConst16());
439
440 StaticCtorSection =
441 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
442 ELF::SHF_ALLOC |ELF::SHF_WRITE,
443 SectionKind::getDataRel());
444
445 StaticDtorSection =
446 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
447 ELF::SHF_ALLOC |ELF::SHF_WRITE,
448 SectionKind::getDataRel());
449
450 // Exception Handling Sections.
451
452 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
453 // it contains relocatable pointers. In PIC mode, this is probably a big
454 // runtime hit for C++ apps. Either the contents of the LSDA need to be
455 // adjusted or this should be a data section.
456 LSDASection =
457 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
458 ELF::SHF_ALLOC,
459 SectionKind::getReadOnly());
460
461 // Debug Info Sections.
462 DwarfAbbrevSection =
463 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
464 SectionKind::getMetadata());
465 DwarfInfoSection =
466 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
467 SectionKind::getMetadata());
468 DwarfLineSection =
469 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
470 SectionKind::getMetadata());
471 DwarfFrameSection =
472 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
473 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000474 DwarfPubNamesSection =
475 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
476 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000477 DwarfPubTypesSection =
478 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
479 SectionKind::getMetadata());
Eric Christopherb0e76942013-09-09 20:03:14 +0000480 DwarfGnuPubNamesSection =
481 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
482 SectionKind::getMetadata());
483 DwarfGnuPubTypesSection =
484 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
485 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000486 DwarfStrSection =
Nick Lewycky1a62d782011-10-26 18:44:32 +0000487 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
488 ELF::SHF_MERGE | ELF::SHF_STRINGS,
489 SectionKind::getMergeable1ByteCString());
Evan Cheng76792992011-07-20 05:58:47 +0000490 DwarfLocSection =
491 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
492 SectionKind::getMetadata());
493 DwarfARangesSection =
494 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
495 SectionKind::getMetadata());
496 DwarfRangesSection =
497 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
498 SectionKind::getMetadata());
499 DwarfMacroInfoSection =
500 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
501 SectionKind::getMetadata());
Eric Christopher27ed8ec2012-11-28 02:49:34 +0000502
503 // DWARF5 Experimental Debug Info
504
505 // Accelerator Tables
Eric Christophera0ad67d2012-10-08 21:41:30 +0000506 DwarfAccelNamesSection =
507 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
508 SectionKind::getMetadata());
509 DwarfAccelObjCSection =
510 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
511 SectionKind::getMetadata());
512 DwarfAccelNamespaceSection =
513 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
514 SectionKind::getMetadata());
515 DwarfAccelTypesSection =
516 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
517 SectionKind::getMetadata());
Eric Christopherc3b434b2012-11-28 02:49:38 +0000518
519 // Fission Sections
520 DwarfInfoDWOSection =
521 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
522 SectionKind::getMetadata());
Eric Christopher3c230092012-11-30 06:47:06 +0000523 DwarfAbbrevDWOSection =
524 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
525 SectionKind::getMetadata());
526 DwarfStrDWOSection =
527 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
528 ELF::SHF_MERGE | ELF::SHF_STRINGS,
529 SectionKind::getMergeable1ByteCString());
530 DwarfLineDWOSection =
531 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
532 SectionKind::getMetadata());
533 DwarfLocDWOSection =
534 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
535 SectionKind::getMetadata());
Eric Christopherc0fa8672013-01-04 17:59:22 +0000536 DwarfStrOffDWOSection =
537 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
538 SectionKind::getMetadata());
Eric Christopher962c9082013-01-15 23:56:56 +0000539 DwarfAddrSection =
540 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
541 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000542}
543
544
545void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
546 // COFF
David Majnemer3d96acb2013-08-13 01:23:53 +0000547 BSSSection =
548 Ctx->getCOFFSection(".bss",
549 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
550 COFF::IMAGE_SCN_MEM_READ |
551 COFF::IMAGE_SCN_MEM_WRITE,
552 SectionKind::getBSS());
Evan Cheng76792992011-07-20 05:58:47 +0000553 TextSection =
554 Ctx->getCOFFSection(".text",
555 COFF::IMAGE_SCN_CNT_CODE |
556 COFF::IMAGE_SCN_MEM_EXECUTE |
557 COFF::IMAGE_SCN_MEM_READ,
558 SectionKind::getText());
559 DataSection =
560 Ctx->getCOFFSection(".data",
561 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
562 COFF::IMAGE_SCN_MEM_READ |
563 COFF::IMAGE_SCN_MEM_WRITE,
564 SectionKind::getDataRel());
565 ReadOnlySection =
566 Ctx->getCOFFSection(".rdata",
567 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
568 COFF::IMAGE_SCN_MEM_READ,
569 SectionKind::getReadOnly());
Michael J. Spencerb560d072012-02-23 21:56:08 +0000570 if (T.getOS() == Triple::Win32) {
571 StaticCtorSection =
572 Ctx->getCOFFSection(".CRT$XCU",
573 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
574 COFF::IMAGE_SCN_MEM_READ,
575 SectionKind::getReadOnly());
576 } else {
577 StaticCtorSection =
578 Ctx->getCOFFSection(".ctors",
579 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
580 COFF::IMAGE_SCN_MEM_READ |
581 COFF::IMAGE_SCN_MEM_WRITE,
582 SectionKind::getDataRel());
583 }
584
585
Anton Korobeynikov37d73002012-09-23 15:53:47 +0000586 if (T.getOS() == Triple::Win32) {
587 StaticDtorSection =
588 Ctx->getCOFFSection(".CRT$XTX",
589 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
590 COFF::IMAGE_SCN_MEM_READ,
591 SectionKind::getReadOnly());
592 } else {
593 StaticDtorSection =
594 Ctx->getCOFFSection(".dtors",
595 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
596 COFF::IMAGE_SCN_MEM_READ |
597 COFF::IMAGE_SCN_MEM_WRITE,
598 SectionKind::getDataRel());
599 }
Evan Cheng76792992011-07-20 05:58:47 +0000600
601 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
602 // though it contains relocatable pointers. In PIC mode, this is probably a
603 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
604 // adjusted or this should be a data section.
Kai Nacke42097302013-07-08 04:43:23 +0000605 LSDASection =
606 Ctx->getCOFFSection(".gcc_except_table",
607 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
608 COFF::IMAGE_SCN_MEM_READ,
609 SectionKind::getReadOnly());
Evan Cheng76792992011-07-20 05:58:47 +0000610
611 // Debug info.
612 DwarfAbbrevSection =
613 Ctx->getCOFFSection(".debug_abbrev",
614 COFF::IMAGE_SCN_MEM_DISCARDABLE |
615 COFF::IMAGE_SCN_MEM_READ,
616 SectionKind::getMetadata());
617 DwarfInfoSection =
618 Ctx->getCOFFSection(".debug_info",
619 COFF::IMAGE_SCN_MEM_DISCARDABLE |
620 COFF::IMAGE_SCN_MEM_READ,
621 SectionKind::getMetadata());
622 DwarfLineSection =
623 Ctx->getCOFFSection(".debug_line",
624 COFF::IMAGE_SCN_MEM_DISCARDABLE |
625 COFF::IMAGE_SCN_MEM_READ,
626 SectionKind::getMetadata());
627 DwarfFrameSection =
628 Ctx->getCOFFSection(".debug_frame",
629 COFF::IMAGE_SCN_MEM_DISCARDABLE |
630 COFF::IMAGE_SCN_MEM_READ,
631 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000632 DwarfPubNamesSection =
633 Ctx->getCOFFSection(".debug_pubnames",
634 COFF::IMAGE_SCN_MEM_DISCARDABLE |
635 COFF::IMAGE_SCN_MEM_READ,
636 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000637 DwarfPubTypesSection =
638 Ctx->getCOFFSection(".debug_pubtypes",
639 COFF::IMAGE_SCN_MEM_DISCARDABLE |
640 COFF::IMAGE_SCN_MEM_READ,
641 SectionKind::getMetadata());
NAKAMURA Takumi0229e352013-09-10 06:01:56 +0000642 DwarfGnuPubNamesSection =
Eric Christopherb0e76942013-09-09 20:03:14 +0000643 Ctx->getCOFFSection(".debug_gnu_pubnames",
644 COFF::IMAGE_SCN_MEM_DISCARDABLE |
645 COFF::IMAGE_SCN_MEM_READ,
646 SectionKind::getMetadata());
NAKAMURA Takumi0229e352013-09-10 06:01:56 +0000647 DwarfGnuPubTypesSection =
Eric Christopherb0e76942013-09-09 20:03:14 +0000648 Ctx->getCOFFSection(".debug_gnu_pubtypes",
649 COFF::IMAGE_SCN_MEM_DISCARDABLE |
650 COFF::IMAGE_SCN_MEM_READ,
651 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000652 DwarfStrSection =
653 Ctx->getCOFFSection(".debug_str",
654 COFF::IMAGE_SCN_MEM_DISCARDABLE |
655 COFF::IMAGE_SCN_MEM_READ,
656 SectionKind::getMetadata());
657 DwarfLocSection =
658 Ctx->getCOFFSection(".debug_loc",
659 COFF::IMAGE_SCN_MEM_DISCARDABLE |
660 COFF::IMAGE_SCN_MEM_READ,
661 SectionKind::getMetadata());
662 DwarfARangesSection =
663 Ctx->getCOFFSection(".debug_aranges",
664 COFF::IMAGE_SCN_MEM_DISCARDABLE |
665 COFF::IMAGE_SCN_MEM_READ,
666 SectionKind::getMetadata());
667 DwarfRangesSection =
668 Ctx->getCOFFSection(".debug_ranges",
669 COFF::IMAGE_SCN_MEM_DISCARDABLE |
670 COFF::IMAGE_SCN_MEM_READ,
671 SectionKind::getMetadata());
672 DwarfMacroInfoSection =
673 Ctx->getCOFFSection(".debug_macinfo",
674 COFF::IMAGE_SCN_MEM_DISCARDABLE |
675 COFF::IMAGE_SCN_MEM_READ,
676 SectionKind::getMetadata());
677
678 DrectveSection =
679 Ctx->getCOFFSection(".drectve",
680 COFF::IMAGE_SCN_LNK_INFO,
681 SectionKind::getMetadata());
682
683 PDataSection =
684 Ctx->getCOFFSection(".pdata",
685 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikovcc8c5392012-08-08 12:46:46 +0000686 COFF::IMAGE_SCN_MEM_READ,
Evan Cheng76792992011-07-20 05:58:47 +0000687 SectionKind::getDataRel());
688
689 XDataSection =
690 Ctx->getCOFFSection(".xdata",
691 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikovcc8c5392012-08-08 12:46:46 +0000692 COFF::IMAGE_SCN_MEM_READ,
Evan Cheng76792992011-07-20 05:58:47 +0000693 SectionKind::getDataRel());
Anton Korobeynikovc6b40172012-02-11 17:26:53 +0000694 TLSDataSection =
695 Ctx->getCOFFSection(".tls$",
696 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
697 COFF::IMAGE_SCN_MEM_READ |
698 COFF::IMAGE_SCN_MEM_WRITE,
699 SectionKind::getDataRel());
Evan Cheng76792992011-07-20 05:58:47 +0000700}
701
702void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000703 CodeModel::Model cm,
Evan Cheng76792992011-07-20 05:58:47 +0000704 MCContext &ctx) {
705 RelocM = relocm;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000706 CMModel = cm;
Evan Cheng76792992011-07-20 05:58:47 +0000707 Ctx = &ctx;
708
709 // Common.
710 CommDirectiveSupportsAlignment = true;
711 SupportsWeakOmittedEHFrame = true;
712 IsFunctionEHFrameSymbolPrivate = true;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000713
714 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
715 TTypeEncoding = dwarf::DW_EH_PE_absptr;
716
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000717 CompactUnwindDwarfEHFrameOnly = 0;
718
Eric Christopher4996c702011-11-07 09:24:32 +0000719 EHFrameSection = 0; // Created on demand.
720 CompactUnwindSection = 0; // Used only by selected targets.
721 DwarfAccelNamesSection = 0; // Used only by selected targets.
722 DwarfAccelObjCSection = 0; // Used only by selected targets.
723 DwarfAccelNamespaceSection = 0; // Used only by selected targets.
724 DwarfAccelTypesSection = 0; // Used only by selected targets.
Evan Cheng76792992011-07-20 05:58:47 +0000725
726 Triple T(TT);
727 Triple::ArchType Arch = T.getArch();
728 // FIXME: Checking for Arch here to filter out bogus triples such as
729 // cellspu-apple-darwin. Perhaps we should fix in Triple?
730 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
731 Arch == Triple::arm || Arch == Triple::thumb ||
732 Arch == Triple::ppc || Arch == Triple::ppc64 ||
733 Arch == Triple::UnknownArch) &&
734 (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
735 Env = IsMachO;
736 InitMachOMCObjectFileInfo(T);
Evan Chengc3035d62011-07-20 23:53:54 +0000737 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
Andrew Kaylorfeb805f2012-10-02 18:38:34 +0000738 (T.getEnvironment() != Triple::ELF) &&
Evan Chengc3035d62011-07-20 23:53:54 +0000739 (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
740 T.getOS() == Triple::Win32)) {
Evan Cheng76792992011-07-20 05:58:47 +0000741 Env = IsCOFF;
742 InitCOFFMCObjectFileInfo(T);
743 } else {
744 Env = IsELF;
745 InitELFMCObjectFileInfo(T);
746 }
747}
748
David Blaikiebc563272013-12-13 21:33:40 +0000749const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
750 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
751 SectionKind::getMetadata(), 0, utostr(Hash));
752}
753
754const MCSection *
755MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
David Blaikie15ed5eb2014-01-10 01:38:41 +0000756 return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS,
757 ELF::SHF_GROUP, SectionKind::getMetadata(), 0,
758 utostr(Hash));
David Blaikiebc563272013-12-13 21:33:40 +0000759}
760
David Chisnall85dd3092012-02-17 16:51:02 +0000761void MCObjectFileInfo::InitEHFrameSection() {
762 if (Env == IsMachO)
763 EHFrameSection =
764 Ctx->getMachOSection("__TEXT", "__eh_frame",
765 MCSectionMachO::S_COALESCED |
766 MCSectionMachO::S_ATTR_NO_TOC |
767 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
768 MCSectionMachO::S_ATTR_LIVE_SUPPORT,
769 SectionKind::getReadOnly());
770 else if (Env == IsELF)
771 EHFrameSection =
David Chisnallbbec8722012-04-10 11:44:33 +0000772 Ctx->getELFSection(".eh_frame", EHSectionType,
David Chisnall07f8d3e2012-02-17 17:31:15 +0000773 EHSectionFlags,
David Chisnall85dd3092012-02-17 16:51:02 +0000774 SectionKind::getDataRel());
775 else
776 EHFrameSection =
777 Ctx->getCOFFSection(".eh_frame",
778 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
779 COFF::IMAGE_SCN_MEM_READ |
780 COFF::IMAGE_SCN_MEM_WRITE,
781 SectionKind::getDataRel());
782}