blob: 0ccd7087badc18c1401b8b53122ecb3e258fc327 [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"
Reid Kleckner1f13d472015-09-03 16:41:50 +000019#include "llvm/Support/COFF.h"
Evan Cheng76792992011-07-20 05:58:47 +000020using namespace llvm;
21
Rafael Espindolabecdf632014-06-20 22:37:01 +000022static bool useCompactUnwind(const Triple &T) {
23 // Only on darwin.
24 if (!T.isOSDarwin())
25 return false;
26
27 // aarch64 always has it.
Tim Northovere19bed72014-07-23 12:32:47 +000028 if (T.getArch() == Triple::aarch64)
Rafael Espindolabecdf632014-06-20 22:37:01 +000029 return true;
30
31 // Use it on newer version of OS X.
32 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
33 return true;
34
Rafael Espindolac3510c72014-06-20 22:40:55 +000035 // And the iOS simulator.
36 if (T.isiOS() &&
37 (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86))
38 return true;
39
Rafael Espindolabecdf632014-06-20 22:37:01 +000040 return false;
41}
42
Jim Grosbachbb2591f2015-06-04 23:35:03 +000043void MCObjectFileInfo::initMachOMCObjectFileInfo(Triple T) {
Evan Cheng76792992011-07-20 05:58:47 +000044 // MachO
Evan Cheng76792992011-07-20 05:58:47 +000045 SupportsWeakOmittedEHFrame = false;
46
Tim Northovere19bed72014-07-23 12:32:47 +000047 if (T.isOSDarwin() && T.getArch() == Triple::aarch64)
Tim Northover00ed9962014-03-29 10:18:08 +000048 SupportsCompactUnwindWithoutEHFrame = true;
49
Evan Chengbbf3b0d2011-07-20 19:50:42 +000050 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
51 | dwarf::DW_EH_PE_sdata4;
Rafael Espindolaaa7851d2014-05-12 13:47:05 +000052 LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
Evan Chengbbf3b0d2011-07-20 19:50:42 +000053 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
54 dwarf::DW_EH_PE_sdata4;
55
Evan Cheng76792992011-07-20 05:58:47 +000056 // .comm doesn't support alignment before Leopard.
57 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
58 CommDirectiveSupportsAlignment = false;
59
60 TextSection // .text
61 = Ctx->getMachOSection("__TEXT", "__text",
David Majnemer7b583052014-03-07 07:36:05 +000062 MachO::S_ATTR_PURE_INSTRUCTIONS,
Evan Cheng76792992011-07-20 05:58:47 +000063 SectionKind::getText());
64 DataSection // .data
65 = Ctx->getMachOSection("__DATA", "__data", 0,
66 SectionKind::getDataRel());
67
NAKAMURA Takumi68fa6f92013-09-21 02:34:45 +000068 // BSSSection might not be expected initialized on msvc.
Craig Topperbb694de2014-04-13 04:57:38 +000069 BSSSection = nullptr;
NAKAMURA Takumi68fa6f92013-09-21 02:34:45 +000070
Evan Cheng76792992011-07-20 05:58:47 +000071 TLSDataSection // .tdata
72 = Ctx->getMachOSection("__DATA", "__thread_data",
David Majnemer7b583052014-03-07 07:36:05 +000073 MachO::S_THREAD_LOCAL_REGULAR,
Evan Cheng76792992011-07-20 05:58:47 +000074 SectionKind::getDataRel());
75 TLSBSSSection // .tbss
76 = Ctx->getMachOSection("__DATA", "__thread_bss",
David Majnemer7b583052014-03-07 07:36:05 +000077 MachO::S_THREAD_LOCAL_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +000078 SectionKind::getThreadBSS());
79
80 // TODO: Verify datarel below.
81 TLSTLVSection // .tlv
82 = Ctx->getMachOSection("__DATA", "__thread_vars",
David Majnemer7b583052014-03-07 07:36:05 +000083 MachO::S_THREAD_LOCAL_VARIABLES,
Evan Cheng76792992011-07-20 05:58:47 +000084 SectionKind::getDataRel());
85
86 TLSThreadInitSection
87 = Ctx->getMachOSection("__DATA", "__thread_init",
David Majnemer7b583052014-03-07 07:36:05 +000088 MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
Jim Grosbach0dde3492011-11-15 16:46:22 +000089 SectionKind::getDataRel());
Evan Cheng76792992011-07-20 05:58:47 +000090
91 CStringSection // .cstring
92 = Ctx->getMachOSection("__TEXT", "__cstring",
David Majnemer7b583052014-03-07 07:36:05 +000093 MachO::S_CSTRING_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +000094 SectionKind::getMergeable1ByteCString());
95 UStringSection
96 = Ctx->getMachOSection("__TEXT","__ustring", 0,
97 SectionKind::getMergeable2ByteCString());
98 FourByteConstantSection // .literal4
99 = Ctx->getMachOSection("__TEXT", "__literal4",
David Majnemer7b583052014-03-07 07:36:05 +0000100 MachO::S_4BYTE_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +0000101 SectionKind::getMergeableConst4());
102 EightByteConstantSection // .literal8
103 = Ctx->getMachOSection("__TEXT", "__literal8",
David Majnemer7b583052014-03-07 07:36:05 +0000104 MachO::S_8BYTE_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +0000105 SectionKind::getMergeableConst8());
106
Rafael Espindola1f3de492014-02-13 23:16:11 +0000107 SixteenByteConstantSection // .literal16
108 = Ctx->getMachOSection("__TEXT", "__literal16",
David Majnemer7b583052014-03-07 07:36:05 +0000109 MachO::S_16BYTE_LITERALS,
Rafael Espindola1f3de492014-02-13 23:16:11 +0000110 SectionKind::getMergeableConst16());
Evan Cheng76792992011-07-20 05:58:47 +0000111
112 ReadOnlySection // .const
113 = Ctx->getMachOSection("__TEXT", "__const", 0,
114 SectionKind::getReadOnly());
115
116 TextCoalSection
117 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
David Majnemer7b583052014-03-07 07:36:05 +0000118 MachO::S_COALESCED |
119 MachO::S_ATTR_PURE_INSTRUCTIONS,
Evan Cheng76792992011-07-20 05:58:47 +0000120 SectionKind::getText());
121 ConstTextCoalSection
122 = Ctx->getMachOSection("__TEXT", "__const_coal",
David Majnemer7b583052014-03-07 07:36:05 +0000123 MachO::S_COALESCED,
Evan Cheng76792992011-07-20 05:58:47 +0000124 SectionKind::getReadOnly());
125 ConstDataSection // .const_data
126 = Ctx->getMachOSection("__DATA", "__const", 0,
127 SectionKind::getReadOnlyWithRel());
128 DataCoalSection
129 = Ctx->getMachOSection("__DATA","__datacoal_nt",
David Majnemer7b583052014-03-07 07:36:05 +0000130 MachO::S_COALESCED,
Evan Cheng76792992011-07-20 05:58:47 +0000131 SectionKind::getDataRel());
132 DataCommonSection
133 = Ctx->getMachOSection("__DATA","__common",
David Majnemer7b583052014-03-07 07:36:05 +0000134 MachO::S_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +0000135 SectionKind::getBSS());
136 DataBSSSection
David Majnemer7b583052014-03-07 07:36:05 +0000137 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +0000138 SectionKind::getBSS());
139
140
141 LazySymbolPointerSection
142 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
David Majnemer7b583052014-03-07 07:36:05 +0000143 MachO::S_LAZY_SYMBOL_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000144 SectionKind::getMetadata());
145 NonLazySymbolPointerSection
146 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
David Majnemer7b583052014-03-07 07:36:05 +0000147 MachO::S_NON_LAZY_SYMBOL_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000148 SectionKind::getMetadata());
149
150 if (RelocM == Reloc::Static) {
151 StaticCtorSection
152 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
153 SectionKind::getDataRel());
154 StaticDtorSection
155 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
156 SectionKind::getDataRel());
157 } else {
158 StaticCtorSection
159 = Ctx->getMachOSection("__DATA", "__mod_init_func",
David Majnemer7b583052014-03-07 07:36:05 +0000160 MachO::S_MOD_INIT_FUNC_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000161 SectionKind::getDataRel());
162 StaticDtorSection
163 = Ctx->getMachOSection("__DATA", "__mod_term_func",
David Majnemer7b583052014-03-07 07:36:05 +0000164 MachO::S_MOD_TERM_FUNC_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000165 SectionKind::getDataRel());
166 }
167
168 // Exception Handling.
169 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
170 SectionKind::getReadOnlyWithRel());
171
Craig Topperbb694de2014-04-13 04:57:38 +0000172 COFFDebugSymbolsSection = nullptr;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000173
Rafael Espindolabecdf632014-06-20 22:37:01 +0000174 if (useCompactUnwind(T)) {
Evan Cheng76792992011-07-20 05:58:47 +0000175 CompactUnwindSection =
Rafael Espindolabecdf632014-06-20 22:37:01 +0000176 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
177 SectionKind::getReadOnly());
Evan Cheng76792992011-07-20 05:58:47 +0000178
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000179 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
180 CompactUnwindDwarfEHFrameOnly = 0x04000000;
Tim Northovere19bed72014-07-23 12:32:47 +0000181 else if (T.getArch() == Triple::aarch64)
Tim Northover00ed9962014-03-29 10:18:08 +0000182 CompactUnwindDwarfEHFrameOnly = 0x03000000;
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000183 }
184
Evan Cheng76792992011-07-20 05:58:47 +0000185 // Debug Information.
Eric Christopher4996c702011-11-07 09:24:32 +0000186 DwarfAccelNamesSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000187 Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000188 SectionKind::getMetadata(), "names_begin");
Eric Christopher4996c702011-11-07 09:24:32 +0000189 DwarfAccelObjCSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000190 Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000191 SectionKind::getMetadata(), "objc_begin");
Eric Christopher4996c702011-11-07 09:24:32 +0000192 // 16 character section limit...
193 DwarfAccelNamespaceSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000194 Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000195 SectionKind::getMetadata(), "namespac_begin");
Eric Christopher4996c702011-11-07 09:24:32 +0000196 DwarfAccelTypesSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000197 Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000198 SectionKind::getMetadata(), "types_begin");
Jim Grosbachdc1e36e2012-05-11 01:41:30 +0000199
Evan Cheng76792992011-07-20 05:58:47 +0000200 DwarfAbbrevSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000201 Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000202 SectionKind::getMetadata(), "section_abbrev");
Evan Cheng76792992011-07-20 05:58:47 +0000203 DwarfInfoSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000204 Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000205 SectionKind::getMetadata(), "section_info");
Evan Cheng76792992011-07-20 05:58:47 +0000206 DwarfLineSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000207 Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000208 SectionKind::getMetadata(), "section_line");
Evan Cheng76792992011-07-20 05:58:47 +0000209 DwarfFrameSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000210 Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
211 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000212 DwarfPubNamesSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000213 Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
214 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000215 DwarfPubTypesSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000216 Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
217 SectionKind::getMetadata());
Eric Christopherb0e76942013-09-09 20:03:14 +0000218 DwarfGnuPubNamesSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000219 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
220 SectionKind::getMetadata());
Eric Christopherb0e76942013-09-09 20:03:14 +0000221 DwarfGnuPubTypesSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000222 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
223 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000224 DwarfStrSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000225 Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000226 SectionKind::getMetadata(), "info_string");
Evan Cheng76792992011-07-20 05:58:47 +0000227 DwarfLocSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000228 Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000229 SectionKind::getMetadata(), "section_debug_loc");
Evan Cheng76792992011-07-20 05:58:47 +0000230 DwarfARangesSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000231 Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
232 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000233 DwarfRangesSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000234 Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000235 SectionKind::getMetadata(), "debug_range");
Evan Cheng76792992011-07-20 05:58:47 +0000236 DwarfDebugInlineSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000237 Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
238 SectionKind::getMetadata());
239 StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
240 0, SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000241
Sanjoy Dasc63244d2015-06-15 18:44:08 +0000242 FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
243 0, SectionKind::getMetadata());
244
Evan Cheng76792992011-07-20 05:58:47 +0000245 TLSExtraDataSection = TLSTLVSection;
246}
247
Jim Grosbachbb2591f2015-06-04 23:35:03 +0000248void MCObjectFileInfo::initELFMCObjectFileInfo(Triple T) {
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000249 switch (T.getArch()) {
250 case Triple::mips:
251 case Triple::mipsel:
Rafael Espindolab9b7ae02013-04-03 03:13:19 +0000252 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000253 break;
254 case Triple::mips64:
255 case Triple::mips64el:
Rafael Espindolab9b7ae02013-04-03 03:13:19 +0000256 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000257 break;
Rafael Espindolad11591b2014-11-27 17:13:56 +0000258 case Triple::x86_64:
259 FDECFIEncoding = dwarf::DW_EH_PE_pcrel |
260 ((CMModel == CodeModel::Large) ? dwarf::DW_EH_PE_sdata8
261 : dwarf::DW_EH_PE_sdata4);
262
263 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000264 default:
Rafael Espindolaef9d3492013-03-15 05:51:57 +0000265 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000266 break;
267 }
Rafael Espindolaef9d3492013-03-15 05:51:57 +0000268
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000269 switch (T.getArch()) {
Joerg Sonnenbergercf86ce12014-05-07 07:49:34 +0000270 case Triple::arm:
271 case Triple::armeb:
272 case Triple::thumb:
273 case Triple::thumbeb:
Joerg Sonnenberger94cbb662014-05-13 17:58:13 +0000274 if (Ctx->getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
275 break;
276 // Fallthrough if not using EHABI
Joerg Sonnenberger6637d4e2014-07-24 19:25:16 +0000277 case Triple::ppc:
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000278 case Triple::x86:
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000279 PersonalityEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach0dde3492011-11-15 16:46:22 +0000280 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
281 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000282 LSDAEncoding = (RelocM == Reloc::PIC_)
283 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
284 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000285 TTypeEncoding = (RelocM == Reloc::PIC_)
Jim Grosbach0dde3492011-11-15 16:46:22 +0000286 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
287 : dwarf::DW_EH_PE_absptr;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000288 break;
289 case Triple::x86_64:
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000290 if (RelocM == Reloc::PIC_) {
291 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
292 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
293 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
294 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
295 (CMModel == CodeModel::Small
296 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000297 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
298 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
299 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
300 } else {
301 PersonalityEncoding =
302 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
303 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
304 LSDAEncoding = (CMModel == CodeModel::Small)
305 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000306 TTypeEncoding = (CMModel == CodeModel::Small)
307 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
308 }
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000309 break;
310 case Triple::aarch64:
311 case Triple::aarch64_be:
Tim Northovere0e3aef2013-01-31 12:12:40 +0000312 // The small model guarantees static code/data size < 4GB, but not where it
313 // will be in memory. Most of these could end up >2GB away so even a signed
314 // pc-relative 32-bit address is insufficient, theoretically.
315 if (RelocM == Reloc::PIC_) {
316 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
317 dwarf::DW_EH_PE_sdata8;
318 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
Tim Northovere0e3aef2013-01-31 12:12:40 +0000319 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
320 dwarf::DW_EH_PE_sdata8;
321 } else {
322 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
323 LSDAEncoding = dwarf::DW_EH_PE_absptr;
Tim Northovere0e3aef2013-01-31 12:12:40 +0000324 TTypeEncoding = dwarf::DW_EH_PE_absptr;
325 }
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000326 break;
Logan Chienc0029812014-05-30 16:48:56 +0000327 case Triple::mips:
328 case Triple::mipsel:
Petar Jovanovic35f05742014-11-05 22:42:31 +0000329 case Triple::mips64:
330 case Triple::mips64el:
Daniel Sandersc95f3f82015-06-02 20:32:50 +0000331 // MIPS uses indirect pointer to refer personality functions and types, so
332 // that the eh_frame section can be read-only. DW.ref.personality will be
333 // generated for relocation.
Logan Chienc0029812014-05-30 16:48:56 +0000334 PersonalityEncoding = dwarf::DW_EH_PE_indirect;
Daniel Sandersc95f3f82015-06-02 20:32:50 +0000335 // FIXME: The N64 ABI probably ought to use DW_EH_PE_sdata8 but we can't
336 // identify N64 from just a triple.
337 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
338 dwarf::DW_EH_PE_sdata4;
339 // We don't support PC-relative LSDA references in GAS so we use the default
340 // DW_EH_PE_absptr for those.
Logan Chienc0029812014-05-30 16:48:56 +0000341 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000342 case Triple::ppc64:
343 case Triple::ppc64le:
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000344 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
345 dwarf::DW_EH_PE_udata8;
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000346 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000347 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
348 dwarf::DW_EH_PE_udata8;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000349 break;
Douglas Katzman9160e782015-04-29 20:30:57 +0000350 case Triple::sparcel:
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000351 case Triple::sparc:
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000352 if (RelocM == Reloc::PIC_) {
353 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
354 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
355 dwarf::DW_EH_PE_sdata4;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000356 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
357 dwarf::DW_EH_PE_sdata4;
358 } else {
359 LSDAEncoding = dwarf::DW_EH_PE_absptr;
360 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000361 TTypeEncoding = dwarf::DW_EH_PE_absptr;
362 }
Joerg Sonnenbergerfa9cf652014-04-30 23:36:24 +0000363 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000364 case Triple::sparcv9:
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000365 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
366 if (RelocM == Reloc::PIC_) {
367 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
368 dwarf::DW_EH_PE_sdata4;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000369 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
370 dwarf::DW_EH_PE_sdata4;
371 } else {
372 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000373 TTypeEncoding = dwarf::DW_EH_PE_absptr;
374 }
Joerg Sonnenbergerfa9cf652014-04-30 23:36:24 +0000375 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000376 case Triple::systemz:
Ulrich Weigand0213e7f2013-05-06 16:11:12 +0000377 // All currently-defined code models guarantee that 4-byte PC-relative
378 // values will be in range.
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000379 if (RelocM == Reloc::PIC_) {
380 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
381 dwarf::DW_EH_PE_sdata4;
382 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000383 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
384 dwarf::DW_EH_PE_sdata4;
385 } else {
386 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
387 LSDAEncoding = dwarf::DW_EH_PE_absptr;
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000388 TTypeEncoding = dwarf::DW_EH_PE_absptr;
389 }
Joerg Sonnenbergerfa9cf652014-04-30 23:36:24 +0000390 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000391 default:
392 break;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000393 }
394
David Chisnall07f8d3e2012-02-17 17:31:15 +0000395 // Solaris requires different flags for .eh_frame to seemingly every other
396 // platform.
David Chisnallbbec8722012-04-10 11:44:33 +0000397 EHSectionType = ELF::SHT_PROGBITS;
David Chisnall07f8d3e2012-02-17 17:31:15 +0000398 EHSectionFlags = ELF::SHF_ALLOC;
Simon Pilgrima2794102014-11-22 19:12:10 +0000399 if (T.isOSSolaris()) {
David Chisnallbbec8722012-04-10 11:44:33 +0000400 if (T.getArch() == Triple::x86_64)
401 EHSectionType = ELF::SHT_X86_64_UNWIND;
402 else
403 EHSectionFlags |= ELF::SHF_WRITE;
404 }
David Chisnall07f8d3e2012-02-17 17:31:15 +0000405
406
Evan Cheng76792992011-07-20 05:58:47 +0000407 // ELF
Rafael Espindolaba31e272015-01-29 17:33:21 +0000408 BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
409 ELF::SHF_WRITE | ELF::SHF_ALLOC);
Evan Cheng76792992011-07-20 05:58:47 +0000410
Rafael Espindolaba31e272015-01-29 17:33:21 +0000411 TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
412 ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
Evan Cheng76792992011-07-20 05:58:47 +0000413
Rafael Espindolaba31e272015-01-29 17:33:21 +0000414 DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
415 ELF::SHF_WRITE | ELF::SHF_ALLOC);
Evan Cheng76792992011-07-20 05:58:47 +0000416
417 ReadOnlySection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000418 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
Evan Cheng76792992011-07-20 05:58:47 +0000419
420 TLSDataSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000421 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
422 ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000423
Rafael Espindolaba31e272015-01-29 17:33:21 +0000424 TLSBSSSection = Ctx->getELFSection(
425 ".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000426
Rafael Espindolaba31e272015-01-29 17:33:21 +0000427 DataRelSection = Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
428 ELF::SHF_ALLOC | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000429
Rafael Espindolaba31e272015-01-29 17:33:21 +0000430 DataRelLocalSection = Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
431 ELF::SHF_ALLOC | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000432
Rafael Espindolaba31e272015-01-29 17:33:21 +0000433 DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
434 ELF::SHF_ALLOC | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000435
Rafael Espindolaba31e272015-01-29 17:33:21 +0000436 DataRelROLocalSection = Ctx->getELFSection(
437 ".data.rel.ro.local", ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000438
439 MergeableConst4Section =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000440 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
441 ELF::SHF_ALLOC | ELF::SHF_MERGE, 4, "");
Evan Cheng76792992011-07-20 05:58:47 +0000442
443 MergeableConst8Section =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000444 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
445 ELF::SHF_ALLOC | ELF::SHF_MERGE, 8, "");
Evan Cheng76792992011-07-20 05:58:47 +0000446
447 MergeableConst16Section =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000448 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
449 ELF::SHF_ALLOC | ELF::SHF_MERGE, 16, "");
Evan Cheng76792992011-07-20 05:58:47 +0000450
Rafael Espindolaba31e272015-01-29 17:33:21 +0000451 StaticCtorSection = Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
452 ELF::SHF_ALLOC | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000453
Rafael Espindolaba31e272015-01-29 17:33:21 +0000454 StaticDtorSection = Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
455 ELF::SHF_ALLOC | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000456
457 // Exception Handling Sections.
458
459 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
460 // it contains relocatable pointers. In PIC mode, this is probably a big
461 // runtime hit for C++ apps. Either the contents of the LSDA need to be
462 // adjusted or this should be a data section.
Rafael Espindolaba31e272015-01-29 17:33:21 +0000463 LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
464 ELF::SHF_ALLOC);
Evan Cheng76792992011-07-20 05:58:47 +0000465
Craig Topperbb694de2014-04-13 04:57:38 +0000466 COFFDebugSymbolsSection = nullptr;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000467
Evan Cheng76792992011-07-20 05:58:47 +0000468 // Debug Info Sections.
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000469 DwarfAbbrevSection = Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
470 "section_abbrev");
471 DwarfInfoSection =
472 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0, "section_info");
Rafael Espindola23562fc2015-03-11 04:20:31 +0000473 DwarfLineSection = Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0);
Rafael Espindolaba31e272015-01-29 17:33:21 +0000474 DwarfFrameSection = Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0);
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000475 DwarfPubNamesSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000476 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0);
Evan Cheng76792992011-07-20 05:58:47 +0000477 DwarfPubTypesSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000478 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0);
Eric Christopherb0e76942013-09-09 20:03:14 +0000479 DwarfGnuPubNamesSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000480 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0);
Eric Christopherb0e76942013-09-09 20:03:14 +0000481 DwarfGnuPubTypesSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000482 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0);
Rafael Espindola23562fc2015-03-11 04:20:31 +0000483 DwarfStrSection =
484 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
485 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
486 DwarfLocSection = Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0);
Evan Cheng76792992011-07-20 05:58:47 +0000487 DwarfARangesSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000488 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0);
Evan Cheng76792992011-07-20 05:58:47 +0000489 DwarfRangesSection =
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000490 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0, "debug_range");
Eric Christopher27ed8ec2012-11-28 02:49:34 +0000491
492 // DWARF5 Experimental Debug Info
493
494 // Accelerator Tables
Eric Christophera0ad67d2012-10-08 21:41:30 +0000495 DwarfAccelNamesSection =
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000496 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0, "names_begin");
Eric Christophera0ad67d2012-10-08 21:41:30 +0000497 DwarfAccelObjCSection =
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000498 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0, "objc_begin");
499 DwarfAccelNamespaceSection = Ctx->getELFSection(
500 ".apple_namespaces", ELF::SHT_PROGBITS, 0, "namespac_begin");
Eric Christophera0ad67d2012-10-08 21:41:30 +0000501 DwarfAccelTypesSection =
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000502 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0, "types_begin");
Eric Christopherc3b434b2012-11-28 02:49:38 +0000503
504 // Fission Sections
Rafael Espindola23562fc2015-03-11 04:20:31 +0000505 DwarfInfoDWOSection =
506 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0);
507 DwarfTypesDWOSection =
508 Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS, 0);
509 DwarfAbbrevDWOSection =
510 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0);
511 DwarfStrDWOSection =
512 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
513 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
Eric Christopher3c230092012-11-30 06:47:06 +0000514 DwarfLineDWOSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000515 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0);
Eric Christopher3c230092012-11-30 06:47:06 +0000516 DwarfLocDWOSection =
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000517 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0, "skel_loc");
Eric Christopherc0fa8672013-01-04 17:59:22 +0000518 DwarfStrOffDWOSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000519 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0);
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000520 DwarfAddrSection =
521 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0, "addr_sec");
Philip Reames76846182014-08-01 18:47:09 +0000522
523 StackMapSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000524 Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
Sanjoy Dasc63244d2015-06-15 18:44:08 +0000525
526 FaultMapSection =
527 Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
Evan Cheng76792992011-07-20 05:58:47 +0000528}
529
Jim Grosbachbb2591f2015-06-04 23:35:03 +0000530void MCObjectFileInfo::initCOFFMCObjectFileInfo(Triple T) {
Saleem Abdulrasool70a02062014-06-08 03:57:49 +0000531 bool IsWoA = T.getArch() == Triple::arm || T.getArch() == Triple::thumb;
532
David Majnemer48227a32014-09-21 09:18:07 +0000533 CommDirectiveSupportsAlignment = true;
David Majnemera9bdb322014-04-08 22:33:40 +0000534
Evan Cheng76792992011-07-20 05:58:47 +0000535 // COFF
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000536 BSSSection = Ctx->getCOFFSection(
537 ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
538 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
539 SectionKind::getBSS());
540 TextSection = Ctx->getCOFFSection(
541 ".text",
542 (IsWoA ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |
543 COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
544 COFF::IMAGE_SCN_MEM_READ,
545 SectionKind::getText());
546 DataSection = Ctx->getCOFFSection(
547 ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
548 COFF::IMAGE_SCN_MEM_WRITE,
549 SectionKind::getDataRel());
550 ReadOnlySection = Ctx->getCOFFSection(
551 ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
552 SectionKind::getReadOnly());
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000553
Saleem Abdulrasooled7fc4b2014-06-08 00:34:27 +0000554 if (T.isKnownWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
Michael J. Spencerb560d072012-02-23 21:56:08 +0000555 StaticCtorSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000556 Ctx->getCOFFSection(".CRT$XCU", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
557 COFF::IMAGE_SCN_MEM_READ,
558 SectionKind::getReadOnly());
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000559 StaticDtorSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000560 Ctx->getCOFFSection(".CRT$XTX", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
561 COFF::IMAGE_SCN_MEM_READ,
562 SectionKind::getReadOnly());
Michael J. Spencerb560d072012-02-23 21:56:08 +0000563 } else {
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000564 StaticCtorSection = Ctx->getCOFFSection(
565 ".ctors", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
566 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
567 SectionKind::getDataRel());
568 StaticDtorSection = Ctx->getCOFFSection(
569 ".dtors", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
570 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
571 SectionKind::getDataRel());
Anton Korobeynikov37d73002012-09-23 15:53:47 +0000572 }
Evan Cheng76792992011-07-20 05:58:47 +0000573
574 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
575 // though it contains relocatable pointers. In PIC mode, this is probably a
576 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
577 // adjusted or this should be a data section.
NAKAMURA Takumi1db59952014-06-25 12:41:52 +0000578 assert(T.isOSWindows() && "Windows is the only supported COFF target");
579 if (T.getArch() == Triple::x86_64) {
580 // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
581 LSDASection = 0;
582 } else {
583 LSDASection = Ctx->getCOFFSection(".gcc_except_table",
584 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
585 COFF::IMAGE_SCN_MEM_READ,
586 SectionKind::getReadOnly());
587 }
Evan Cheng76792992011-07-20 05:58:47 +0000588
589 // Debug info.
Timur Iskhodzhanov31377c52014-01-28 03:48:44 +0000590 COFFDebugSymbolsSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000591 Ctx->getCOFFSection(".debug$S", COFF::IMAGE_SCN_MEM_DISCARDABLE |
592 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
593 COFF::IMAGE_SCN_MEM_READ,
594 SectionKind::getMetadata());
Timur Iskhodzhanov31377c52014-01-28 03:48:44 +0000595
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000596 DwarfAbbrevSection = Ctx->getCOFFSection(
597 ".debug_abbrev",
598 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
599 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000600 SectionKind::getMetadata(), "section_abbrev");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000601 DwarfInfoSection = Ctx->getCOFFSection(
602 ".debug_info",
603 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
604 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000605 SectionKind::getMetadata(), "section_info");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000606 DwarfLineSection = Ctx->getCOFFSection(
607 ".debug_line",
608 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
609 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000610 SectionKind::getMetadata(), "section_line");
611
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000612 DwarfFrameSection = Ctx->getCOFFSection(
613 ".debug_frame",
614 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
615 COFF::IMAGE_SCN_MEM_READ,
616 SectionKind::getMetadata());
617 DwarfPubNamesSection = Ctx->getCOFFSection(
618 ".debug_pubnames",
619 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
620 COFF::IMAGE_SCN_MEM_READ,
621 SectionKind::getMetadata());
622 DwarfPubTypesSection = Ctx->getCOFFSection(
623 ".debug_pubtypes",
624 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
625 COFF::IMAGE_SCN_MEM_READ,
626 SectionKind::getMetadata());
627 DwarfGnuPubNamesSection = Ctx->getCOFFSection(
628 ".debug_gnu_pubnames",
629 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
630 COFF::IMAGE_SCN_MEM_READ,
631 SectionKind::getMetadata());
632 DwarfGnuPubTypesSection = Ctx->getCOFFSection(
633 ".debug_gnu_pubtypes",
634 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
635 COFF::IMAGE_SCN_MEM_READ,
636 SectionKind::getMetadata());
637 DwarfStrSection = Ctx->getCOFFSection(
638 ".debug_str",
639 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
640 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000641 SectionKind::getMetadata(), "info_string");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000642 DwarfLocSection = Ctx->getCOFFSection(
643 ".debug_loc",
644 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
645 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000646 SectionKind::getMetadata(), "section_debug_loc");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000647 DwarfARangesSection = Ctx->getCOFFSection(
648 ".debug_aranges",
649 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
650 COFF::IMAGE_SCN_MEM_READ,
651 SectionKind::getMetadata());
652 DwarfRangesSection = Ctx->getCOFFSection(
653 ".debug_ranges",
654 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
655 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000656 SectionKind::getMetadata(), "debug_range");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000657 DwarfInfoDWOSection = Ctx->getCOFFSection(
658 ".debug_info.dwo",
659 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
660 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000661 SectionKind::getMetadata(), "section_info_dwo");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000662 DwarfTypesDWOSection = Ctx->getCOFFSection(
663 ".debug_types.dwo",
664 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
665 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindolab03bc792015-03-10 23:06:32 +0000666 SectionKind::getMetadata(), "section_types_dwo");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000667 DwarfAbbrevDWOSection = Ctx->getCOFFSection(
668 ".debug_abbrev.dwo",
669 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
670 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000671 SectionKind::getMetadata(), "section_abbrev_dwo");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000672 DwarfStrDWOSection = Ctx->getCOFFSection(
673 ".debug_str.dwo",
674 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
675 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000676 SectionKind::getMetadata(), "skel_string");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000677 DwarfLineDWOSection = Ctx->getCOFFSection(
678 ".debug_line.dwo",
679 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
680 COFF::IMAGE_SCN_MEM_READ,
681 SectionKind::getMetadata());
682 DwarfLocDWOSection = Ctx->getCOFFSection(
683 ".debug_loc.dwo",
684 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
685 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000686 SectionKind::getMetadata(), "skel_loc");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000687 DwarfStrOffDWOSection = Ctx->getCOFFSection(
688 ".debug_str_offsets.dwo",
689 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
690 COFF::IMAGE_SCN_MEM_READ,
691 SectionKind::getMetadata());
692 DwarfAddrSection = Ctx->getCOFFSection(
693 ".debug_addr",
694 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
695 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000696 SectionKind::getMetadata(), "addr_sec");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000697 DwarfAccelNamesSection = Ctx->getCOFFSection(
698 ".apple_names",
699 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
700 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000701 SectionKind::getMetadata(), "names_begin");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000702 DwarfAccelNamespaceSection = Ctx->getCOFFSection(
703 ".apple_namespaces",
704 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
705 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000706 SectionKind::getMetadata(), "namespac_begin");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000707 DwarfAccelTypesSection = Ctx->getCOFFSection(
708 ".apple_types",
709 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
710 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000711 SectionKind::getMetadata(), "types_begin");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000712 DwarfAccelObjCSection = Ctx->getCOFFSection(
713 ".apple_objc",
714 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
715 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000716 SectionKind::getMetadata(), "objc_begin");
Frederic Riss3f1a0a72014-11-14 20:33:40 +0000717
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000718 DrectveSection = Ctx->getCOFFSection(
719 ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
720 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000721
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000722 PDataSection = Ctx->getCOFFSection(
723 ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
724 SectionKind::getDataRel());
Evan Cheng76792992011-07-20 05:58:47 +0000725
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000726 XDataSection = Ctx->getCOFFSection(
727 ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
728 SectionKind::getDataRel());
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000729
David Majnemer4eecd302015-05-30 04:56:02 +0000730 SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO,
731 SectionKind::getMetadata());
732
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000733 TLSDataSection = Ctx->getCOFFSection(
734 ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
735 COFF::IMAGE_SCN_MEM_WRITE,
736 SectionKind::getDataRel());
Swaroop Sridhare9247ab2015-06-25 00:28:42 +0000737
738 StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
739 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
740 COFF::IMAGE_SCN_MEM_READ,
741 SectionKind::getReadOnly());
Evan Cheng76792992011-07-20 05:58:47 +0000742}
743
Daniel Sanders8d8b13d2015-06-16 12:18:07 +0000744void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple,
745 Reloc::Model relocm,
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000746 CodeModel::Model cm,
Evan Cheng76792992011-07-20 05:58:47 +0000747 MCContext &ctx) {
748 RelocM = relocm;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000749 CMModel = cm;
Evan Cheng76792992011-07-20 05:58:47 +0000750 Ctx = &ctx;
751
752 // Common.
753 CommDirectiveSupportsAlignment = true;
754 SupportsWeakOmittedEHFrame = true;
Tim Northoverd1c6f512014-03-29 09:03:13 +0000755 SupportsCompactUnwindWithoutEHFrame = false;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000756
Rafael Espindolaaa7851d2014-05-12 13:47:05 +0000757 PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
758 dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000759
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000760 CompactUnwindDwarfEHFrameOnly = 0;
761
Craig Topperbb694de2014-04-13 04:57:38 +0000762 EHFrameSection = nullptr; // Created on demand.
763 CompactUnwindSection = nullptr; // Used only by selected targets.
764 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
765 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
766 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
767 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
Evan Cheng76792992011-07-20 05:58:47 +0000768
Daniel Sanders8d8b13d2015-06-16 12:18:07 +0000769 TT = TheTriple;
Saleem Abdulrasoolbdbc0082014-06-22 22:25:01 +0000770
Rafael Espindoladbaf0492015-08-14 15:48:41 +0000771 Triple::ArchType Arch = TT.getArch();
772 // FIXME: Checking for Arch here to filter out bogus triples such as
773 // cellspu-apple-darwin. Perhaps we should fix in Triple?
774 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
775 Arch == Triple::arm || Arch == Triple::thumb ||
776 Arch == Triple::aarch64 ||
777 Arch == Triple::ppc || Arch == Triple::ppc64 ||
778 Arch == Triple::UnknownArch) &&
779 TT.isOSBinFormatMachO()) {
780 Env = IsMachO;
Jim Grosbachbb2591f2015-06-04 23:35:03 +0000781 initMachOMCObjectFileInfo(TT);
Rafael Espindoladbaf0492015-08-14 15:48:41 +0000782 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
783 Arch == Triple::arm || Arch == Triple::thumb) &&
784 (TT.isOSWindows() && TT.getObjectFormat() == Triple::COFF)) {
785 Env = IsCOFF;
Jim Grosbachbb2591f2015-06-04 23:35:03 +0000786 initCOFFMCObjectFileInfo(TT);
Rafael Espindoladbaf0492015-08-14 15:48:41 +0000787 } else {
788 Env = IsELF;
Jim Grosbachbb2591f2015-06-04 23:35:03 +0000789 initELFMCObjectFileInfo(TT);
Evan Cheng76792992011-07-20 05:58:47 +0000790 }
791}
792
Daniel Sanders8d8b13d2015-06-16 12:18:07 +0000793void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model RM,
794 CodeModel::Model CM,
795 MCContext &ctx) {
796 InitMCObjectFileInfo(Triple(TT), RM, CM, ctx);
797}
798
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000799MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
David Blaikiebc563272013-12-13 21:33:40 +0000800 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
Rafael Espindolaba31e272015-01-29 17:33:21 +0000801 0, utostr(Hash));
David Blaikiebc563272013-12-13 21:33:40 +0000802}
803
David Chisnall85dd3092012-02-17 16:51:02 +0000804void MCObjectFileInfo::InitEHFrameSection() {
Rafael Espindoladbaf0492015-08-14 15:48:41 +0000805 if (Env == IsMachO)
David Chisnall85dd3092012-02-17 16:51:02 +0000806 EHFrameSection =
807 Ctx->getMachOSection("__TEXT", "__eh_frame",
David Majnemer7b583052014-03-07 07:36:05 +0000808 MachO::S_COALESCED |
809 MachO::S_ATTR_NO_TOC |
810 MachO::S_ATTR_STRIP_STATIC_SYMS |
811 MachO::S_ATTR_LIVE_SUPPORT,
David Chisnall85dd3092012-02-17 16:51:02 +0000812 SectionKind::getReadOnly());
Rafael Espindoladbaf0492015-08-14 15:48:41 +0000813 else if (Env == IsELF)
David Chisnall85dd3092012-02-17 16:51:02 +0000814 EHFrameSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000815 Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
Rafael Espindoladbaf0492015-08-14 15:48:41 +0000816 else
David Chisnall85dd3092012-02-17 16:51:02 +0000817 EHFrameSection =
818 Ctx->getCOFFSection(".eh_frame",
819 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
820 COFF::IMAGE_SCN_MEM_READ |
821 COFF::IMAGE_SCN_MEM_WRITE,
822 SectionKind::getDataRel());
823}