blob: edb38a7f4873e3bcfa37326b2eeb8bf59851963e [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
Evan Cheng76792992011-07-20 05:58:47 +0000406 // ELF
Rafael Espindolaba31e272015-01-29 17:33:21 +0000407 BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
408 ELF::SHF_WRITE | ELF::SHF_ALLOC);
Evan Cheng76792992011-07-20 05:58:47 +0000409
Rafael Espindolaba31e272015-01-29 17:33:21 +0000410 TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
411 ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
Evan Cheng76792992011-07-20 05:58:47 +0000412
Rafael Espindolaba31e272015-01-29 17:33:21 +0000413 DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
414 ELF::SHF_WRITE | ELF::SHF_ALLOC);
Evan Cheng76792992011-07-20 05:58:47 +0000415
416 ReadOnlySection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000417 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
Evan Cheng76792992011-07-20 05:58:47 +0000418
419 TLSDataSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000420 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
421 ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000422
Rafael Espindolaba31e272015-01-29 17:33:21 +0000423 TLSBSSSection = Ctx->getELFSection(
424 ".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000425
Rafael Espindolaba31e272015-01-29 17:33:21 +0000426 DataRelSection = Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
427 ELF::SHF_ALLOC | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000428
Rafael Espindolaba31e272015-01-29 17:33:21 +0000429 DataRelLocalSection = Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
430 ELF::SHF_ALLOC | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000431
Rafael Espindolaba31e272015-01-29 17:33:21 +0000432 DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
433 ELF::SHF_ALLOC | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000434
Rafael Espindolaba31e272015-01-29 17:33:21 +0000435 DataRelROLocalSection = Ctx->getELFSection(
436 ".data.rel.ro.local", ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000437
438 MergeableConst4Section =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000439 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
440 ELF::SHF_ALLOC | ELF::SHF_MERGE, 4, "");
Evan Cheng76792992011-07-20 05:58:47 +0000441
442 MergeableConst8Section =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000443 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
444 ELF::SHF_ALLOC | ELF::SHF_MERGE, 8, "");
Evan Cheng76792992011-07-20 05:58:47 +0000445
446 MergeableConst16Section =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000447 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
448 ELF::SHF_ALLOC | ELF::SHF_MERGE, 16, "");
Evan Cheng76792992011-07-20 05:58:47 +0000449
Rafael Espindolaba31e272015-01-29 17:33:21 +0000450 StaticCtorSection = Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
451 ELF::SHF_ALLOC | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000452
Rafael Espindolaba31e272015-01-29 17:33:21 +0000453 StaticDtorSection = Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
454 ELF::SHF_ALLOC | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000455
456 // Exception Handling Sections.
457
458 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
459 // it contains relocatable pointers. In PIC mode, this is probably a big
460 // runtime hit for C++ apps. Either the contents of the LSDA need to be
461 // adjusted or this should be a data section.
Rafael Espindolaba31e272015-01-29 17:33:21 +0000462 LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
463 ELF::SHF_ALLOC);
Evan Cheng76792992011-07-20 05:58:47 +0000464
Craig Topperbb694de2014-04-13 04:57:38 +0000465 COFFDebugSymbolsSection = nullptr;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000466
Evan Cheng76792992011-07-20 05:58:47 +0000467 // Debug Info Sections.
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000468 DwarfAbbrevSection = Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
469 "section_abbrev");
470 DwarfInfoSection =
471 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0, "section_info");
Rafael Espindola23562fc2015-03-11 04:20:31 +0000472 DwarfLineSection = Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0);
Rafael Espindolaba31e272015-01-29 17:33:21 +0000473 DwarfFrameSection = Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0);
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000474 DwarfPubNamesSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000475 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0);
Evan Cheng76792992011-07-20 05:58:47 +0000476 DwarfPubTypesSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000477 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0);
Eric Christopherb0e76942013-09-09 20:03:14 +0000478 DwarfGnuPubNamesSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000479 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0);
Eric Christopherb0e76942013-09-09 20:03:14 +0000480 DwarfGnuPubTypesSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000481 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0);
Rafael Espindola23562fc2015-03-11 04:20:31 +0000482 DwarfStrSection =
483 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
484 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
485 DwarfLocSection = Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0);
Evan Cheng76792992011-07-20 05:58:47 +0000486 DwarfARangesSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000487 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0);
Evan Cheng76792992011-07-20 05:58:47 +0000488 DwarfRangesSection =
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000489 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0, "debug_range");
Eric Christopher27ed8ec2012-11-28 02:49:34 +0000490
491 // DWARF5 Experimental Debug Info
492
493 // Accelerator Tables
Eric Christophera0ad67d2012-10-08 21:41:30 +0000494 DwarfAccelNamesSection =
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000495 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0, "names_begin");
Eric Christophera0ad67d2012-10-08 21:41:30 +0000496 DwarfAccelObjCSection =
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000497 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0, "objc_begin");
498 DwarfAccelNamespaceSection = Ctx->getELFSection(
499 ".apple_namespaces", ELF::SHT_PROGBITS, 0, "namespac_begin");
Eric Christophera0ad67d2012-10-08 21:41:30 +0000500 DwarfAccelTypesSection =
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000501 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0, "types_begin");
Eric Christopherc3b434b2012-11-28 02:49:38 +0000502
503 // Fission Sections
Rafael Espindola23562fc2015-03-11 04:20:31 +0000504 DwarfInfoDWOSection =
505 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0);
506 DwarfTypesDWOSection =
507 Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS, 0);
508 DwarfAbbrevDWOSection =
509 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0);
510 DwarfStrDWOSection =
511 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
512 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
Eric Christopher3c230092012-11-30 06:47:06 +0000513 DwarfLineDWOSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000514 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0);
Eric Christopher3c230092012-11-30 06:47:06 +0000515 DwarfLocDWOSection =
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000516 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0, "skel_loc");
Eric Christopherc0fa8672013-01-04 17:59:22 +0000517 DwarfStrOffDWOSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000518 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0);
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000519 DwarfAddrSection =
520 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0, "addr_sec");
Philip Reames76846182014-08-01 18:47:09 +0000521
522 StackMapSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000523 Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
Sanjoy Dasc63244d2015-06-15 18:44:08 +0000524
525 FaultMapSection =
526 Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
Evan Cheng76792992011-07-20 05:58:47 +0000527}
528
Jim Grosbachbb2591f2015-06-04 23:35:03 +0000529void MCObjectFileInfo::initCOFFMCObjectFileInfo(Triple T) {
Saleem Abdulrasool70a02062014-06-08 03:57:49 +0000530 bool IsWoA = T.getArch() == Triple::arm || T.getArch() == Triple::thumb;
531
David Majnemer48227a32014-09-21 09:18:07 +0000532 CommDirectiveSupportsAlignment = true;
David Majnemera9bdb322014-04-08 22:33:40 +0000533
Evan Cheng76792992011-07-20 05:58:47 +0000534 // COFF
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000535 BSSSection = Ctx->getCOFFSection(
536 ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
537 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
538 SectionKind::getBSS());
539 TextSection = Ctx->getCOFFSection(
540 ".text",
541 (IsWoA ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |
542 COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
543 COFF::IMAGE_SCN_MEM_READ,
544 SectionKind::getText());
545 DataSection = Ctx->getCOFFSection(
546 ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
547 COFF::IMAGE_SCN_MEM_WRITE,
548 SectionKind::getDataRel());
549 ReadOnlySection = Ctx->getCOFFSection(
550 ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
551 SectionKind::getReadOnly());
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000552
Saleem Abdulrasooled7fc4b2014-06-08 00:34:27 +0000553 if (T.isKnownWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
Michael J. Spencerb560d072012-02-23 21:56:08 +0000554 StaticCtorSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000555 Ctx->getCOFFSection(".CRT$XCU", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
556 COFF::IMAGE_SCN_MEM_READ,
557 SectionKind::getReadOnly());
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000558 StaticDtorSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000559 Ctx->getCOFFSection(".CRT$XTX", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
560 COFF::IMAGE_SCN_MEM_READ,
561 SectionKind::getReadOnly());
Michael J. Spencerb560d072012-02-23 21:56:08 +0000562 } else {
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000563 StaticCtorSection = Ctx->getCOFFSection(
564 ".ctors", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
565 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
566 SectionKind::getDataRel());
567 StaticDtorSection = Ctx->getCOFFSection(
568 ".dtors", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
569 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
570 SectionKind::getDataRel());
Anton Korobeynikov37d73002012-09-23 15:53:47 +0000571 }
Evan Cheng76792992011-07-20 05:58:47 +0000572
573 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
574 // though it contains relocatable pointers. In PIC mode, this is probably a
575 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
576 // adjusted or this should be a data section.
NAKAMURA Takumi1db59952014-06-25 12:41:52 +0000577 assert(T.isOSWindows() && "Windows is the only supported COFF target");
578 if (T.getArch() == Triple::x86_64) {
579 // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
580 LSDASection = 0;
581 } else {
582 LSDASection = Ctx->getCOFFSection(".gcc_except_table",
583 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
584 COFF::IMAGE_SCN_MEM_READ,
585 SectionKind::getReadOnly());
586 }
Evan Cheng76792992011-07-20 05:58:47 +0000587
588 // Debug info.
Timur Iskhodzhanov31377c52014-01-28 03:48:44 +0000589 COFFDebugSymbolsSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000590 Ctx->getCOFFSection(".debug$S", COFF::IMAGE_SCN_MEM_DISCARDABLE |
591 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
592 COFF::IMAGE_SCN_MEM_READ,
593 SectionKind::getMetadata());
Timur Iskhodzhanov31377c52014-01-28 03:48:44 +0000594
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000595 DwarfAbbrevSection = Ctx->getCOFFSection(
596 ".debug_abbrev",
597 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
598 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000599 SectionKind::getMetadata(), "section_abbrev");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000600 DwarfInfoSection = Ctx->getCOFFSection(
601 ".debug_info",
602 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
603 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000604 SectionKind::getMetadata(), "section_info");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000605 DwarfLineSection = Ctx->getCOFFSection(
606 ".debug_line",
607 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
608 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000609 SectionKind::getMetadata(), "section_line");
610
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000611 DwarfFrameSection = Ctx->getCOFFSection(
612 ".debug_frame",
613 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
614 COFF::IMAGE_SCN_MEM_READ,
615 SectionKind::getMetadata());
616 DwarfPubNamesSection = Ctx->getCOFFSection(
617 ".debug_pubnames",
618 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
619 COFF::IMAGE_SCN_MEM_READ,
620 SectionKind::getMetadata());
621 DwarfPubTypesSection = Ctx->getCOFFSection(
622 ".debug_pubtypes",
623 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
624 COFF::IMAGE_SCN_MEM_READ,
625 SectionKind::getMetadata());
626 DwarfGnuPubNamesSection = Ctx->getCOFFSection(
627 ".debug_gnu_pubnames",
628 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
629 COFF::IMAGE_SCN_MEM_READ,
630 SectionKind::getMetadata());
631 DwarfGnuPubTypesSection = Ctx->getCOFFSection(
632 ".debug_gnu_pubtypes",
633 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
634 COFF::IMAGE_SCN_MEM_READ,
635 SectionKind::getMetadata());
636 DwarfStrSection = Ctx->getCOFFSection(
637 ".debug_str",
638 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
639 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000640 SectionKind::getMetadata(), "info_string");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000641 DwarfLocSection = Ctx->getCOFFSection(
642 ".debug_loc",
643 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
644 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000645 SectionKind::getMetadata(), "section_debug_loc");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000646 DwarfARangesSection = Ctx->getCOFFSection(
647 ".debug_aranges",
648 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
649 COFF::IMAGE_SCN_MEM_READ,
650 SectionKind::getMetadata());
651 DwarfRangesSection = Ctx->getCOFFSection(
652 ".debug_ranges",
653 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
654 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000655 SectionKind::getMetadata(), "debug_range");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000656 DwarfInfoDWOSection = Ctx->getCOFFSection(
657 ".debug_info.dwo",
658 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
659 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000660 SectionKind::getMetadata(), "section_info_dwo");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000661 DwarfTypesDWOSection = Ctx->getCOFFSection(
662 ".debug_types.dwo",
663 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
664 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindolab03bc792015-03-10 23:06:32 +0000665 SectionKind::getMetadata(), "section_types_dwo");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000666 DwarfAbbrevDWOSection = Ctx->getCOFFSection(
667 ".debug_abbrev.dwo",
668 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
669 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000670 SectionKind::getMetadata(), "section_abbrev_dwo");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000671 DwarfStrDWOSection = Ctx->getCOFFSection(
672 ".debug_str.dwo",
673 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
674 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000675 SectionKind::getMetadata(), "skel_string");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000676 DwarfLineDWOSection = Ctx->getCOFFSection(
677 ".debug_line.dwo",
678 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
679 COFF::IMAGE_SCN_MEM_READ,
680 SectionKind::getMetadata());
681 DwarfLocDWOSection = Ctx->getCOFFSection(
682 ".debug_loc.dwo",
683 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
684 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000685 SectionKind::getMetadata(), "skel_loc");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000686 DwarfStrOffDWOSection = Ctx->getCOFFSection(
687 ".debug_str_offsets.dwo",
688 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
689 COFF::IMAGE_SCN_MEM_READ,
690 SectionKind::getMetadata());
691 DwarfAddrSection = Ctx->getCOFFSection(
692 ".debug_addr",
693 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
694 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000695 SectionKind::getMetadata(), "addr_sec");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000696 DwarfAccelNamesSection = Ctx->getCOFFSection(
697 ".apple_names",
698 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
699 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000700 SectionKind::getMetadata(), "names_begin");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000701 DwarfAccelNamespaceSection = Ctx->getCOFFSection(
702 ".apple_namespaces",
703 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
704 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000705 SectionKind::getMetadata(), "namespac_begin");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000706 DwarfAccelTypesSection = Ctx->getCOFFSection(
707 ".apple_types",
708 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
709 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000710 SectionKind::getMetadata(), "types_begin");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000711 DwarfAccelObjCSection = Ctx->getCOFFSection(
712 ".apple_objc",
713 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
714 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000715 SectionKind::getMetadata(), "objc_begin");
Frederic Riss3f1a0a72014-11-14 20:33:40 +0000716
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000717 DrectveSection = Ctx->getCOFFSection(
718 ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
719 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000720
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000721 PDataSection = Ctx->getCOFFSection(
722 ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
723 SectionKind::getDataRel());
Evan Cheng76792992011-07-20 05:58:47 +0000724
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000725 XDataSection = Ctx->getCOFFSection(
726 ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
727 SectionKind::getDataRel());
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000728
David Majnemer4eecd302015-05-30 04:56:02 +0000729 SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO,
730 SectionKind::getMetadata());
731
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000732 TLSDataSection = Ctx->getCOFFSection(
733 ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
734 COFF::IMAGE_SCN_MEM_WRITE,
735 SectionKind::getDataRel());
Swaroop Sridhare9247ab2015-06-25 00:28:42 +0000736
737 StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
738 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
739 COFF::IMAGE_SCN_MEM_READ,
740 SectionKind::getReadOnly());
Evan Cheng76792992011-07-20 05:58:47 +0000741}
742
Daniel Sanders8d8b13d2015-06-16 12:18:07 +0000743void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple,
744 Reloc::Model relocm,
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000745 CodeModel::Model cm,
Evan Cheng76792992011-07-20 05:58:47 +0000746 MCContext &ctx) {
747 RelocM = relocm;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000748 CMModel = cm;
Evan Cheng76792992011-07-20 05:58:47 +0000749 Ctx = &ctx;
750
751 // Common.
752 CommDirectiveSupportsAlignment = true;
753 SupportsWeakOmittedEHFrame = true;
Tim Northoverd1c6f512014-03-29 09:03:13 +0000754 SupportsCompactUnwindWithoutEHFrame = false;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000755
Rafael Espindolaaa7851d2014-05-12 13:47:05 +0000756 PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
757 dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000758
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000759 CompactUnwindDwarfEHFrameOnly = 0;
760
Craig Topperbb694de2014-04-13 04:57:38 +0000761 EHFrameSection = nullptr; // Created on demand.
762 CompactUnwindSection = nullptr; // Used only by selected targets.
763 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
764 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
765 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
766 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
Evan Cheng76792992011-07-20 05:58:47 +0000767
Daniel Sanders8d8b13d2015-06-16 12:18:07 +0000768 TT = TheTriple;
Saleem Abdulrasoolbdbc0082014-06-22 22:25:01 +0000769
Rafael Espindoladbaf0492015-08-14 15:48:41 +0000770 Triple::ArchType Arch = TT.getArch();
771 // FIXME: Checking for Arch here to filter out bogus triples such as
772 // cellspu-apple-darwin. Perhaps we should fix in Triple?
773 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
774 Arch == Triple::arm || Arch == Triple::thumb ||
775 Arch == Triple::aarch64 ||
776 Arch == Triple::ppc || Arch == Triple::ppc64 ||
777 Arch == Triple::UnknownArch) &&
778 TT.isOSBinFormatMachO()) {
779 Env = IsMachO;
Jim Grosbachbb2591f2015-06-04 23:35:03 +0000780 initMachOMCObjectFileInfo(TT);
Rafael Espindoladbaf0492015-08-14 15:48:41 +0000781 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
782 Arch == Triple::arm || Arch == Triple::thumb) &&
783 (TT.isOSWindows() && TT.getObjectFormat() == Triple::COFF)) {
784 Env = IsCOFF;
Jim Grosbachbb2591f2015-06-04 23:35:03 +0000785 initCOFFMCObjectFileInfo(TT);
Rafael Espindoladbaf0492015-08-14 15:48:41 +0000786 } else {
787 Env = IsELF;
Jim Grosbachbb2591f2015-06-04 23:35:03 +0000788 initELFMCObjectFileInfo(TT);
Evan Cheng76792992011-07-20 05:58:47 +0000789 }
790}
791
Daniel Sanders8d8b13d2015-06-16 12:18:07 +0000792void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model RM,
793 CodeModel::Model CM,
794 MCContext &ctx) {
795 InitMCObjectFileInfo(Triple(TT), RM, CM, ctx);
796}
797
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000798MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
David Blaikiebc563272013-12-13 21:33:40 +0000799 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
Rafael Espindolaba31e272015-01-29 17:33:21 +0000800 0, utostr(Hash));
David Blaikiebc563272013-12-13 21:33:40 +0000801}
802
David Chisnall85dd3092012-02-17 16:51:02 +0000803void MCObjectFileInfo::InitEHFrameSection() {
Rafael Espindoladbaf0492015-08-14 15:48:41 +0000804 if (Env == IsMachO)
David Chisnall85dd3092012-02-17 16:51:02 +0000805 EHFrameSection =
806 Ctx->getMachOSection("__TEXT", "__eh_frame",
David Majnemer7b583052014-03-07 07:36:05 +0000807 MachO::S_COALESCED |
808 MachO::S_ATTR_NO_TOC |
809 MachO::S_ATTR_STRIP_STATIC_SYMS |
810 MachO::S_ATTR_LIVE_SUPPORT,
David Chisnall85dd3092012-02-17 16:51:02 +0000811 SectionKind::getReadOnly());
Rafael Espindoladbaf0492015-08-14 15:48:41 +0000812 else if (Env == IsELF)
David Chisnall85dd3092012-02-17 16:51:02 +0000813 EHFrameSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000814 Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
Rafael Espindoladbaf0492015-08-14 15:48:41 +0000815 else
David Chisnall85dd3092012-02-17 16:51:02 +0000816 EHFrameSection =
817 Ctx->getCOFFSection(".eh_frame",
818 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
819 COFF::IMAGE_SCN_MEM_READ |
820 COFF::IMAGE_SCN_MEM_WRITE,
821 SectionKind::getDataRel());
822}