blob: 8281db913ef5cec7c0919344e88c3d9f7d08ba8a [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
Tim Northover00ed9962014-03-29 10:18:08 +000025 if (T.isOSDarwin() && T.getArch() == Triple::arm64)
26 SupportsCompactUnwindWithoutEHFrame = true;
27
Evan Chengbbf3b0d2011-07-20 19:50:42 +000028 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
29 | dwarf::DW_EH_PE_sdata4;
30 LSDAEncoding = FDEEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
31 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
32 dwarf::DW_EH_PE_sdata4;
33
Evan Cheng76792992011-07-20 05:58:47 +000034 // .comm doesn't support alignment before Leopard.
35 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
36 CommDirectiveSupportsAlignment = false;
37
38 TextSection // .text
39 = Ctx->getMachOSection("__TEXT", "__text",
David Majnemer7b583052014-03-07 07:36:05 +000040 MachO::S_ATTR_PURE_INSTRUCTIONS,
Evan Cheng76792992011-07-20 05:58:47 +000041 SectionKind::getText());
42 DataSection // .data
43 = Ctx->getMachOSection("__DATA", "__data", 0,
44 SectionKind::getDataRel());
45
NAKAMURA Takumi68fa6f92013-09-21 02:34:45 +000046 // BSSSection might not be expected initialized on msvc.
Craig Topperbb694de2014-04-13 04:57:38 +000047 BSSSection = nullptr;
NAKAMURA Takumi68fa6f92013-09-21 02:34:45 +000048
Evan Cheng76792992011-07-20 05:58:47 +000049 TLSDataSection // .tdata
50 = Ctx->getMachOSection("__DATA", "__thread_data",
David Majnemer7b583052014-03-07 07:36:05 +000051 MachO::S_THREAD_LOCAL_REGULAR,
Evan Cheng76792992011-07-20 05:58:47 +000052 SectionKind::getDataRel());
53 TLSBSSSection // .tbss
54 = Ctx->getMachOSection("__DATA", "__thread_bss",
David Majnemer7b583052014-03-07 07:36:05 +000055 MachO::S_THREAD_LOCAL_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +000056 SectionKind::getThreadBSS());
57
58 // TODO: Verify datarel below.
59 TLSTLVSection // .tlv
60 = Ctx->getMachOSection("__DATA", "__thread_vars",
David Majnemer7b583052014-03-07 07:36:05 +000061 MachO::S_THREAD_LOCAL_VARIABLES,
Evan Cheng76792992011-07-20 05:58:47 +000062 SectionKind::getDataRel());
63
64 TLSThreadInitSection
65 = Ctx->getMachOSection("__DATA", "__thread_init",
David Majnemer7b583052014-03-07 07:36:05 +000066 MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
Jim Grosbach0dde3492011-11-15 16:46:22 +000067 SectionKind::getDataRel());
Evan Cheng76792992011-07-20 05:58:47 +000068
69 CStringSection // .cstring
70 = Ctx->getMachOSection("__TEXT", "__cstring",
David Majnemer7b583052014-03-07 07:36:05 +000071 MachO::S_CSTRING_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +000072 SectionKind::getMergeable1ByteCString());
73 UStringSection
74 = Ctx->getMachOSection("__TEXT","__ustring", 0,
75 SectionKind::getMergeable2ByteCString());
76 FourByteConstantSection // .literal4
77 = Ctx->getMachOSection("__TEXT", "__literal4",
David Majnemer7b583052014-03-07 07:36:05 +000078 MachO::S_4BYTE_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +000079 SectionKind::getMergeableConst4());
80 EightByteConstantSection // .literal8
81 = Ctx->getMachOSection("__TEXT", "__literal8",
David Majnemer7b583052014-03-07 07:36:05 +000082 MachO::S_8BYTE_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +000083 SectionKind::getMergeableConst8());
84
Rafael Espindola1f3de492014-02-13 23:16:11 +000085 SixteenByteConstantSection // .literal16
86 = Ctx->getMachOSection("__TEXT", "__literal16",
David Majnemer7b583052014-03-07 07:36:05 +000087 MachO::S_16BYTE_LITERALS,
Rafael Espindola1f3de492014-02-13 23:16:11 +000088 SectionKind::getMergeableConst16());
Evan Cheng76792992011-07-20 05:58:47 +000089
90 ReadOnlySection // .const
91 = Ctx->getMachOSection("__TEXT", "__const", 0,
92 SectionKind::getReadOnly());
93
94 TextCoalSection
95 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
David Majnemer7b583052014-03-07 07:36:05 +000096 MachO::S_COALESCED |
97 MachO::S_ATTR_PURE_INSTRUCTIONS,
Evan Cheng76792992011-07-20 05:58:47 +000098 SectionKind::getText());
99 ConstTextCoalSection
100 = Ctx->getMachOSection("__TEXT", "__const_coal",
David Majnemer7b583052014-03-07 07:36:05 +0000101 MachO::S_COALESCED,
Evan Cheng76792992011-07-20 05:58:47 +0000102 SectionKind::getReadOnly());
103 ConstDataSection // .const_data
104 = Ctx->getMachOSection("__DATA", "__const", 0,
105 SectionKind::getReadOnlyWithRel());
106 DataCoalSection
107 = Ctx->getMachOSection("__DATA","__datacoal_nt",
David Majnemer7b583052014-03-07 07:36:05 +0000108 MachO::S_COALESCED,
Evan Cheng76792992011-07-20 05:58:47 +0000109 SectionKind::getDataRel());
110 DataCommonSection
111 = Ctx->getMachOSection("__DATA","__common",
David Majnemer7b583052014-03-07 07:36:05 +0000112 MachO::S_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +0000113 SectionKind::getBSS());
114 DataBSSSection
David Majnemer7b583052014-03-07 07:36:05 +0000115 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +0000116 SectionKind::getBSS());
117
118
119 LazySymbolPointerSection
120 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
David Majnemer7b583052014-03-07 07:36:05 +0000121 MachO::S_LAZY_SYMBOL_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000122 SectionKind::getMetadata());
123 NonLazySymbolPointerSection
124 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
David Majnemer7b583052014-03-07 07:36:05 +0000125 MachO::S_NON_LAZY_SYMBOL_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000126 SectionKind::getMetadata());
127
128 if (RelocM == Reloc::Static) {
129 StaticCtorSection
130 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
131 SectionKind::getDataRel());
132 StaticDtorSection
133 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
134 SectionKind::getDataRel());
135 } else {
136 StaticCtorSection
137 = Ctx->getMachOSection("__DATA", "__mod_init_func",
David Majnemer7b583052014-03-07 07:36:05 +0000138 MachO::S_MOD_INIT_FUNC_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000139 SectionKind::getDataRel());
140 StaticDtorSection
141 = Ctx->getMachOSection("__DATA", "__mod_term_func",
David Majnemer7b583052014-03-07 07:36:05 +0000142 MachO::S_MOD_TERM_FUNC_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000143 SectionKind::getDataRel());
144 }
145
146 // Exception Handling.
147 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
148 SectionKind::getReadOnlyWithRel());
149
Craig Topperbb694de2014-04-13 04:57:38 +0000150 COFFDebugSymbolsSection = nullptr;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000151
Tim Northover00ed9962014-03-29 10:18:08 +0000152 if ((T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) ||
153 (T.isOSDarwin() && T.getArch() == Triple::arm64)) {
Evan Cheng76792992011-07-20 05:58:47 +0000154 CompactUnwindSection =
155 Ctx->getMachOSection("__LD", "__compact_unwind",
David Majnemer7b583052014-03-07 07:36:05 +0000156 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000157 SectionKind::getReadOnly());
158
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000159 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
160 CompactUnwindDwarfEHFrameOnly = 0x04000000;
Tim Northover00ed9962014-03-29 10:18:08 +0000161 else if (T.getArch() == Triple::arm64)
162 CompactUnwindDwarfEHFrameOnly = 0x03000000;
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000163 }
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",
David Majnemer7b583052014-03-07 07:36:05 +0000168 MachO::S_ATTR_DEBUG,
Eric Christopher4996c702011-11-07 09:24:32 +0000169 SectionKind::getMetadata());
170 DwarfAccelObjCSection =
171 Ctx->getMachOSection("__DWARF", "__apple_objc",
David Majnemer7b583052014-03-07 07:36:05 +0000172 MachO::S_ATTR_DEBUG,
Eric Christopher4996c702011-11-07 09:24:32 +0000173 SectionKind::getMetadata());
174 // 16 character section limit...
175 DwarfAccelNamespaceSection =
176 Ctx->getMachOSection("__DWARF", "__apple_namespac",
David Majnemer7b583052014-03-07 07:36:05 +0000177 MachO::S_ATTR_DEBUG,
Eric Christopher4996c702011-11-07 09:24:32 +0000178 SectionKind::getMetadata());
179 DwarfAccelTypesSection =
180 Ctx->getMachOSection("__DWARF", "__apple_types",
David Majnemer7b583052014-03-07 07:36:05 +0000181 MachO::S_ATTR_DEBUG,
Eric Christopher4996c702011-11-07 09:24:32 +0000182 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",
David Majnemer7b583052014-03-07 07:36:05 +0000186 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000187 SectionKind::getMetadata());
188 DwarfInfoSection =
189 Ctx->getMachOSection("__DWARF", "__debug_info",
David Majnemer7b583052014-03-07 07:36:05 +0000190 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000191 SectionKind::getMetadata());
192 DwarfLineSection =
193 Ctx->getMachOSection("__DWARF", "__debug_line",
David Majnemer7b583052014-03-07 07:36:05 +0000194 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000195 SectionKind::getMetadata());
196 DwarfFrameSection =
197 Ctx->getMachOSection("__DWARF", "__debug_frame",
David Majnemer7b583052014-03-07 07:36:05 +0000198 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000199 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000200 DwarfPubNamesSection =
201 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
David Majnemer7b583052014-03-07 07:36:05 +0000202 MachO::S_ATTR_DEBUG,
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000203 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000204 DwarfPubTypesSection =
205 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
David Majnemer7b583052014-03-07 07:36:05 +0000206 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000207 SectionKind::getMetadata());
Eric Christopherb0e76942013-09-09 20:03:14 +0000208 DwarfGnuPubNamesSection =
209 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
David Majnemer7b583052014-03-07 07:36:05 +0000210 MachO::S_ATTR_DEBUG,
Eric Christopherb0e76942013-09-09 20:03:14 +0000211 SectionKind::getMetadata());
212 DwarfGnuPubTypesSection =
213 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
David Majnemer7b583052014-03-07 07:36:05 +0000214 MachO::S_ATTR_DEBUG,
Eric Christopherb0e76942013-09-09 20:03:14 +0000215 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000216 DwarfStrSection =
217 Ctx->getMachOSection("__DWARF", "__debug_str",
David Majnemer7b583052014-03-07 07:36:05 +0000218 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000219 SectionKind::getMetadata());
220 DwarfLocSection =
221 Ctx->getMachOSection("__DWARF", "__debug_loc",
David Majnemer7b583052014-03-07 07:36:05 +0000222 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000223 SectionKind::getMetadata());
224 DwarfARangesSection =
225 Ctx->getMachOSection("__DWARF", "__debug_aranges",
David Majnemer7b583052014-03-07 07:36:05 +0000226 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000227 SectionKind::getMetadata());
228 DwarfRangesSection =
229 Ctx->getMachOSection("__DWARF", "__debug_ranges",
David Majnemer7b583052014-03-07 07:36:05 +0000230 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000231 SectionKind::getMetadata());
232 DwarfMacroInfoSection =
233 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
David Majnemer7b583052014-03-07 07:36:05 +0000234 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000235 SectionKind::getMetadata());
236 DwarfDebugInlineSection =
237 Ctx->getMachOSection("__DWARF", "__debug_inlined",
David Majnemer7b583052014-03-07 07:36:05 +0000238 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000239 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) {
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000248 switch (T.getArch()) {
249 case Triple::mips:
250 case Triple::mipsel:
Rafael Espindolab9b7ae02013-04-03 03:13:19 +0000251 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000252 break;
253 case Triple::mips64:
254 case Triple::mips64el:
Rafael Espindolab9b7ae02013-04-03 03:13:19 +0000255 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000256 break;
257 default:
Rafael Espindolaef9d3492013-03-15 05:51:57 +0000258 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000259 break;
260 }
Rafael Espindolaef9d3492013-03-15 05:51:57 +0000261
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000262 switch (T.getArch()) {
263 case Triple::x86:
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000264 PersonalityEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach0dde3492011-11-15 16:46:22 +0000265 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
266 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000267 LSDAEncoding = (RelocM == Reloc::PIC_)
268 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
269 : dwarf::DW_EH_PE_absptr;
Rafael Espindolaef9d3492013-03-15 05:51:57 +0000270 FDEEncoding = (RelocM == Reloc::PIC_)
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000271 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
272 : dwarf::DW_EH_PE_absptr;
273 TTypeEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach0dde3492011-11-15 16:46:22 +0000274 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
275 : dwarf::DW_EH_PE_absptr;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000276 break;
277 case Triple::x86_64:
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000278 if (RelocM == Reloc::PIC_) {
279 PersonalityEncoding = 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 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
283 (CMModel == CodeModel::Small
284 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
285 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
286 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
287 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
288 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
289 } else {
290 PersonalityEncoding =
291 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
292 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
293 LSDAEncoding = (CMModel == CodeModel::Small)
294 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
295 FDEEncoding = dwarf::DW_EH_PE_udata4;
296 TTypeEncoding = (CMModel == CodeModel::Small)
297 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
298 }
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000299 break;
300 case Triple::aarch64:
301 case Triple::aarch64_be:
302 case Triple::arm64:
303 case Triple::arm64_be:
Tim Northovere0e3aef2013-01-31 12:12:40 +0000304 // The small model guarantees static code/data size < 4GB, but not where it
305 // will be in memory. Most of these could end up >2GB away so even a signed
306 // pc-relative 32-bit address is insufficient, theoretically.
307 if (RelocM == Reloc::PIC_) {
308 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
309 dwarf::DW_EH_PE_sdata8;
310 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
311 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
312 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
313 dwarf::DW_EH_PE_sdata8;
314 } else {
315 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
316 LSDAEncoding = dwarf::DW_EH_PE_absptr;
317 FDEEncoding = dwarf::DW_EH_PE_udata4;
318 TTypeEncoding = dwarf::DW_EH_PE_absptr;
319 }
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000320 break;
321 case Triple::ppc64:
322 case Triple::ppc64le:
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000323 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
324 dwarf::DW_EH_PE_udata8;
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000325 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
326 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
327 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
328 dwarf::DW_EH_PE_udata8;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000329 break;
330 case Triple::sparc:
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000331 if (RelocM == Reloc::PIC_) {
332 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
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 LSDAEncoding = dwarf::DW_EH_PE_absptr;
340 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
341 FDEEncoding = dwarf::DW_EH_PE_udata4;
342 TTypeEncoding = dwarf::DW_EH_PE_absptr;
343 }
Joerg Sonnenbergerfa9cf652014-04-30 23:36:24 +0000344 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000345 case Triple::sparcv9:
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000346 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
347 if (RelocM == Reloc::PIC_) {
348 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
349 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 FDEEncoding = dwarf::DW_EH_PE_udata4;
356 TTypeEncoding = dwarf::DW_EH_PE_absptr;
357 }
Joerg Sonnenbergerfa9cf652014-04-30 23:36:24 +0000358 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000359 case Triple::systemz:
Ulrich Weigand0213e7f2013-05-06 16:11:12 +0000360 // All currently-defined code models guarantee that 4-byte PC-relative
361 // values will be in range.
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000362 if (RelocM == Reloc::PIC_) {
363 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
364 dwarf::DW_EH_PE_sdata4;
365 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
366 FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
367 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
368 dwarf::DW_EH_PE_sdata4;
369 } else {
370 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
371 LSDAEncoding = dwarf::DW_EH_PE_absptr;
372 FDEEncoding = dwarf::DW_EH_PE_absptr;
373 TTypeEncoding = dwarf::DW_EH_PE_absptr;
374 }
Joerg Sonnenbergerfa9cf652014-04-30 23:36:24 +0000375 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000376 default:
377 break;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000378 }
379
David Chisnall07f8d3e2012-02-17 17:31:15 +0000380 // Solaris requires different flags for .eh_frame to seemingly every other
381 // platform.
David Chisnallbbec8722012-04-10 11:44:33 +0000382 EHSectionType = ELF::SHT_PROGBITS;
David Chisnall07f8d3e2012-02-17 17:31:15 +0000383 EHSectionFlags = ELF::SHF_ALLOC;
David Chisnallbbec8722012-04-10 11:44:33 +0000384 if (T.getOS() == Triple::Solaris) {
385 if (T.getArch() == Triple::x86_64)
386 EHSectionType = ELF::SHT_X86_64_UNWIND;
387 else
388 EHSectionFlags |= ELF::SHF_WRITE;
389 }
David Chisnall07f8d3e2012-02-17 17:31:15 +0000390
391
Evan Cheng76792992011-07-20 05:58:47 +0000392 // ELF
393 BSSSection =
394 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
Anton Korobeynikov7722a2d2012-01-25 22:24:19 +0000395 ELF::SHF_WRITE | ELF::SHF_ALLOC,
Evan Cheng76792992011-07-20 05:58:47 +0000396 SectionKind::getBSS());
397
398 TextSection =
399 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
400 ELF::SHF_EXECINSTR |
401 ELF::SHF_ALLOC,
402 SectionKind::getText());
403
404 DataSection =
405 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
406 ELF::SHF_WRITE |ELF::SHF_ALLOC,
407 SectionKind::getDataRel());
408
409 ReadOnlySection =
410 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
411 ELF::SHF_ALLOC,
412 SectionKind::getReadOnly());
413
414 TLSDataSection =
415 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
416 ELF::SHF_ALLOC | ELF::SHF_TLS |
417 ELF::SHF_WRITE,
418 SectionKind::getThreadData());
419
420 TLSBSSSection =
421 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
422 ELF::SHF_ALLOC | ELF::SHF_TLS |
423 ELF::SHF_WRITE,
424 SectionKind::getThreadBSS());
425
426 DataRelSection =
427 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
428 ELF::SHF_ALLOC |ELF::SHF_WRITE,
429 SectionKind::getDataRel());
430
431 DataRelLocalSection =
432 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
433 ELF::SHF_ALLOC |ELF::SHF_WRITE,
434 SectionKind::getDataRelLocal());
435
436 DataRelROSection =
437 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
438 ELF::SHF_ALLOC |ELF::SHF_WRITE,
439 SectionKind::getReadOnlyWithRel());
440
441 DataRelROLocalSection =
442 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
443 ELF::SHF_ALLOC |ELF::SHF_WRITE,
444 SectionKind::getReadOnlyWithRelLocal());
445
446 MergeableConst4Section =
447 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
448 ELF::SHF_ALLOC |ELF::SHF_MERGE,
449 SectionKind::getMergeableConst4());
450
451 MergeableConst8Section =
452 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
453 ELF::SHF_ALLOC |ELF::SHF_MERGE,
454 SectionKind::getMergeableConst8());
455
456 MergeableConst16Section =
457 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
458 ELF::SHF_ALLOC |ELF::SHF_MERGE,
459 SectionKind::getMergeableConst16());
460
461 StaticCtorSection =
462 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
463 ELF::SHF_ALLOC |ELF::SHF_WRITE,
464 SectionKind::getDataRel());
465
466 StaticDtorSection =
467 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
468 ELF::SHF_ALLOC |ELF::SHF_WRITE,
469 SectionKind::getDataRel());
470
471 // Exception Handling Sections.
472
473 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
474 // it contains relocatable pointers. In PIC mode, this is probably a big
475 // runtime hit for C++ apps. Either the contents of the LSDA need to be
476 // adjusted or this should be a data section.
477 LSDASection =
478 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
479 ELF::SHF_ALLOC,
480 SectionKind::getReadOnly());
481
Craig Topperbb694de2014-04-13 04:57:38 +0000482 COFFDebugSymbolsSection = nullptr;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000483
Evan Cheng76792992011-07-20 05:58:47 +0000484 // Debug Info Sections.
485 DwarfAbbrevSection =
486 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
487 SectionKind::getMetadata());
488 DwarfInfoSection =
489 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
490 SectionKind::getMetadata());
491 DwarfLineSection =
492 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
493 SectionKind::getMetadata());
494 DwarfFrameSection =
495 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
496 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000497 DwarfPubNamesSection =
498 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
499 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000500 DwarfPubTypesSection =
501 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
502 SectionKind::getMetadata());
Eric Christopherb0e76942013-09-09 20:03:14 +0000503 DwarfGnuPubNamesSection =
504 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
505 SectionKind::getMetadata());
506 DwarfGnuPubTypesSection =
507 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
508 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000509 DwarfStrSection =
Nick Lewycky1a62d782011-10-26 18:44:32 +0000510 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
511 ELF::SHF_MERGE | ELF::SHF_STRINGS,
512 SectionKind::getMergeable1ByteCString());
Evan Cheng76792992011-07-20 05:58:47 +0000513 DwarfLocSection =
514 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
515 SectionKind::getMetadata());
516 DwarfARangesSection =
517 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
518 SectionKind::getMetadata());
519 DwarfRangesSection =
520 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
521 SectionKind::getMetadata());
522 DwarfMacroInfoSection =
523 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
524 SectionKind::getMetadata());
Eric Christopher27ed8ec2012-11-28 02:49:34 +0000525
526 // DWARF5 Experimental Debug Info
527
528 // Accelerator Tables
Eric Christophera0ad67d2012-10-08 21:41:30 +0000529 DwarfAccelNamesSection =
530 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
531 SectionKind::getMetadata());
532 DwarfAccelObjCSection =
533 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
534 SectionKind::getMetadata());
535 DwarfAccelNamespaceSection =
536 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
537 SectionKind::getMetadata());
538 DwarfAccelTypesSection =
539 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
540 SectionKind::getMetadata());
Eric Christopherc3b434b2012-11-28 02:49:38 +0000541
542 // Fission Sections
543 DwarfInfoDWOSection =
544 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
545 SectionKind::getMetadata());
Eric Christopher3c230092012-11-30 06:47:06 +0000546 DwarfAbbrevDWOSection =
547 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
548 SectionKind::getMetadata());
549 DwarfStrDWOSection =
550 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
551 ELF::SHF_MERGE | ELF::SHF_STRINGS,
552 SectionKind::getMergeable1ByteCString());
553 DwarfLineDWOSection =
554 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
555 SectionKind::getMetadata());
556 DwarfLocDWOSection =
557 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
558 SectionKind::getMetadata());
Eric Christopherc0fa8672013-01-04 17:59:22 +0000559 DwarfStrOffDWOSection =
560 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
561 SectionKind::getMetadata());
Eric Christopher962c9082013-01-15 23:56:56 +0000562 DwarfAddrSection =
563 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
564 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000565}
566
567
568void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
David Majnemera9bdb322014-04-08 22:33:40 +0000569 // The object file format cannot represent common symbols with explicit
570 // alignments.
571 CommDirectiveSupportsAlignment = false;
572
Evan Cheng76792992011-07-20 05:58:47 +0000573 // COFF
David Majnemer3d96acb2013-08-13 01:23:53 +0000574 BSSSection =
575 Ctx->getCOFFSection(".bss",
576 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
577 COFF::IMAGE_SCN_MEM_READ |
578 COFF::IMAGE_SCN_MEM_WRITE,
579 SectionKind::getBSS());
Evan Cheng76792992011-07-20 05:58:47 +0000580 TextSection =
581 Ctx->getCOFFSection(".text",
582 COFF::IMAGE_SCN_CNT_CODE |
583 COFF::IMAGE_SCN_MEM_EXECUTE |
584 COFF::IMAGE_SCN_MEM_READ,
585 SectionKind::getText());
586 DataSection =
587 Ctx->getCOFFSection(".data",
588 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
589 COFF::IMAGE_SCN_MEM_READ |
590 COFF::IMAGE_SCN_MEM_WRITE,
591 SectionKind::getDataRel());
592 ReadOnlySection =
593 Ctx->getCOFFSection(".rdata",
594 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
595 COFF::IMAGE_SCN_MEM_READ,
596 SectionKind::getReadOnly());
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000597 if (T.isKnownWindowsMSVCEnvironment()) {
Michael J. Spencerb560d072012-02-23 21:56:08 +0000598 StaticCtorSection =
599 Ctx->getCOFFSection(".CRT$XCU",
600 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
601 COFF::IMAGE_SCN_MEM_READ,
602 SectionKind::getReadOnly());
603 } else {
604 StaticCtorSection =
605 Ctx->getCOFFSection(".ctors",
606 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
607 COFF::IMAGE_SCN_MEM_READ |
608 COFF::IMAGE_SCN_MEM_WRITE,
609 SectionKind::getDataRel());
610 }
611
612
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000613 if (T.isKnownWindowsMSVCEnvironment()) {
Anton Korobeynikov37d73002012-09-23 15:53:47 +0000614 StaticDtorSection =
615 Ctx->getCOFFSection(".CRT$XTX",
616 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
617 COFF::IMAGE_SCN_MEM_READ,
618 SectionKind::getReadOnly());
619 } else {
620 StaticDtorSection =
621 Ctx->getCOFFSection(".dtors",
622 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
623 COFF::IMAGE_SCN_MEM_READ |
624 COFF::IMAGE_SCN_MEM_WRITE,
625 SectionKind::getDataRel());
626 }
Evan Cheng76792992011-07-20 05:58:47 +0000627
628 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
629 // though it contains relocatable pointers. In PIC mode, this is probably a
630 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
631 // adjusted or this should be a data section.
Kai Nacke42097302013-07-08 04:43:23 +0000632 LSDASection =
633 Ctx->getCOFFSection(".gcc_except_table",
634 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
635 COFF::IMAGE_SCN_MEM_READ,
636 SectionKind::getReadOnly());
Evan Cheng76792992011-07-20 05:58:47 +0000637
638 // Debug info.
Timur Iskhodzhanov31377c52014-01-28 03:48:44 +0000639 COFFDebugSymbolsSection =
640 Ctx->getCOFFSection(".debug$S",
641 COFF::IMAGE_SCN_MEM_DISCARDABLE |
642 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
643 COFF::IMAGE_SCN_MEM_READ,
644 SectionKind::getMetadata());
645
Evan Cheng76792992011-07-20 05:58:47 +0000646 DwarfAbbrevSection =
647 Ctx->getCOFFSection(".debug_abbrev",
648 COFF::IMAGE_SCN_MEM_DISCARDABLE |
649 COFF::IMAGE_SCN_MEM_READ,
650 SectionKind::getMetadata());
651 DwarfInfoSection =
652 Ctx->getCOFFSection(".debug_info",
653 COFF::IMAGE_SCN_MEM_DISCARDABLE |
654 COFF::IMAGE_SCN_MEM_READ,
655 SectionKind::getMetadata());
656 DwarfLineSection =
657 Ctx->getCOFFSection(".debug_line",
658 COFF::IMAGE_SCN_MEM_DISCARDABLE |
659 COFF::IMAGE_SCN_MEM_READ,
660 SectionKind::getMetadata());
661 DwarfFrameSection =
662 Ctx->getCOFFSection(".debug_frame",
663 COFF::IMAGE_SCN_MEM_DISCARDABLE |
664 COFF::IMAGE_SCN_MEM_READ,
665 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000666 DwarfPubNamesSection =
667 Ctx->getCOFFSection(".debug_pubnames",
668 COFF::IMAGE_SCN_MEM_DISCARDABLE |
669 COFF::IMAGE_SCN_MEM_READ,
670 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000671 DwarfPubTypesSection =
672 Ctx->getCOFFSection(".debug_pubtypes",
673 COFF::IMAGE_SCN_MEM_DISCARDABLE |
674 COFF::IMAGE_SCN_MEM_READ,
675 SectionKind::getMetadata());
NAKAMURA Takumi0229e352013-09-10 06:01:56 +0000676 DwarfGnuPubNamesSection =
Eric Christopherb0e76942013-09-09 20:03:14 +0000677 Ctx->getCOFFSection(".debug_gnu_pubnames",
678 COFF::IMAGE_SCN_MEM_DISCARDABLE |
679 COFF::IMAGE_SCN_MEM_READ,
680 SectionKind::getMetadata());
NAKAMURA Takumi0229e352013-09-10 06:01:56 +0000681 DwarfGnuPubTypesSection =
Eric Christopherb0e76942013-09-09 20:03:14 +0000682 Ctx->getCOFFSection(".debug_gnu_pubtypes",
683 COFF::IMAGE_SCN_MEM_DISCARDABLE |
684 COFF::IMAGE_SCN_MEM_READ,
685 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000686 DwarfStrSection =
687 Ctx->getCOFFSection(".debug_str",
688 COFF::IMAGE_SCN_MEM_DISCARDABLE |
689 COFF::IMAGE_SCN_MEM_READ,
690 SectionKind::getMetadata());
691 DwarfLocSection =
692 Ctx->getCOFFSection(".debug_loc",
693 COFF::IMAGE_SCN_MEM_DISCARDABLE |
694 COFF::IMAGE_SCN_MEM_READ,
695 SectionKind::getMetadata());
696 DwarfARangesSection =
697 Ctx->getCOFFSection(".debug_aranges",
698 COFF::IMAGE_SCN_MEM_DISCARDABLE |
699 COFF::IMAGE_SCN_MEM_READ,
700 SectionKind::getMetadata());
701 DwarfRangesSection =
702 Ctx->getCOFFSection(".debug_ranges",
703 COFF::IMAGE_SCN_MEM_DISCARDABLE |
704 COFF::IMAGE_SCN_MEM_READ,
705 SectionKind::getMetadata());
706 DwarfMacroInfoSection =
707 Ctx->getCOFFSection(".debug_macinfo",
708 COFF::IMAGE_SCN_MEM_DISCARDABLE |
709 COFF::IMAGE_SCN_MEM_READ,
710 SectionKind::getMetadata());
David Blaikie62dd7df2014-03-26 03:05:10 +0000711 DwarfInfoDWOSection =
712 Ctx->getCOFFSection(".debug_info.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
713 COFF::IMAGE_SCN_MEM_READ,
714 SectionKind::getMetadata());
715 DwarfAbbrevDWOSection =
716 Ctx->getCOFFSection(".debug_abbrev.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
717 COFF::IMAGE_SCN_MEM_READ,
718 SectionKind::getMetadata());
719 DwarfStrDWOSection =
720 Ctx->getCOFFSection(".debug_str.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
721 COFF::IMAGE_SCN_MEM_READ,
722 SectionKind::getMetadata());
723 DwarfLineDWOSection =
724 Ctx->getCOFFSection(".debug_line.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
725 COFF::IMAGE_SCN_MEM_READ,
726 SectionKind::getMetadata());
727 DwarfLocDWOSection =
728 Ctx->getCOFFSection(".debug_loc.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
729 COFF::IMAGE_SCN_MEM_READ,
730 SectionKind::getMetadata());
731 DwarfStrOffDWOSection =
732 Ctx->getCOFFSection(".debug_str_offsets.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
733 COFF::IMAGE_SCN_MEM_READ,
734 SectionKind::getMetadata());
735 DwarfAddrSection = Ctx->getCOFFSection(
736 ".debug_addr", COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_MEM_READ,
737 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000738
739 DrectveSection =
740 Ctx->getCOFFSection(".drectve",
741 COFF::IMAGE_SCN_LNK_INFO,
742 SectionKind::getMetadata());
743
744 PDataSection =
745 Ctx->getCOFFSection(".pdata",
746 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikovcc8c5392012-08-08 12:46:46 +0000747 COFF::IMAGE_SCN_MEM_READ,
Evan Cheng76792992011-07-20 05:58:47 +0000748 SectionKind::getDataRel());
749
750 XDataSection =
751 Ctx->getCOFFSection(".xdata",
752 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikovcc8c5392012-08-08 12:46:46 +0000753 COFF::IMAGE_SCN_MEM_READ,
Evan Cheng76792992011-07-20 05:58:47 +0000754 SectionKind::getDataRel());
Anton Korobeynikovc6b40172012-02-11 17:26:53 +0000755 TLSDataSection =
756 Ctx->getCOFFSection(".tls$",
757 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
758 COFF::IMAGE_SCN_MEM_READ |
759 COFF::IMAGE_SCN_MEM_WRITE,
760 SectionKind::getDataRel());
Evan Cheng76792992011-07-20 05:58:47 +0000761}
762
763void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000764 CodeModel::Model cm,
Evan Cheng76792992011-07-20 05:58:47 +0000765 MCContext &ctx) {
766 RelocM = relocm;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000767 CMModel = cm;
Evan Cheng76792992011-07-20 05:58:47 +0000768 Ctx = &ctx;
769
770 // Common.
771 CommDirectiveSupportsAlignment = true;
772 SupportsWeakOmittedEHFrame = true;
773 IsFunctionEHFrameSymbolPrivate = true;
Tim Northoverd1c6f512014-03-29 09:03:13 +0000774 SupportsCompactUnwindWithoutEHFrame = false;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000775
776 PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
777 TTypeEncoding = dwarf::DW_EH_PE_absptr;
778
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000779 CompactUnwindDwarfEHFrameOnly = 0;
780
Craig Topperbb694de2014-04-13 04:57:38 +0000781 EHFrameSection = nullptr; // Created on demand.
782 CompactUnwindSection = nullptr; // Used only by selected targets.
783 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
784 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
785 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
786 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
Evan Cheng76792992011-07-20 05:58:47 +0000787
788 Triple T(TT);
789 Triple::ArchType Arch = T.getArch();
790 // FIXME: Checking for Arch here to filter out bogus triples such as
791 // cellspu-apple-darwin. Perhaps we should fix in Triple?
792 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
793 Arch == Triple::arm || Arch == Triple::thumb ||
Tim Northover00ed9962014-03-29 10:18:08 +0000794 Arch == Triple::arm64 ||
Evan Cheng76792992011-07-20 05:58:47 +0000795 Arch == Triple::ppc || Arch == Triple::ppc64 ||
796 Arch == Triple::UnknownArch) &&
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000797 (T.isOSDarwin() || T.isOSBinFormatMachO())) {
Evan Cheng76792992011-07-20 05:58:47 +0000798 Env = IsMachO;
799 InitMachOMCObjectFileInfo(T);
Saleem Abdulrasoolffdb92a702014-04-27 04:54:16 +0000800 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
801 Arch == Triple::arm || Arch == Triple::thumb) &&
802 (T.isOSWindows() && T.getObjectFormat() == Triple::COFF)) {
Evan Cheng76792992011-07-20 05:58:47 +0000803 Env = IsCOFF;
804 InitCOFFMCObjectFileInfo(T);
805 } else {
806 Env = IsELF;
807 InitELFMCObjectFileInfo(T);
808 }
809}
810
David Blaikiebc563272013-12-13 21:33:40 +0000811const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
812 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
813 SectionKind::getMetadata(), 0, utostr(Hash));
814}
815
816const MCSection *
817MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
David Blaikie15ed5eb2014-01-10 01:38:41 +0000818 return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS,
819 ELF::SHF_GROUP, SectionKind::getMetadata(), 0,
820 utostr(Hash));
David Blaikiebc563272013-12-13 21:33:40 +0000821}
822
David Chisnall85dd3092012-02-17 16:51:02 +0000823void MCObjectFileInfo::InitEHFrameSection() {
824 if (Env == IsMachO)
825 EHFrameSection =
826 Ctx->getMachOSection("__TEXT", "__eh_frame",
David Majnemer7b583052014-03-07 07:36:05 +0000827 MachO::S_COALESCED |
828 MachO::S_ATTR_NO_TOC |
829 MachO::S_ATTR_STRIP_STATIC_SYMS |
830 MachO::S_ATTR_LIVE_SUPPORT,
David Chisnall85dd3092012-02-17 16:51:02 +0000831 SectionKind::getReadOnly());
832 else if (Env == IsELF)
833 EHFrameSection =
David Chisnallbbec8722012-04-10 11:44:33 +0000834 Ctx->getELFSection(".eh_frame", EHSectionType,
David Chisnall07f8d3e2012-02-17 17:31:15 +0000835 EHSectionFlags,
David Chisnall85dd3092012-02-17 16:51:02 +0000836 SectionKind::getDataRel());
837 else
838 EHFrameSection =
839 Ctx->getCOFFSection(".eh_frame",
840 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
841 COFF::IMAGE_SCN_MEM_READ |
842 COFF::IMAGE_SCN_MEM_WRITE,
843 SectionKind::getDataRel());
844}