blob: a160f298e180dfbb6f5274106f8f417a372ae4f2 [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
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000153 COFFDebugSymbolsSection = 0;
154
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000155 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) {
Evan Cheng76792992011-07-20 05:58:47 +0000156 CompactUnwindSection =
157 Ctx->getMachOSection("__LD", "__compact_unwind",
158 MCSectionMachO::S_ATTR_DEBUG,
159 SectionKind::getReadOnly());
160
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000161 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
162 CompactUnwindDwarfEHFrameOnly = 0x04000000;
163 }
164
Evan Cheng76792992011-07-20 05:58:47 +0000165 // Debug Information.
Eric Christopher4996c702011-11-07 09:24:32 +0000166 DwarfAccelNamesSection =
167 Ctx->getMachOSection("__DWARF", "__apple_names",
168 MCSectionMachO::S_ATTR_DEBUG,
169 SectionKind::getMetadata());
170 DwarfAccelObjCSection =
171 Ctx->getMachOSection("__DWARF", "__apple_objc",
172 MCSectionMachO::S_ATTR_DEBUG,
173 SectionKind::getMetadata());
174 // 16 character section limit...
175 DwarfAccelNamespaceSection =
176 Ctx->getMachOSection("__DWARF", "__apple_namespac",
177 MCSectionMachO::S_ATTR_DEBUG,
178 SectionKind::getMetadata());
179 DwarfAccelTypesSection =
180 Ctx->getMachOSection("__DWARF", "__apple_types",
181 MCSectionMachO::S_ATTR_DEBUG,
182 SectionKind::getMetadata());
Jim Grosbachdc1e36e2012-05-11 01:41:30 +0000183
Evan Cheng76792992011-07-20 05:58:47 +0000184 DwarfAbbrevSection =
185 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
186 MCSectionMachO::S_ATTR_DEBUG,
187 SectionKind::getMetadata());
188 DwarfInfoSection =
189 Ctx->getMachOSection("__DWARF", "__debug_info",
190 MCSectionMachO::S_ATTR_DEBUG,
191 SectionKind::getMetadata());
192 DwarfLineSection =
193 Ctx->getMachOSection("__DWARF", "__debug_line",
194 MCSectionMachO::S_ATTR_DEBUG,
195 SectionKind::getMetadata());
196 DwarfFrameSection =
197 Ctx->getMachOSection("__DWARF", "__debug_frame",
198 MCSectionMachO::S_ATTR_DEBUG,
199 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000200 DwarfPubNamesSection =
201 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
202 MCSectionMachO::S_ATTR_DEBUG,
203 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000204 DwarfPubTypesSection =
205 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
206 MCSectionMachO::S_ATTR_DEBUG,
207 SectionKind::getMetadata());
Eric Christopherb0e76942013-09-09 20:03:14 +0000208 DwarfGnuPubNamesSection =
209 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
210 MCSectionMachO::S_ATTR_DEBUG,
211 SectionKind::getMetadata());
212 DwarfGnuPubTypesSection =
213 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
214 MCSectionMachO::S_ATTR_DEBUG,
215 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000216 DwarfStrSection =
217 Ctx->getMachOSection("__DWARF", "__debug_str",
218 MCSectionMachO::S_ATTR_DEBUG,
219 SectionKind::getMetadata());
220 DwarfLocSection =
221 Ctx->getMachOSection("__DWARF", "__debug_loc",
222 MCSectionMachO::S_ATTR_DEBUG,
223 SectionKind::getMetadata());
224 DwarfARangesSection =
225 Ctx->getMachOSection("__DWARF", "__debug_aranges",
226 MCSectionMachO::S_ATTR_DEBUG,
227 SectionKind::getMetadata());
228 DwarfRangesSection =
229 Ctx->getMachOSection("__DWARF", "__debug_ranges",
230 MCSectionMachO::S_ATTR_DEBUG,
231 SectionKind::getMetadata());
232 DwarfMacroInfoSection =
233 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
234 MCSectionMachO::S_ATTR_DEBUG,
235 SectionKind::getMetadata());
236 DwarfDebugInlineSection =
237 Ctx->getMachOSection("__DWARF", "__debug_inlined",
238 MCSectionMachO::S_ATTR_DEBUG,
239 SectionKind::getMetadata());
Lang Hames30789772013-11-08 22:14:49 +0000240 StackMapSection =
241 Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
242 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000243
244 TLSExtraDataSection = TLSTLVSection;
245}
246
247void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
Rafael Espindolab9b7ae02013-04-03 03:13:19 +0000248 if (T.getArch() == Triple::mips ||
249 T.getArch() == Triple::mipsel)
250 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
251 else if (T.getArch() == Triple::mips64 ||
252 T.getArch() == Triple::mips64el)
253 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
254 else
Rafael Espindolaef9d3492013-03-15 05:51:57 +0000255 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
256
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000257 if (T.getArch() == Triple::x86) {
258 PersonalityEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach0dde3492011-11-15 16:46:22 +0000259 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
260 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000261 LSDAEncoding = (RelocM == Reloc::PIC_)
262 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
263 : dwarf::DW_EH_PE_absptr;
Rafael Espindolaef9d3492013-03-15 05:51:57 +0000264 FDEEncoding = (RelocM == Reloc::PIC_)
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000265 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
266 : dwarf::DW_EH_PE_absptr;
267 TTypeEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach0dde3492011-11-15 16:46:22 +0000268 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
269 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000270 } else if (T.getArch() == Triple::x86_64) {
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000271 if (RelocM == Reloc::PIC_) {
272 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
273 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
274 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
275 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
276 (CMModel == CodeModel::Small
277 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
278 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
279 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
280 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
281 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
282 } else {
283 PersonalityEncoding =
284 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
285 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
286 LSDAEncoding = (CMModel == CodeModel::Small)
287 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
288 FDEEncoding = dwarf::DW_EH_PE_udata4;
289 TTypeEncoding = (CMModel == CodeModel::Small)
290 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
291 }
Tim Northovere0e3aef2013-01-31 12:12:40 +0000292 } else if (T.getArch() == Triple::aarch64) {
Tim Northovere0e3aef2013-01-31 12:12:40 +0000293 // The small model guarantees static code/data size < 4GB, but not where it
294 // will be in memory. Most of these could end up >2GB away so even a signed
295 // pc-relative 32-bit address is insufficient, theoretically.
296 if (RelocM == Reloc::PIC_) {
297 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
298 dwarf::DW_EH_PE_sdata8;
299 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
300 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
301 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
302 dwarf::DW_EH_PE_sdata8;
303 } else {
304 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
305 LSDAEncoding = dwarf::DW_EH_PE_absptr;
306 FDEEncoding = dwarf::DW_EH_PE_udata4;
307 TTypeEncoding = dwarf::DW_EH_PE_absptr;
308 }
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000309 } else if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le) {
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000310 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
311 dwarf::DW_EH_PE_udata8;
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000312 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
313 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
314 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
315 dwarf::DW_EH_PE_udata8;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000316 } else if (T.getArch() == Triple::sparc) {
317 if (RelocM == Reloc::PIC_) {
318 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
319 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
320 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 LSDAEncoding = dwarf::DW_EH_PE_absptr;
326 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
327 FDEEncoding = dwarf::DW_EH_PE_udata4;
328 TTypeEncoding = dwarf::DW_EH_PE_absptr;
329 }
330 } else if (T.getArch() == Triple::sparcv9) {
331 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
332 if (RelocM == Reloc::PIC_) {
333 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
334 dwarf::DW_EH_PE_sdata4;
335 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
336 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
337 dwarf::DW_EH_PE_sdata4;
338 } else {
339 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
340 FDEEncoding = dwarf::DW_EH_PE_udata4;
341 TTypeEncoding = dwarf::DW_EH_PE_absptr;
342 }
Ulrich Weigand0213e7f2013-05-06 16:11:12 +0000343 } else if (T.getArch() == Triple::systemz) {
344 // All currently-defined code models guarantee that 4-byte PC-relative
345 // values will be in range.
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000346 if (RelocM == Reloc::PIC_) {
347 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
348 dwarf::DW_EH_PE_sdata4;
349 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
350 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
351 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
352 dwarf::DW_EH_PE_sdata4;
353 } else {
354 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
355 LSDAEncoding = dwarf::DW_EH_PE_absptr;
356 FDEEncoding = dwarf::DW_EH_PE_absptr;
357 TTypeEncoding = dwarf::DW_EH_PE_absptr;
358 }
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000359 }
360
David Chisnall07f8d3e2012-02-17 17:31:15 +0000361 // Solaris requires different flags for .eh_frame to seemingly every other
362 // platform.
David Chisnallbbec8722012-04-10 11:44:33 +0000363 EHSectionType = ELF::SHT_PROGBITS;
David Chisnall07f8d3e2012-02-17 17:31:15 +0000364 EHSectionFlags = ELF::SHF_ALLOC;
David Chisnallbbec8722012-04-10 11:44:33 +0000365 if (T.getOS() == Triple::Solaris) {
366 if (T.getArch() == Triple::x86_64)
367 EHSectionType = ELF::SHT_X86_64_UNWIND;
368 else
369 EHSectionFlags |= ELF::SHF_WRITE;
370 }
David Chisnall07f8d3e2012-02-17 17:31:15 +0000371
372
Evan Cheng76792992011-07-20 05:58:47 +0000373 // ELF
374 BSSSection =
375 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
Anton Korobeynikov7722a2d2012-01-25 22:24:19 +0000376 ELF::SHF_WRITE | ELF::SHF_ALLOC,
Evan Cheng76792992011-07-20 05:58:47 +0000377 SectionKind::getBSS());
378
379 TextSection =
380 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
381 ELF::SHF_EXECINSTR |
382 ELF::SHF_ALLOC,
383 SectionKind::getText());
384
385 DataSection =
386 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
387 ELF::SHF_WRITE |ELF::SHF_ALLOC,
388 SectionKind::getDataRel());
389
390 ReadOnlySection =
391 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
392 ELF::SHF_ALLOC,
393 SectionKind::getReadOnly());
394
395 TLSDataSection =
396 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
397 ELF::SHF_ALLOC | ELF::SHF_TLS |
398 ELF::SHF_WRITE,
399 SectionKind::getThreadData());
400
401 TLSBSSSection =
402 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
403 ELF::SHF_ALLOC | ELF::SHF_TLS |
404 ELF::SHF_WRITE,
405 SectionKind::getThreadBSS());
406
407 DataRelSection =
408 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
409 ELF::SHF_ALLOC |ELF::SHF_WRITE,
410 SectionKind::getDataRel());
411
412 DataRelLocalSection =
413 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
414 ELF::SHF_ALLOC |ELF::SHF_WRITE,
415 SectionKind::getDataRelLocal());
416
417 DataRelROSection =
418 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
419 ELF::SHF_ALLOC |ELF::SHF_WRITE,
420 SectionKind::getReadOnlyWithRel());
421
422 DataRelROLocalSection =
423 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
424 ELF::SHF_ALLOC |ELF::SHF_WRITE,
425 SectionKind::getReadOnlyWithRelLocal());
426
427 MergeableConst4Section =
428 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
429 ELF::SHF_ALLOC |ELF::SHF_MERGE,
430 SectionKind::getMergeableConst4());
431
432 MergeableConst8Section =
433 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
434 ELF::SHF_ALLOC |ELF::SHF_MERGE,
435 SectionKind::getMergeableConst8());
436
437 MergeableConst16Section =
438 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
439 ELF::SHF_ALLOC |ELF::SHF_MERGE,
440 SectionKind::getMergeableConst16());
441
442 StaticCtorSection =
443 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
444 ELF::SHF_ALLOC |ELF::SHF_WRITE,
445 SectionKind::getDataRel());
446
447 StaticDtorSection =
448 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
449 ELF::SHF_ALLOC |ELF::SHF_WRITE,
450 SectionKind::getDataRel());
451
452 // Exception Handling Sections.
453
454 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
455 // it contains relocatable pointers. In PIC mode, this is probably a big
456 // runtime hit for C++ apps. Either the contents of the LSDA need to be
457 // adjusted or this should be a data section.
458 LSDASection =
459 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
460 ELF::SHF_ALLOC,
461 SectionKind::getReadOnly());
462
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000463 COFFDebugSymbolsSection = 0;
464
Evan Cheng76792992011-07-20 05:58:47 +0000465 // Debug Info Sections.
466 DwarfAbbrevSection =
467 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
468 SectionKind::getMetadata());
469 DwarfInfoSection =
470 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
471 SectionKind::getMetadata());
472 DwarfLineSection =
473 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
474 SectionKind::getMetadata());
475 DwarfFrameSection =
476 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
477 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000478 DwarfPubNamesSection =
479 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
480 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000481 DwarfPubTypesSection =
482 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
483 SectionKind::getMetadata());
Eric Christopherb0e76942013-09-09 20:03:14 +0000484 DwarfGnuPubNamesSection =
485 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
486 SectionKind::getMetadata());
487 DwarfGnuPubTypesSection =
488 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
489 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000490 DwarfStrSection =
Nick Lewycky1a62d782011-10-26 18:44:32 +0000491 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
492 ELF::SHF_MERGE | ELF::SHF_STRINGS,
493 SectionKind::getMergeable1ByteCString());
Evan Cheng76792992011-07-20 05:58:47 +0000494 DwarfLocSection =
495 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
496 SectionKind::getMetadata());
497 DwarfARangesSection =
498 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
499 SectionKind::getMetadata());
500 DwarfRangesSection =
501 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
502 SectionKind::getMetadata());
503 DwarfMacroInfoSection =
504 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
505 SectionKind::getMetadata());
Eric Christopher27ed8ec2012-11-28 02:49:34 +0000506
507 // DWARF5 Experimental Debug Info
508
509 // Accelerator Tables
Eric Christophera0ad67d2012-10-08 21:41:30 +0000510 DwarfAccelNamesSection =
511 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
512 SectionKind::getMetadata());
513 DwarfAccelObjCSection =
514 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
515 SectionKind::getMetadata());
516 DwarfAccelNamespaceSection =
517 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
518 SectionKind::getMetadata());
519 DwarfAccelTypesSection =
520 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
521 SectionKind::getMetadata());
Eric Christopherc3b434b2012-11-28 02:49:38 +0000522
523 // Fission Sections
524 DwarfInfoDWOSection =
525 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
526 SectionKind::getMetadata());
Eric Christopher3c230092012-11-30 06:47:06 +0000527 DwarfAbbrevDWOSection =
528 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
529 SectionKind::getMetadata());
530 DwarfStrDWOSection =
531 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
532 ELF::SHF_MERGE | ELF::SHF_STRINGS,
533 SectionKind::getMergeable1ByteCString());
534 DwarfLineDWOSection =
535 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
536 SectionKind::getMetadata());
537 DwarfLocDWOSection =
538 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
539 SectionKind::getMetadata());
Eric Christopherc0fa8672013-01-04 17:59:22 +0000540 DwarfStrOffDWOSection =
541 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
542 SectionKind::getMetadata());
Eric Christopher962c9082013-01-15 23:56:56 +0000543 DwarfAddrSection =
544 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
545 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000546}
547
548
549void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
550 // COFF
David Majnemer3d96acb2013-08-13 01:23:53 +0000551 BSSSection =
552 Ctx->getCOFFSection(".bss",
553 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
554 COFF::IMAGE_SCN_MEM_READ |
555 COFF::IMAGE_SCN_MEM_WRITE,
556 SectionKind::getBSS());
Evan Cheng76792992011-07-20 05:58:47 +0000557 TextSection =
558 Ctx->getCOFFSection(".text",
559 COFF::IMAGE_SCN_CNT_CODE |
560 COFF::IMAGE_SCN_MEM_EXECUTE |
561 COFF::IMAGE_SCN_MEM_READ,
562 SectionKind::getText());
563 DataSection =
564 Ctx->getCOFFSection(".data",
565 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
566 COFF::IMAGE_SCN_MEM_READ |
567 COFF::IMAGE_SCN_MEM_WRITE,
568 SectionKind::getDataRel());
569 ReadOnlySection =
570 Ctx->getCOFFSection(".rdata",
571 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
572 COFF::IMAGE_SCN_MEM_READ,
573 SectionKind::getReadOnly());
Michael J. Spencerb560d072012-02-23 21:56:08 +0000574 if (T.getOS() == Triple::Win32) {
575 StaticCtorSection =
576 Ctx->getCOFFSection(".CRT$XCU",
577 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
578 COFF::IMAGE_SCN_MEM_READ,
579 SectionKind::getReadOnly());
580 } else {
581 StaticCtorSection =
582 Ctx->getCOFFSection(".ctors",
583 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
584 COFF::IMAGE_SCN_MEM_READ |
585 COFF::IMAGE_SCN_MEM_WRITE,
586 SectionKind::getDataRel());
587 }
588
589
Anton Korobeynikov37d73002012-09-23 15:53:47 +0000590 if (T.getOS() == Triple::Win32) {
591 StaticDtorSection =
592 Ctx->getCOFFSection(".CRT$XTX",
593 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
594 COFF::IMAGE_SCN_MEM_READ,
595 SectionKind::getReadOnly());
596 } else {
597 StaticDtorSection =
598 Ctx->getCOFFSection(".dtors",
599 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
600 COFF::IMAGE_SCN_MEM_READ |
601 COFF::IMAGE_SCN_MEM_WRITE,
602 SectionKind::getDataRel());
603 }
Evan Cheng76792992011-07-20 05:58:47 +0000604
605 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
606 // though it contains relocatable pointers. In PIC mode, this is probably a
607 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
608 // adjusted or this should be a data section.
Kai Nacke42097302013-07-08 04:43:23 +0000609 LSDASection =
610 Ctx->getCOFFSection(".gcc_except_table",
611 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
612 COFF::IMAGE_SCN_MEM_READ,
613 SectionKind::getReadOnly());
Evan Cheng76792992011-07-20 05:58:47 +0000614
615 // Debug info.
Timur Iskhodzhanov31377c52014-01-28 03:48:44 +0000616 COFFDebugSymbolsSection =
617 Ctx->getCOFFSection(".debug$S",
618 COFF::IMAGE_SCN_MEM_DISCARDABLE |
619 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
620 COFF::IMAGE_SCN_MEM_READ,
621 SectionKind::getMetadata());
622
Evan Cheng76792992011-07-20 05:58:47 +0000623 DwarfAbbrevSection =
624 Ctx->getCOFFSection(".debug_abbrev",
625 COFF::IMAGE_SCN_MEM_DISCARDABLE |
626 COFF::IMAGE_SCN_MEM_READ,
627 SectionKind::getMetadata());
628 DwarfInfoSection =
629 Ctx->getCOFFSection(".debug_info",
630 COFF::IMAGE_SCN_MEM_DISCARDABLE |
631 COFF::IMAGE_SCN_MEM_READ,
632 SectionKind::getMetadata());
633 DwarfLineSection =
634 Ctx->getCOFFSection(".debug_line",
635 COFF::IMAGE_SCN_MEM_DISCARDABLE |
636 COFF::IMAGE_SCN_MEM_READ,
637 SectionKind::getMetadata());
638 DwarfFrameSection =
639 Ctx->getCOFFSection(".debug_frame",
640 COFF::IMAGE_SCN_MEM_DISCARDABLE |
641 COFF::IMAGE_SCN_MEM_READ,
642 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000643 DwarfPubNamesSection =
644 Ctx->getCOFFSection(".debug_pubnames",
645 COFF::IMAGE_SCN_MEM_DISCARDABLE |
646 COFF::IMAGE_SCN_MEM_READ,
647 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000648 DwarfPubTypesSection =
649 Ctx->getCOFFSection(".debug_pubtypes",
650 COFF::IMAGE_SCN_MEM_DISCARDABLE |
651 COFF::IMAGE_SCN_MEM_READ,
652 SectionKind::getMetadata());
NAKAMURA Takumi0229e352013-09-10 06:01:56 +0000653 DwarfGnuPubNamesSection =
Eric Christopherb0e76942013-09-09 20:03:14 +0000654 Ctx->getCOFFSection(".debug_gnu_pubnames",
655 COFF::IMAGE_SCN_MEM_DISCARDABLE |
656 COFF::IMAGE_SCN_MEM_READ,
657 SectionKind::getMetadata());
NAKAMURA Takumi0229e352013-09-10 06:01:56 +0000658 DwarfGnuPubTypesSection =
Eric Christopherb0e76942013-09-09 20:03:14 +0000659 Ctx->getCOFFSection(".debug_gnu_pubtypes",
660 COFF::IMAGE_SCN_MEM_DISCARDABLE |
661 COFF::IMAGE_SCN_MEM_READ,
662 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000663 DwarfStrSection =
664 Ctx->getCOFFSection(".debug_str",
665 COFF::IMAGE_SCN_MEM_DISCARDABLE |
666 COFF::IMAGE_SCN_MEM_READ,
667 SectionKind::getMetadata());
668 DwarfLocSection =
669 Ctx->getCOFFSection(".debug_loc",
670 COFF::IMAGE_SCN_MEM_DISCARDABLE |
671 COFF::IMAGE_SCN_MEM_READ,
672 SectionKind::getMetadata());
673 DwarfARangesSection =
674 Ctx->getCOFFSection(".debug_aranges",
675 COFF::IMAGE_SCN_MEM_DISCARDABLE |
676 COFF::IMAGE_SCN_MEM_READ,
677 SectionKind::getMetadata());
678 DwarfRangesSection =
679 Ctx->getCOFFSection(".debug_ranges",
680 COFF::IMAGE_SCN_MEM_DISCARDABLE |
681 COFF::IMAGE_SCN_MEM_READ,
682 SectionKind::getMetadata());
683 DwarfMacroInfoSection =
684 Ctx->getCOFFSection(".debug_macinfo",
685 COFF::IMAGE_SCN_MEM_DISCARDABLE |
686 COFF::IMAGE_SCN_MEM_READ,
687 SectionKind::getMetadata());
688
689 DrectveSection =
690 Ctx->getCOFFSection(".drectve",
691 COFF::IMAGE_SCN_LNK_INFO,
692 SectionKind::getMetadata());
693
694 PDataSection =
695 Ctx->getCOFFSection(".pdata",
696 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikovcc8c5392012-08-08 12:46:46 +0000697 COFF::IMAGE_SCN_MEM_READ,
Evan Cheng76792992011-07-20 05:58:47 +0000698 SectionKind::getDataRel());
699
700 XDataSection =
701 Ctx->getCOFFSection(".xdata",
702 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikovcc8c5392012-08-08 12:46:46 +0000703 COFF::IMAGE_SCN_MEM_READ,
Evan Cheng76792992011-07-20 05:58:47 +0000704 SectionKind::getDataRel());
Anton Korobeynikovc6b40172012-02-11 17:26:53 +0000705 TLSDataSection =
706 Ctx->getCOFFSection(".tls$",
707 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
708 COFF::IMAGE_SCN_MEM_READ |
709 COFF::IMAGE_SCN_MEM_WRITE,
710 SectionKind::getDataRel());
Evan Cheng76792992011-07-20 05:58:47 +0000711}
712
713void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000714 CodeModel::Model cm,
Evan Cheng76792992011-07-20 05:58:47 +0000715 MCContext &ctx) {
716 RelocM = relocm;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000717 CMModel = cm;
Evan Cheng76792992011-07-20 05:58:47 +0000718 Ctx = &ctx;
719
720 // Common.
721 CommDirectiveSupportsAlignment = true;
722 SupportsWeakOmittedEHFrame = true;
723 IsFunctionEHFrameSymbolPrivate = true;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000724
725 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
726 TTypeEncoding = dwarf::DW_EH_PE_absptr;
727
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000728 CompactUnwindDwarfEHFrameOnly = 0;
729
Eric Christopher4996c702011-11-07 09:24:32 +0000730 EHFrameSection = 0; // Created on demand.
731 CompactUnwindSection = 0; // Used only by selected targets.
732 DwarfAccelNamesSection = 0; // Used only by selected targets.
733 DwarfAccelObjCSection = 0; // Used only by selected targets.
734 DwarfAccelNamespaceSection = 0; // Used only by selected targets.
735 DwarfAccelTypesSection = 0; // Used only by selected targets.
Evan Cheng76792992011-07-20 05:58:47 +0000736
737 Triple T(TT);
738 Triple::ArchType Arch = T.getArch();
739 // FIXME: Checking for Arch here to filter out bogus triples such as
740 // cellspu-apple-darwin. Perhaps we should fix in Triple?
741 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
742 Arch == Triple::arm || Arch == Triple::thumb ||
743 Arch == Triple::ppc || Arch == Triple::ppc64 ||
744 Arch == Triple::UnknownArch) &&
745 (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
746 Env = IsMachO;
747 InitMachOMCObjectFileInfo(T);
Evan Chengc3035d62011-07-20 23:53:54 +0000748 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
Andrew Kaylorfeb805f2012-10-02 18:38:34 +0000749 (T.getEnvironment() != Triple::ELF) &&
Evan Chengc3035d62011-07-20 23:53:54 +0000750 (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
751 T.getOS() == Triple::Win32)) {
Evan Cheng76792992011-07-20 05:58:47 +0000752 Env = IsCOFF;
753 InitCOFFMCObjectFileInfo(T);
754 } else {
755 Env = IsELF;
756 InitELFMCObjectFileInfo(T);
757 }
758}
759
David Blaikiebc563272013-12-13 21:33:40 +0000760const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
761 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
762 SectionKind::getMetadata(), 0, utostr(Hash));
763}
764
765const MCSection *
766MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
David Blaikie15ed5eb2014-01-10 01:38:41 +0000767 return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS,
768 ELF::SHF_GROUP, SectionKind::getMetadata(), 0,
769 utostr(Hash));
David Blaikiebc563272013-12-13 21:33:40 +0000770}
771
David Chisnall85dd3092012-02-17 16:51:02 +0000772void MCObjectFileInfo::InitEHFrameSection() {
773 if (Env == IsMachO)
774 EHFrameSection =
775 Ctx->getMachOSection("__TEXT", "__eh_frame",
776 MCSectionMachO::S_COALESCED |
777 MCSectionMachO::S_ATTR_NO_TOC |
778 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
779 MCSectionMachO::S_ATTR_LIVE_SUPPORT,
780 SectionKind::getReadOnly());
781 else if (Env == IsELF)
782 EHFrameSection =
David Chisnallbbec8722012-04-10 11:44:33 +0000783 Ctx->getELFSection(".eh_frame", EHSectionType,
David Chisnall07f8d3e2012-02-17 17:31:15 +0000784 EHSectionFlags,
David Chisnall85dd3092012-02-17 16:51:02 +0000785 SectionKind::getDataRel());
786 else
787 EHFrameSection =
788 Ctx->getCOFFSection(".eh_frame",
789 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
790 COFF::IMAGE_SCN_MEM_READ |
791 COFF::IMAGE_SCN_MEM_WRITE,
792 SectionKind::getDataRel());
793}