blob: ebc67acf4cc3c9ca128499ee11bafef45332b5a7 [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
Rafael Espindolabecdf632014-06-20 22:37:01 +000021static bool useCompactUnwind(const Triple &T) {
22 // Only on darwin.
23 if (!T.isOSDarwin())
24 return false;
25
26 // aarch64 always has it.
27 if (T.getArch() == Triple::arm64 || T.getArch() == Triple::aarch64)
28 return true;
29
30 // Use it on newer version of OS X.
31 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
32 return true;
33
34 return false;
35}
36
Evan Cheng76792992011-07-20 05:58:47 +000037void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
38 // MachO
39 IsFunctionEHFrameSymbolPrivate = false;
40 SupportsWeakOmittedEHFrame = false;
41
Tim Northover3b0846e2014-05-24 12:50:23 +000042 if (T.isOSDarwin() &&
43 (T.getArch() == Triple::arm64 || T.getArch() == Triple::aarch64))
Tim Northover00ed9962014-03-29 10:18:08 +000044 SupportsCompactUnwindWithoutEHFrame = true;
45
Evan Chengbbf3b0d2011-07-20 19:50:42 +000046 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
47 | dwarf::DW_EH_PE_sdata4;
Rafael Espindolaaa7851d2014-05-12 13:47:05 +000048 LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
Evan Chengbbf3b0d2011-07-20 19:50:42 +000049 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
50 dwarf::DW_EH_PE_sdata4;
51
Evan Cheng76792992011-07-20 05:58:47 +000052 // .comm doesn't support alignment before Leopard.
53 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
54 CommDirectiveSupportsAlignment = false;
55
56 TextSection // .text
57 = Ctx->getMachOSection("__TEXT", "__text",
David Majnemer7b583052014-03-07 07:36:05 +000058 MachO::S_ATTR_PURE_INSTRUCTIONS,
Evan Cheng76792992011-07-20 05:58:47 +000059 SectionKind::getText());
60 DataSection // .data
61 = Ctx->getMachOSection("__DATA", "__data", 0,
62 SectionKind::getDataRel());
63
NAKAMURA Takumi68fa6f92013-09-21 02:34:45 +000064 // BSSSection might not be expected initialized on msvc.
Craig Topperbb694de2014-04-13 04:57:38 +000065 BSSSection = nullptr;
NAKAMURA Takumi68fa6f92013-09-21 02:34:45 +000066
Evan Cheng76792992011-07-20 05:58:47 +000067 TLSDataSection // .tdata
68 = Ctx->getMachOSection("__DATA", "__thread_data",
David Majnemer7b583052014-03-07 07:36:05 +000069 MachO::S_THREAD_LOCAL_REGULAR,
Evan Cheng76792992011-07-20 05:58:47 +000070 SectionKind::getDataRel());
71 TLSBSSSection // .tbss
72 = Ctx->getMachOSection("__DATA", "__thread_bss",
David Majnemer7b583052014-03-07 07:36:05 +000073 MachO::S_THREAD_LOCAL_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +000074 SectionKind::getThreadBSS());
75
76 // TODO: Verify datarel below.
77 TLSTLVSection // .tlv
78 = Ctx->getMachOSection("__DATA", "__thread_vars",
David Majnemer7b583052014-03-07 07:36:05 +000079 MachO::S_THREAD_LOCAL_VARIABLES,
Evan Cheng76792992011-07-20 05:58:47 +000080 SectionKind::getDataRel());
81
82 TLSThreadInitSection
83 = Ctx->getMachOSection("__DATA", "__thread_init",
David Majnemer7b583052014-03-07 07:36:05 +000084 MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
Jim Grosbach0dde3492011-11-15 16:46:22 +000085 SectionKind::getDataRel());
Evan Cheng76792992011-07-20 05:58:47 +000086
87 CStringSection // .cstring
88 = Ctx->getMachOSection("__TEXT", "__cstring",
David Majnemer7b583052014-03-07 07:36:05 +000089 MachO::S_CSTRING_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +000090 SectionKind::getMergeable1ByteCString());
91 UStringSection
92 = Ctx->getMachOSection("__TEXT","__ustring", 0,
93 SectionKind::getMergeable2ByteCString());
94 FourByteConstantSection // .literal4
95 = Ctx->getMachOSection("__TEXT", "__literal4",
David Majnemer7b583052014-03-07 07:36:05 +000096 MachO::S_4BYTE_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +000097 SectionKind::getMergeableConst4());
98 EightByteConstantSection // .literal8
99 = Ctx->getMachOSection("__TEXT", "__literal8",
David Majnemer7b583052014-03-07 07:36:05 +0000100 MachO::S_8BYTE_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +0000101 SectionKind::getMergeableConst8());
102
Rafael Espindola1f3de492014-02-13 23:16:11 +0000103 SixteenByteConstantSection // .literal16
104 = Ctx->getMachOSection("__TEXT", "__literal16",
David Majnemer7b583052014-03-07 07:36:05 +0000105 MachO::S_16BYTE_LITERALS,
Rafael Espindola1f3de492014-02-13 23:16:11 +0000106 SectionKind::getMergeableConst16());
Evan Cheng76792992011-07-20 05:58:47 +0000107
108 ReadOnlySection // .const
109 = Ctx->getMachOSection("__TEXT", "__const", 0,
110 SectionKind::getReadOnly());
111
112 TextCoalSection
113 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
David Majnemer7b583052014-03-07 07:36:05 +0000114 MachO::S_COALESCED |
115 MachO::S_ATTR_PURE_INSTRUCTIONS,
Evan Cheng76792992011-07-20 05:58:47 +0000116 SectionKind::getText());
117 ConstTextCoalSection
118 = Ctx->getMachOSection("__TEXT", "__const_coal",
David Majnemer7b583052014-03-07 07:36:05 +0000119 MachO::S_COALESCED,
Evan Cheng76792992011-07-20 05:58:47 +0000120 SectionKind::getReadOnly());
121 ConstDataSection // .const_data
122 = Ctx->getMachOSection("__DATA", "__const", 0,
123 SectionKind::getReadOnlyWithRel());
124 DataCoalSection
125 = Ctx->getMachOSection("__DATA","__datacoal_nt",
David Majnemer7b583052014-03-07 07:36:05 +0000126 MachO::S_COALESCED,
Evan Cheng76792992011-07-20 05:58:47 +0000127 SectionKind::getDataRel());
128 DataCommonSection
129 = Ctx->getMachOSection("__DATA","__common",
David Majnemer7b583052014-03-07 07:36:05 +0000130 MachO::S_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +0000131 SectionKind::getBSS());
132 DataBSSSection
David Majnemer7b583052014-03-07 07:36:05 +0000133 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +0000134 SectionKind::getBSS());
135
136
137 LazySymbolPointerSection
138 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
David Majnemer7b583052014-03-07 07:36:05 +0000139 MachO::S_LAZY_SYMBOL_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000140 SectionKind::getMetadata());
141 NonLazySymbolPointerSection
142 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
David Majnemer7b583052014-03-07 07:36:05 +0000143 MachO::S_NON_LAZY_SYMBOL_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000144 SectionKind::getMetadata());
145
146 if (RelocM == Reloc::Static) {
147 StaticCtorSection
148 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
149 SectionKind::getDataRel());
150 StaticDtorSection
151 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
152 SectionKind::getDataRel());
153 } else {
154 StaticCtorSection
155 = Ctx->getMachOSection("__DATA", "__mod_init_func",
David Majnemer7b583052014-03-07 07:36:05 +0000156 MachO::S_MOD_INIT_FUNC_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000157 SectionKind::getDataRel());
158 StaticDtorSection
159 = Ctx->getMachOSection("__DATA", "__mod_term_func",
David Majnemer7b583052014-03-07 07:36:05 +0000160 MachO::S_MOD_TERM_FUNC_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000161 SectionKind::getDataRel());
162 }
163
164 // Exception Handling.
165 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
166 SectionKind::getReadOnlyWithRel());
167
Craig Topperbb694de2014-04-13 04:57:38 +0000168 COFFDebugSymbolsSection = nullptr;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000169
Rafael Espindolabecdf632014-06-20 22:37:01 +0000170 if (useCompactUnwind(T)) {
Evan Cheng76792992011-07-20 05:58:47 +0000171 CompactUnwindSection =
Rafael Espindolabecdf632014-06-20 22:37:01 +0000172 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
173 SectionKind::getReadOnly());
Evan Cheng76792992011-07-20 05:58:47 +0000174
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000175 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
176 CompactUnwindDwarfEHFrameOnly = 0x04000000;
Tim Northover3b0846e2014-05-24 12:50:23 +0000177 else if (T.getArch() == Triple::arm64 || T.getArch() == Triple::aarch64)
Tim Northover00ed9962014-03-29 10:18:08 +0000178 CompactUnwindDwarfEHFrameOnly = 0x03000000;
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000179 }
180
Evan Cheng76792992011-07-20 05:58:47 +0000181 // Debug Information.
Eric Christopher4996c702011-11-07 09:24:32 +0000182 DwarfAccelNamesSection =
183 Ctx->getMachOSection("__DWARF", "__apple_names",
David Majnemer7b583052014-03-07 07:36:05 +0000184 MachO::S_ATTR_DEBUG,
Eric Christopher4996c702011-11-07 09:24:32 +0000185 SectionKind::getMetadata());
186 DwarfAccelObjCSection =
187 Ctx->getMachOSection("__DWARF", "__apple_objc",
David Majnemer7b583052014-03-07 07:36:05 +0000188 MachO::S_ATTR_DEBUG,
Eric Christopher4996c702011-11-07 09:24:32 +0000189 SectionKind::getMetadata());
190 // 16 character section limit...
191 DwarfAccelNamespaceSection =
192 Ctx->getMachOSection("__DWARF", "__apple_namespac",
David Majnemer7b583052014-03-07 07:36:05 +0000193 MachO::S_ATTR_DEBUG,
Eric Christopher4996c702011-11-07 09:24:32 +0000194 SectionKind::getMetadata());
195 DwarfAccelTypesSection =
196 Ctx->getMachOSection("__DWARF", "__apple_types",
David Majnemer7b583052014-03-07 07:36:05 +0000197 MachO::S_ATTR_DEBUG,
Eric Christopher4996c702011-11-07 09:24:32 +0000198 SectionKind::getMetadata());
Jim Grosbachdc1e36e2012-05-11 01:41:30 +0000199
Evan Cheng76792992011-07-20 05:58:47 +0000200 DwarfAbbrevSection =
201 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
David Majnemer7b583052014-03-07 07:36:05 +0000202 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000203 SectionKind::getMetadata());
204 DwarfInfoSection =
205 Ctx->getMachOSection("__DWARF", "__debug_info",
David Majnemer7b583052014-03-07 07:36:05 +0000206 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000207 SectionKind::getMetadata());
208 DwarfLineSection =
209 Ctx->getMachOSection("__DWARF", "__debug_line",
David Majnemer7b583052014-03-07 07:36:05 +0000210 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000211 SectionKind::getMetadata());
212 DwarfFrameSection =
213 Ctx->getMachOSection("__DWARF", "__debug_frame",
David Majnemer7b583052014-03-07 07:36:05 +0000214 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000215 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000216 DwarfPubNamesSection =
217 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
David Majnemer7b583052014-03-07 07:36:05 +0000218 MachO::S_ATTR_DEBUG,
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000219 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000220 DwarfPubTypesSection =
221 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
David Majnemer7b583052014-03-07 07:36:05 +0000222 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000223 SectionKind::getMetadata());
Eric Christopherb0e76942013-09-09 20:03:14 +0000224 DwarfGnuPubNamesSection =
225 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
David Majnemer7b583052014-03-07 07:36:05 +0000226 MachO::S_ATTR_DEBUG,
Eric Christopherb0e76942013-09-09 20:03:14 +0000227 SectionKind::getMetadata());
228 DwarfGnuPubTypesSection =
229 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
David Majnemer7b583052014-03-07 07:36:05 +0000230 MachO::S_ATTR_DEBUG,
Eric Christopherb0e76942013-09-09 20:03:14 +0000231 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000232 DwarfStrSection =
233 Ctx->getMachOSection("__DWARF", "__debug_str",
David Majnemer7b583052014-03-07 07:36:05 +0000234 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000235 SectionKind::getMetadata());
236 DwarfLocSection =
237 Ctx->getMachOSection("__DWARF", "__debug_loc",
David Majnemer7b583052014-03-07 07:36:05 +0000238 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000239 SectionKind::getMetadata());
240 DwarfARangesSection =
241 Ctx->getMachOSection("__DWARF", "__debug_aranges",
David Majnemer7b583052014-03-07 07:36:05 +0000242 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000243 SectionKind::getMetadata());
244 DwarfRangesSection =
245 Ctx->getMachOSection("__DWARF", "__debug_ranges",
David Majnemer7b583052014-03-07 07:36:05 +0000246 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000247 SectionKind::getMetadata());
248 DwarfMacroInfoSection =
249 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
David Majnemer7b583052014-03-07 07:36:05 +0000250 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000251 SectionKind::getMetadata());
252 DwarfDebugInlineSection =
253 Ctx->getMachOSection("__DWARF", "__debug_inlined",
David Majnemer7b583052014-03-07 07:36:05 +0000254 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000255 SectionKind::getMetadata());
Lang Hames30789772013-11-08 22:14:49 +0000256 StackMapSection =
257 Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
258 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000259
260 TLSExtraDataSection = TLSTLVSection;
261}
262
263void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000264 switch (T.getArch()) {
265 case Triple::mips:
266 case Triple::mipsel:
Rafael Espindolab9b7ae02013-04-03 03:13:19 +0000267 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000268 break;
269 case Triple::mips64:
270 case Triple::mips64el:
Rafael Espindolab9b7ae02013-04-03 03:13:19 +0000271 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000272 break;
273 default:
Rafael Espindolaef9d3492013-03-15 05:51:57 +0000274 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000275 break;
276 }
Rafael Espindolaef9d3492013-03-15 05:51:57 +0000277
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000278 switch (T.getArch()) {
Joerg Sonnenbergercf86ce12014-05-07 07:49:34 +0000279 case Triple::arm:
280 case Triple::armeb:
281 case Triple::thumb:
282 case Triple::thumbeb:
Joerg Sonnenberger94cbb662014-05-13 17:58:13 +0000283 if (Ctx->getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
284 break;
285 // Fallthrough if not using EHABI
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000286 case Triple::x86:
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000287 PersonalityEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach0dde3492011-11-15 16:46:22 +0000288 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
289 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000290 LSDAEncoding = (RelocM == Reloc::PIC_)
291 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
292 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000293 TTypeEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach0dde3492011-11-15 16:46:22 +0000294 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
295 : dwarf::DW_EH_PE_absptr;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000296 break;
297 case Triple::x86_64:
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000298 if (RelocM == Reloc::PIC_) {
299 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
300 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
301 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
302 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
303 (CMModel == CodeModel::Small
304 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000305 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
306 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
307 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
308 } else {
309 PersonalityEncoding =
310 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
311 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
312 LSDAEncoding = (CMModel == CodeModel::Small)
313 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000314 TTypeEncoding = (CMModel == CodeModel::Small)
315 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
316 }
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000317 break;
318 case Triple::aarch64:
319 case Triple::aarch64_be:
320 case Triple::arm64:
321 case Triple::arm64_be:
Tim Northovere0e3aef2013-01-31 12:12:40 +0000322 // The small model guarantees static code/data size < 4GB, but not where it
323 // will be in memory. Most of these could end up >2GB away so even a signed
324 // pc-relative 32-bit address is insufficient, theoretically.
325 if (RelocM == Reloc::PIC_) {
326 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
327 dwarf::DW_EH_PE_sdata8;
328 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
Tim Northovere0e3aef2013-01-31 12:12:40 +0000329 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
330 dwarf::DW_EH_PE_sdata8;
331 } else {
332 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
333 LSDAEncoding = dwarf::DW_EH_PE_absptr;
Tim Northovere0e3aef2013-01-31 12:12:40 +0000334 TTypeEncoding = dwarf::DW_EH_PE_absptr;
335 }
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000336 break;
Logan Chienc0029812014-05-30 16:48:56 +0000337 case Triple::mips:
338 case Triple::mipsel:
339 // MIPS uses indirect pointer to refer personality functions, so that the
340 // eh_frame section can be read-only. DW.ref.personality will be generated
341 // for relocation.
342 PersonalityEncoding = dwarf::DW_EH_PE_indirect;
343 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000344 case Triple::ppc64:
345 case Triple::ppc64le:
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000346 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
347 dwarf::DW_EH_PE_udata8;
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000348 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000349 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
350 dwarf::DW_EH_PE_udata8;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000351 break;
352 case Triple::sparc:
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000353 if (RelocM == Reloc::PIC_) {
354 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
355 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
356 dwarf::DW_EH_PE_sdata4;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000357 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
358 dwarf::DW_EH_PE_sdata4;
359 } else {
360 LSDAEncoding = dwarf::DW_EH_PE_absptr;
361 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000362 TTypeEncoding = dwarf::DW_EH_PE_absptr;
363 }
Joerg Sonnenbergerfa9cf652014-04-30 23:36:24 +0000364 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000365 case Triple::sparcv9:
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000366 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
367 if (RelocM == Reloc::PIC_) {
368 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
369 dwarf::DW_EH_PE_sdata4;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000370 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
371 dwarf::DW_EH_PE_sdata4;
372 } else {
373 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000374 TTypeEncoding = dwarf::DW_EH_PE_absptr;
375 }
Joerg Sonnenbergerfa9cf652014-04-30 23:36:24 +0000376 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000377 case Triple::systemz:
Ulrich Weigand0213e7f2013-05-06 16:11:12 +0000378 // All currently-defined code models guarantee that 4-byte PC-relative
379 // values will be in range.
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000380 if (RelocM == Reloc::PIC_) {
381 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
382 dwarf::DW_EH_PE_sdata4;
383 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000384 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
385 dwarf::DW_EH_PE_sdata4;
386 } else {
387 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
388 LSDAEncoding = dwarf::DW_EH_PE_absptr;
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000389 TTypeEncoding = dwarf::DW_EH_PE_absptr;
390 }
Joerg Sonnenbergerfa9cf652014-04-30 23:36:24 +0000391 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000392 default:
393 break;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000394 }
395
David Chisnall07f8d3e2012-02-17 17:31:15 +0000396 // Solaris requires different flags for .eh_frame to seemingly every other
397 // platform.
David Chisnallbbec8722012-04-10 11:44:33 +0000398 EHSectionType = ELF::SHT_PROGBITS;
David Chisnall07f8d3e2012-02-17 17:31:15 +0000399 EHSectionFlags = ELF::SHF_ALLOC;
David Chisnallbbec8722012-04-10 11:44:33 +0000400 if (T.getOS() == Triple::Solaris) {
401 if (T.getArch() == Triple::x86_64)
402 EHSectionType = ELF::SHT_X86_64_UNWIND;
403 else
404 EHSectionFlags |= ELF::SHF_WRITE;
405 }
David Chisnall07f8d3e2012-02-17 17:31:15 +0000406
407
Evan Cheng76792992011-07-20 05:58:47 +0000408 // ELF
409 BSSSection =
410 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
Anton Korobeynikov7722a2d2012-01-25 22:24:19 +0000411 ELF::SHF_WRITE | ELF::SHF_ALLOC,
Evan Cheng76792992011-07-20 05:58:47 +0000412 SectionKind::getBSS());
413
414 TextSection =
415 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
416 ELF::SHF_EXECINSTR |
417 ELF::SHF_ALLOC,
418 SectionKind::getText());
419
420 DataSection =
421 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
422 ELF::SHF_WRITE |ELF::SHF_ALLOC,
423 SectionKind::getDataRel());
424
425 ReadOnlySection =
426 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
427 ELF::SHF_ALLOC,
428 SectionKind::getReadOnly());
429
430 TLSDataSection =
431 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
432 ELF::SHF_ALLOC | ELF::SHF_TLS |
433 ELF::SHF_WRITE,
434 SectionKind::getThreadData());
435
436 TLSBSSSection =
437 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
438 ELF::SHF_ALLOC | ELF::SHF_TLS |
439 ELF::SHF_WRITE,
440 SectionKind::getThreadBSS());
441
442 DataRelSection =
443 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
444 ELF::SHF_ALLOC |ELF::SHF_WRITE,
445 SectionKind::getDataRel());
446
447 DataRelLocalSection =
448 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
449 ELF::SHF_ALLOC |ELF::SHF_WRITE,
450 SectionKind::getDataRelLocal());
451
452 DataRelROSection =
453 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
454 ELF::SHF_ALLOC |ELF::SHF_WRITE,
455 SectionKind::getReadOnlyWithRel());
456
457 DataRelROLocalSection =
458 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
459 ELF::SHF_ALLOC |ELF::SHF_WRITE,
460 SectionKind::getReadOnlyWithRelLocal());
461
462 MergeableConst4Section =
463 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
464 ELF::SHF_ALLOC |ELF::SHF_MERGE,
465 SectionKind::getMergeableConst4());
466
467 MergeableConst8Section =
468 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
469 ELF::SHF_ALLOC |ELF::SHF_MERGE,
470 SectionKind::getMergeableConst8());
471
472 MergeableConst16Section =
473 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
474 ELF::SHF_ALLOC |ELF::SHF_MERGE,
475 SectionKind::getMergeableConst16());
476
477 StaticCtorSection =
478 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
479 ELF::SHF_ALLOC |ELF::SHF_WRITE,
480 SectionKind::getDataRel());
481
482 StaticDtorSection =
483 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
484 ELF::SHF_ALLOC |ELF::SHF_WRITE,
485 SectionKind::getDataRel());
486
487 // Exception Handling Sections.
488
489 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
490 // it contains relocatable pointers. In PIC mode, this is probably a big
491 // runtime hit for C++ apps. Either the contents of the LSDA need to be
492 // adjusted or this should be a data section.
493 LSDASection =
494 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
495 ELF::SHF_ALLOC,
496 SectionKind::getReadOnly());
497
Craig Topperbb694de2014-04-13 04:57:38 +0000498 COFFDebugSymbolsSection = nullptr;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000499
Evan Cheng76792992011-07-20 05:58:47 +0000500 // Debug Info Sections.
501 DwarfAbbrevSection =
502 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
503 SectionKind::getMetadata());
504 DwarfInfoSection =
505 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
506 SectionKind::getMetadata());
507 DwarfLineSection =
508 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
509 SectionKind::getMetadata());
510 DwarfFrameSection =
511 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
512 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000513 DwarfPubNamesSection =
514 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
515 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000516 DwarfPubTypesSection =
517 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
518 SectionKind::getMetadata());
Eric Christopherb0e76942013-09-09 20:03:14 +0000519 DwarfGnuPubNamesSection =
520 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
521 SectionKind::getMetadata());
522 DwarfGnuPubTypesSection =
523 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
524 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000525 DwarfStrSection =
Nick Lewycky1a62d782011-10-26 18:44:32 +0000526 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
527 ELF::SHF_MERGE | ELF::SHF_STRINGS,
528 SectionKind::getMergeable1ByteCString());
Evan Cheng76792992011-07-20 05:58:47 +0000529 DwarfLocSection =
530 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
531 SectionKind::getMetadata());
532 DwarfARangesSection =
533 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
534 SectionKind::getMetadata());
535 DwarfRangesSection =
536 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
537 SectionKind::getMetadata());
538 DwarfMacroInfoSection =
539 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
540 SectionKind::getMetadata());
Eric Christopher27ed8ec2012-11-28 02:49:34 +0000541
542 // DWARF5 Experimental Debug Info
543
544 // Accelerator Tables
Eric Christophera0ad67d2012-10-08 21:41:30 +0000545 DwarfAccelNamesSection =
546 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
547 SectionKind::getMetadata());
548 DwarfAccelObjCSection =
549 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
550 SectionKind::getMetadata());
551 DwarfAccelNamespaceSection =
552 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
553 SectionKind::getMetadata());
554 DwarfAccelTypesSection =
555 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
556 SectionKind::getMetadata());
Eric Christopherc3b434b2012-11-28 02:49:38 +0000557
558 // Fission Sections
559 DwarfInfoDWOSection =
560 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
561 SectionKind::getMetadata());
Eric Christopher3c230092012-11-30 06:47:06 +0000562 DwarfAbbrevDWOSection =
563 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
564 SectionKind::getMetadata());
565 DwarfStrDWOSection =
566 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
567 ELF::SHF_MERGE | ELF::SHF_STRINGS,
568 SectionKind::getMergeable1ByteCString());
569 DwarfLineDWOSection =
570 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
571 SectionKind::getMetadata());
572 DwarfLocDWOSection =
573 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
574 SectionKind::getMetadata());
Eric Christopherc0fa8672013-01-04 17:59:22 +0000575 DwarfStrOffDWOSection =
576 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
577 SectionKind::getMetadata());
Eric Christopher962c9082013-01-15 23:56:56 +0000578 DwarfAddrSection =
579 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
580 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000581}
582
583
584void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
Saleem Abdulrasool70a02062014-06-08 03:57:49 +0000585 bool IsWoA = T.getArch() == Triple::arm || T.getArch() == Triple::thumb;
586
David Majnemera9bdb322014-04-08 22:33:40 +0000587 // The object file format cannot represent common symbols with explicit
588 // alignments.
589 CommDirectiveSupportsAlignment = false;
590
Evan Cheng76792992011-07-20 05:58:47 +0000591 // COFF
David Majnemer3d96acb2013-08-13 01:23:53 +0000592 BSSSection =
593 Ctx->getCOFFSection(".bss",
594 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
595 COFF::IMAGE_SCN_MEM_READ |
596 COFF::IMAGE_SCN_MEM_WRITE,
597 SectionKind::getBSS());
Evan Cheng76792992011-07-20 05:58:47 +0000598 TextSection =
599 Ctx->getCOFFSection(".text",
Patrik Hagglundaad35e72014-06-09 07:35:07 +0000600 (IsWoA ? COFF::IMAGE_SCN_MEM_16BIT
601 : (COFF::SectionCharacteristics)0) |
Evan Cheng76792992011-07-20 05:58:47 +0000602 COFF::IMAGE_SCN_CNT_CODE |
603 COFF::IMAGE_SCN_MEM_EXECUTE |
604 COFF::IMAGE_SCN_MEM_READ,
605 SectionKind::getText());
606 DataSection =
607 Ctx->getCOFFSection(".data",
608 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
609 COFF::IMAGE_SCN_MEM_READ |
610 COFF::IMAGE_SCN_MEM_WRITE,
611 SectionKind::getDataRel());
612 ReadOnlySection =
613 Ctx->getCOFFSection(".rdata",
614 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
615 COFF::IMAGE_SCN_MEM_READ,
616 SectionKind::getReadOnly());
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000617
Saleem Abdulrasooled7fc4b2014-06-08 00:34:27 +0000618 if (T.isKnownWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
Michael J. Spencerb560d072012-02-23 21:56:08 +0000619 StaticCtorSection =
620 Ctx->getCOFFSection(".CRT$XCU",
621 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
622 COFF::IMAGE_SCN_MEM_READ,
623 SectionKind::getReadOnly());
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000624 StaticDtorSection =
625 Ctx->getCOFFSection(".CRT$XTX",
626 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
627 COFF::IMAGE_SCN_MEM_READ,
628 SectionKind::getReadOnly());
Michael J. Spencerb560d072012-02-23 21:56:08 +0000629 } else {
630 StaticCtorSection =
631 Ctx->getCOFFSection(".ctors",
632 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
633 COFF::IMAGE_SCN_MEM_READ |
634 COFF::IMAGE_SCN_MEM_WRITE,
635 SectionKind::getDataRel());
Anton Korobeynikov37d73002012-09-23 15:53:47 +0000636 StaticDtorSection =
637 Ctx->getCOFFSection(".dtors",
638 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
639 COFF::IMAGE_SCN_MEM_READ |
640 COFF::IMAGE_SCN_MEM_WRITE,
641 SectionKind::getDataRel());
642 }
Evan Cheng76792992011-07-20 05:58:47 +0000643
644 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
645 // though it contains relocatable pointers. In PIC mode, this is probably a
646 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
647 // adjusted or this should be a data section.
Reid Kleckner4a012302014-06-20 20:35:47 +0000648 assert(T.isOSWindows() && "Windows is the only supported COFF target");
649 if (T.getArch() == Triple::x86_64) {
650 // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
651 LSDASection = 0;
652 } else {
653 LSDASection = Ctx->getCOFFSection(".gcc_except_table",
654 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
655 COFF::IMAGE_SCN_MEM_READ,
656 SectionKind::getReadOnly());
657 }
Evan Cheng76792992011-07-20 05:58:47 +0000658
659 // Debug info.
Timur Iskhodzhanov31377c52014-01-28 03:48:44 +0000660 COFFDebugSymbolsSection =
661 Ctx->getCOFFSection(".debug$S",
662 COFF::IMAGE_SCN_MEM_DISCARDABLE |
663 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
664 COFF::IMAGE_SCN_MEM_READ,
665 SectionKind::getMetadata());
666
Evan Cheng76792992011-07-20 05:58:47 +0000667 DwarfAbbrevSection =
668 Ctx->getCOFFSection(".debug_abbrev",
669 COFF::IMAGE_SCN_MEM_DISCARDABLE |
670 COFF::IMAGE_SCN_MEM_READ,
671 SectionKind::getMetadata());
672 DwarfInfoSection =
673 Ctx->getCOFFSection(".debug_info",
674 COFF::IMAGE_SCN_MEM_DISCARDABLE |
675 COFF::IMAGE_SCN_MEM_READ,
676 SectionKind::getMetadata());
677 DwarfLineSection =
678 Ctx->getCOFFSection(".debug_line",
679 COFF::IMAGE_SCN_MEM_DISCARDABLE |
680 COFF::IMAGE_SCN_MEM_READ,
681 SectionKind::getMetadata());
682 DwarfFrameSection =
683 Ctx->getCOFFSection(".debug_frame",
684 COFF::IMAGE_SCN_MEM_DISCARDABLE |
685 COFF::IMAGE_SCN_MEM_READ,
686 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000687 DwarfPubNamesSection =
688 Ctx->getCOFFSection(".debug_pubnames",
689 COFF::IMAGE_SCN_MEM_DISCARDABLE |
690 COFF::IMAGE_SCN_MEM_READ,
691 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000692 DwarfPubTypesSection =
693 Ctx->getCOFFSection(".debug_pubtypes",
694 COFF::IMAGE_SCN_MEM_DISCARDABLE |
695 COFF::IMAGE_SCN_MEM_READ,
696 SectionKind::getMetadata());
NAKAMURA Takumi0229e352013-09-10 06:01:56 +0000697 DwarfGnuPubNamesSection =
Eric Christopherb0e76942013-09-09 20:03:14 +0000698 Ctx->getCOFFSection(".debug_gnu_pubnames",
699 COFF::IMAGE_SCN_MEM_DISCARDABLE |
700 COFF::IMAGE_SCN_MEM_READ,
701 SectionKind::getMetadata());
NAKAMURA Takumi0229e352013-09-10 06:01:56 +0000702 DwarfGnuPubTypesSection =
Eric Christopherb0e76942013-09-09 20:03:14 +0000703 Ctx->getCOFFSection(".debug_gnu_pubtypes",
704 COFF::IMAGE_SCN_MEM_DISCARDABLE |
705 COFF::IMAGE_SCN_MEM_READ,
706 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000707 DwarfStrSection =
708 Ctx->getCOFFSection(".debug_str",
709 COFF::IMAGE_SCN_MEM_DISCARDABLE |
710 COFF::IMAGE_SCN_MEM_READ,
711 SectionKind::getMetadata());
712 DwarfLocSection =
713 Ctx->getCOFFSection(".debug_loc",
714 COFF::IMAGE_SCN_MEM_DISCARDABLE |
715 COFF::IMAGE_SCN_MEM_READ,
716 SectionKind::getMetadata());
717 DwarfARangesSection =
718 Ctx->getCOFFSection(".debug_aranges",
719 COFF::IMAGE_SCN_MEM_DISCARDABLE |
720 COFF::IMAGE_SCN_MEM_READ,
721 SectionKind::getMetadata());
722 DwarfRangesSection =
723 Ctx->getCOFFSection(".debug_ranges",
724 COFF::IMAGE_SCN_MEM_DISCARDABLE |
725 COFF::IMAGE_SCN_MEM_READ,
726 SectionKind::getMetadata());
727 DwarfMacroInfoSection =
728 Ctx->getCOFFSection(".debug_macinfo",
729 COFF::IMAGE_SCN_MEM_DISCARDABLE |
730 COFF::IMAGE_SCN_MEM_READ,
731 SectionKind::getMetadata());
David Blaikie62dd7df2014-03-26 03:05:10 +0000732 DwarfInfoDWOSection =
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000733 Ctx->getCOFFSection(".debug_info.dwo",
734 COFF::IMAGE_SCN_MEM_DISCARDABLE |
735 COFF::IMAGE_SCN_MEM_READ,
David Blaikie62dd7df2014-03-26 03:05:10 +0000736 SectionKind::getMetadata());
737 DwarfAbbrevDWOSection =
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000738 Ctx->getCOFFSection(".debug_abbrev.dwo",
739 COFF::IMAGE_SCN_MEM_DISCARDABLE |
740 COFF::IMAGE_SCN_MEM_READ,
David Blaikie62dd7df2014-03-26 03:05:10 +0000741 SectionKind::getMetadata());
742 DwarfStrDWOSection =
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000743 Ctx->getCOFFSection(".debug_str.dwo",
744 COFF::IMAGE_SCN_MEM_DISCARDABLE |
745 COFF::IMAGE_SCN_MEM_READ,
David Blaikie62dd7df2014-03-26 03:05:10 +0000746 SectionKind::getMetadata());
747 DwarfLineDWOSection =
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000748 Ctx->getCOFFSection(".debug_line.dwo",
749 COFF::IMAGE_SCN_MEM_DISCARDABLE |
750 COFF::IMAGE_SCN_MEM_READ,
David Blaikie62dd7df2014-03-26 03:05:10 +0000751 SectionKind::getMetadata());
752 DwarfLocDWOSection =
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000753 Ctx->getCOFFSection(".debug_loc.dwo",
754 COFF::IMAGE_SCN_MEM_DISCARDABLE |
755 COFF::IMAGE_SCN_MEM_READ,
David Blaikie62dd7df2014-03-26 03:05:10 +0000756 SectionKind::getMetadata());
757 DwarfStrOffDWOSection =
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000758 Ctx->getCOFFSection(".debug_str_offsets.dwo",
759 COFF::IMAGE_SCN_MEM_DISCARDABLE |
760 COFF::IMAGE_SCN_MEM_READ,
David Blaikie62dd7df2014-03-26 03:05:10 +0000761 SectionKind::getMetadata());
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000762
763 DwarfAddrSection =
764 Ctx->getCOFFSection(".debug_addr",
765 COFF::IMAGE_SCN_MEM_DISCARDABLE |
766 COFF::IMAGE_SCN_MEM_READ,
767 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000768
769 DrectveSection =
770 Ctx->getCOFFSection(".drectve",
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000771 COFF::IMAGE_SCN_LNK_INFO |
772 COFF::IMAGE_SCN_LNK_REMOVE,
Evan Cheng76792992011-07-20 05:58:47 +0000773 SectionKind::getMetadata());
774
775 PDataSection =
776 Ctx->getCOFFSection(".pdata",
777 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikovcc8c5392012-08-08 12:46:46 +0000778 COFF::IMAGE_SCN_MEM_READ,
Evan Cheng76792992011-07-20 05:58:47 +0000779 SectionKind::getDataRel());
780
781 XDataSection =
782 Ctx->getCOFFSection(".xdata",
783 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikovcc8c5392012-08-08 12:46:46 +0000784 COFF::IMAGE_SCN_MEM_READ,
Evan Cheng76792992011-07-20 05:58:47 +0000785 SectionKind::getDataRel());
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000786
Anton Korobeynikovc6b40172012-02-11 17:26:53 +0000787 TLSDataSection =
788 Ctx->getCOFFSection(".tls$",
789 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
790 COFF::IMAGE_SCN_MEM_READ |
791 COFF::IMAGE_SCN_MEM_WRITE,
792 SectionKind::getDataRel());
Evan Cheng76792992011-07-20 05:58:47 +0000793}
794
795void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000796 CodeModel::Model cm,
Evan Cheng76792992011-07-20 05:58:47 +0000797 MCContext &ctx) {
798 RelocM = relocm;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000799 CMModel = cm;
Evan Cheng76792992011-07-20 05:58:47 +0000800 Ctx = &ctx;
801
802 // Common.
803 CommDirectiveSupportsAlignment = true;
804 SupportsWeakOmittedEHFrame = true;
805 IsFunctionEHFrameSymbolPrivate = true;
Tim Northoverd1c6f512014-03-29 09:03:13 +0000806 SupportsCompactUnwindWithoutEHFrame = false;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000807
Rafael Espindolaaa7851d2014-05-12 13:47:05 +0000808 PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
809 dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000810
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000811 CompactUnwindDwarfEHFrameOnly = 0;
812
Craig Topperbb694de2014-04-13 04:57:38 +0000813 EHFrameSection = nullptr; // Created on demand.
814 CompactUnwindSection = nullptr; // Used only by selected targets.
815 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
816 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
817 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
818 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
Evan Cheng76792992011-07-20 05:58:47 +0000819
820 Triple T(TT);
821 Triple::ArchType Arch = T.getArch();
822 // FIXME: Checking for Arch here to filter out bogus triples such as
823 // cellspu-apple-darwin. Perhaps we should fix in Triple?
824 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
825 Arch == Triple::arm || Arch == Triple::thumb ||
Tim Northover3b0846e2014-05-24 12:50:23 +0000826 Arch == Triple::arm64 || Arch == Triple::aarch64 ||
Evan Cheng76792992011-07-20 05:58:47 +0000827 Arch == Triple::ppc || Arch == Triple::ppc64 ||
828 Arch == Triple::UnknownArch) &&
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000829 (T.isOSDarwin() || T.isOSBinFormatMachO())) {
Evan Cheng76792992011-07-20 05:58:47 +0000830 Env = IsMachO;
831 InitMachOMCObjectFileInfo(T);
Saleem Abdulrasoolffdb92a702014-04-27 04:54:16 +0000832 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
833 Arch == Triple::arm || Arch == Triple::thumb) &&
834 (T.isOSWindows() && T.getObjectFormat() == Triple::COFF)) {
Evan Cheng76792992011-07-20 05:58:47 +0000835 Env = IsCOFF;
836 InitCOFFMCObjectFileInfo(T);
837 } else {
838 Env = IsELF;
839 InitELFMCObjectFileInfo(T);
840 }
841}
842
David Blaikiebc563272013-12-13 21:33:40 +0000843const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
844 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
845 SectionKind::getMetadata(), 0, utostr(Hash));
846}
847
David Blaikie2da282b2014-05-21 23:27:41 +0000848const MCSection *
849MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
850 return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS,
851 ELF::SHF_GROUP, SectionKind::getMetadata(), 0,
852 utostr(Hash));
853}
854
David Chisnall85dd3092012-02-17 16:51:02 +0000855void MCObjectFileInfo::InitEHFrameSection() {
856 if (Env == IsMachO)
857 EHFrameSection =
858 Ctx->getMachOSection("__TEXT", "__eh_frame",
David Majnemer7b583052014-03-07 07:36:05 +0000859 MachO::S_COALESCED |
860 MachO::S_ATTR_NO_TOC |
861 MachO::S_ATTR_STRIP_STATIC_SYMS |
862 MachO::S_ATTR_LIVE_SUPPORT,
David Chisnall85dd3092012-02-17 16:51:02 +0000863 SectionKind::getReadOnly());
864 else if (Env == IsELF)
865 EHFrameSection =
David Chisnallbbec8722012-04-10 11:44:33 +0000866 Ctx->getELFSection(".eh_frame", EHSectionType,
David Chisnall07f8d3e2012-02-17 17:31:15 +0000867 EHSectionFlags,
David Chisnall85dd3092012-02-17 16:51:02 +0000868 SectionKind::getDataRel());
869 else
870 EHFrameSection =
871 Ctx->getCOFFSection(".eh_frame",
872 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
873 COFF::IMAGE_SCN_MEM_READ |
874 COFF::IMAGE_SCN_MEM_WRITE,
875 SectionKind::getDataRel());
876}