blob: b9ba011a6731fbce5ea94b4329d678d2dc105d81 [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
Rafael Espindolac3510c72014-06-20 22:40:55 +000034 // And the iOS simulator.
35 if (T.isiOS() &&
36 (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86))
37 return true;
38
Rafael Espindolabecdf632014-06-20 22:37:01 +000039 return false;
40}
41
Evan Cheng76792992011-07-20 05:58:47 +000042void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
43 // MachO
44 IsFunctionEHFrameSymbolPrivate = false;
45 SupportsWeakOmittedEHFrame = false;
46
Tim Northover3b0846e2014-05-24 12:50:23 +000047 if (T.isOSDarwin() &&
48 (T.getArch() == Triple::arm64 || T.getArch() == Triple::aarch64))
Tim Northover00ed9962014-03-29 10:18:08 +000049 SupportsCompactUnwindWithoutEHFrame = true;
50
Evan Chengbbf3b0d2011-07-20 19:50:42 +000051 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
52 | dwarf::DW_EH_PE_sdata4;
Rafael Espindolaaa7851d2014-05-12 13:47:05 +000053 LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
Evan Chengbbf3b0d2011-07-20 19:50:42 +000054 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
55 dwarf::DW_EH_PE_sdata4;
56
Evan Cheng76792992011-07-20 05:58:47 +000057 // .comm doesn't support alignment before Leopard.
58 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
59 CommDirectiveSupportsAlignment = false;
60
61 TextSection // .text
62 = Ctx->getMachOSection("__TEXT", "__text",
David Majnemer7b583052014-03-07 07:36:05 +000063 MachO::S_ATTR_PURE_INSTRUCTIONS,
Evan Cheng76792992011-07-20 05:58:47 +000064 SectionKind::getText());
65 DataSection // .data
66 = Ctx->getMachOSection("__DATA", "__data", 0,
67 SectionKind::getDataRel());
68
NAKAMURA Takumi68fa6f92013-09-21 02:34:45 +000069 // BSSSection might not be expected initialized on msvc.
Craig Topperbb694de2014-04-13 04:57:38 +000070 BSSSection = nullptr;
NAKAMURA Takumi68fa6f92013-09-21 02:34:45 +000071
Evan Cheng76792992011-07-20 05:58:47 +000072 TLSDataSection // .tdata
73 = Ctx->getMachOSection("__DATA", "__thread_data",
David Majnemer7b583052014-03-07 07:36:05 +000074 MachO::S_THREAD_LOCAL_REGULAR,
Evan Cheng76792992011-07-20 05:58:47 +000075 SectionKind::getDataRel());
76 TLSBSSSection // .tbss
77 = Ctx->getMachOSection("__DATA", "__thread_bss",
David Majnemer7b583052014-03-07 07:36:05 +000078 MachO::S_THREAD_LOCAL_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +000079 SectionKind::getThreadBSS());
80
81 // TODO: Verify datarel below.
82 TLSTLVSection // .tlv
83 = Ctx->getMachOSection("__DATA", "__thread_vars",
David Majnemer7b583052014-03-07 07:36:05 +000084 MachO::S_THREAD_LOCAL_VARIABLES,
Evan Cheng76792992011-07-20 05:58:47 +000085 SectionKind::getDataRel());
86
87 TLSThreadInitSection
88 = Ctx->getMachOSection("__DATA", "__thread_init",
David Majnemer7b583052014-03-07 07:36:05 +000089 MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
Jim Grosbach0dde3492011-11-15 16:46:22 +000090 SectionKind::getDataRel());
Evan Cheng76792992011-07-20 05:58:47 +000091
92 CStringSection // .cstring
93 = Ctx->getMachOSection("__TEXT", "__cstring",
David Majnemer7b583052014-03-07 07:36:05 +000094 MachO::S_CSTRING_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +000095 SectionKind::getMergeable1ByteCString());
96 UStringSection
97 = Ctx->getMachOSection("__TEXT","__ustring", 0,
98 SectionKind::getMergeable2ByteCString());
99 FourByteConstantSection // .literal4
100 = Ctx->getMachOSection("__TEXT", "__literal4",
David Majnemer7b583052014-03-07 07:36:05 +0000101 MachO::S_4BYTE_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +0000102 SectionKind::getMergeableConst4());
103 EightByteConstantSection // .literal8
104 = Ctx->getMachOSection("__TEXT", "__literal8",
David Majnemer7b583052014-03-07 07:36:05 +0000105 MachO::S_8BYTE_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +0000106 SectionKind::getMergeableConst8());
107
Rafael Espindola1f3de492014-02-13 23:16:11 +0000108 SixteenByteConstantSection // .literal16
109 = Ctx->getMachOSection("__TEXT", "__literal16",
David Majnemer7b583052014-03-07 07:36:05 +0000110 MachO::S_16BYTE_LITERALS,
Rafael Espindola1f3de492014-02-13 23:16:11 +0000111 SectionKind::getMergeableConst16());
Evan Cheng76792992011-07-20 05:58:47 +0000112
113 ReadOnlySection // .const
114 = Ctx->getMachOSection("__TEXT", "__const", 0,
115 SectionKind::getReadOnly());
116
117 TextCoalSection
118 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
David Majnemer7b583052014-03-07 07:36:05 +0000119 MachO::S_COALESCED |
120 MachO::S_ATTR_PURE_INSTRUCTIONS,
Evan Cheng76792992011-07-20 05:58:47 +0000121 SectionKind::getText());
122 ConstTextCoalSection
123 = Ctx->getMachOSection("__TEXT", "__const_coal",
David Majnemer7b583052014-03-07 07:36:05 +0000124 MachO::S_COALESCED,
Evan Cheng76792992011-07-20 05:58:47 +0000125 SectionKind::getReadOnly());
126 ConstDataSection // .const_data
127 = Ctx->getMachOSection("__DATA", "__const", 0,
128 SectionKind::getReadOnlyWithRel());
129 DataCoalSection
130 = Ctx->getMachOSection("__DATA","__datacoal_nt",
David Majnemer7b583052014-03-07 07:36:05 +0000131 MachO::S_COALESCED,
Evan Cheng76792992011-07-20 05:58:47 +0000132 SectionKind::getDataRel());
133 DataCommonSection
134 = Ctx->getMachOSection("__DATA","__common",
David Majnemer7b583052014-03-07 07:36:05 +0000135 MachO::S_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +0000136 SectionKind::getBSS());
137 DataBSSSection
David Majnemer7b583052014-03-07 07:36:05 +0000138 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +0000139 SectionKind::getBSS());
140
141
142 LazySymbolPointerSection
143 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
David Majnemer7b583052014-03-07 07:36:05 +0000144 MachO::S_LAZY_SYMBOL_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000145 SectionKind::getMetadata());
146 NonLazySymbolPointerSection
147 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
David Majnemer7b583052014-03-07 07:36:05 +0000148 MachO::S_NON_LAZY_SYMBOL_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000149 SectionKind::getMetadata());
150
151 if (RelocM == Reloc::Static) {
152 StaticCtorSection
153 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
154 SectionKind::getDataRel());
155 StaticDtorSection
156 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
157 SectionKind::getDataRel());
158 } else {
159 StaticCtorSection
160 = Ctx->getMachOSection("__DATA", "__mod_init_func",
David Majnemer7b583052014-03-07 07:36:05 +0000161 MachO::S_MOD_INIT_FUNC_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000162 SectionKind::getDataRel());
163 StaticDtorSection
164 = Ctx->getMachOSection("__DATA", "__mod_term_func",
David Majnemer7b583052014-03-07 07:36:05 +0000165 MachO::S_MOD_TERM_FUNC_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000166 SectionKind::getDataRel());
167 }
168
169 // Exception Handling.
170 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
171 SectionKind::getReadOnlyWithRel());
172
Craig Topperbb694de2014-04-13 04:57:38 +0000173 COFFDebugSymbolsSection = nullptr;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000174
Rafael Espindolabecdf632014-06-20 22:37:01 +0000175 if (useCompactUnwind(T)) {
Evan Cheng76792992011-07-20 05:58:47 +0000176 CompactUnwindSection =
Rafael Espindolabecdf632014-06-20 22:37:01 +0000177 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
178 SectionKind::getReadOnly());
Evan Cheng76792992011-07-20 05:58:47 +0000179
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000180 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
181 CompactUnwindDwarfEHFrameOnly = 0x04000000;
Tim Northover3b0846e2014-05-24 12:50:23 +0000182 else if (T.getArch() == Triple::arm64 || T.getArch() == Triple::aarch64)
Tim Northover00ed9962014-03-29 10:18:08 +0000183 CompactUnwindDwarfEHFrameOnly = 0x03000000;
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000184 }
185
Evan Cheng76792992011-07-20 05:58:47 +0000186 // Debug Information.
Eric Christopher4996c702011-11-07 09:24:32 +0000187 DwarfAccelNamesSection =
188 Ctx->getMachOSection("__DWARF", "__apple_names",
David Majnemer7b583052014-03-07 07:36:05 +0000189 MachO::S_ATTR_DEBUG,
Eric Christopher4996c702011-11-07 09:24:32 +0000190 SectionKind::getMetadata());
191 DwarfAccelObjCSection =
192 Ctx->getMachOSection("__DWARF", "__apple_objc",
David Majnemer7b583052014-03-07 07:36:05 +0000193 MachO::S_ATTR_DEBUG,
Eric Christopher4996c702011-11-07 09:24:32 +0000194 SectionKind::getMetadata());
195 // 16 character section limit...
196 DwarfAccelNamespaceSection =
197 Ctx->getMachOSection("__DWARF", "__apple_namespac",
David Majnemer7b583052014-03-07 07:36:05 +0000198 MachO::S_ATTR_DEBUG,
Eric Christopher4996c702011-11-07 09:24:32 +0000199 SectionKind::getMetadata());
200 DwarfAccelTypesSection =
201 Ctx->getMachOSection("__DWARF", "__apple_types",
David Majnemer7b583052014-03-07 07:36:05 +0000202 MachO::S_ATTR_DEBUG,
Eric Christopher4996c702011-11-07 09:24:32 +0000203 SectionKind::getMetadata());
Jim Grosbachdc1e36e2012-05-11 01:41:30 +0000204
Evan Cheng76792992011-07-20 05:58:47 +0000205 DwarfAbbrevSection =
206 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
David Majnemer7b583052014-03-07 07:36:05 +0000207 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000208 SectionKind::getMetadata());
209 DwarfInfoSection =
210 Ctx->getMachOSection("__DWARF", "__debug_info",
David Majnemer7b583052014-03-07 07:36:05 +0000211 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000212 SectionKind::getMetadata());
213 DwarfLineSection =
214 Ctx->getMachOSection("__DWARF", "__debug_line",
David Majnemer7b583052014-03-07 07:36:05 +0000215 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000216 SectionKind::getMetadata());
217 DwarfFrameSection =
218 Ctx->getMachOSection("__DWARF", "__debug_frame",
David Majnemer7b583052014-03-07 07:36:05 +0000219 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000220 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000221 DwarfPubNamesSection =
222 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
David Majnemer7b583052014-03-07 07:36:05 +0000223 MachO::S_ATTR_DEBUG,
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000224 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000225 DwarfPubTypesSection =
226 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
David Majnemer7b583052014-03-07 07:36:05 +0000227 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000228 SectionKind::getMetadata());
Eric Christopherb0e76942013-09-09 20:03:14 +0000229 DwarfGnuPubNamesSection =
230 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
David Majnemer7b583052014-03-07 07:36:05 +0000231 MachO::S_ATTR_DEBUG,
Eric Christopherb0e76942013-09-09 20:03:14 +0000232 SectionKind::getMetadata());
233 DwarfGnuPubTypesSection =
234 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
David Majnemer7b583052014-03-07 07:36:05 +0000235 MachO::S_ATTR_DEBUG,
Eric Christopherb0e76942013-09-09 20:03:14 +0000236 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000237 DwarfStrSection =
238 Ctx->getMachOSection("__DWARF", "__debug_str",
David Majnemer7b583052014-03-07 07:36:05 +0000239 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000240 SectionKind::getMetadata());
241 DwarfLocSection =
242 Ctx->getMachOSection("__DWARF", "__debug_loc",
David Majnemer7b583052014-03-07 07:36:05 +0000243 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000244 SectionKind::getMetadata());
245 DwarfARangesSection =
246 Ctx->getMachOSection("__DWARF", "__debug_aranges",
David Majnemer7b583052014-03-07 07:36:05 +0000247 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000248 SectionKind::getMetadata());
249 DwarfRangesSection =
250 Ctx->getMachOSection("__DWARF", "__debug_ranges",
David Majnemer7b583052014-03-07 07:36:05 +0000251 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000252 SectionKind::getMetadata());
253 DwarfMacroInfoSection =
254 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
David Majnemer7b583052014-03-07 07:36:05 +0000255 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000256 SectionKind::getMetadata());
257 DwarfDebugInlineSection =
258 Ctx->getMachOSection("__DWARF", "__debug_inlined",
David Majnemer7b583052014-03-07 07:36:05 +0000259 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000260 SectionKind::getMetadata());
Lang Hames30789772013-11-08 22:14:49 +0000261 StackMapSection =
262 Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
263 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000264
265 TLSExtraDataSection = TLSTLVSection;
266}
267
268void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000269 switch (T.getArch()) {
270 case Triple::mips:
271 case Triple::mipsel:
Rafael Espindolab9b7ae02013-04-03 03:13:19 +0000272 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000273 break;
274 case Triple::mips64:
275 case Triple::mips64el:
Rafael Espindolab9b7ae02013-04-03 03:13:19 +0000276 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000277 break;
278 default:
Rafael Espindolaef9d3492013-03-15 05:51:57 +0000279 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000280 break;
281 }
Rafael Espindolaef9d3492013-03-15 05:51:57 +0000282
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000283 switch (T.getArch()) {
Joerg Sonnenbergercf86ce12014-05-07 07:49:34 +0000284 case Triple::arm:
285 case Triple::armeb:
286 case Triple::thumb:
287 case Triple::thumbeb:
Joerg Sonnenberger94cbb662014-05-13 17:58:13 +0000288 if (Ctx->getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
289 break;
290 // Fallthrough if not using EHABI
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000291 case Triple::x86:
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000292 PersonalityEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach0dde3492011-11-15 16:46:22 +0000293 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
294 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000295 LSDAEncoding = (RelocM == Reloc::PIC_)
296 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
297 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000298 TTypeEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach0dde3492011-11-15 16:46:22 +0000299 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
300 : dwarf::DW_EH_PE_absptr;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000301 break;
302 case Triple::x86_64:
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000303 if (RelocM == Reloc::PIC_) {
304 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
305 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
306 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
307 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
308 (CMModel == CodeModel::Small
309 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000310 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
311 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
312 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
313 } else {
314 PersonalityEncoding =
315 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
316 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
317 LSDAEncoding = (CMModel == CodeModel::Small)
318 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000319 TTypeEncoding = (CMModel == CodeModel::Small)
320 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
321 }
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000322 break;
323 case Triple::aarch64:
324 case Triple::aarch64_be:
325 case Triple::arm64:
326 case Triple::arm64_be:
Tim Northovere0e3aef2013-01-31 12:12:40 +0000327 // The small model guarantees static code/data size < 4GB, but not where it
328 // will be in memory. Most of these could end up >2GB away so even a signed
329 // pc-relative 32-bit address is insufficient, theoretically.
330 if (RelocM == Reloc::PIC_) {
331 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
332 dwarf::DW_EH_PE_sdata8;
333 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
Tim Northovere0e3aef2013-01-31 12:12:40 +0000334 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
335 dwarf::DW_EH_PE_sdata8;
336 } else {
337 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
338 LSDAEncoding = dwarf::DW_EH_PE_absptr;
Tim Northovere0e3aef2013-01-31 12:12:40 +0000339 TTypeEncoding = dwarf::DW_EH_PE_absptr;
340 }
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000341 break;
Logan Chienc0029812014-05-30 16:48:56 +0000342 case Triple::mips:
343 case Triple::mipsel:
344 // MIPS uses indirect pointer to refer personality functions, so that the
345 // eh_frame section can be read-only. DW.ref.personality will be generated
346 // for relocation.
347 PersonalityEncoding = dwarf::DW_EH_PE_indirect;
348 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000349 case Triple::ppc64:
350 case Triple::ppc64le:
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000351 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
352 dwarf::DW_EH_PE_udata8;
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000353 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000354 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
355 dwarf::DW_EH_PE_udata8;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000356 break;
357 case Triple::sparc:
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000358 if (RelocM == Reloc::PIC_) {
359 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
360 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
361 dwarf::DW_EH_PE_sdata4;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000362 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
363 dwarf::DW_EH_PE_sdata4;
364 } else {
365 LSDAEncoding = dwarf::DW_EH_PE_absptr;
366 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +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 case Triple::sparcv9:
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000371 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
372 if (RelocM == Reloc::PIC_) {
373 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
374 dwarf::DW_EH_PE_sdata4;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000375 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
376 dwarf::DW_EH_PE_sdata4;
377 } else {
378 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000379 TTypeEncoding = dwarf::DW_EH_PE_absptr;
380 }
Joerg Sonnenbergerfa9cf652014-04-30 23:36:24 +0000381 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000382 case Triple::systemz:
Ulrich Weigand0213e7f2013-05-06 16:11:12 +0000383 // All currently-defined code models guarantee that 4-byte PC-relative
384 // values will be in range.
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000385 if (RelocM == Reloc::PIC_) {
386 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
387 dwarf::DW_EH_PE_sdata4;
388 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000389 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
390 dwarf::DW_EH_PE_sdata4;
391 } else {
392 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
393 LSDAEncoding = dwarf::DW_EH_PE_absptr;
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000394 TTypeEncoding = dwarf::DW_EH_PE_absptr;
395 }
Joerg Sonnenbergerfa9cf652014-04-30 23:36:24 +0000396 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000397 default:
398 break;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000399 }
400
David Chisnall07f8d3e2012-02-17 17:31:15 +0000401 // Solaris requires different flags for .eh_frame to seemingly every other
402 // platform.
David Chisnallbbec8722012-04-10 11:44:33 +0000403 EHSectionType = ELF::SHT_PROGBITS;
David Chisnall07f8d3e2012-02-17 17:31:15 +0000404 EHSectionFlags = ELF::SHF_ALLOC;
David Chisnallbbec8722012-04-10 11:44:33 +0000405 if (T.getOS() == Triple::Solaris) {
406 if (T.getArch() == Triple::x86_64)
407 EHSectionType = ELF::SHT_X86_64_UNWIND;
408 else
409 EHSectionFlags |= ELF::SHF_WRITE;
410 }
David Chisnall07f8d3e2012-02-17 17:31:15 +0000411
412
Evan Cheng76792992011-07-20 05:58:47 +0000413 // ELF
414 BSSSection =
415 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
Anton Korobeynikov7722a2d2012-01-25 22:24:19 +0000416 ELF::SHF_WRITE | ELF::SHF_ALLOC,
Evan Cheng76792992011-07-20 05:58:47 +0000417 SectionKind::getBSS());
418
419 TextSection =
420 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
421 ELF::SHF_EXECINSTR |
422 ELF::SHF_ALLOC,
423 SectionKind::getText());
424
425 DataSection =
426 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
427 ELF::SHF_WRITE |ELF::SHF_ALLOC,
428 SectionKind::getDataRel());
429
430 ReadOnlySection =
431 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
432 ELF::SHF_ALLOC,
433 SectionKind::getReadOnly());
434
435 TLSDataSection =
436 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
437 ELF::SHF_ALLOC | ELF::SHF_TLS |
438 ELF::SHF_WRITE,
439 SectionKind::getThreadData());
440
441 TLSBSSSection =
442 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
443 ELF::SHF_ALLOC | ELF::SHF_TLS |
444 ELF::SHF_WRITE,
445 SectionKind::getThreadBSS());
446
447 DataRelSection =
448 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
449 ELF::SHF_ALLOC |ELF::SHF_WRITE,
450 SectionKind::getDataRel());
451
452 DataRelLocalSection =
453 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
454 ELF::SHF_ALLOC |ELF::SHF_WRITE,
455 SectionKind::getDataRelLocal());
456
457 DataRelROSection =
458 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
459 ELF::SHF_ALLOC |ELF::SHF_WRITE,
460 SectionKind::getReadOnlyWithRel());
461
462 DataRelROLocalSection =
463 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
464 ELF::SHF_ALLOC |ELF::SHF_WRITE,
465 SectionKind::getReadOnlyWithRelLocal());
466
467 MergeableConst4Section =
468 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
469 ELF::SHF_ALLOC |ELF::SHF_MERGE,
470 SectionKind::getMergeableConst4());
471
472 MergeableConst8Section =
473 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
474 ELF::SHF_ALLOC |ELF::SHF_MERGE,
475 SectionKind::getMergeableConst8());
476
477 MergeableConst16Section =
478 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
479 ELF::SHF_ALLOC |ELF::SHF_MERGE,
480 SectionKind::getMergeableConst16());
481
482 StaticCtorSection =
483 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
484 ELF::SHF_ALLOC |ELF::SHF_WRITE,
485 SectionKind::getDataRel());
486
487 StaticDtorSection =
488 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
489 ELF::SHF_ALLOC |ELF::SHF_WRITE,
490 SectionKind::getDataRel());
491
492 // Exception Handling Sections.
493
494 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
495 // it contains relocatable pointers. In PIC mode, this is probably a big
496 // runtime hit for C++ apps. Either the contents of the LSDA need to be
497 // adjusted or this should be a data section.
498 LSDASection =
499 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
500 ELF::SHF_ALLOC,
501 SectionKind::getReadOnly());
502
Craig Topperbb694de2014-04-13 04:57:38 +0000503 COFFDebugSymbolsSection = nullptr;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000504
Evan Cheng76792992011-07-20 05:58:47 +0000505 // Debug Info Sections.
506 DwarfAbbrevSection =
507 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
508 SectionKind::getMetadata());
509 DwarfInfoSection =
510 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
511 SectionKind::getMetadata());
512 DwarfLineSection =
513 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
514 SectionKind::getMetadata());
515 DwarfFrameSection =
516 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
517 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000518 DwarfPubNamesSection =
519 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
520 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000521 DwarfPubTypesSection =
522 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
523 SectionKind::getMetadata());
Eric Christopherb0e76942013-09-09 20:03:14 +0000524 DwarfGnuPubNamesSection =
525 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
526 SectionKind::getMetadata());
527 DwarfGnuPubTypesSection =
528 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
529 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000530 DwarfStrSection =
Nick Lewycky1a62d782011-10-26 18:44:32 +0000531 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
532 ELF::SHF_MERGE | ELF::SHF_STRINGS,
533 SectionKind::getMergeable1ByteCString());
Evan Cheng76792992011-07-20 05:58:47 +0000534 DwarfLocSection =
535 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
536 SectionKind::getMetadata());
537 DwarfARangesSection =
538 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
539 SectionKind::getMetadata());
540 DwarfRangesSection =
541 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
542 SectionKind::getMetadata());
543 DwarfMacroInfoSection =
544 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
545 SectionKind::getMetadata());
Eric Christopher27ed8ec2012-11-28 02:49:34 +0000546
547 // DWARF5 Experimental Debug Info
548
549 // Accelerator Tables
Eric Christophera0ad67d2012-10-08 21:41:30 +0000550 DwarfAccelNamesSection =
551 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
552 SectionKind::getMetadata());
553 DwarfAccelObjCSection =
554 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
555 SectionKind::getMetadata());
556 DwarfAccelNamespaceSection =
557 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
558 SectionKind::getMetadata());
559 DwarfAccelTypesSection =
560 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
561 SectionKind::getMetadata());
Eric Christopherc3b434b2012-11-28 02:49:38 +0000562
563 // Fission Sections
564 DwarfInfoDWOSection =
565 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
566 SectionKind::getMetadata());
Eric Christopher3c230092012-11-30 06:47:06 +0000567 DwarfAbbrevDWOSection =
568 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
569 SectionKind::getMetadata());
570 DwarfStrDWOSection =
571 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
572 ELF::SHF_MERGE | ELF::SHF_STRINGS,
573 SectionKind::getMergeable1ByteCString());
574 DwarfLineDWOSection =
575 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
576 SectionKind::getMetadata());
577 DwarfLocDWOSection =
578 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
579 SectionKind::getMetadata());
Eric Christopherc0fa8672013-01-04 17:59:22 +0000580 DwarfStrOffDWOSection =
581 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
582 SectionKind::getMetadata());
Eric Christopher962c9082013-01-15 23:56:56 +0000583 DwarfAddrSection =
584 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
585 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000586}
587
588
589void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
Saleem Abdulrasool70a02062014-06-08 03:57:49 +0000590 bool IsWoA = T.getArch() == Triple::arm || T.getArch() == Triple::thumb;
591
David Majnemera9bdb322014-04-08 22:33:40 +0000592 // The object file format cannot represent common symbols with explicit
593 // alignments.
594 CommDirectiveSupportsAlignment = false;
595
Evan Cheng76792992011-07-20 05:58:47 +0000596 // COFF
David Majnemer3d96acb2013-08-13 01:23:53 +0000597 BSSSection =
598 Ctx->getCOFFSection(".bss",
599 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
600 COFF::IMAGE_SCN_MEM_READ |
601 COFF::IMAGE_SCN_MEM_WRITE,
602 SectionKind::getBSS());
Evan Cheng76792992011-07-20 05:58:47 +0000603 TextSection =
604 Ctx->getCOFFSection(".text",
Patrik Hagglundaad35e72014-06-09 07:35:07 +0000605 (IsWoA ? COFF::IMAGE_SCN_MEM_16BIT
606 : (COFF::SectionCharacteristics)0) |
Evan Cheng76792992011-07-20 05:58:47 +0000607 COFF::IMAGE_SCN_CNT_CODE |
608 COFF::IMAGE_SCN_MEM_EXECUTE |
609 COFF::IMAGE_SCN_MEM_READ,
610 SectionKind::getText());
611 DataSection =
612 Ctx->getCOFFSection(".data",
613 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
614 COFF::IMAGE_SCN_MEM_READ |
615 COFF::IMAGE_SCN_MEM_WRITE,
616 SectionKind::getDataRel());
617 ReadOnlySection =
618 Ctx->getCOFFSection(".rdata",
619 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
620 COFF::IMAGE_SCN_MEM_READ,
621 SectionKind::getReadOnly());
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000622
Saleem Abdulrasooled7fc4b2014-06-08 00:34:27 +0000623 if (T.isKnownWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
Michael J. Spencerb560d072012-02-23 21:56:08 +0000624 StaticCtorSection =
625 Ctx->getCOFFSection(".CRT$XCU",
626 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
627 COFF::IMAGE_SCN_MEM_READ,
628 SectionKind::getReadOnly());
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000629 StaticDtorSection =
630 Ctx->getCOFFSection(".CRT$XTX",
631 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
632 COFF::IMAGE_SCN_MEM_READ,
633 SectionKind::getReadOnly());
Michael J. Spencerb560d072012-02-23 21:56:08 +0000634 } else {
635 StaticCtorSection =
636 Ctx->getCOFFSection(".ctors",
637 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
638 COFF::IMAGE_SCN_MEM_READ |
639 COFF::IMAGE_SCN_MEM_WRITE,
640 SectionKind::getDataRel());
Anton Korobeynikov37d73002012-09-23 15:53:47 +0000641 StaticDtorSection =
642 Ctx->getCOFFSection(".dtors",
643 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
644 COFF::IMAGE_SCN_MEM_READ |
645 COFF::IMAGE_SCN_MEM_WRITE,
646 SectionKind::getDataRel());
647 }
Evan Cheng76792992011-07-20 05:58:47 +0000648
649 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
650 // though it contains relocatable pointers. In PIC mode, this is probably a
651 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
652 // adjusted or this should be a data section.
NAKAMURA Takumid77cefe2014-06-22 22:00:56 +0000653 LSDASection =
654 Ctx->getCOFFSection(".gcc_except_table",
655 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
656 COFF::IMAGE_SCN_MEM_READ,
657 SectionKind::getReadOnly());
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
Saleem Abdulrasoolbdbc0082014-06-22 22:25:01 +0000795void MCObjectFileInfo::InitMCObjectFileInfo(StringRef T, 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
Saleem Abdulrasoolbdbc0082014-06-22 22:25:01 +0000820 TT = Triple(T);
821
822 Triple::ArchType Arch = TT.getArch();
Evan Cheng76792992011-07-20 05:58:47 +0000823 // FIXME: Checking for Arch here to filter out bogus triples such as
824 // cellspu-apple-darwin. Perhaps we should fix in Triple?
825 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
826 Arch == Triple::arm || Arch == Triple::thumb ||
Tim Northover3b0846e2014-05-24 12:50:23 +0000827 Arch == Triple::arm64 || Arch == Triple::aarch64 ||
Evan Cheng76792992011-07-20 05:58:47 +0000828 Arch == Triple::ppc || Arch == Triple::ppc64 ||
829 Arch == Triple::UnknownArch) &&
Saleem Abdulrasoolbdbc0082014-06-22 22:25:01 +0000830 (TT.isOSDarwin() || TT.isOSBinFormatMachO())) {
Evan Cheng76792992011-07-20 05:58:47 +0000831 Env = IsMachO;
Saleem Abdulrasoolbdbc0082014-06-22 22:25:01 +0000832 InitMachOMCObjectFileInfo(TT);
Saleem Abdulrasoolffdb92a702014-04-27 04:54:16 +0000833 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
834 Arch == Triple::arm || Arch == Triple::thumb) &&
Saleem Abdulrasoolbdbc0082014-06-22 22:25:01 +0000835 (TT.isOSWindows() && TT.getObjectFormat() == Triple::COFF)) {
Evan Cheng76792992011-07-20 05:58:47 +0000836 Env = IsCOFF;
Saleem Abdulrasoolbdbc0082014-06-22 22:25:01 +0000837 InitCOFFMCObjectFileInfo(TT);
Evan Cheng76792992011-07-20 05:58:47 +0000838 } else {
839 Env = IsELF;
Saleem Abdulrasoolbdbc0082014-06-22 22:25:01 +0000840 InitELFMCObjectFileInfo(TT);
Evan Cheng76792992011-07-20 05:58:47 +0000841 }
842}
843
David Blaikiebc563272013-12-13 21:33:40 +0000844const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
845 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
846 SectionKind::getMetadata(), 0, utostr(Hash));
847}
848
David Blaikie2da282b2014-05-21 23:27:41 +0000849const MCSection *
850MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
851 return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS,
852 ELF::SHF_GROUP, SectionKind::getMetadata(), 0,
853 utostr(Hash));
854}
855
David Chisnall85dd3092012-02-17 16:51:02 +0000856void MCObjectFileInfo::InitEHFrameSection() {
857 if (Env == IsMachO)
858 EHFrameSection =
859 Ctx->getMachOSection("__TEXT", "__eh_frame",
David Majnemer7b583052014-03-07 07:36:05 +0000860 MachO::S_COALESCED |
861 MachO::S_ATTR_NO_TOC |
862 MachO::S_ATTR_STRIP_STATIC_SYMS |
863 MachO::S_ATTR_LIVE_SUPPORT,
David Chisnall85dd3092012-02-17 16:51:02 +0000864 SectionKind::getReadOnly());
865 else if (Env == IsELF)
866 EHFrameSection =
David Chisnallbbec8722012-04-10 11:44:33 +0000867 Ctx->getELFSection(".eh_frame", EHSectionType,
David Chisnall07f8d3e2012-02-17 17:31:15 +0000868 EHSectionFlags,
David Chisnall85dd3092012-02-17 16:51:02 +0000869 SectionKind::getDataRel());
870 else
871 EHFrameSection =
872 Ctx->getCOFFSection(".eh_frame",
873 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
874 COFF::IMAGE_SCN_MEM_READ |
875 COFF::IMAGE_SCN_MEM_WRITE,
876 SectionKind::getDataRel());
877}