blob: 9d413afe5db1b0948c62ca6792e904ac0fee12b6 [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 Northover3b0846e2014-05-24 12:50:23 +000026 if (T.isOSDarwin() &&
27 (T.getArch() == Triple::arm64 || T.getArch() == Triple::aarch64))
Tim Northover00ed9962014-03-29 10:18:08 +000028 SupportsCompactUnwindWithoutEHFrame = true;
29
Evan Chengbbf3b0d2011-07-20 19:50:42 +000030 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
31 | dwarf::DW_EH_PE_sdata4;
Rafael Espindolaaa7851d2014-05-12 13:47:05 +000032 LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
Evan Chengbbf3b0d2011-07-20 19:50:42 +000033 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
34 dwarf::DW_EH_PE_sdata4;
35
Evan Cheng76792992011-07-20 05:58:47 +000036 // .comm doesn't support alignment before Leopard.
37 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
38 CommDirectiveSupportsAlignment = false;
39
40 TextSection // .text
41 = Ctx->getMachOSection("__TEXT", "__text",
David Majnemer7b583052014-03-07 07:36:05 +000042 MachO::S_ATTR_PURE_INSTRUCTIONS,
Evan Cheng76792992011-07-20 05:58:47 +000043 SectionKind::getText());
44 DataSection // .data
45 = Ctx->getMachOSection("__DATA", "__data", 0,
46 SectionKind::getDataRel());
47
NAKAMURA Takumi68fa6f92013-09-21 02:34:45 +000048 // BSSSection might not be expected initialized on msvc.
Craig Topperbb694de2014-04-13 04:57:38 +000049 BSSSection = nullptr;
NAKAMURA Takumi68fa6f92013-09-21 02:34:45 +000050
Evan Cheng76792992011-07-20 05:58:47 +000051 TLSDataSection // .tdata
52 = Ctx->getMachOSection("__DATA", "__thread_data",
David Majnemer7b583052014-03-07 07:36:05 +000053 MachO::S_THREAD_LOCAL_REGULAR,
Evan Cheng76792992011-07-20 05:58:47 +000054 SectionKind::getDataRel());
55 TLSBSSSection // .tbss
56 = Ctx->getMachOSection("__DATA", "__thread_bss",
David Majnemer7b583052014-03-07 07:36:05 +000057 MachO::S_THREAD_LOCAL_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +000058 SectionKind::getThreadBSS());
59
60 // TODO: Verify datarel below.
61 TLSTLVSection // .tlv
62 = Ctx->getMachOSection("__DATA", "__thread_vars",
David Majnemer7b583052014-03-07 07:36:05 +000063 MachO::S_THREAD_LOCAL_VARIABLES,
Evan Cheng76792992011-07-20 05:58:47 +000064 SectionKind::getDataRel());
65
66 TLSThreadInitSection
67 = Ctx->getMachOSection("__DATA", "__thread_init",
David Majnemer7b583052014-03-07 07:36:05 +000068 MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
Jim Grosbach0dde3492011-11-15 16:46:22 +000069 SectionKind::getDataRel());
Evan Cheng76792992011-07-20 05:58:47 +000070
71 CStringSection // .cstring
72 = Ctx->getMachOSection("__TEXT", "__cstring",
David Majnemer7b583052014-03-07 07:36:05 +000073 MachO::S_CSTRING_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +000074 SectionKind::getMergeable1ByteCString());
75 UStringSection
76 = Ctx->getMachOSection("__TEXT","__ustring", 0,
77 SectionKind::getMergeable2ByteCString());
78 FourByteConstantSection // .literal4
79 = Ctx->getMachOSection("__TEXT", "__literal4",
David Majnemer7b583052014-03-07 07:36:05 +000080 MachO::S_4BYTE_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +000081 SectionKind::getMergeableConst4());
82 EightByteConstantSection // .literal8
83 = Ctx->getMachOSection("__TEXT", "__literal8",
David Majnemer7b583052014-03-07 07:36:05 +000084 MachO::S_8BYTE_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +000085 SectionKind::getMergeableConst8());
86
Rafael Espindola1f3de492014-02-13 23:16:11 +000087 SixteenByteConstantSection // .literal16
88 = Ctx->getMachOSection("__TEXT", "__literal16",
David Majnemer7b583052014-03-07 07:36:05 +000089 MachO::S_16BYTE_LITERALS,
Rafael Espindola1f3de492014-02-13 23:16:11 +000090 SectionKind::getMergeableConst16());
Evan Cheng76792992011-07-20 05:58:47 +000091
92 ReadOnlySection // .const
93 = Ctx->getMachOSection("__TEXT", "__const", 0,
94 SectionKind::getReadOnly());
95
96 TextCoalSection
97 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
David Majnemer7b583052014-03-07 07:36:05 +000098 MachO::S_COALESCED |
99 MachO::S_ATTR_PURE_INSTRUCTIONS,
Evan Cheng76792992011-07-20 05:58:47 +0000100 SectionKind::getText());
101 ConstTextCoalSection
102 = Ctx->getMachOSection("__TEXT", "__const_coal",
David Majnemer7b583052014-03-07 07:36:05 +0000103 MachO::S_COALESCED,
Evan Cheng76792992011-07-20 05:58:47 +0000104 SectionKind::getReadOnly());
105 ConstDataSection // .const_data
106 = Ctx->getMachOSection("__DATA", "__const", 0,
107 SectionKind::getReadOnlyWithRel());
108 DataCoalSection
109 = Ctx->getMachOSection("__DATA","__datacoal_nt",
David Majnemer7b583052014-03-07 07:36:05 +0000110 MachO::S_COALESCED,
Evan Cheng76792992011-07-20 05:58:47 +0000111 SectionKind::getDataRel());
112 DataCommonSection
113 = Ctx->getMachOSection("__DATA","__common",
David Majnemer7b583052014-03-07 07:36:05 +0000114 MachO::S_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +0000115 SectionKind::getBSS());
116 DataBSSSection
David Majnemer7b583052014-03-07 07:36:05 +0000117 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +0000118 SectionKind::getBSS());
119
120
121 LazySymbolPointerSection
122 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
David Majnemer7b583052014-03-07 07:36:05 +0000123 MachO::S_LAZY_SYMBOL_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000124 SectionKind::getMetadata());
125 NonLazySymbolPointerSection
126 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
David Majnemer7b583052014-03-07 07:36:05 +0000127 MachO::S_NON_LAZY_SYMBOL_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000128 SectionKind::getMetadata());
129
130 if (RelocM == Reloc::Static) {
131 StaticCtorSection
132 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
133 SectionKind::getDataRel());
134 StaticDtorSection
135 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
136 SectionKind::getDataRel());
137 } else {
138 StaticCtorSection
139 = Ctx->getMachOSection("__DATA", "__mod_init_func",
David Majnemer7b583052014-03-07 07:36:05 +0000140 MachO::S_MOD_INIT_FUNC_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000141 SectionKind::getDataRel());
142 StaticDtorSection
143 = Ctx->getMachOSection("__DATA", "__mod_term_func",
David Majnemer7b583052014-03-07 07:36:05 +0000144 MachO::S_MOD_TERM_FUNC_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000145 SectionKind::getDataRel());
146 }
147
148 // Exception Handling.
149 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
150 SectionKind::getReadOnlyWithRel());
151
Craig Topperbb694de2014-04-13 04:57:38 +0000152 COFFDebugSymbolsSection = nullptr;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000153
Tim Northover00ed9962014-03-29 10:18:08 +0000154 if ((T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) ||
Tim Northover3b0846e2014-05-24 12:50:23 +0000155 (T.isOSDarwin() &&
156 (T.getArch() == Triple::arm64 || T.getArch() == Triple::aarch64))) {
Evan Cheng76792992011-07-20 05:58:47 +0000157 CompactUnwindSection =
158 Ctx->getMachOSection("__LD", "__compact_unwind",
David Majnemer7b583052014-03-07 07:36:05 +0000159 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000160 SectionKind::getReadOnly());
161
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000162 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
163 CompactUnwindDwarfEHFrameOnly = 0x04000000;
Tim Northover3b0846e2014-05-24 12:50:23 +0000164 else if (T.getArch() == Triple::arm64 || T.getArch() == Triple::aarch64)
Tim Northover00ed9962014-03-29 10:18:08 +0000165 CompactUnwindDwarfEHFrameOnly = 0x03000000;
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000166 }
167
Evan Cheng76792992011-07-20 05:58:47 +0000168 // Debug Information.
Eric Christopher4996c702011-11-07 09:24:32 +0000169 DwarfAccelNamesSection =
170 Ctx->getMachOSection("__DWARF", "__apple_names",
David Majnemer7b583052014-03-07 07:36:05 +0000171 MachO::S_ATTR_DEBUG,
Eric Christopher4996c702011-11-07 09:24:32 +0000172 SectionKind::getMetadata());
173 DwarfAccelObjCSection =
174 Ctx->getMachOSection("__DWARF", "__apple_objc",
David Majnemer7b583052014-03-07 07:36:05 +0000175 MachO::S_ATTR_DEBUG,
Eric Christopher4996c702011-11-07 09:24:32 +0000176 SectionKind::getMetadata());
177 // 16 character section limit...
178 DwarfAccelNamespaceSection =
179 Ctx->getMachOSection("__DWARF", "__apple_namespac",
David Majnemer7b583052014-03-07 07:36:05 +0000180 MachO::S_ATTR_DEBUG,
Eric Christopher4996c702011-11-07 09:24:32 +0000181 SectionKind::getMetadata());
182 DwarfAccelTypesSection =
183 Ctx->getMachOSection("__DWARF", "__apple_types",
David Majnemer7b583052014-03-07 07:36:05 +0000184 MachO::S_ATTR_DEBUG,
Eric Christopher4996c702011-11-07 09:24:32 +0000185 SectionKind::getMetadata());
Jim Grosbachdc1e36e2012-05-11 01:41:30 +0000186
Evan Cheng76792992011-07-20 05:58:47 +0000187 DwarfAbbrevSection =
188 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
David Majnemer7b583052014-03-07 07:36:05 +0000189 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000190 SectionKind::getMetadata());
191 DwarfInfoSection =
192 Ctx->getMachOSection("__DWARF", "__debug_info",
David Majnemer7b583052014-03-07 07:36:05 +0000193 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000194 SectionKind::getMetadata());
195 DwarfLineSection =
196 Ctx->getMachOSection("__DWARF", "__debug_line",
David Majnemer7b583052014-03-07 07:36:05 +0000197 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000198 SectionKind::getMetadata());
199 DwarfFrameSection =
200 Ctx->getMachOSection("__DWARF", "__debug_frame",
David Majnemer7b583052014-03-07 07:36:05 +0000201 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000202 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000203 DwarfPubNamesSection =
204 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
David Majnemer7b583052014-03-07 07:36:05 +0000205 MachO::S_ATTR_DEBUG,
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000206 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000207 DwarfPubTypesSection =
208 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
David Majnemer7b583052014-03-07 07:36:05 +0000209 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000210 SectionKind::getMetadata());
Eric Christopherb0e76942013-09-09 20:03:14 +0000211 DwarfGnuPubNamesSection =
212 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
David Majnemer7b583052014-03-07 07:36:05 +0000213 MachO::S_ATTR_DEBUG,
Eric Christopherb0e76942013-09-09 20:03:14 +0000214 SectionKind::getMetadata());
215 DwarfGnuPubTypesSection =
216 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
David Majnemer7b583052014-03-07 07:36:05 +0000217 MachO::S_ATTR_DEBUG,
Eric Christopherb0e76942013-09-09 20:03:14 +0000218 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000219 DwarfStrSection =
220 Ctx->getMachOSection("__DWARF", "__debug_str",
David Majnemer7b583052014-03-07 07:36:05 +0000221 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000222 SectionKind::getMetadata());
223 DwarfLocSection =
224 Ctx->getMachOSection("__DWARF", "__debug_loc",
David Majnemer7b583052014-03-07 07:36:05 +0000225 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000226 SectionKind::getMetadata());
227 DwarfARangesSection =
228 Ctx->getMachOSection("__DWARF", "__debug_aranges",
David Majnemer7b583052014-03-07 07:36:05 +0000229 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000230 SectionKind::getMetadata());
231 DwarfRangesSection =
232 Ctx->getMachOSection("__DWARF", "__debug_ranges",
David Majnemer7b583052014-03-07 07:36:05 +0000233 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000234 SectionKind::getMetadata());
235 DwarfMacroInfoSection =
236 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
David Majnemer7b583052014-03-07 07:36:05 +0000237 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000238 SectionKind::getMetadata());
239 DwarfDebugInlineSection =
240 Ctx->getMachOSection("__DWARF", "__debug_inlined",
David Majnemer7b583052014-03-07 07:36:05 +0000241 MachO::S_ATTR_DEBUG,
Evan Cheng76792992011-07-20 05:58:47 +0000242 SectionKind::getMetadata());
Lang Hames30789772013-11-08 22:14:49 +0000243 StackMapSection =
244 Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
245 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000246
247 TLSExtraDataSection = TLSTLVSection;
248}
249
250void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000251 switch (T.getArch()) {
252 case Triple::mips:
253 case Triple::mipsel:
Rafael Espindolab9b7ae02013-04-03 03:13:19 +0000254 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000255 break;
256 case Triple::mips64:
257 case Triple::mips64el:
Rafael Espindolab9b7ae02013-04-03 03:13:19 +0000258 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000259 break;
260 default:
Rafael Espindolaef9d3492013-03-15 05:51:57 +0000261 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000262 break;
263 }
Rafael Espindolaef9d3492013-03-15 05:51:57 +0000264
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000265 switch (T.getArch()) {
Joerg Sonnenbergercf86ce12014-05-07 07:49:34 +0000266 case Triple::arm:
267 case Triple::armeb:
268 case Triple::thumb:
269 case Triple::thumbeb:
Joerg Sonnenberger94cbb662014-05-13 17:58:13 +0000270 if (Ctx->getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
271 break;
272 // Fallthrough if not using EHABI
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000273 case Triple::x86:
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000274 PersonalityEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach0dde3492011-11-15 16:46:22 +0000275 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
276 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000277 LSDAEncoding = (RelocM == Reloc::PIC_)
278 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
279 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000280 TTypeEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach0dde3492011-11-15 16:46:22 +0000281 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
282 : dwarf::DW_EH_PE_absptr;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000283 break;
284 case Triple::x86_64:
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000285 if (RelocM == Reloc::PIC_) {
286 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
287 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
288 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
289 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
290 (CMModel == CodeModel::Small
291 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000292 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
293 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
294 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
295 } else {
296 PersonalityEncoding =
297 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
298 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
299 LSDAEncoding = (CMModel == CodeModel::Small)
300 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000301 TTypeEncoding = (CMModel == CodeModel::Small)
302 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
303 }
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000304 break;
305 case Triple::aarch64:
306 case Triple::aarch64_be:
307 case Triple::arm64:
308 case Triple::arm64_be:
Tim Northovere0e3aef2013-01-31 12:12:40 +0000309 // The small model guarantees static code/data size < 4GB, but not where it
310 // will be in memory. Most of these could end up >2GB away so even a signed
311 // pc-relative 32-bit address is insufficient, theoretically.
312 if (RelocM == Reloc::PIC_) {
313 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
314 dwarf::DW_EH_PE_sdata8;
315 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
Tim Northovere0e3aef2013-01-31 12:12:40 +0000316 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
317 dwarf::DW_EH_PE_sdata8;
318 } else {
319 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
320 LSDAEncoding = dwarf::DW_EH_PE_absptr;
Tim Northovere0e3aef2013-01-31 12:12:40 +0000321 TTypeEncoding = dwarf::DW_EH_PE_absptr;
322 }
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000323 break;
324 case Triple::ppc64:
325 case Triple::ppc64le:
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000326 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
327 dwarf::DW_EH_PE_udata8;
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000328 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000329 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
330 dwarf::DW_EH_PE_udata8;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000331 break;
332 case Triple::sparc:
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000333 if (RelocM == Reloc::PIC_) {
334 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
335 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
336 dwarf::DW_EH_PE_sdata4;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000337 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
338 dwarf::DW_EH_PE_sdata4;
339 } else {
340 LSDAEncoding = dwarf::DW_EH_PE_absptr;
341 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000342 TTypeEncoding = dwarf::DW_EH_PE_absptr;
343 }
Joerg Sonnenbergerfa9cf652014-04-30 23:36:24 +0000344 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000345 case Triple::sparcv9:
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000346 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
347 if (RelocM == Reloc::PIC_) {
348 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
349 dwarf::DW_EH_PE_sdata4;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000350 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
351 dwarf::DW_EH_PE_sdata4;
352 } else {
353 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000354 TTypeEncoding = dwarf::DW_EH_PE_absptr;
355 }
Joerg Sonnenbergerfa9cf652014-04-30 23:36:24 +0000356 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000357 case Triple::systemz:
Ulrich Weigand0213e7f2013-05-06 16:11:12 +0000358 // All currently-defined code models guarantee that 4-byte PC-relative
359 // values will be in range.
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000360 if (RelocM == Reloc::PIC_) {
361 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
362 dwarf::DW_EH_PE_sdata4;
363 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000364 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
365 dwarf::DW_EH_PE_sdata4;
366 } else {
367 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
368 LSDAEncoding = dwarf::DW_EH_PE_absptr;
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000369 TTypeEncoding = dwarf::DW_EH_PE_absptr;
370 }
Joerg Sonnenbergerfa9cf652014-04-30 23:36:24 +0000371 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000372 default:
373 break;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000374 }
375
David Chisnall07f8d3e2012-02-17 17:31:15 +0000376 // Solaris requires different flags for .eh_frame to seemingly every other
377 // platform.
David Chisnallbbec8722012-04-10 11:44:33 +0000378 EHSectionType = ELF::SHT_PROGBITS;
David Chisnall07f8d3e2012-02-17 17:31:15 +0000379 EHSectionFlags = ELF::SHF_ALLOC;
David Chisnallbbec8722012-04-10 11:44:33 +0000380 if (T.getOS() == Triple::Solaris) {
381 if (T.getArch() == Triple::x86_64)
382 EHSectionType = ELF::SHT_X86_64_UNWIND;
383 else
384 EHSectionFlags |= ELF::SHF_WRITE;
385 }
David Chisnall07f8d3e2012-02-17 17:31:15 +0000386
387
Evan Cheng76792992011-07-20 05:58:47 +0000388 // ELF
389 BSSSection =
390 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
Anton Korobeynikov7722a2d2012-01-25 22:24:19 +0000391 ELF::SHF_WRITE | ELF::SHF_ALLOC,
Evan Cheng76792992011-07-20 05:58:47 +0000392 SectionKind::getBSS());
393
394 TextSection =
395 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
396 ELF::SHF_EXECINSTR |
397 ELF::SHF_ALLOC,
398 SectionKind::getText());
399
400 DataSection =
401 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
402 ELF::SHF_WRITE |ELF::SHF_ALLOC,
403 SectionKind::getDataRel());
404
405 ReadOnlySection =
406 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
407 ELF::SHF_ALLOC,
408 SectionKind::getReadOnly());
409
410 TLSDataSection =
411 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
412 ELF::SHF_ALLOC | ELF::SHF_TLS |
413 ELF::SHF_WRITE,
414 SectionKind::getThreadData());
415
416 TLSBSSSection =
417 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
418 ELF::SHF_ALLOC | ELF::SHF_TLS |
419 ELF::SHF_WRITE,
420 SectionKind::getThreadBSS());
421
422 DataRelSection =
423 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
424 ELF::SHF_ALLOC |ELF::SHF_WRITE,
425 SectionKind::getDataRel());
426
427 DataRelLocalSection =
428 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
429 ELF::SHF_ALLOC |ELF::SHF_WRITE,
430 SectionKind::getDataRelLocal());
431
432 DataRelROSection =
433 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
434 ELF::SHF_ALLOC |ELF::SHF_WRITE,
435 SectionKind::getReadOnlyWithRel());
436
437 DataRelROLocalSection =
438 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
439 ELF::SHF_ALLOC |ELF::SHF_WRITE,
440 SectionKind::getReadOnlyWithRelLocal());
441
442 MergeableConst4Section =
443 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
444 ELF::SHF_ALLOC |ELF::SHF_MERGE,
445 SectionKind::getMergeableConst4());
446
447 MergeableConst8Section =
448 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
449 ELF::SHF_ALLOC |ELF::SHF_MERGE,
450 SectionKind::getMergeableConst8());
451
452 MergeableConst16Section =
453 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
454 ELF::SHF_ALLOC |ELF::SHF_MERGE,
455 SectionKind::getMergeableConst16());
456
457 StaticCtorSection =
458 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
459 ELF::SHF_ALLOC |ELF::SHF_WRITE,
460 SectionKind::getDataRel());
461
462 StaticDtorSection =
463 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
464 ELF::SHF_ALLOC |ELF::SHF_WRITE,
465 SectionKind::getDataRel());
466
467 // Exception Handling Sections.
468
469 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
470 // it contains relocatable pointers. In PIC mode, this is probably a big
471 // runtime hit for C++ apps. Either the contents of the LSDA need to be
472 // adjusted or this should be a data section.
473 LSDASection =
474 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
475 ELF::SHF_ALLOC,
476 SectionKind::getReadOnly());
477
Craig Topperbb694de2014-04-13 04:57:38 +0000478 COFFDebugSymbolsSection = nullptr;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000479
Evan Cheng76792992011-07-20 05:58:47 +0000480 // Debug Info Sections.
481 DwarfAbbrevSection =
482 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
483 SectionKind::getMetadata());
484 DwarfInfoSection =
485 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
486 SectionKind::getMetadata());
487 DwarfLineSection =
488 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
489 SectionKind::getMetadata());
490 DwarfFrameSection =
491 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
492 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000493 DwarfPubNamesSection =
494 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
495 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000496 DwarfPubTypesSection =
497 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
498 SectionKind::getMetadata());
Eric Christopherb0e76942013-09-09 20:03:14 +0000499 DwarfGnuPubNamesSection =
500 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
501 SectionKind::getMetadata());
502 DwarfGnuPubTypesSection =
503 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
504 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000505 DwarfStrSection =
Nick Lewycky1a62d782011-10-26 18:44:32 +0000506 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
507 ELF::SHF_MERGE | ELF::SHF_STRINGS,
508 SectionKind::getMergeable1ByteCString());
Evan Cheng76792992011-07-20 05:58:47 +0000509 DwarfLocSection =
510 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
511 SectionKind::getMetadata());
512 DwarfARangesSection =
513 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
514 SectionKind::getMetadata());
515 DwarfRangesSection =
516 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
517 SectionKind::getMetadata());
518 DwarfMacroInfoSection =
519 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
520 SectionKind::getMetadata());
Eric Christopher27ed8ec2012-11-28 02:49:34 +0000521
522 // DWARF5 Experimental Debug Info
523
524 // Accelerator Tables
Eric Christophera0ad67d2012-10-08 21:41:30 +0000525 DwarfAccelNamesSection =
526 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
527 SectionKind::getMetadata());
528 DwarfAccelObjCSection =
529 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
530 SectionKind::getMetadata());
531 DwarfAccelNamespaceSection =
532 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
533 SectionKind::getMetadata());
534 DwarfAccelTypesSection =
535 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
536 SectionKind::getMetadata());
Eric Christopherc3b434b2012-11-28 02:49:38 +0000537
538 // Fission Sections
539 DwarfInfoDWOSection =
540 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
541 SectionKind::getMetadata());
Eric Christopher3c230092012-11-30 06:47:06 +0000542 DwarfAbbrevDWOSection =
543 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
544 SectionKind::getMetadata());
545 DwarfStrDWOSection =
546 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
547 ELF::SHF_MERGE | ELF::SHF_STRINGS,
548 SectionKind::getMergeable1ByteCString());
549 DwarfLineDWOSection =
550 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
551 SectionKind::getMetadata());
552 DwarfLocDWOSection =
553 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
554 SectionKind::getMetadata());
Eric Christopherc0fa8672013-01-04 17:59:22 +0000555 DwarfStrOffDWOSection =
556 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
557 SectionKind::getMetadata());
Eric Christopher962c9082013-01-15 23:56:56 +0000558 DwarfAddrSection =
559 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
560 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000561}
562
563
564void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
David Majnemera9bdb322014-04-08 22:33:40 +0000565 // The object file format cannot represent common symbols with explicit
566 // alignments.
567 CommDirectiveSupportsAlignment = false;
568
Evan Cheng76792992011-07-20 05:58:47 +0000569 // COFF
David Majnemer3d96acb2013-08-13 01:23:53 +0000570 BSSSection =
571 Ctx->getCOFFSection(".bss",
572 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
573 COFF::IMAGE_SCN_MEM_READ |
574 COFF::IMAGE_SCN_MEM_WRITE,
575 SectionKind::getBSS());
Evan Cheng76792992011-07-20 05:58:47 +0000576 TextSection =
577 Ctx->getCOFFSection(".text",
578 COFF::IMAGE_SCN_CNT_CODE |
579 COFF::IMAGE_SCN_MEM_EXECUTE |
580 COFF::IMAGE_SCN_MEM_READ,
581 SectionKind::getText());
582 DataSection =
583 Ctx->getCOFFSection(".data",
584 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
585 COFF::IMAGE_SCN_MEM_READ |
586 COFF::IMAGE_SCN_MEM_WRITE,
587 SectionKind::getDataRel());
588 ReadOnlySection =
589 Ctx->getCOFFSection(".rdata",
590 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
591 COFF::IMAGE_SCN_MEM_READ,
592 SectionKind::getReadOnly());
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000593 if (T.isKnownWindowsMSVCEnvironment()) {
Michael J. Spencerb560d072012-02-23 21:56:08 +0000594 StaticCtorSection =
595 Ctx->getCOFFSection(".CRT$XCU",
596 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
597 COFF::IMAGE_SCN_MEM_READ,
598 SectionKind::getReadOnly());
599 } else {
600 StaticCtorSection =
601 Ctx->getCOFFSection(".ctors",
602 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
603 COFF::IMAGE_SCN_MEM_READ |
604 COFF::IMAGE_SCN_MEM_WRITE,
605 SectionKind::getDataRel());
606 }
607
608
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000609 if (T.isKnownWindowsMSVCEnvironment()) {
Anton Korobeynikov37d73002012-09-23 15:53:47 +0000610 StaticDtorSection =
611 Ctx->getCOFFSection(".CRT$XTX",
612 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
613 COFF::IMAGE_SCN_MEM_READ,
614 SectionKind::getReadOnly());
615 } else {
616 StaticDtorSection =
617 Ctx->getCOFFSection(".dtors",
618 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
619 COFF::IMAGE_SCN_MEM_READ |
620 COFF::IMAGE_SCN_MEM_WRITE,
621 SectionKind::getDataRel());
622 }
Evan Cheng76792992011-07-20 05:58:47 +0000623
624 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
625 // though it contains relocatable pointers. In PIC mode, this is probably a
626 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
627 // adjusted or this should be a data section.
Kai Nacke42097302013-07-08 04:43:23 +0000628 LSDASection =
629 Ctx->getCOFFSection(".gcc_except_table",
630 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
631 COFF::IMAGE_SCN_MEM_READ,
632 SectionKind::getReadOnly());
Evan Cheng76792992011-07-20 05:58:47 +0000633
634 // Debug info.
Timur Iskhodzhanov31377c52014-01-28 03:48:44 +0000635 COFFDebugSymbolsSection =
636 Ctx->getCOFFSection(".debug$S",
637 COFF::IMAGE_SCN_MEM_DISCARDABLE |
638 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
639 COFF::IMAGE_SCN_MEM_READ,
640 SectionKind::getMetadata());
641
Evan Cheng76792992011-07-20 05:58:47 +0000642 DwarfAbbrevSection =
643 Ctx->getCOFFSection(".debug_abbrev",
644 COFF::IMAGE_SCN_MEM_DISCARDABLE |
645 COFF::IMAGE_SCN_MEM_READ,
646 SectionKind::getMetadata());
647 DwarfInfoSection =
648 Ctx->getCOFFSection(".debug_info",
649 COFF::IMAGE_SCN_MEM_DISCARDABLE |
650 COFF::IMAGE_SCN_MEM_READ,
651 SectionKind::getMetadata());
652 DwarfLineSection =
653 Ctx->getCOFFSection(".debug_line",
654 COFF::IMAGE_SCN_MEM_DISCARDABLE |
655 COFF::IMAGE_SCN_MEM_READ,
656 SectionKind::getMetadata());
657 DwarfFrameSection =
658 Ctx->getCOFFSection(".debug_frame",
659 COFF::IMAGE_SCN_MEM_DISCARDABLE |
660 COFF::IMAGE_SCN_MEM_READ,
661 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000662 DwarfPubNamesSection =
663 Ctx->getCOFFSection(".debug_pubnames",
664 COFF::IMAGE_SCN_MEM_DISCARDABLE |
665 COFF::IMAGE_SCN_MEM_READ,
666 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000667 DwarfPubTypesSection =
668 Ctx->getCOFFSection(".debug_pubtypes",
669 COFF::IMAGE_SCN_MEM_DISCARDABLE |
670 COFF::IMAGE_SCN_MEM_READ,
671 SectionKind::getMetadata());
NAKAMURA Takumi0229e352013-09-10 06:01:56 +0000672 DwarfGnuPubNamesSection =
Eric Christopherb0e76942013-09-09 20:03:14 +0000673 Ctx->getCOFFSection(".debug_gnu_pubnames",
674 COFF::IMAGE_SCN_MEM_DISCARDABLE |
675 COFF::IMAGE_SCN_MEM_READ,
676 SectionKind::getMetadata());
NAKAMURA Takumi0229e352013-09-10 06:01:56 +0000677 DwarfGnuPubTypesSection =
Eric Christopherb0e76942013-09-09 20:03:14 +0000678 Ctx->getCOFFSection(".debug_gnu_pubtypes",
679 COFF::IMAGE_SCN_MEM_DISCARDABLE |
680 COFF::IMAGE_SCN_MEM_READ,
681 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000682 DwarfStrSection =
683 Ctx->getCOFFSection(".debug_str",
684 COFF::IMAGE_SCN_MEM_DISCARDABLE |
685 COFF::IMAGE_SCN_MEM_READ,
686 SectionKind::getMetadata());
687 DwarfLocSection =
688 Ctx->getCOFFSection(".debug_loc",
689 COFF::IMAGE_SCN_MEM_DISCARDABLE |
690 COFF::IMAGE_SCN_MEM_READ,
691 SectionKind::getMetadata());
692 DwarfARangesSection =
693 Ctx->getCOFFSection(".debug_aranges",
694 COFF::IMAGE_SCN_MEM_DISCARDABLE |
695 COFF::IMAGE_SCN_MEM_READ,
696 SectionKind::getMetadata());
697 DwarfRangesSection =
698 Ctx->getCOFFSection(".debug_ranges",
699 COFF::IMAGE_SCN_MEM_DISCARDABLE |
700 COFF::IMAGE_SCN_MEM_READ,
701 SectionKind::getMetadata());
702 DwarfMacroInfoSection =
703 Ctx->getCOFFSection(".debug_macinfo",
704 COFF::IMAGE_SCN_MEM_DISCARDABLE |
705 COFF::IMAGE_SCN_MEM_READ,
706 SectionKind::getMetadata());
David Blaikie62dd7df2014-03-26 03:05:10 +0000707 DwarfInfoDWOSection =
708 Ctx->getCOFFSection(".debug_info.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
709 COFF::IMAGE_SCN_MEM_READ,
710 SectionKind::getMetadata());
711 DwarfAbbrevDWOSection =
712 Ctx->getCOFFSection(".debug_abbrev.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
713 COFF::IMAGE_SCN_MEM_READ,
714 SectionKind::getMetadata());
715 DwarfStrDWOSection =
716 Ctx->getCOFFSection(".debug_str.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
717 COFF::IMAGE_SCN_MEM_READ,
718 SectionKind::getMetadata());
719 DwarfLineDWOSection =
720 Ctx->getCOFFSection(".debug_line.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
721 COFF::IMAGE_SCN_MEM_READ,
722 SectionKind::getMetadata());
723 DwarfLocDWOSection =
724 Ctx->getCOFFSection(".debug_loc.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
725 COFF::IMAGE_SCN_MEM_READ,
726 SectionKind::getMetadata());
727 DwarfStrOffDWOSection =
728 Ctx->getCOFFSection(".debug_str_offsets.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
729 COFF::IMAGE_SCN_MEM_READ,
730 SectionKind::getMetadata());
731 DwarfAddrSection = Ctx->getCOFFSection(
732 ".debug_addr", COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_MEM_READ,
733 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000734
735 DrectveSection =
736 Ctx->getCOFFSection(".drectve",
Saleem Abdulrasoolec8c2db2014-05-21 05:15:01 +0000737 COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
Evan Cheng76792992011-07-20 05:58:47 +0000738 SectionKind::getMetadata());
739
740 PDataSection =
741 Ctx->getCOFFSection(".pdata",
742 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikovcc8c5392012-08-08 12:46:46 +0000743 COFF::IMAGE_SCN_MEM_READ,
Evan Cheng76792992011-07-20 05:58:47 +0000744 SectionKind::getDataRel());
745
746 XDataSection =
747 Ctx->getCOFFSection(".xdata",
748 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Anton Korobeynikovcc8c5392012-08-08 12:46:46 +0000749 COFF::IMAGE_SCN_MEM_READ,
Evan Cheng76792992011-07-20 05:58:47 +0000750 SectionKind::getDataRel());
Anton Korobeynikovc6b40172012-02-11 17:26:53 +0000751 TLSDataSection =
752 Ctx->getCOFFSection(".tls$",
753 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
754 COFF::IMAGE_SCN_MEM_READ |
755 COFF::IMAGE_SCN_MEM_WRITE,
756 SectionKind::getDataRel());
Evan Cheng76792992011-07-20 05:58:47 +0000757}
758
759void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000760 CodeModel::Model cm,
Evan Cheng76792992011-07-20 05:58:47 +0000761 MCContext &ctx) {
762 RelocM = relocm;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000763 CMModel = cm;
Evan Cheng76792992011-07-20 05:58:47 +0000764 Ctx = &ctx;
765
766 // Common.
767 CommDirectiveSupportsAlignment = true;
768 SupportsWeakOmittedEHFrame = true;
769 IsFunctionEHFrameSymbolPrivate = true;
Tim Northoverd1c6f512014-03-29 09:03:13 +0000770 SupportsCompactUnwindWithoutEHFrame = false;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000771
Rafael Espindolaaa7851d2014-05-12 13:47:05 +0000772 PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
773 dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000774
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000775 CompactUnwindDwarfEHFrameOnly = 0;
776
Craig Topperbb694de2014-04-13 04:57:38 +0000777 EHFrameSection = nullptr; // Created on demand.
778 CompactUnwindSection = nullptr; // Used only by selected targets.
779 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
780 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
781 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
782 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
Evan Cheng76792992011-07-20 05:58:47 +0000783
784 Triple T(TT);
785 Triple::ArchType Arch = T.getArch();
786 // FIXME: Checking for Arch here to filter out bogus triples such as
787 // cellspu-apple-darwin. Perhaps we should fix in Triple?
788 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
789 Arch == Triple::arm || Arch == Triple::thumb ||
Tim Northover3b0846e2014-05-24 12:50:23 +0000790 Arch == Triple::arm64 || Arch == Triple::aarch64 ||
Evan Cheng76792992011-07-20 05:58:47 +0000791 Arch == Triple::ppc || Arch == Triple::ppc64 ||
792 Arch == Triple::UnknownArch) &&
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000793 (T.isOSDarwin() || T.isOSBinFormatMachO())) {
Evan Cheng76792992011-07-20 05:58:47 +0000794 Env = IsMachO;
795 InitMachOMCObjectFileInfo(T);
Saleem Abdulrasoolffdb92a702014-04-27 04:54:16 +0000796 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
797 Arch == Triple::arm || Arch == Triple::thumb) &&
798 (T.isOSWindows() && T.getObjectFormat() == Triple::COFF)) {
Evan Cheng76792992011-07-20 05:58:47 +0000799 Env = IsCOFF;
800 InitCOFFMCObjectFileInfo(T);
801 } else {
802 Env = IsELF;
803 InitELFMCObjectFileInfo(T);
804 }
805}
806
David Blaikiebc563272013-12-13 21:33:40 +0000807const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
808 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
809 SectionKind::getMetadata(), 0, utostr(Hash));
810}
811
David Blaikie2da282b2014-05-21 23:27:41 +0000812const MCSection *
813MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
814 return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS,
815 ELF::SHF_GROUP, SectionKind::getMetadata(), 0,
816 utostr(Hash));
817}
818
David Chisnall85dd3092012-02-17 16:51:02 +0000819void MCObjectFileInfo::InitEHFrameSection() {
820 if (Env == IsMachO)
821 EHFrameSection =
822 Ctx->getMachOSection("__TEXT", "__eh_frame",
David Majnemer7b583052014-03-07 07:36:05 +0000823 MachO::S_COALESCED |
824 MachO::S_ATTR_NO_TOC |
825 MachO::S_ATTR_STRIP_STATIC_SYMS |
826 MachO::S_ATTR_LIVE_SUPPORT,
David Chisnall85dd3092012-02-17 16:51:02 +0000827 SectionKind::getReadOnly());
828 else if (Env == IsELF)
829 EHFrameSection =
David Chisnallbbec8722012-04-10 11:44:33 +0000830 Ctx->getELFSection(".eh_frame", EHSectionType,
David Chisnall07f8d3e2012-02-17 17:31:15 +0000831 EHSectionFlags,
David Chisnall85dd3092012-02-17 16:51:02 +0000832 SectionKind::getDataRel());
833 else
834 EHFrameSection =
835 Ctx->getCOFFSection(".eh_frame",
836 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
837 COFF::IMAGE_SCN_MEM_READ |
838 COFF::IMAGE_SCN_MEM_WRITE,
839 SectionKind::getDataRel());
840}