blob: 79e9dcc0a24f55572cdd33cc918444bcf3907662 [file] [log] [blame]
Jeroen Ketema5a02dc42016-01-04 12:22:34 +00001//===-- MCObjectFileInfo.cpp - Object File Information --------------------===//
Evan Cheng76792992011-07-20 05:58:47 +00002//
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"
Hans Wennborg083ca9b2015-10-06 23:24:35 +000020
Evan Cheng76792992011-07-20 05:58:47 +000021using namespace llvm;
22
Rafael Espindolabecdf632014-06-20 22:37:01 +000023static bool useCompactUnwind(const Triple &T) {
24 // Only on darwin.
25 if (!T.isOSDarwin())
26 return false;
27
28 // aarch64 always has it.
Tim Northovere19bed72014-07-23 12:32:47 +000029 if (T.getArch() == Triple::aarch64)
Rafael Espindolabecdf632014-06-20 22:37:01 +000030 return true;
31
Tim Northoverf8e47e42015-10-28 22:56:36 +000032 // armv7k always has it.
Tim Northover042a6c12016-01-27 19:32:29 +000033 if (T.isWatchABI())
Tim Northoverf8e47e42015-10-28 22:56:36 +000034 return true;
35
Rafael Espindolabecdf632014-06-20 22:37:01 +000036 // Use it on newer version of OS X.
37 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
38 return true;
39
Rafael Espindolac3510c72014-06-20 22:40:55 +000040 // And the iOS simulator.
41 if (T.isiOS() &&
42 (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86))
43 return true;
44
Rafael Espindolabecdf632014-06-20 22:37:01 +000045 return false;
46}
47
Benjamin Kramerc321e532016-06-08 19:09:22 +000048void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
Evan Cheng76792992011-07-20 05:58:47 +000049 // MachO
Evan Cheng76792992011-07-20 05:58:47 +000050 SupportsWeakOmittedEHFrame = false;
51
Rafael Espindola889d7bb2015-11-06 15:30:45 +000052 EHFrameSection = Ctx->getMachOSection(
53 "__TEXT", "__eh_frame",
54 MachO::S_COALESCED | MachO::S_ATTR_NO_TOC |
55 MachO::S_ATTR_STRIP_STATIC_SYMS | MachO::S_ATTR_LIVE_SUPPORT,
56 SectionKind::getReadOnly());
57
Tim Northovere19bed72014-07-23 12:32:47 +000058 if (T.isOSDarwin() && T.getArch() == Triple::aarch64)
Tim Northover00ed9962014-03-29 10:18:08 +000059 SupportsCompactUnwindWithoutEHFrame = true;
60
Tim Northover042a6c12016-01-27 19:32:29 +000061 if (T.isWatchABI())
Tim Northoverf8e47e42015-10-28 22:56:36 +000062 OmitDwarfIfHaveCompactUnwind = true;
63
Evan Chengbbf3b0d2011-07-20 19:50:42 +000064 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
65 | dwarf::DW_EH_PE_sdata4;
Rafael Espindolaaa7851d2014-05-12 13:47:05 +000066 LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
Evan Chengbbf3b0d2011-07-20 19:50:42 +000067 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
68 dwarf::DW_EH_PE_sdata4;
69
Evan Cheng76792992011-07-20 05:58:47 +000070 // .comm doesn't support alignment before Leopard.
71 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
72 CommDirectiveSupportsAlignment = false;
73
74 TextSection // .text
75 = Ctx->getMachOSection("__TEXT", "__text",
David Majnemer7b583052014-03-07 07:36:05 +000076 MachO::S_ATTR_PURE_INSTRUCTIONS,
Evan Cheng76792992011-07-20 05:58:47 +000077 SectionKind::getText());
78 DataSection // .data
Rafael Espindola449711c2015-11-18 06:02:15 +000079 = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
Evan Cheng76792992011-07-20 05:58:47 +000080
NAKAMURA Takumi68fa6f92013-09-21 02:34:45 +000081 // BSSSection might not be expected initialized on msvc.
Craig Topperbb694de2014-04-13 04:57:38 +000082 BSSSection = nullptr;
NAKAMURA Takumi68fa6f92013-09-21 02:34:45 +000083
Evan Cheng76792992011-07-20 05:58:47 +000084 TLSDataSection // .tdata
Rafael Espindola449711c2015-11-18 06:02:15 +000085 = Ctx->getMachOSection("__DATA", "__thread_data",
86 MachO::S_THREAD_LOCAL_REGULAR,
87 SectionKind::getData());
Evan Cheng76792992011-07-20 05:58:47 +000088 TLSBSSSection // .tbss
89 = Ctx->getMachOSection("__DATA", "__thread_bss",
David Majnemer7b583052014-03-07 07:36:05 +000090 MachO::S_THREAD_LOCAL_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +000091 SectionKind::getThreadBSS());
92
93 // TODO: Verify datarel below.
94 TLSTLVSection // .tlv
Rafael Espindola449711c2015-11-18 06:02:15 +000095 = Ctx->getMachOSection("__DATA", "__thread_vars",
96 MachO::S_THREAD_LOCAL_VARIABLES,
97 SectionKind::getData());
Evan Cheng76792992011-07-20 05:58:47 +000098
Rafael Espindola449711c2015-11-18 06:02:15 +000099 TLSThreadInitSection = Ctx->getMachOSection(
100 "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
101 SectionKind::getData());
Evan Cheng76792992011-07-20 05:58:47 +0000102
103 CStringSection // .cstring
104 = Ctx->getMachOSection("__TEXT", "__cstring",
David Majnemer7b583052014-03-07 07:36:05 +0000105 MachO::S_CSTRING_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +0000106 SectionKind::getMergeable1ByteCString());
107 UStringSection
108 = Ctx->getMachOSection("__TEXT","__ustring", 0,
109 SectionKind::getMergeable2ByteCString());
110 FourByteConstantSection // .literal4
111 = Ctx->getMachOSection("__TEXT", "__literal4",
David Majnemer7b583052014-03-07 07:36:05 +0000112 MachO::S_4BYTE_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +0000113 SectionKind::getMergeableConst4());
114 EightByteConstantSection // .literal8
115 = Ctx->getMachOSection("__TEXT", "__literal8",
David Majnemer7b583052014-03-07 07:36:05 +0000116 MachO::S_8BYTE_LITERALS,
Evan Cheng76792992011-07-20 05:58:47 +0000117 SectionKind::getMergeableConst8());
118
Rafael Espindola1f3de492014-02-13 23:16:11 +0000119 SixteenByteConstantSection // .literal16
120 = Ctx->getMachOSection("__TEXT", "__literal16",
David Majnemer7b583052014-03-07 07:36:05 +0000121 MachO::S_16BYTE_LITERALS,
Rafael Espindola1f3de492014-02-13 23:16:11 +0000122 SectionKind::getMergeableConst16());
Evan Cheng76792992011-07-20 05:58:47 +0000123
124 ReadOnlySection // .const
125 = Ctx->getMachOSection("__TEXT", "__const", 0,
126 SectionKind::getReadOnly());
127
Akira Hatanaka8ad73992015-10-15 05:28:38 +0000128 // If the target is not powerpc, map the coal sections to the non-coal
129 // sections.
130 //
131 // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
132 // "__TEXT/__const_coal" => section "__TEXT/__const"
133 // "__DATA/__datacoal_nt" => section "__DATA/__data"
134 Triple::ArchType ArchTy = T.getArch();
135
136 if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
137 TextCoalSection
138 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
139 MachO::S_COALESCED |
140 MachO::S_ATTR_PURE_INSTRUCTIONS,
141 SectionKind::getText());
142 ConstTextCoalSection
143 = Ctx->getMachOSection("__TEXT", "__const_coal",
144 MachO::S_COALESCED,
145 SectionKind::getReadOnly());
Rafael Espindola449711c2015-11-18 06:02:15 +0000146 DataCoalSection = Ctx->getMachOSection(
147 "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());
Akira Hatanaka8ad73992015-10-15 05:28:38 +0000148 } else {
149 TextCoalSection = TextSection;
150 ConstTextCoalSection = ReadOnlySection;
151 DataCoalSection = DataSection;
152 }
153
Evan Cheng76792992011-07-20 05:58:47 +0000154 ConstDataSection // .const_data
155 = Ctx->getMachOSection("__DATA", "__const", 0,
156 SectionKind::getReadOnlyWithRel());
Evan Cheng76792992011-07-20 05:58:47 +0000157 DataCommonSection
158 = Ctx->getMachOSection("__DATA","__common",
David Majnemer7b583052014-03-07 07:36:05 +0000159 MachO::S_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +0000160 SectionKind::getBSS());
161 DataBSSSection
David Majnemer7b583052014-03-07 07:36:05 +0000162 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
Evan Cheng76792992011-07-20 05:58:47 +0000163 SectionKind::getBSS());
164
165
166 LazySymbolPointerSection
167 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
David Majnemer7b583052014-03-07 07:36:05 +0000168 MachO::S_LAZY_SYMBOL_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000169 SectionKind::getMetadata());
170 NonLazySymbolPointerSection
171 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
David Majnemer7b583052014-03-07 07:36:05 +0000172 MachO::S_NON_LAZY_SYMBOL_POINTERS,
Evan Cheng76792992011-07-20 05:58:47 +0000173 SectionKind::getMetadata());
174
Tim Northover5c3140f2016-04-25 21:12:04 +0000175 ThreadLocalPointerSection
176 = Ctx->getMachOSection("__DATA", "__thread_ptr",
177 MachO::S_THREAD_LOCAL_VARIABLE_POINTERS,
178 SectionKind::getMetadata());
179
Rafael Espindola699281c2016-05-18 11:58:50 +0000180 if (!PositionIndependent) {
Rafael Espindola449711c2015-11-18 06:02:15 +0000181 StaticCtorSection = Ctx->getMachOSection("__TEXT", "__constructor", 0,
182 SectionKind::getData());
183 StaticDtorSection = Ctx->getMachOSection("__TEXT", "__destructor", 0,
184 SectionKind::getData());
Evan Cheng76792992011-07-20 05:58:47 +0000185 } else {
Rafael Espindola449711c2015-11-18 06:02:15 +0000186 StaticCtorSection = Ctx->getMachOSection("__DATA", "__mod_init_func",
187 MachO::S_MOD_INIT_FUNC_POINTERS,
188 SectionKind::getData());
189 StaticDtorSection = Ctx->getMachOSection("__DATA", "__mod_term_func",
190 MachO::S_MOD_TERM_FUNC_POINTERS,
191 SectionKind::getData());
Evan Cheng76792992011-07-20 05:58:47 +0000192 }
193
194 // Exception Handling.
195 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
196 SectionKind::getReadOnlyWithRel());
197
Craig Topperbb694de2014-04-13 04:57:38 +0000198 COFFDebugSymbolsSection = nullptr;
Reid Klecknerf3b9ba42016-01-29 18:16:43 +0000199 COFFDebugTypesSection = nullptr;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000200
Rafael Espindolabecdf632014-06-20 22:37:01 +0000201 if (useCompactUnwind(T)) {
Evan Cheng76792992011-07-20 05:58:47 +0000202 CompactUnwindSection =
Rafael Espindolabecdf632014-06-20 22:37:01 +0000203 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
204 SectionKind::getReadOnly());
Evan Cheng76792992011-07-20 05:58:47 +0000205
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000206 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
Tim Northoverf8e47e42015-10-28 22:56:36 +0000207 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF
Tim Northovere19bed72014-07-23 12:32:47 +0000208 else if (T.getArch() == Triple::aarch64)
Tim Northoverf8e47e42015-10-28 22:56:36 +0000209 CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF
210 else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
211 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000212 }
213
Evan Cheng76792992011-07-20 05:58:47 +0000214 // Debug Information.
Eric Christopher4996c702011-11-07 09:24:32 +0000215 DwarfAccelNamesSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000216 Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000217 SectionKind::getMetadata(), "names_begin");
Eric Christopher4996c702011-11-07 09:24:32 +0000218 DwarfAccelObjCSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000219 Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000220 SectionKind::getMetadata(), "objc_begin");
Eric Christopher4996c702011-11-07 09:24:32 +0000221 // 16 character section limit...
222 DwarfAccelNamespaceSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000223 Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000224 SectionKind::getMetadata(), "namespac_begin");
Eric Christopher4996c702011-11-07 09:24:32 +0000225 DwarfAccelTypesSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000226 Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000227 SectionKind::getMetadata(), "types_begin");
Jim Grosbachdc1e36e2012-05-11 01:41:30 +0000228
Evan Cheng76792992011-07-20 05:58:47 +0000229 DwarfAbbrevSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000230 Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000231 SectionKind::getMetadata(), "section_abbrev");
Evan Cheng76792992011-07-20 05:58:47 +0000232 DwarfInfoSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000233 Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000234 SectionKind::getMetadata(), "section_info");
Evan Cheng76792992011-07-20 05:58:47 +0000235 DwarfLineSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000236 Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000237 SectionKind::getMetadata(), "section_line");
Evan Cheng76792992011-07-20 05:58:47 +0000238 DwarfFrameSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000239 Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
240 SectionKind::getMetadata());
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000241 DwarfPubNamesSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000242 Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
243 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000244 DwarfPubTypesSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000245 Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
246 SectionKind::getMetadata());
Eric Christopherb0e76942013-09-09 20:03:14 +0000247 DwarfGnuPubNamesSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000248 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
249 SectionKind::getMetadata());
Eric Christopherb0e76942013-09-09 20:03:14 +0000250 DwarfGnuPubTypesSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000251 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
252 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000253 DwarfStrSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000254 Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000255 SectionKind::getMetadata(), "info_string");
Evan Cheng76792992011-07-20 05:58:47 +0000256 DwarfLocSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000257 Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000258 SectionKind::getMetadata(), "section_debug_loc");
Evan Cheng76792992011-07-20 05:58:47 +0000259 DwarfARangesSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000260 Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
261 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000262 DwarfRangesSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000263 Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000264 SectionKind::getMetadata(), "debug_range");
Amjad Aboudd7cfb482016-01-07 14:28:20 +0000265 DwarfMacinfoSection =
266 Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG,
Amjad Aboud8bbce8a2016-02-01 14:09:41 +0000267 SectionKind::getMetadata(), "debug_macinfo");
Evan Cheng76792992011-07-20 05:58:47 +0000268 DwarfDebugInlineSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000269 Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
270 SectionKind::getMetadata());
David Blaikieb073cb92015-12-02 06:21:34 +0000271 DwarfCUIndexSection =
272 Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,
273 SectionKind::getMetadata());
David Blaikie24c8ac92015-12-05 03:05:45 +0000274 DwarfTUIndexSection =
275 Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG,
276 SectionKind::getMetadata());
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000277 StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
278 0, SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000279
Sanjoy Dasc63244d2015-06-15 18:44:08 +0000280 FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
281 0, SectionKind::getMetadata());
282
Evan Cheng76792992011-07-20 05:58:47 +0000283 TLSExtraDataSection = TLSTLVSection;
284}
285
Benjamin Kramerc321e532016-06-08 19:09:22 +0000286void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T) {
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000287 switch (T.getArch()) {
288 case Triple::mips:
289 case Triple::mipsel:
Rafael Espindolab9b7ae02013-04-03 03:13:19 +0000290 FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000291 break;
292 case Triple::mips64:
293 case Triple::mips64el:
Rafael Espindolab9b7ae02013-04-03 03:13:19 +0000294 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000295 break;
Rafael Espindolad11591b2014-11-27 17:13:56 +0000296 case Triple::x86_64:
297 FDECFIEncoding = dwarf::DW_EH_PE_pcrel |
298 ((CMModel == CodeModel::Large) ? dwarf::DW_EH_PE_sdata8
299 : dwarf::DW_EH_PE_sdata4);
Rafael Espindolad11591b2014-11-27 17:13:56 +0000300 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000301 default:
Rafael Espindolaef9d3492013-03-15 05:51:57 +0000302 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000303 break;
304 }
Rafael Espindolaef9d3492013-03-15 05:51:57 +0000305
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000306 switch (T.getArch()) {
Joerg Sonnenbergercf86ce12014-05-07 07:49:34 +0000307 case Triple::arm:
308 case Triple::armeb:
309 case Triple::thumb:
310 case Triple::thumbeb:
Joerg Sonnenberger94cbb662014-05-13 17:58:13 +0000311 if (Ctx->getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
312 break;
313 // Fallthrough if not using EHABI
Justin Bognercd1d5aa2016-08-17 20:30:52 +0000314 LLVM_FALLTHROUGH;
Joerg Sonnenberger6637d4e2014-07-24 19:25:16 +0000315 case Triple::ppc:
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000316 case Triple::x86:
Rafael Espindola699281c2016-05-18 11:58:50 +0000317 PersonalityEncoding = PositionIndependent
318 ? dwarf::DW_EH_PE_indirect |
319 dwarf::DW_EH_PE_pcrel |
320 dwarf::DW_EH_PE_sdata4
321 : dwarf::DW_EH_PE_absptr;
322 LSDAEncoding = PositionIndependent
323 ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
324 : dwarf::DW_EH_PE_absptr;
325 TTypeEncoding = PositionIndependent
326 ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
327 dwarf::DW_EH_PE_sdata4
328 : dwarf::DW_EH_PE_absptr;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000329 break;
330 case Triple::x86_64:
Rafael Espindola699281c2016-05-18 11:58:50 +0000331 if (PositionIndependent) {
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000332 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
333 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
334 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
335 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
336 (CMModel == CodeModel::Small
337 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000338 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
339 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
340 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
341 } else {
342 PersonalityEncoding =
343 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
344 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
345 LSDAEncoding = (CMModel == CodeModel::Small)
346 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000347 TTypeEncoding = (CMModel == CodeModel::Small)
348 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
349 }
Krzysztof Parzyszek1711f2d2016-04-25 21:28:52 +0000350 break;
Krzysztof Parzyszek3e282292016-04-25 21:05:19 +0000351 case Triple::hexagon:
352 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
353 LSDAEncoding = dwarf::DW_EH_PE_absptr;
354 FDECFIEncoding = dwarf::DW_EH_PE_absptr;
355 TTypeEncoding = dwarf::DW_EH_PE_absptr;
Rafael Espindola699281c2016-05-18 11:58:50 +0000356 if (PositionIndependent) {
Krzysztof Parzyszek3e282292016-04-25 21:05:19 +0000357 PersonalityEncoding |= dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel;
358 LSDAEncoding |= dwarf::DW_EH_PE_pcrel;
359 FDECFIEncoding |= dwarf::DW_EH_PE_pcrel;
360 TTypeEncoding |= dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel;
361 }
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000362 break;
363 case Triple::aarch64:
364 case Triple::aarch64_be:
Tim Northovere0e3aef2013-01-31 12:12:40 +0000365 // The small model guarantees static code/data size < 4GB, but not where it
366 // will be in memory. Most of these could end up >2GB away so even a signed
367 // pc-relative 32-bit address is insufficient, theoretically.
Rafael Espindola699281c2016-05-18 11:58:50 +0000368 if (PositionIndependent) {
Tim Northovere0e3aef2013-01-31 12:12:40 +0000369 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
370 dwarf::DW_EH_PE_sdata8;
371 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
Tim Northovere0e3aef2013-01-31 12:12:40 +0000372 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
373 dwarf::DW_EH_PE_sdata8;
374 } else {
375 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
376 LSDAEncoding = dwarf::DW_EH_PE_absptr;
Tim Northovere0e3aef2013-01-31 12:12:40 +0000377 TTypeEncoding = dwarf::DW_EH_PE_absptr;
378 }
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000379 break;
Jacques Pienaarea9f25a2016-03-01 21:21:42 +0000380 case Triple::lanai:
381 LSDAEncoding = dwarf::DW_EH_PE_absptr;
382 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
383 TTypeEncoding = dwarf::DW_EH_PE_absptr;
384 break;
Logan Chienc0029812014-05-30 16:48:56 +0000385 case Triple::mips:
386 case Triple::mipsel:
Petar Jovanovic35f05742014-11-05 22:42:31 +0000387 case Triple::mips64:
388 case Triple::mips64el:
Daniel Sandersc95f3f82015-06-02 20:32:50 +0000389 // MIPS uses indirect pointer to refer personality functions and types, so
390 // that the eh_frame section can be read-only. DW.ref.personality will be
391 // generated for relocation.
Logan Chienc0029812014-05-30 16:48:56 +0000392 PersonalityEncoding = dwarf::DW_EH_PE_indirect;
Daniel Sandersc95f3f82015-06-02 20:32:50 +0000393 // FIXME: The N64 ABI probably ought to use DW_EH_PE_sdata8 but we can't
394 // identify N64 from just a triple.
395 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
396 dwarf::DW_EH_PE_sdata4;
397 // We don't support PC-relative LSDA references in GAS so we use the default
398 // DW_EH_PE_absptr for those.
Daniel Sanders5dcbac52016-08-04 15:36:03 +0000399
400 // FreeBSD must be explicit about the data size and using pcrel since it's
401 // assembler/linker won't do the automatic conversion that the Linux tools
402 // do.
403 if (T.isOSFreeBSD()) {
404 PersonalityEncoding |= dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
405 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
406 }
Logan Chienc0029812014-05-30 16:48:56 +0000407 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000408 case Triple::ppc64:
409 case Triple::ppc64le:
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000410 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
411 dwarf::DW_EH_PE_udata8;
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000412 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
Adhemerval Zanella1ae22482013-01-09 17:08:15 +0000413 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
414 dwarf::DW_EH_PE_udata8;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000415 break;
Douglas Katzman9160e782015-04-29 20:30:57 +0000416 case Triple::sparcel:
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000417 case Triple::sparc:
Rafael Espindola699281c2016-05-18 11:58:50 +0000418 if (PositionIndependent) {
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000419 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
420 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
421 dwarf::DW_EH_PE_sdata4;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000422 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
423 dwarf::DW_EH_PE_sdata4;
424 } else {
425 LSDAEncoding = dwarf::DW_EH_PE_absptr;
426 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000427 TTypeEncoding = dwarf::DW_EH_PE_absptr;
428 }
Joerg Sonnenbergerfa9cf652014-04-30 23:36:24 +0000429 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000430 case Triple::sparcv9:
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000431 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
Rafael Espindola699281c2016-05-18 11:58:50 +0000432 if (PositionIndependent) {
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000433 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
434 dwarf::DW_EH_PE_sdata4;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000435 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
436 dwarf::DW_EH_PE_sdata4;
437 } else {
438 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
Jakob Stoklund Olesen83c67732014-01-28 02:52:26 +0000439 TTypeEncoding = dwarf::DW_EH_PE_absptr;
440 }
Joerg Sonnenbergerfa9cf652014-04-30 23:36:24 +0000441 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000442 case Triple::systemz:
Ulrich Weigand0213e7f2013-05-06 16:11:12 +0000443 // All currently-defined code models guarantee that 4-byte PC-relative
444 // values will be in range.
Rafael Espindola699281c2016-05-18 11:58:50 +0000445 if (PositionIndependent) {
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000446 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
447 dwarf::DW_EH_PE_sdata4;
448 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000449 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
450 dwarf::DW_EH_PE_sdata4;
451 } else {
452 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
453 LSDAEncoding = dwarf::DW_EH_PE_absptr;
Ulrich Weigande7c6dfe2013-05-06 17:28:30 +0000454 TTypeEncoding = dwarf::DW_EH_PE_absptr;
455 }
Joerg Sonnenbergerfa9cf652014-04-30 23:36:24 +0000456 break;
Joerg Sonnenberger7c442522014-04-30 23:23:14 +0000457 default:
458 break;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000459 }
460
Rafael Espindola889d7bb2015-11-06 15:30:45 +0000461 unsigned EHSectionType = T.getArch() == Triple::x86_64
462 ? ELF::SHT_X86_64_UNWIND
463 : ELF::SHT_PROGBITS;
Rafael Espindolab20b7062015-11-06 13:35:35 +0000464
David Chisnall07f8d3e2012-02-17 17:31:15 +0000465 // Solaris requires different flags for .eh_frame to seemingly every other
466 // platform.
Rafael Espindola889d7bb2015-11-06 15:30:45 +0000467 unsigned EHSectionFlags = ELF::SHF_ALLOC;
Rafael Espindolab20b7062015-11-06 13:35:35 +0000468 if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
469 EHSectionFlags |= ELF::SHF_WRITE;
David Chisnall07f8d3e2012-02-17 17:31:15 +0000470
Evan Cheng76792992011-07-20 05:58:47 +0000471 // ELF
Rafael Espindolaba31e272015-01-29 17:33:21 +0000472 BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
473 ELF::SHF_WRITE | ELF::SHF_ALLOC);
Evan Cheng76792992011-07-20 05:58:47 +0000474
Rafael Espindolaba31e272015-01-29 17:33:21 +0000475 TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
476 ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
Evan Cheng76792992011-07-20 05:58:47 +0000477
Rafael Espindolaba31e272015-01-29 17:33:21 +0000478 DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
479 ELF::SHF_WRITE | ELF::SHF_ALLOC);
Evan Cheng76792992011-07-20 05:58:47 +0000480
481 ReadOnlySection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000482 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
Evan Cheng76792992011-07-20 05:58:47 +0000483
484 TLSDataSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000485 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
486 ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000487
Rafael Espindolaba31e272015-01-29 17:33:21 +0000488 TLSBSSSection = Ctx->getELFSection(
489 ".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000490
Rafael Espindolaba31e272015-01-29 17:33:21 +0000491 DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
492 ELF::SHF_ALLOC | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000493
Evan Cheng76792992011-07-20 05:58:47 +0000494 MergeableConst4Section =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000495 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
496 ELF::SHF_ALLOC | ELF::SHF_MERGE, 4, "");
Evan Cheng76792992011-07-20 05:58:47 +0000497
498 MergeableConst8Section =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000499 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
500 ELF::SHF_ALLOC | ELF::SHF_MERGE, 8, "");
Evan Cheng76792992011-07-20 05:58:47 +0000501
502 MergeableConst16Section =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000503 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
504 ELF::SHF_ALLOC | ELF::SHF_MERGE, 16, "");
Evan Cheng76792992011-07-20 05:58:47 +0000505
David Majnemer964b70d2016-02-22 22:23:11 +0000506 MergeableConst32Section =
507 Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS,
508 ELF::SHF_ALLOC | ELF::SHF_MERGE, 32, "");
509
Rafael Espindolaba31e272015-01-29 17:33:21 +0000510 StaticCtorSection = Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
511 ELF::SHF_ALLOC | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000512
Rafael Espindolaba31e272015-01-29 17:33:21 +0000513 StaticDtorSection = Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
514 ELF::SHF_ALLOC | ELF::SHF_WRITE);
Evan Cheng76792992011-07-20 05:58:47 +0000515
516 // Exception Handling Sections.
517
518 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
519 // it contains relocatable pointers. In PIC mode, this is probably a big
520 // runtime hit for C++ apps. Either the contents of the LSDA need to be
521 // adjusted or this should be a data section.
Rafael Espindolaba31e272015-01-29 17:33:21 +0000522 LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
523 ELF::SHF_ALLOC);
Evan Cheng76792992011-07-20 05:58:47 +0000524
Craig Topperbb694de2014-04-13 04:57:38 +0000525 COFFDebugSymbolsSection = nullptr;
Reid Klecknerf3b9ba42016-01-29 18:16:43 +0000526 COFFDebugTypesSection = nullptr;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +0000527
Evan Cheng76792992011-07-20 05:58:47 +0000528 // Debug Info Sections.
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000529 DwarfAbbrevSection = Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
530 "section_abbrev");
531 DwarfInfoSection =
532 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0, "section_info");
Rafael Espindola23562fc2015-03-11 04:20:31 +0000533 DwarfLineSection = Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0);
Rafael Espindolaba31e272015-01-29 17:33:21 +0000534 DwarfFrameSection = Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0);
Krzysztof Parzyszek228daa62013-02-12 18:00:14 +0000535 DwarfPubNamesSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000536 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0);
Evan Cheng76792992011-07-20 05:58:47 +0000537 DwarfPubTypesSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000538 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0);
Eric Christopherb0e76942013-09-09 20:03:14 +0000539 DwarfGnuPubNamesSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000540 Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0);
Eric Christopherb0e76942013-09-09 20:03:14 +0000541 DwarfGnuPubTypesSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000542 Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0);
Rafael Espindola23562fc2015-03-11 04:20:31 +0000543 DwarfStrSection =
544 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
545 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
546 DwarfLocSection = Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0);
Evan Cheng76792992011-07-20 05:58:47 +0000547 DwarfARangesSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000548 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0);
Evan Cheng76792992011-07-20 05:58:47 +0000549 DwarfRangesSection =
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000550 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0, "debug_range");
Amjad Aboud8bbce8a2016-02-01 14:09:41 +0000551 DwarfMacinfoSection = Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS,
552 0, "debug_macinfo");
Eric Christopher27ed8ec2012-11-28 02:49:34 +0000553
554 // DWARF5 Experimental Debug Info
555
556 // Accelerator Tables
Eric Christophera0ad67d2012-10-08 21:41:30 +0000557 DwarfAccelNamesSection =
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000558 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0, "names_begin");
Eric Christophera0ad67d2012-10-08 21:41:30 +0000559 DwarfAccelObjCSection =
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000560 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0, "objc_begin");
561 DwarfAccelNamespaceSection = Ctx->getELFSection(
562 ".apple_namespaces", ELF::SHT_PROGBITS, 0, "namespac_begin");
Eric Christophera0ad67d2012-10-08 21:41:30 +0000563 DwarfAccelTypesSection =
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000564 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0, "types_begin");
Eric Christopherc3b434b2012-11-28 02:49:38 +0000565
566 // Fission Sections
Rafael Espindola23562fc2015-03-11 04:20:31 +0000567 DwarfInfoDWOSection =
568 Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0);
569 DwarfTypesDWOSection =
570 Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS, 0);
571 DwarfAbbrevDWOSection =
572 Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0);
573 DwarfStrDWOSection =
574 Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
575 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
Eric Christopher3c230092012-11-30 06:47:06 +0000576 DwarfLineDWOSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000577 Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0);
Eric Christopher3c230092012-11-30 06:47:06 +0000578 DwarfLocDWOSection =
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000579 Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0, "skel_loc");
Eric Christopherc0fa8672013-01-04 17:59:22 +0000580 DwarfStrOffDWOSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000581 Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0);
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000582 DwarfAddrSection =
583 Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0, "addr_sec");
Philip Reames76846182014-08-01 18:47:09 +0000584
David Blaikieb073cb92015-12-02 06:21:34 +0000585 // DWP Sections
586 DwarfCUIndexSection =
587 Ctx->getELFSection(".debug_cu_index", ELF::SHT_PROGBITS, 0);
David Blaikie24c8ac92015-12-05 03:05:45 +0000588 DwarfTUIndexSection =
589 Ctx->getELFSection(".debug_tu_index", ELF::SHT_PROGBITS, 0);
David Blaikieb073cb92015-12-02 06:21:34 +0000590
Philip Reames76846182014-08-01 18:47:09 +0000591 StackMapSection =
Rafael Espindolaba31e272015-01-29 17:33:21 +0000592 Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
Sanjoy Dasc63244d2015-06-15 18:44:08 +0000593
594 FaultMapSection =
595 Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
Rafael Espindola889d7bb2015-11-06 15:30:45 +0000596
597 EHFrameSection =
598 Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
Evan Cheng76792992011-07-20 05:58:47 +0000599}
600
Benjamin Kramerc321e532016-06-08 19:09:22 +0000601void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
Rafael Espindola889d7bb2015-11-06 15:30:45 +0000602 EHFrameSection = Ctx->getCOFFSection(
603 ".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
604 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
Rafael Espindola449711c2015-11-18 06:02:15 +0000605 SectionKind::getData());
Rafael Espindola889d7bb2015-11-06 15:30:45 +0000606
Renato Golinef3eb062016-06-27 14:42:20 +0000607 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
608 // used to indicate to the linker that the text segment contains thumb instructions
609 // and to set the ISA selection bit for calls accordingly.
610 const bool IsThumb = T.getArch() == Triple::thumb;
Saleem Abdulrasool70a02062014-06-08 03:57:49 +0000611
David Majnemer48227a32014-09-21 09:18:07 +0000612 CommDirectiveSupportsAlignment = true;
David Majnemera9bdb322014-04-08 22:33:40 +0000613
Evan Cheng76792992011-07-20 05:58:47 +0000614 // COFF
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000615 BSSSection = Ctx->getCOFFSection(
616 ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
617 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
618 SectionKind::getBSS());
619 TextSection = Ctx->getCOFFSection(
620 ".text",
Renato Golinef3eb062016-06-27 14:42:20 +0000621 (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000622 COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
623 COFF::IMAGE_SCN_MEM_READ,
624 SectionKind::getText());
625 DataSection = Ctx->getCOFFSection(
626 ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
627 COFF::IMAGE_SCN_MEM_WRITE,
Rafael Espindola449711c2015-11-18 06:02:15 +0000628 SectionKind::getData());
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000629 ReadOnlySection = Ctx->getCOFFSection(
630 ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
631 SectionKind::getReadOnly());
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000632
Saleem Abdulrasooled7fc4b2014-06-08 00:34:27 +0000633 if (T.isKnownWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
Michael J. Spencerb560d072012-02-23 21:56:08 +0000634 StaticCtorSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000635 Ctx->getCOFFSection(".CRT$XCU", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
636 COFF::IMAGE_SCN_MEM_READ,
637 SectionKind::getReadOnly());
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000638 StaticDtorSection =
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000639 Ctx->getCOFFSection(".CRT$XTX", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
640 COFF::IMAGE_SCN_MEM_READ,
641 SectionKind::getReadOnly());
Michael J. Spencerb560d072012-02-23 21:56:08 +0000642 } else {
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000643 StaticCtorSection = Ctx->getCOFFSection(
644 ".ctors", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
645 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
Rafael Espindola449711c2015-11-18 06:02:15 +0000646 SectionKind::getData());
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000647 StaticDtorSection = Ctx->getCOFFSection(
648 ".dtors", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
649 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
Rafael Espindola449711c2015-11-18 06:02:15 +0000650 SectionKind::getData());
Anton Korobeynikov37d73002012-09-23 15:53:47 +0000651 }
Evan Cheng76792992011-07-20 05:58:47 +0000652
653 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
654 // though it contains relocatable pointers. In PIC mode, this is probably a
655 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
656 // adjusted or this should be a data section.
NAKAMURA Takumi1db59952014-06-25 12:41:52 +0000657 if (T.getArch() == Triple::x86_64) {
658 // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
Hans Wennborg083ca9b2015-10-06 23:24:35 +0000659 LSDASection = nullptr;
NAKAMURA Takumi1db59952014-06-25 12:41:52 +0000660 } else {
661 LSDASection = Ctx->getCOFFSection(".gcc_except_table",
662 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
663 COFF::IMAGE_SCN_MEM_READ,
664 SectionKind::getReadOnly());
665 }
Evan Cheng76792992011-07-20 05:58:47 +0000666
667 // Debug info.
Timur Iskhodzhanov31377c52014-01-28 03:48:44 +0000668 COFFDebugSymbolsSection =
Reid Klecknerf3b9ba42016-01-29 18:16:43 +0000669 Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
670 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
671 COFF::IMAGE_SCN_MEM_READ),
672 SectionKind::getMetadata());
673 COFFDebugTypesSection =
674 Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
675 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
676 COFF::IMAGE_SCN_MEM_READ),
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000677 SectionKind::getMetadata());
Timur Iskhodzhanov31377c52014-01-28 03:48:44 +0000678
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000679 DwarfAbbrevSection = Ctx->getCOFFSection(
680 ".debug_abbrev",
681 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
682 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000683 SectionKind::getMetadata(), "section_abbrev");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000684 DwarfInfoSection = Ctx->getCOFFSection(
685 ".debug_info",
686 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
687 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000688 SectionKind::getMetadata(), "section_info");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000689 DwarfLineSection = Ctx->getCOFFSection(
690 ".debug_line",
691 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
692 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000693 SectionKind::getMetadata(), "section_line");
694
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000695 DwarfFrameSection = Ctx->getCOFFSection(
696 ".debug_frame",
697 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
698 COFF::IMAGE_SCN_MEM_READ,
699 SectionKind::getMetadata());
700 DwarfPubNamesSection = Ctx->getCOFFSection(
701 ".debug_pubnames",
702 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
703 COFF::IMAGE_SCN_MEM_READ,
704 SectionKind::getMetadata());
705 DwarfPubTypesSection = Ctx->getCOFFSection(
706 ".debug_pubtypes",
707 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
708 COFF::IMAGE_SCN_MEM_READ,
709 SectionKind::getMetadata());
710 DwarfGnuPubNamesSection = Ctx->getCOFFSection(
711 ".debug_gnu_pubnames",
712 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
713 COFF::IMAGE_SCN_MEM_READ,
714 SectionKind::getMetadata());
715 DwarfGnuPubTypesSection = Ctx->getCOFFSection(
716 ".debug_gnu_pubtypes",
717 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
718 COFF::IMAGE_SCN_MEM_READ,
719 SectionKind::getMetadata());
720 DwarfStrSection = Ctx->getCOFFSection(
721 ".debug_str",
722 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
723 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000724 SectionKind::getMetadata(), "info_string");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000725 DwarfLocSection = Ctx->getCOFFSection(
726 ".debug_loc",
727 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
728 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000729 SectionKind::getMetadata(), "section_debug_loc");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000730 DwarfARangesSection = Ctx->getCOFFSection(
731 ".debug_aranges",
732 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
733 COFF::IMAGE_SCN_MEM_READ,
734 SectionKind::getMetadata());
735 DwarfRangesSection = Ctx->getCOFFSection(
736 ".debug_ranges",
737 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
738 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000739 SectionKind::getMetadata(), "debug_range");
Amjad Aboudd7cfb482016-01-07 14:28:20 +0000740 DwarfMacinfoSection = Ctx->getCOFFSection(
741 ".debug_macinfo",
742 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
743 COFF::IMAGE_SCN_MEM_READ,
Amjad Aboud8bbce8a2016-02-01 14:09:41 +0000744 SectionKind::getMetadata(), "debug_macinfo");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000745 DwarfInfoDWOSection = Ctx->getCOFFSection(
746 ".debug_info.dwo",
747 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
748 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000749 SectionKind::getMetadata(), "section_info_dwo");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000750 DwarfTypesDWOSection = Ctx->getCOFFSection(
751 ".debug_types.dwo",
752 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
753 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindolab03bc792015-03-10 23:06:32 +0000754 SectionKind::getMetadata(), "section_types_dwo");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000755 DwarfAbbrevDWOSection = Ctx->getCOFFSection(
756 ".debug_abbrev.dwo",
757 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
758 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000759 SectionKind::getMetadata(), "section_abbrev_dwo");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000760 DwarfStrDWOSection = Ctx->getCOFFSection(
761 ".debug_str.dwo",
762 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
763 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000764 SectionKind::getMetadata(), "skel_string");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000765 DwarfLineDWOSection = Ctx->getCOFFSection(
766 ".debug_line.dwo",
767 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
768 COFF::IMAGE_SCN_MEM_READ,
769 SectionKind::getMetadata());
770 DwarfLocDWOSection = Ctx->getCOFFSection(
771 ".debug_loc.dwo",
772 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
773 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000774 SectionKind::getMetadata(), "skel_loc");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000775 DwarfStrOffDWOSection = Ctx->getCOFFSection(
776 ".debug_str_offsets.dwo",
777 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
778 COFF::IMAGE_SCN_MEM_READ,
779 SectionKind::getMetadata());
780 DwarfAddrSection = Ctx->getCOFFSection(
781 ".debug_addr",
782 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
783 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000784 SectionKind::getMetadata(), "addr_sec");
David Blaikieb073cb92015-12-02 06:21:34 +0000785 DwarfCUIndexSection = Ctx->getCOFFSection(
786 ".debug_cu_index",
787 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
788 COFF::IMAGE_SCN_MEM_READ,
789 SectionKind::getMetadata());
David Blaikie24c8ac92015-12-05 03:05:45 +0000790 DwarfTUIndexSection = Ctx->getCOFFSection(
791 ".debug_tu_index",
792 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
793 COFF::IMAGE_SCN_MEM_READ,
794 SectionKind::getMetadata());
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000795 DwarfAccelNamesSection = Ctx->getCOFFSection(
796 ".apple_names",
797 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
798 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000799 SectionKind::getMetadata(), "names_begin");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000800 DwarfAccelNamespaceSection = Ctx->getCOFFSection(
801 ".apple_namespaces",
802 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
803 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000804 SectionKind::getMetadata(), "namespac_begin");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000805 DwarfAccelTypesSection = Ctx->getCOFFSection(
806 ".apple_types",
807 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
808 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000809 SectionKind::getMetadata(), "types_begin");
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000810 DwarfAccelObjCSection = Ctx->getCOFFSection(
811 ".apple_objc",
812 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
813 COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola6b9998b2015-03-10 22:00:25 +0000814 SectionKind::getMetadata(), "objc_begin");
Frederic Riss3f1a0a72014-11-14 20:33:40 +0000815
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000816 DrectveSection = Ctx->getCOFFSection(
817 ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
818 SectionKind::getMetadata());
Evan Cheng76792992011-07-20 05:58:47 +0000819
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000820 PDataSection = Ctx->getCOFFSection(
821 ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola449711c2015-11-18 06:02:15 +0000822 SectionKind::getData());
Evan Cheng76792992011-07-20 05:58:47 +0000823
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000824 XDataSection = Ctx->getCOFFSection(
825 ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
Rafael Espindola449711c2015-11-18 06:02:15 +0000826 SectionKind::getData());
Saleem Abdulrasoola35f04a2014-06-08 00:34:23 +0000827
David Majnemer4eecd302015-05-30 04:56:02 +0000828 SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO,
829 SectionKind::getMetadata());
830
Rafael Espindola6ed58a22015-03-10 21:16:18 +0000831 TLSDataSection = Ctx->getCOFFSection(
832 ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
833 COFF::IMAGE_SCN_MEM_WRITE,
Rafael Espindola449711c2015-11-18 06:02:15 +0000834 SectionKind::getData());
NAKAMURA Takumi0a7d0ad2015-09-22 11:15:07 +0000835
Swaroop Sridhare9247ab2015-06-25 00:28:42 +0000836 StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
837 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
838 COFF::IMAGE_SCN_MEM_READ,
NAKAMURA Takumi0a7d0ad2015-09-22 11:15:07 +0000839 SectionKind::getReadOnly());
Evan Cheng76792992011-07-20 05:58:47 +0000840}
841
Rafael Espindola699281c2016-05-18 11:58:50 +0000842void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000843 CodeModel::Model cm,
Evan Cheng76792992011-07-20 05:58:47 +0000844 MCContext &ctx) {
Rafael Espindola699281c2016-05-18 11:58:50 +0000845 PositionIndependent = PIC;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000846 CMModel = cm;
Evan Cheng76792992011-07-20 05:58:47 +0000847 Ctx = &ctx;
848
849 // Common.
850 CommDirectiveSupportsAlignment = true;
851 SupportsWeakOmittedEHFrame = true;
Tim Northoverd1c6f512014-03-29 09:03:13 +0000852 SupportsCompactUnwindWithoutEHFrame = false;
Tim Northoverf8e47e42015-10-28 22:56:36 +0000853 OmitDwarfIfHaveCompactUnwind = false;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000854
Rafael Espindolaaa7851d2014-05-12 13:47:05 +0000855 PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
856 dwarf::DW_EH_PE_absptr;
Evan Chengbbf3b0d2011-07-20 19:50:42 +0000857
Bill Wendling2d1df6b2013-04-10 21:42:06 +0000858 CompactUnwindDwarfEHFrameOnly = 0;
859
Craig Topperbb694de2014-04-13 04:57:38 +0000860 EHFrameSection = nullptr; // Created on demand.
861 CompactUnwindSection = nullptr; // Used only by selected targets.
862 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
863 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
864 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
865 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
Evan Cheng76792992011-07-20 05:58:47 +0000866
Daniel Sanders8d8b13d2015-06-16 12:18:07 +0000867 TT = TheTriple;
Saleem Abdulrasoolbdbc0082014-06-22 22:25:01 +0000868
David Majnemerff1d0842015-12-22 01:39:04 +0000869 switch (TT.getObjectFormat()) {
870 case Triple::MachO:
Rafael Espindoladbaf0492015-08-14 15:48:41 +0000871 Env = IsMachO;
Jim Grosbachbb2591f2015-06-04 23:35:03 +0000872 initMachOMCObjectFileInfo(TT);
David Majnemerff1d0842015-12-22 01:39:04 +0000873 break;
874 case Triple::COFF:
875 if (!TT.isOSWindows())
876 report_fatal_error(
877 "Cannot initialize MC for non-Windows COFF object files.");
878
Rafael Espindoladbaf0492015-08-14 15:48:41 +0000879 Env = IsCOFF;
Jim Grosbachbb2591f2015-06-04 23:35:03 +0000880 initCOFFMCObjectFileInfo(TT);
David Majnemerff1d0842015-12-22 01:39:04 +0000881 break;
882 case Triple::ELF:
Rafael Espindoladbaf0492015-08-14 15:48:41 +0000883 Env = IsELF;
Jim Grosbachbb2591f2015-06-04 23:35:03 +0000884 initELFMCObjectFileInfo(TT);
David Majnemerff1d0842015-12-22 01:39:04 +0000885 break;
886 case Triple::UnknownObjectFormat:
887 report_fatal_error("Cannot initialize MC for unknown object file format.");
888 break;
Evan Cheng76792992011-07-20 05:58:47 +0000889 }
890}
891
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000892MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
David Blaikiebc563272013-12-13 21:33:40 +0000893 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
Rafael Espindolaba31e272015-01-29 17:33:21 +0000894 0, utostr(Hash));
David Blaikiebc563272013-12-13 21:33:40 +0000895}