blob: e5377890da5baad48fd43ff65acfb4dc6b2a90c2 [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"
Joerg Sonnenberger94cbb662014-05-13 17:58:13 +000013#include "llvm/MC/MCAsmInfo.h"
Evan Cheng76792992011-07-20 05:58:47 +000014#include "llvm/MC/MCContext.h"
15#include "llvm/MC/MCSection.h"
16#include "llvm/MC/MCSectionCOFF.h"
17#include "llvm/MC/MCSectionELF.h"
18#include "llvm/MC/MCSectionMachO.h"
Evan Cheng76792992011-07-20 05:58:47 +000019using namespace llvm;
20
21void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
22 // MachO
23 IsFunctionEHFrameSymbolPrivate = false;
24 SupportsWeakOmittedEHFrame = false;
25
Tim Northover00ed9962014-03-29 10:18:08 +000026 if (T.isOSDarwin() && T.getArch() == Triple::arm64)
27 SupportsCompactUnwindWithoutEHFrame = true;
28
Evan Chengbbf3b0d2011-07-20 19:50:42 +000029 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
30 | dwarf::DW_EH_PE_sdata4;
Rafael Espindolaaa7851d2014-05-12 13:47:05 +000031 LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
Evan Chengbbf3b0d2011-07-20 19:50:42 +000032 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
33 dwarf::DW_EH_PE_sdata4;
34
Evan Cheng76792992011-07-20 05:58:47 +000035 // .comm doesn't support alignment before Leopard.
36 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
37 CommDirectiveSupportsAlignment = false;
38
39 TextSection // .text
40 = Ctx->getMachOSection("__TEXT", "__text",
David Majnemer7b583052014-03-07 07:36:05 +000041 MachO::S_ATTR_PURE_INSTRUCTIONS,
Evan Cheng76792992011-07-20 05:58:47 +000042 SectionKind::getText());
43 DataSection // .data
44 = Ctx->getMachOSection("__DATA", "__data", 0,
45 SectionKind::getDataRel());
46
NAKAMURA Takumi68fa6f92013-09-21 02:34:45 +000047 // BSSSection might not be expected initialized on msvc.
Craig Topperbb694de2014-04-13 04:57:38 +000048 BSSSection = nullptr;
NAKAMURA Takumi68fa6f92013-09-21 02:34:45 +000049
Evan Cheng76792992011-07-20 05:58:47 +000050 TLSDataSection // .tdata
51 = Ctx->getMachOSection("__DATA", "__thread_data",
David Majnemer7b583052014-03-07 07:36:05 +000052 MachO::S_THREAD_LOCAL_REGULAR,
Evan Cheng76792992011-07-20 05:58:47 +000053 SectionKind::getDataRel());
54 TLSBSSSection // .tbss
55 = Ctx->getMachOSection("__DATA", "__thread_bss",
David Majnemer7b583052014-03-07 07:36:05 +000056 MachO::S_THREAD_LOCAL_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +000057 SectionKind::getThreadBSS());
58
59 // TODO: Verify datarel below.
60 TLSTLVSection // .tlv
61 = Ctx->getMachOSection("__DATA", "__thread_vars",
David Majnemer7b583052014-03-07 07:36:05 +000062 MachO::S_THREAD_LOCAL_VARIABLES,
Evan Cheng76792992011-07-20 05:58:47 +000063 SectionKind::getDataRel());
64
65 TLSThreadInitSection
66 = Ctx->getMachOSection("__DATA", "__thread_init",
David Majnemer7b583052014-03-07 07:36:05 +000067 MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
Jim Grosbach0dde3492011-11-15 16:46:22 +000068 SectionKind::getDataRel());
Evan Cheng76792992011-07-20 05:58:47 +000069
70 CStringSection // .cstring
71 = Ctx->getMachOSection("__TEXT", "__cstring",
David Majnemer7b583052014-03-07 07:36:05 +000072 MachO::S_CSTRING_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +000073 SectionKind::getMergeable1ByteCString());
74 UStringSection
75 = Ctx->getMachOSection("__TEXT","__ustring", 0,
76 SectionKind::getMergeable2ByteCString());
77 FourByteConstantSection // .literal4
78 = Ctx->getMachOSection("__TEXT", "__literal4",
David Majnemer7b583052014-03-07 07:36:05 +000079 MachO::S_4BYTE_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +000080 SectionKind::getMergeableConst4());
81 EightByteConstantSection // .literal8
82 = Ctx->getMachOSection("__TEXT", "__literal8",
David Majnemer7b583052014-03-07 07:36:05 +000083 MachO::S_8BYTE_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +000084 SectionKind::getMergeableConst8());
85
Rafael Espindola1f3de492014-02-13 23:16:11 +000086 SixteenByteConstantSection // .literal16
87 = Ctx->getMachOSection("__TEXT", "__literal16",
David Majnemer7b583052014-03-07 07:36:05 +000088 MachO::S_16BYTE_LITERALS,
Rafael Espindola1f3de492014-02-13 23:16:11 +000089 SectionKind::getMergeableConst16());
Evan Cheng76792992011-07-20 05:58:47 +000090
91 ReadOnlySection // .const
92 = Ctx->getMachOSection("__TEXT", "__const", 0,
93 SectionKind::getReadOnly());
94
95 TextCoalSection
96 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
David Majnemer7b583052014-03-07 07:36:05 +000097 MachO::S_COALESCED |
98 MachO::S_ATTR_PURE_INSTRUCTIONS,
Evan Cheng76792992011-07-20 05:58:47 +000099 SectionKind::getText());
100 ConstTextCoalSection
101 = Ctx->getMachOSection("__TEXT", "__const_coal",
David Majnemer7b583052014-03-07 07:36:05 +0000102 MachO::S_COALESCED,
Evan Cheng76792992011-07-20 05:58:47 +0000103 SectionKind::getReadOnly());
104 ConstDataSection // .const_data
105 = Ctx->getMachOSection("__DATA", "__const", 0,
106 SectionKind::getReadOnlyWithRel());
107 DataCoalSection
108 = Ctx->getMachOSection("__DATA","__datacoal_nt",
David Majnemer7b583052014-03-07 07:36:05 +0000109 MachO::S_COALESCED,
Evan Cheng76792992011-07-20 05:58:47 +0000110 SectionKind::getDataRel());
111 DataCommonSection
112 = Ctx->getMachOSection("__DATA","__common",
David Majnemer7b583052014-03-07 07:36:05 +0000113 MachO::S_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +0000114 SectionKind::getBSS());
115 DataBSSSection
David Majnemer7b583052014-03-07 07:36:05 +0000116 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +0000117 SectionKind::getBSS());
118
119
120 LazySymbolPointerSection
121 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
David Majnemer7b583052014-03-07 07:36:05 +0000122 MachO::S_LAZY_SYMBOL_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000123 SectionKind::getMetadata());
124 NonLazySymbolPointerSection
125 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
David Majnemer7b583052014-03-07 07:36:05 +0000126 MachO::S_NON_LAZY_SYMBOL_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000127 SectionKind::getMetadata());
128
129 if (RelocM == Reloc::Static) {
130 StaticCtorSection
131 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
132 SectionKind::getDataRel());
133 StaticDtorSection
134 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
135 SectionKind::getDataRel());
136 } else {
137 StaticCtorSection
138 = Ctx->getMachOSection("__DATA", "__mod_init_func",
David Majnemer7b583052014-03-07 07:36:05 +0000139 MachO::S_MOD_INIT_FUNC_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000140 SectionKind::getDataRel());
141 StaticDtorSection
142 = Ctx->getMachOSection("__DATA", "__mod_term_func",
David Majnemer7b583052014-03-07 07:36:05 +0000143 MachO::S_MOD_TERM_FUNC_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000144 SectionKind::getDataRel());
145 }
146
147 // Exception Handling.
148 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
149 SectionKind::getReadOnlyWithRel());
150
Craig Topperbb694de2014-04-13 04:57:38 +0000151 COFFDebugSymbolsSection = nullptr;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000152
Tim Northover00ed9962014-03-29 10:18:08 +0000153 if ((T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) ||
154 (T.isOSDarwin() && T.getArch() == Triple::arm64)) {
Evan Cheng76792992011-07-20 05:58:47 +0000155 CompactUnwindSection =
156 Ctx->getMachOSection("__LD", "__compact_unwind",
David Majnemer7b583052014-03-07 07:36:05 +0000157 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000158 SectionKind::getReadOnly());
159
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000160 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
161 CompactUnwindDwarfEHFrameOnly = 0x04000000;
Tim Northover00ed9962014-03-29 10:18:08 +0000162 else if (T.getArch() == Triple::arm64)
163 CompactUnwindDwarfEHFrameOnly = 0x03000000;
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000164 }
165
Evan Cheng76792992011-07-20 05:58:47 +0000166 // Debug Information.
Eric Christopher4996c702011-11-07 09:24:32 +0000167 DwarfAccelNamesSection =
168 Ctx->getMachOSection("__DWARF", "__apple_names",
David Majnemer7b583052014-03-07 07:36:05 +0000169 MachO::S_ATTR_DEBUG,
Eric Christopher4996c702011-11-07 09:24:32 +0000170 SectionKind::getMetadata());
171 DwarfAccelObjCSection =
172 Ctx->getMachOSection("__DWARF", "__apple_objc",
David Majnemer7b583052014-03-07 07:36:05 +0000173 MachO::S_ATTR_DEBUG,
Eric Christopher4996c702011-11-07 09:24:32 +0000174 SectionKind::getMetadata());
175 // 16 character section limit...
176 DwarfAccelNamespaceSection =
177 Ctx->getMachOSection("__DWARF", "__apple_namespac",
David Majnemer7b583052014-03-07 07:36:05 +0000178 MachO::S_ATTR_DEBUG,
Eric Christopher4996c702011-11-07 09:24:32 +0000179 SectionKind::getMetadata());
180 DwarfAccelTypesSection =
181 Ctx->getMachOSection("__DWARF", "__apple_types",
David Majnemer7b583052014-03-07 07:36:05 +0000182 MachO::S_ATTR_DEBUG,
Eric Christopher4996c702011-11-07 09:24:32 +0000183 SectionKind::getMetadata());
Jim Grosbachdc1e36e2012-05-11 01:41:30 +0000184
Evan Cheng76792992011-07-20 05:58:47 +0000185 DwarfAbbrevSection =
186 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
David Majnemer7b583052014-03-07 07:36:05 +0000187 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000188 SectionKind::getMetadata());
189 DwarfInfoSection =
190 Ctx->getMachOSection("__DWARF", "__debug_info",
David Majnemer7b583052014-03-07 07:36:05 +0000191 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000192 SectionKind::getMetadata());
193 DwarfLineSection =
194 Ctx->getMachOSection("__DWARF", "__debug_line",
David Majnemer7b583052014-03-07 07:36:05 +0000195 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000196 SectionKind::getMetadata());
197 DwarfFrameSection =
198 Ctx->getMachOSection("__DWARF", "__debug_frame",
David Majnemer7b583052014-03-07 07:36:05 +0000199 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000200 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000201 DwarfPubNamesSection =
202 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
David Majnemer7b583052014-03-07 07:36:05 +0000203 MachO::S_ATTR_DEBUG,
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000204 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000205 DwarfPubTypesSection =
206 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
David Majnemer7b583052014-03-07 07:36:05 +0000207 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000208 SectionKind::getMetadata());
Eric Christopherb0e76942013-09-09 20:03:14 +0000209 DwarfGnuPubNamesSection =
210 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
David Majnemer7b583052014-03-07 07:36:05 +0000211 MachO::S_ATTR_DEBUG,
Eric Christopherb0e76942013-09-09 20:03:14 +0000212 SectionKind::getMetadata());
213 DwarfGnuPubTypesSection =
214 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
David Majnemer7b583052014-03-07 07:36:05 +0000215 MachO::S_ATTR_DEBUG,
Eric Christopherb0e76942013-09-09 20:03:14 +0000216 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000217 DwarfStrSection =
218 Ctx->getMachOSection("__DWARF", "__debug_str",
David Majnemer7b583052014-03-07 07:36:05 +0000219 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000220 SectionKind::getMetadata());
221 DwarfLocSection =
222 Ctx->getMachOSection("__DWARF", "__debug_loc",
David Majnemer7b583052014-03-07 07:36:05 +0000223 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000224 SectionKind::getMetadata());
225 DwarfARangesSection =
226 Ctx->getMachOSection("__DWARF", "__debug_aranges",
David Majnemer7b583052014-03-07 07:36:05 +0000227 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000228 SectionKind::getMetadata());
229 DwarfRangesSection =
230 Ctx->getMachOSection("__DWARF", "__debug_ranges",
David Majnemer7b583052014-03-07 07:36:05 +0000231 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000232 SectionKind::getMetadata());
233 DwarfMacroInfoSection =
234 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
David Majnemer7b583052014-03-07 07:36:05 +0000235 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000236 SectionKind::getMetadata());
237 DwarfDebugInlineSection =
238 Ctx->getMachOSection("__DWARF", "__debug_inlined",
David Majnemer7b583052014-03-07 07:36:05 +0000239 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000240 SectionKind::getMetadata());
Lang Hames30789772013-11-08 22:14:49 +0000241 StackMapSection =
242 Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
243 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000244
245 TLSExtraDataSection = TLSTLVSection;
246}
247
248void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000249 switch (T.getArch()) {
250 case Triple::mips:
251 case Triple::mipsel:
Rafael Espindolab9b7ae02013-04-03 03:13:19 +0000252 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000253 break;
254 case Triple::mips64:
255 case Triple::mips64el:
Rafael Espindolab9b7ae02013-04-03 03:13:19 +0000256 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000257 break;
258 default:
Rafael Espindolaef9d3492013-03-15 05:51:57 +0000259 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000260 break;
261 }
Rafael Espindolaef9d3492013-03-15 05:51:57 +0000262
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000263 switch (T.getArch()) {
Joerg Sonnenbergercf86ce12014-05-07 07:49:34 +0000264 case Triple::arm:
265 case Triple::armeb:
266 case Triple::thumb:
267 case Triple::thumbeb:
Joerg Sonnenberger94cbb662014-05-13 17:58:13 +0000268 if (Ctx->getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
269 break;
270 // Fallthrough if not using EHABI
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000271 case Triple::x86:
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000272 PersonalityEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach0dde3492011-11-15 16:46:22 +0000273 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
274 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000275 LSDAEncoding = (RelocM == Reloc::PIC_)
276 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
277 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000278 TTypeEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach0dde3492011-11-15 16:46:22 +0000279 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
280 : dwarf::DW_EH_PE_absptr;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000281 break;
282 case Triple::x86_64:
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000283 if (RelocM == Reloc::PIC_) {
284 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
285 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
286 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
287 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
288 (CMModel == CodeModel::Small
289 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000290 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
291 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
292 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
293 } else {
294 PersonalityEncoding =
295 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
296 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
297 LSDAEncoding = (CMModel == CodeModel::Small)
298 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000299 TTypeEncoding = (CMModel == CodeModel::Small)
300 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
301 }
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000302 break;
303 case Triple::aarch64:
304 case Triple::aarch64_be:
305 case Triple::arm64:
306 case Triple::arm64_be:
Tim Northovere0e3aef2013-01-31 12:12:40 +0000307 // The small model guarantees static code/data size < 4GB, but not where it
308 // will be in memory. Most of these could end up >2GB away so even a signed
309 // pc-relative 32-bit address is insufficient, theoretically.
310 if (RelocM == Reloc::PIC_) {
311 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
312 dwarf::DW_EH_PE_sdata8;
313 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
Tim Northovere0e3aef2013-01-31 12:12:40 +0000314 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
315 dwarf::DW_EH_PE_sdata8;
316 } else {
317 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
318 LSDAEncoding = dwarf::DW_EH_PE_absptr;
Tim Northovere0e3aef2013-01-31 12:12:40 +0000319 TTypeEncoding = dwarf::DW_EH_PE_absptr;
320 }
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000321 break;
322 case Triple::ppc64:
323 case Triple::ppc64le:
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000324 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
325 dwarf::DW_EH_PE_udata8;
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000326 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000327 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;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000335 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
336 dwarf::DW_EH_PE_sdata4;
337 } else {
338 LSDAEncoding = dwarf::DW_EH_PE_absptr;
339 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000340 TTypeEncoding = dwarf::DW_EH_PE_absptr;
341 }
Joerg Sonnenbergerfa9cf652014-04-30 23:36:24 +0000342 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000343 case Triple::sparcv9:
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000344 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
345 if (RelocM == Reloc::PIC_) {
346 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
347 dwarf::DW_EH_PE_sdata4;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000348 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
349 dwarf::DW_EH_PE_sdata4;
350 } else {
351 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000352 TTypeEncoding = dwarf::DW_EH_PE_absptr;
353 }
Joerg Sonnenbergerfa9cf652014-04-30 23:36:24 +0000354 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000355 case Triple::systemz:
Ulrich Weigand0213e7f2013-05-06 16:11:12 +0000356 // All currently-defined code models guarantee that 4-byte PC-relative
357 // values will be in range.
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000358 if (RelocM == Reloc::PIC_) {
359 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
360 dwarf::DW_EH_PE_sdata4;
361 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000362 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
363 dwarf::DW_EH_PE_sdata4;
364 } else {
365 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
366 LSDAEncoding = dwarf::DW_EH_PE_absptr;
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000367 TTypeEncoding = dwarf::DW_EH_PE_absptr;
368 }
Joerg Sonnenbergerfa9cf652014-04-30 23:36:24 +0000369 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000370 default:
371 break;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000372 }
373
David Chisnall07f8d3e2012-02-17 17:31:15 +0000374 // Solaris requires different flags for .eh_frame to seemingly every other
375 // platform.
David Chisnallbbec8722012-04-10 11:44:33 +0000376 EHSectionType = ELF::SHT_PROGBITS;
David Chisnall07f8d3e2012-02-17 17:31:15 +0000377 EHSectionFlags = ELF::SHF_ALLOC;
David Chisnallbbec8722012-04-10 11:44:33 +0000378 if (T.getOS() == Triple::Solaris) {
379 if (T.getArch() == Triple::x86_64)
380 EHSectionType = ELF::SHT_X86_64_UNWIND;
381 else
382 EHSectionFlags |= ELF::SHF_WRITE;
383 }
David Chisnall07f8d3e2012-02-17 17:31:15 +0000384
385
Evan Cheng76792992011-07-20 05:58:47 +0000386 // ELF
387 BSSSection =
388 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
Anton Korobeynikov7722a2d2012-01-25 22:24:19 +0000389 ELF::SHF_WRITE | ELF::SHF_ALLOC,
Evan Cheng76792992011-07-20 05:58:47 +0000390 SectionKind::getBSS());
391
392 TextSection =
393 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
394 ELF::SHF_EXECINSTR |
395 ELF::SHF_ALLOC,
396 SectionKind::getText());
397
398 DataSection =
399 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
400 ELF::SHF_WRITE |ELF::SHF_ALLOC,
401 SectionKind::getDataRel());
402
403 ReadOnlySection =
404 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
405 ELF::SHF_ALLOC,
406 SectionKind::getReadOnly());
407
408 TLSDataSection =
409 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
410 ELF::SHF_ALLOC | ELF::SHF_TLS |
411 ELF::SHF_WRITE,
412 SectionKind::getThreadData());
413
414 TLSBSSSection =
415 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
416 ELF::SHF_ALLOC | ELF::SHF_TLS |
417 ELF::SHF_WRITE,
418 SectionKind::getThreadBSS());
419
420 DataRelSection =
421 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
422 ELF::SHF_ALLOC |ELF::SHF_WRITE,
423 SectionKind::getDataRel());
424
425 DataRelLocalSection =
426 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
427 ELF::SHF_ALLOC |ELF::SHF_WRITE,
428 SectionKind::getDataRelLocal());
429
430 DataRelROSection =
431 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
432 ELF::SHF_ALLOC |ELF::SHF_WRITE,
433 SectionKind::getReadOnlyWithRel());
434
435 DataRelROLocalSection =
436 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
437 ELF::SHF_ALLOC |ELF::SHF_WRITE,
438 SectionKind::getReadOnlyWithRelLocal());
439
440 MergeableConst4Section =
441 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
442 ELF::SHF_ALLOC |ELF::SHF_MERGE,
443 SectionKind::getMergeableConst4());
444
445 MergeableConst8Section =
446 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
447 ELF::SHF_ALLOC |ELF::SHF_MERGE,
448 SectionKind::getMergeableConst8());
449
450 MergeableConst16Section =
451 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
452 ELF::SHF_ALLOC |ELF::SHF_MERGE,
453 SectionKind::getMergeableConst16());
454
455 StaticCtorSection =
456 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
457 ELF::SHF_ALLOC |ELF::SHF_WRITE,
458 SectionKind::getDataRel());
459
460 StaticDtorSection =
461 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
462 ELF::SHF_ALLOC |ELF::SHF_WRITE,
463 SectionKind::getDataRel());
464
465 // Exception Handling Sections.
466
467 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
468 // it contains relocatable pointers. In PIC mode, this is probably a big
469 // runtime hit for C++ apps. Either the contents of the LSDA need to be
470 // adjusted or this should be a data section.
471 LSDASection =
472 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
473 ELF::SHF_ALLOC,
474 SectionKind::getReadOnly());
475
Craig Topperbb694de2014-04-13 04:57:38 +0000476 COFFDebugSymbolsSection = nullptr;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000477
Evan Cheng76792992011-07-20 05:58:47 +0000478 // Debug Info Sections.
479 DwarfAbbrevSection =
480 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
481 SectionKind::getMetadata());
482 DwarfInfoSection =
483 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
484 SectionKind::getMetadata());
485 DwarfLineSection =
486 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
487 SectionKind::getMetadata());
488 DwarfFrameSection =
489 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
490 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000491 DwarfPubNamesSection =
492 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
493 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000494 DwarfPubTypesSection =
495 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
496 SectionKind::getMetadata());
Eric Christopherb0e76942013-09-09 20:03:14 +0000497 DwarfGnuPubNamesSection =
498 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
499 SectionKind::getMetadata());
500 DwarfGnuPubTypesSection =
501 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
502 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000503 DwarfStrSection =
Nick Lewycky1a62d782011-10-26 18:44:32 +0000504 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
505 ELF::SHF_MERGE | ELF::SHF_STRINGS,
506 SectionKind::getMergeable1ByteCString());
Evan Cheng76792992011-07-20 05:58:47 +0000507 DwarfLocSection =
508 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
509 SectionKind::getMetadata());
510 DwarfARangesSection =
511 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
512 SectionKind::getMetadata());
513 DwarfRangesSection =
514 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
515 SectionKind::getMetadata());
516 DwarfMacroInfoSection =
517 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
518 SectionKind::getMetadata());
Eric Christopher27ed8ec2012-11-28 02:49:34 +0000519
520 // DWARF5 Experimental Debug Info
521
522 // Accelerator Tables
Eric Christophera0ad67d2012-10-08 21:41:30 +0000523 DwarfAccelNamesSection =
524 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
525 SectionKind::getMetadata());
526 DwarfAccelObjCSection =
527 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
528 SectionKind::getMetadata());
529 DwarfAccelNamespaceSection =
530 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
531 SectionKind::getMetadata());
532 DwarfAccelTypesSection =
533 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
534 SectionKind::getMetadata());
Eric Christopherc3b434b2012-11-28 02:49:38 +0000535
536 // Fission Sections
537 DwarfInfoDWOSection =
538 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
539 SectionKind::getMetadata());
David Blaikiebc094f32014-05-15 23:18:15 +0000540 DwarfTypesDWOSection =
541 Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS, 0,
542 SectionKind::getMetadata());
Eric Christopher3c230092012-11-30 06:47:06 +0000543 DwarfAbbrevDWOSection =
544 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
545 SectionKind::getMetadata());
546 DwarfStrDWOSection =
547 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
548 ELF::SHF_MERGE | ELF::SHF_STRINGS,
549 SectionKind::getMergeable1ByteCString());
550 DwarfLineDWOSection =
551 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
552 SectionKind::getMetadata());
553 DwarfLocDWOSection =
554 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
555 SectionKind::getMetadata());
Eric Christopherc0fa8672013-01-04 17:59:22 +0000556 DwarfStrOffDWOSection =
557 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
558 SectionKind::getMetadata());
Eric Christopher962c9082013-01-15 23:56:56 +0000559 DwarfAddrSection =
560 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
561 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000562}
563
564
565void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
David Majnemera9bdb322014-04-08 22:33:40 +0000566 // The object file format cannot represent common symbols with explicit
567 // alignments.
568 CommDirectiveSupportsAlignment = false;
569
Evan Cheng76792992011-07-20 05:58:47 +0000570 // COFF
David Majnemer3d96acb2013-08-13 01:23:53 +0000571 BSSSection =
572 Ctx->getCOFFSection(".bss",
573 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
574 COFF::IMAGE_SCN_MEM_READ |
575 COFF::IMAGE_SCN_MEM_WRITE,
576 SectionKind::getBSS());
Evan Cheng76792992011-07-20 05:58:47 +0000577 TextSection =
578 Ctx->getCOFFSection(".text",
579 COFF::IMAGE_SCN_CNT_CODE |
580 COFF::IMAGE_SCN_MEM_EXECUTE |
581 COFF::IMAGE_SCN_MEM_READ,
582 SectionKind::getText());
583 DataSection =
584 Ctx->getCOFFSection(".data",
585 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
586 COFF::IMAGE_SCN_MEM_READ |
587 COFF::IMAGE_SCN_MEM_WRITE,
588 SectionKind::getDataRel());
589 ReadOnlySection =
590 Ctx->getCOFFSection(".rdata",
591 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
592 COFF::IMAGE_SCN_MEM_READ,
593 SectionKind::getReadOnly());
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000594 if (T.isKnownWindowsMSVCEnvironment()) {
Michael J. Spencerb560d072012-02-23 21:56:08 +0000595 StaticCtorSection =
596 Ctx->getCOFFSection(".CRT$XCU",
597 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
598 COFF::IMAGE_SCN_MEM_READ,
599 SectionKind::getReadOnly());
600 } else {
601 StaticCtorSection =
602 Ctx->getCOFFSection(".ctors",
603 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
604 COFF::IMAGE_SCN_MEM_READ |
605 COFF::IMAGE_SCN_MEM_WRITE,
606 SectionKind::getDataRel());
607 }
608
609
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000610 if (T.isKnownWindowsMSVCEnvironment()) {
Anton Korobeynikov37d73002012-09-23 15:53:47 +0000611 StaticDtorSection =
612 Ctx->getCOFFSection(".CRT$XTX",
613 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
614 COFF::IMAGE_SCN_MEM_READ,
615 SectionKind::getReadOnly());
616 } else {
617 StaticDtorSection =
618 Ctx->getCOFFSection(".dtors",
619 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
620 COFF::IMAGE_SCN_MEM_READ |
621 COFF::IMAGE_SCN_MEM_WRITE,
622 SectionKind::getDataRel());
623 }
Evan Cheng76792992011-07-20 05:58:47 +0000624
625 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
626 // though it contains relocatable pointers. In PIC mode, this is probably a
627 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
628 // adjusted or this should be a data section.
Kai Nacke42097302013-07-08 04:43:23 +0000629 LSDASection =
630 Ctx->getCOFFSection(".gcc_except_table",
631 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
632 COFF::IMAGE_SCN_MEM_READ,
633 SectionKind::getReadOnly());
Evan Cheng76792992011-07-20 05:58:47 +0000634
635 // Debug info.
Timur Iskhodzhanov31377c52014-01-28 03:48:44 +0000636 COFFDebugSymbolsSection =
637 Ctx->getCOFFSection(".debug$S",
638 COFF::IMAGE_SCN_MEM_DISCARDABLE |
639 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
640 COFF::IMAGE_SCN_MEM_READ,
641 SectionKind::getMetadata());
642
Evan Cheng76792992011-07-20 05:58:47 +0000643 DwarfAbbrevSection =
644 Ctx->getCOFFSection(".debug_abbrev",
645 COFF::IMAGE_SCN_MEM_DISCARDABLE |
646 COFF::IMAGE_SCN_MEM_READ,
647 SectionKind::getMetadata());
648 DwarfInfoSection =
649 Ctx->getCOFFSection(".debug_info",
650 COFF::IMAGE_SCN_MEM_DISCARDABLE |
651 COFF::IMAGE_SCN_MEM_READ,
652 SectionKind::getMetadata());
653 DwarfLineSection =
654 Ctx->getCOFFSection(".debug_line",
655 COFF::IMAGE_SCN_MEM_DISCARDABLE |
656 COFF::IMAGE_SCN_MEM_READ,
657 SectionKind::getMetadata());
658 DwarfFrameSection =
659 Ctx->getCOFFSection(".debug_frame",
660 COFF::IMAGE_SCN_MEM_DISCARDABLE |
661 COFF::IMAGE_SCN_MEM_READ,
662 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000663 DwarfPubNamesSection =
664 Ctx->getCOFFSection(".debug_pubnames",
665 COFF::IMAGE_SCN_MEM_DISCARDABLE |
666 COFF::IMAGE_SCN_MEM_READ,
667 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000668 DwarfPubTypesSection =
669 Ctx->getCOFFSection(".debug_pubtypes",
670 COFF::IMAGE_SCN_MEM_DISCARDABLE |
671 COFF::IMAGE_SCN_MEM_READ,
672 SectionKind::getMetadata());
NAKAMURA Takumi0229e352013-09-10 06:01:56 +0000673 DwarfGnuPubNamesSection =
Eric Christopherb0e76942013-09-09 20:03:14 +0000674 Ctx->getCOFFSection(".debug_gnu_pubnames",
675 COFF::IMAGE_SCN_MEM_DISCARDABLE |
676 COFF::IMAGE_SCN_MEM_READ,
677 SectionKind::getMetadata());
NAKAMURA Takumi0229e352013-09-10 06:01:56 +0000678 DwarfGnuPubTypesSection =
Eric Christopherb0e76942013-09-09 20:03:14 +0000679 Ctx->getCOFFSection(".debug_gnu_pubtypes",
680 COFF::IMAGE_SCN_MEM_DISCARDABLE |
681 COFF::IMAGE_SCN_MEM_READ,
682 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000683 DwarfStrSection =
684 Ctx->getCOFFSection(".debug_str",
685 COFF::IMAGE_SCN_MEM_DISCARDABLE |
686 COFF::IMAGE_SCN_MEM_READ,
687 SectionKind::getMetadata());
688 DwarfLocSection =
689 Ctx->getCOFFSection(".debug_loc",
690 COFF::IMAGE_SCN_MEM_DISCARDABLE |
691 COFF::IMAGE_SCN_MEM_READ,
692 SectionKind::getMetadata());
693 DwarfARangesSection =
694 Ctx->getCOFFSection(".debug_aranges",
695 COFF::IMAGE_SCN_MEM_DISCARDABLE |
696 COFF::IMAGE_SCN_MEM_READ,
697 SectionKind::getMetadata());
698 DwarfRangesSection =
699 Ctx->getCOFFSection(".debug_ranges",
700 COFF::IMAGE_SCN_MEM_DISCARDABLE |
701 COFF::IMAGE_SCN_MEM_READ,
702 SectionKind::getMetadata());
703 DwarfMacroInfoSection =
704 Ctx->getCOFFSection(".debug_macinfo",
705 COFF::IMAGE_SCN_MEM_DISCARDABLE |
706 COFF::IMAGE_SCN_MEM_READ,
707 SectionKind::getMetadata());
David Blaikie62dd7df2014-03-26 03:05:10 +0000708 DwarfInfoDWOSection =
709 Ctx->getCOFFSection(".debug_info.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
710 COFF::IMAGE_SCN_MEM_READ,
711 SectionKind::getMetadata());
NAKAMURA Takumi9ba87f42014-05-16 11:14:51 +0000712 DwarfTypesDWOSection =
713 Ctx->getCOFFSection(".debug_types.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
714 COFF::IMAGE_SCN_MEM_READ,
715 SectionKind::getMetadata());
David Blaikie62dd7df2014-03-26 03:05:10 +0000716 DwarfAbbrevDWOSection =
717 Ctx->getCOFFSection(".debug_abbrev.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
718 COFF::IMAGE_SCN_MEM_READ,
719 SectionKind::getMetadata());
720 DwarfStrDWOSection =
721 Ctx->getCOFFSection(".debug_str.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
722 COFF::IMAGE_SCN_MEM_READ,
723 SectionKind::getMetadata());
724 DwarfLineDWOSection =
725 Ctx->getCOFFSection(".debug_line.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
726 COFF::IMAGE_SCN_MEM_READ,
727 SectionKind::getMetadata());
728 DwarfLocDWOSection =
729 Ctx->getCOFFSection(".debug_loc.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
730 COFF::IMAGE_SCN_MEM_READ,
731 SectionKind::getMetadata());
732 DwarfStrOffDWOSection =
733 Ctx->getCOFFSection(".debug_str_offsets.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
734 COFF::IMAGE_SCN_MEM_READ,
735 SectionKind::getMetadata());
736 DwarfAddrSection = Ctx->getCOFFSection(
737 ".debug_addr", COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_MEM_READ,
738 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000739
740 DrectveSection =
741 Ctx->getCOFFSection(".drectve",
Saleem Abdulrasoolec8c2db2014-05-21 05:15:01 +0000742 COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
Evan Cheng76792992011-07-20 05:58:47 +0000743 SectionKind::getMetadata());
744
745 PDataSection =
746 Ctx->getCOFFSection(".pdata",
747 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikovcc8c5392012-08-08 12:46:46 +0000748 COFF::IMAGE_SCN_MEM_READ,
Evan Cheng76792992011-07-20 05:58:47 +0000749 SectionKind::getDataRel());
750
751 XDataSection =
752 Ctx->getCOFFSection(".xdata",
753 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikovcc8c5392012-08-08 12:46:46 +0000754 COFF::IMAGE_SCN_MEM_READ,
Evan Cheng76792992011-07-20 05:58:47 +0000755 SectionKind::getDataRel());
Anton Korobeynikovc6b40172012-02-11 17:26:53 +0000756 TLSDataSection =
757 Ctx->getCOFFSection(".tls$",
758 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
759 COFF::IMAGE_SCN_MEM_READ |
760 COFF::IMAGE_SCN_MEM_WRITE,
761 SectionKind::getDataRel());
Evan Cheng76792992011-07-20 05:58:47 +0000762}
763
764void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000765 CodeModel::Model cm,
Evan Cheng76792992011-07-20 05:58:47 +0000766 MCContext &ctx) {
767 RelocM = relocm;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000768 CMModel = cm;
Evan Cheng76792992011-07-20 05:58:47 +0000769 Ctx = &ctx;
770
771 // Common.
772 CommDirectiveSupportsAlignment = true;
773 SupportsWeakOmittedEHFrame = true;
774 IsFunctionEHFrameSymbolPrivate = true;
Tim Northoverd1c6f512014-03-29 09:03:13 +0000775 SupportsCompactUnwindWithoutEHFrame = false;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000776
Rafael Espindolaaa7851d2014-05-12 13:47:05 +0000777 PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
778 dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000779
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000780 CompactUnwindDwarfEHFrameOnly = 0;
781
Craig Topperbb694de2014-04-13 04:57:38 +0000782 EHFrameSection = nullptr; // Created on demand.
783 CompactUnwindSection = nullptr; // Used only by selected targets.
784 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
785 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
786 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
787 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
Evan Cheng76792992011-07-20 05:58:47 +0000788
789 Triple T(TT);
790 Triple::ArchType Arch = T.getArch();
791 // FIXME: Checking for Arch here to filter out bogus triples such as
792 // cellspu-apple-darwin. Perhaps we should fix in Triple?
793 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
794 Arch == Triple::arm || Arch == Triple::thumb ||
Tim Northover00ed9962014-03-29 10:18:08 +0000795 Arch == Triple::arm64 ||
Evan Cheng76792992011-07-20 05:58:47 +0000796 Arch == Triple::ppc || Arch == Triple::ppc64 ||
797 Arch == Triple::UnknownArch) &&
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000798 (T.isOSDarwin() || T.isOSBinFormatMachO())) {
Evan Cheng76792992011-07-20 05:58:47 +0000799 Env = IsMachO;
800 InitMachOMCObjectFileInfo(T);
Saleem Abdulrasoolffdb92a702014-04-27 04:54:16 +0000801 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
802 Arch == Triple::arm || Arch == Triple::thumb) &&
803 (T.isOSWindows() && T.getObjectFormat() == Triple::COFF)) {
Evan Cheng76792992011-07-20 05:58:47 +0000804 Env = IsCOFF;
805 InitCOFFMCObjectFileInfo(T);
806 } else {
807 Env = IsELF;
808 InitELFMCObjectFileInfo(T);
809 }
810}
811
David Blaikiebc563272013-12-13 21:33:40 +0000812const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
813 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
814 SectionKind::getMetadata(), 0, utostr(Hash));
815}
816
David Chisnall85dd3092012-02-17 16:51:02 +0000817void MCObjectFileInfo::InitEHFrameSection() {
818 if (Env == IsMachO)
819 EHFrameSection =
820 Ctx->getMachOSection("__TEXT", "__eh_frame",
David Majnemer7b583052014-03-07 07:36:05 +0000821 MachO::S_COALESCED |
822 MachO::S_ATTR_NO_TOC |
823 MachO::S_ATTR_STRIP_STATIC_SYMS |
824 MachO::S_ATTR_LIVE_SUPPORT,
David Chisnall85dd3092012-02-17 16:51:02 +0000825 SectionKind::getReadOnly());
826 else if (Env == IsELF)
827 EHFrameSection =
David Chisnallbbec8722012-04-10 11:44:33 +0000828 Ctx->getELFSection(".eh_frame", EHSectionType,
David Chisnall07f8d3e2012-02-17 17:31:15 +0000829 EHSectionFlags,
David Chisnall85dd3092012-02-17 16:51:02 +0000830 SectionKind::getDataRel());
831 else
832 EHFrameSection =
833 Ctx->getCOFFSection(".eh_frame",
834 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
835 COFF::IMAGE_SCN_MEM_READ |
836 COFF::IMAGE_SCN_MEM_WRITE,
837 SectionKind::getDataRel());
838}