blob: 9aee0a5ca4e5e1af4a6c0e6f16d2a64229b4b55e [file] [log] [blame]
Sean Eveson661e4fb2017-11-30 12:43:25 +00001//===-- MCObjectFileInfo.cpp - Object File Information --------------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Sean Eveson661e4fb2017-11-30 12:43:25 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/MC/MCObjectFileInfo.h"
10#include "llvm/ADT/StringExtras.h"
11#include "llvm/ADT/Triple.h"
12#include "llvm/BinaryFormat/COFF.h"
13#include "llvm/BinaryFormat/ELF.h"
14#include "llvm/MC/MCAsmInfo.h"
15#include "llvm/MC/MCContext.h"
16#include "llvm/MC/MCSection.h"
17#include "llvm/MC/MCSectionCOFF.h"
18#include "llvm/MC/MCSectionELF.h"
19#include "llvm/MC/MCSectionMachO.h"
20#include "llvm/MC/MCSectionWasm.h"
Sean Fertilef09d54e2019-07-09 19:21:01 +000021#include "llvm/MC/MCSectionXCOFF.h"
Sean Eveson661e4fb2017-11-30 12:43:25 +000022
23using namespace llvm;
24
25static bool useCompactUnwind(const Triple &T) {
26 // Only on darwin.
27 if (!T.isOSDarwin())
28 return false;
29
30 // aarch64 always has it.
Tim Northoverf1c28922019-09-12 10:22:23 +000031 if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)
Sean Eveson661e4fb2017-11-30 12:43:25 +000032 return true;
33
34 // armv7k always has it.
35 if (T.isWatchABI())
36 return true;
37
38 // Use it on newer version of OS X.
39 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
40 return true;
41
42 // And the iOS simulator.
43 if (T.isiOS() &&
44 (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86))
45 return true;
46
47 return false;
48}
49
50void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
51 // MachO
52 SupportsWeakOmittedEHFrame = false;
53
54 EHFrameSection = Ctx->getMachOSection(
55 "__TEXT", "__eh_frame",
56 MachO::S_COALESCED | MachO::S_ATTR_NO_TOC |
57 MachO::S_ATTR_STRIP_STATIC_SYMS | MachO::S_ATTR_LIVE_SUPPORT,
58 SectionKind::getReadOnly());
59
Tim Northoverf1c28922019-09-12 10:22:23 +000060 if (T.isOSDarwin() &&
61 (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32))
Sean Eveson661e4fb2017-11-30 12:43:25 +000062 SupportsCompactUnwindWithoutEHFrame = true;
63
64 if (T.isWatchABI())
65 OmitDwarfIfHaveCompactUnwind = true;
66
Reid Klecknerfce7f732018-08-09 22:24:04 +000067 FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
Sean Eveson661e4fb2017-11-30 12:43:25 +000068
69 // .comm doesn't support alignment before Leopard.
70 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
71 CommDirectiveSupportsAlignment = false;
72
73 TextSection // .text
74 = Ctx->getMachOSection("__TEXT", "__text",
75 MachO::S_ATTR_PURE_INSTRUCTIONS,
76 SectionKind::getText());
77 DataSection // .data
78 = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
79
80 // BSSSection might not be expected initialized on msvc.
81 BSSSection = nullptr;
82
83 TLSDataSection // .tdata
84 = Ctx->getMachOSection("__DATA", "__thread_data",
85 MachO::S_THREAD_LOCAL_REGULAR,
86 SectionKind::getData());
87 TLSBSSSection // .tbss
88 = Ctx->getMachOSection("__DATA", "__thread_bss",
89 MachO::S_THREAD_LOCAL_ZEROFILL,
90 SectionKind::getThreadBSS());
91
92 // TODO: Verify datarel below.
93 TLSTLVSection // .tlv
94 = Ctx->getMachOSection("__DATA", "__thread_vars",
95 MachO::S_THREAD_LOCAL_VARIABLES,
96 SectionKind::getData());
97
98 TLSThreadInitSection = Ctx->getMachOSection(
99 "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
100 SectionKind::getData());
101
102 CStringSection // .cstring
103 = Ctx->getMachOSection("__TEXT", "__cstring",
104 MachO::S_CSTRING_LITERALS,
105 SectionKind::getMergeable1ByteCString());
106 UStringSection
107 = Ctx->getMachOSection("__TEXT","__ustring", 0,
108 SectionKind::getMergeable2ByteCString());
109 FourByteConstantSection // .literal4
110 = Ctx->getMachOSection("__TEXT", "__literal4",
111 MachO::S_4BYTE_LITERALS,
112 SectionKind::getMergeableConst4());
113 EightByteConstantSection // .literal8
114 = Ctx->getMachOSection("__TEXT", "__literal8",
115 MachO::S_8BYTE_LITERALS,
116 SectionKind::getMergeableConst8());
117
118 SixteenByteConstantSection // .literal16
119 = Ctx->getMachOSection("__TEXT", "__literal16",
120 MachO::S_16BYTE_LITERALS,
121 SectionKind::getMergeableConst16());
122
123 ReadOnlySection // .const
124 = Ctx->getMachOSection("__TEXT", "__const", 0,
125 SectionKind::getReadOnly());
126
127 // If the target is not powerpc, map the coal sections to the non-coal
128 // sections.
129 //
130 // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
131 // "__TEXT/__const_coal" => section "__TEXT/__const"
132 // "__DATA/__datacoal_nt" => section "__DATA/__data"
133 Triple::ArchType ArchTy = T.getArch();
134
Steven Wud0804aa2018-04-10 20:16:35 +0000135 ConstDataSection // .const_data
136 = Ctx->getMachOSection("__DATA", "__const", 0,
137 SectionKind::getReadOnlyWithRel());
138
Sean Eveson661e4fb2017-11-30 12:43:25 +0000139 if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
140 TextCoalSection
141 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
142 MachO::S_COALESCED |
143 MachO::S_ATTR_PURE_INSTRUCTIONS,
144 SectionKind::getText());
145 ConstTextCoalSection
146 = Ctx->getMachOSection("__TEXT", "__const_coal",
147 MachO::S_COALESCED,
148 SectionKind::getReadOnly());
149 DataCoalSection = Ctx->getMachOSection(
150 "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());
Steven Wud0804aa2018-04-10 20:16:35 +0000151 ConstDataCoalSection = DataCoalSection;
Sean Eveson661e4fb2017-11-30 12:43:25 +0000152 } else {
153 TextCoalSection = TextSection;
154 ConstTextCoalSection = ReadOnlySection;
155 DataCoalSection = DataSection;
Steven Wud0804aa2018-04-10 20:16:35 +0000156 ConstDataCoalSection = ConstDataSection;
Sean Eveson661e4fb2017-11-30 12:43:25 +0000157 }
158
Sean Eveson661e4fb2017-11-30 12:43:25 +0000159 DataCommonSection
160 = Ctx->getMachOSection("__DATA","__common",
161 MachO::S_ZEROFILL,
162 SectionKind::getBSS());
163 DataBSSSection
164 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
165 SectionKind::getBSS());
166
167
168 LazySymbolPointerSection
169 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
170 MachO::S_LAZY_SYMBOL_POINTERS,
171 SectionKind::getMetadata());
172 NonLazySymbolPointerSection
173 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
174 MachO::S_NON_LAZY_SYMBOL_POINTERS,
175 SectionKind::getMetadata());
176
177 ThreadLocalPointerSection
178 = Ctx->getMachOSection("__DATA", "__thread_ptr",
179 MachO::S_THREAD_LOCAL_VARIABLE_POINTERS,
180 SectionKind::getMetadata());
181
182 // Exception Handling.
183 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
184 SectionKind::getReadOnlyWithRel());
185
186 COFFDebugSymbolsSection = nullptr;
187 COFFDebugTypesSection = nullptr;
Zachary Turner048f8f92017-12-13 22:33:58 +0000188 COFFGlobalTypeHashesSection = nullptr;
Sean Eveson661e4fb2017-11-30 12:43:25 +0000189
190 if (useCompactUnwind(T)) {
191 CompactUnwindSection =
192 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
193 SectionKind::getReadOnly());
194
195 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
196 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF
Tim Northoverf1c28922019-09-12 10:22:23 +0000197 else if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)
Sean Eveson661e4fb2017-11-30 12:43:25 +0000198 CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF
199 else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
200 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF
201 }
202
203 // Debug Information.
Pavel Labath6088c232018-04-04 14:42:14 +0000204 DwarfDebugNamesSection =
205 Ctx->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG,
206 SectionKind::getMetadata(), "debug_names_begin");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000207 DwarfAccelNamesSection =
208 Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
209 SectionKind::getMetadata(), "names_begin");
210 DwarfAccelObjCSection =
211 Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
212 SectionKind::getMetadata(), "objc_begin");
213 // 16 character section limit...
214 DwarfAccelNamespaceSection =
215 Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
216 SectionKind::getMetadata(), "namespac_begin");
217 DwarfAccelTypesSection =
218 Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
219 SectionKind::getMetadata(), "types_begin");
220
221 DwarfSwiftASTSection =
222 Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG,
223 SectionKind::getMetadata());
224
225 DwarfAbbrevSection =
226 Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
227 SectionKind::getMetadata(), "section_abbrev");
228 DwarfInfoSection =
229 Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
230 SectionKind::getMetadata(), "section_info");
231 DwarfLineSection =
232 Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
233 SectionKind::getMetadata(), "section_line");
Paul Robinson1f900292018-02-06 20:29:21 +0000234 DwarfLineStrSection =
235 Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,
236 SectionKind::getMetadata(), "section_line_str");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000237 DwarfFrameSection =
238 Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
239 SectionKind::getMetadata());
240 DwarfPubNamesSection =
241 Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
242 SectionKind::getMetadata());
243 DwarfPubTypesSection =
244 Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
245 SectionKind::getMetadata());
246 DwarfGnuPubNamesSection =
247 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
248 SectionKind::getMetadata());
249 DwarfGnuPubTypesSection =
250 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
251 SectionKind::getMetadata());
252 DwarfStrSection =
253 Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
254 SectionKind::getMetadata(), "info_string");
255 DwarfStrOffSection =
256 Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG,
257 SectionKind::getMetadata(), "section_str_off");
David Blaikied0e5eca2018-10-20 08:55:51 +0000258 DwarfAddrSection =
259 Ctx->getMachOSection("__DWARF", "__debug_addr", MachO::S_ATTR_DEBUG,
260 SectionKind::getMetadata(), "section_info");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000261 DwarfLocSection =
262 Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
263 SectionKind::getMetadata(), "section_debug_loc");
George Rimar088d96b2018-10-26 11:25:12 +0000264 DwarfLoclistsSection =
265 Ctx->getMachOSection("__DWARF", "__debug_loclists", MachO::S_ATTR_DEBUG,
266 SectionKind::getMetadata(), "section_debug_loc");
267
Sean Eveson661e4fb2017-11-30 12:43:25 +0000268 DwarfARangesSection =
269 Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
270 SectionKind::getMetadata());
271 DwarfRangesSection =
272 Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
273 SectionKind::getMetadata(), "debug_range");
Wolfgang Piebfcf38102018-07-12 18:18:21 +0000274 DwarfRnglistsSection =
275 Ctx->getMachOSection("__DWARF", "__debug_rnglists", MachO::S_ATTR_DEBUG,
276 SectionKind::getMetadata(), "debug_range");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000277 DwarfMacinfoSection =
278 Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG,
279 SectionKind::getMetadata(), "debug_macinfo");
280 DwarfDebugInlineSection =
281 Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
282 SectionKind::getMetadata());
283 DwarfCUIndexSection =
284 Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,
285 SectionKind::getMetadata());
286 DwarfTUIndexSection =
287 Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG,
288 SectionKind::getMetadata());
289 StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
290 0, SectionKind::getMetadata());
291
292 FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
293 0, SectionKind::getMetadata());
294
Francis Visoiu Mistrihee1a6e72019-03-27 01:13:59 +0000295 RemarksSection = Ctx->getMachOSection(
296 "__LLVM", "__remarks", MachO::S_ATTR_DEBUG, SectionKind::getMetadata());
297
Sean Eveson661e4fb2017-11-30 12:43:25 +0000298 TLSExtraDataSection = TLSTLVSection;
299}
300
301void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
302 switch (T.getArch()) {
303 case Triple::mips:
304 case Triple::mipsel:
Sean Eveson661e4fb2017-11-30 12:43:25 +0000305 case Triple::mips64:
306 case Triple::mips64el:
Simon Atanasyan4d6f4252018-10-09 11:29:51 +0000307 FDECFIEncoding = Ctx->getAsmInfo()->getCodePointerSize() == 4
308 ? dwarf::DW_EH_PE_sdata4
309 : dwarf::DW_EH_PE_sdata8;
Sean Eveson661e4fb2017-11-30 12:43:25 +0000310 break;
Eric Christopherfe6e6d92018-03-24 00:07:38 +0000311 case Triple::ppc64:
312 case Triple::ppc64le:
Sean Eveson661e4fb2017-11-30 12:43:25 +0000313 case Triple::x86_64:
314 FDECFIEncoding = dwarf::DW_EH_PE_pcrel |
315 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
316 break;
317 case Triple::bpfel:
318 case Triple::bpfeb:
319 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
320 break;
Reid Klecknerfce7f732018-08-09 22:24:04 +0000321 case Triple::hexagon:
322 FDECFIEncoding =
323 PositionIndependent ? dwarf::DW_EH_PE_pcrel : dwarf::DW_EH_PE_absptr;
Simon Pilgrim3640d852018-08-10 11:02:44 +0000324 break;
Sean Eveson661e4fb2017-11-30 12:43:25 +0000325 default:
326 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
327 break;
328 }
329
Sean Eveson661e4fb2017-11-30 12:43:25 +0000330 unsigned EHSectionType = T.getArch() == Triple::x86_64
331 ? ELF::SHT_X86_64_UNWIND
332 : ELF::SHT_PROGBITS;
333
334 // Solaris requires different flags for .eh_frame to seemingly every other
335 // platform.
336 unsigned EHSectionFlags = ELF::SHF_ALLOC;
337 if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
338 EHSectionFlags |= ELF::SHF_WRITE;
339
340 // ELF
341 BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
342 ELF::SHF_WRITE | ELF::SHF_ALLOC);
343
344 TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
345 ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
346
347 DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
348 ELF::SHF_WRITE | ELF::SHF_ALLOC);
349
350 ReadOnlySection =
351 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
352
353 TLSDataSection =
354 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
355 ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
356
357 TLSBSSSection = Ctx->getELFSection(
358 ".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
359
360 DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
361 ELF::SHF_ALLOC | ELF::SHF_WRITE);
362
363 MergeableConst4Section =
364 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
365 ELF::SHF_ALLOC | ELF::SHF_MERGE, 4, "");
366
367 MergeableConst8Section =
368 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
369 ELF::SHF_ALLOC | ELF::SHF_MERGE, 8, "");
370
371 MergeableConst16Section =
372 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
373 ELF::SHF_ALLOC | ELF::SHF_MERGE, 16, "");
374
375 MergeableConst32Section =
376 Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS,
377 ELF::SHF_ALLOC | ELF::SHF_MERGE, 32, "");
378
379 // Exception Handling Sections.
380
381 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
382 // it contains relocatable pointers. In PIC mode, this is probably a big
383 // runtime hit for C++ apps. Either the contents of the LSDA need to be
384 // adjusted or this should be a data section.
385 LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
386 ELF::SHF_ALLOC);
387
388 COFFDebugSymbolsSection = nullptr;
389 COFFDebugTypesSection = nullptr;
390
391 unsigned DebugSecType = ELF::SHT_PROGBITS;
392
393 // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
394 // to distinguish among sections contain DWARF and ECOFF debug formats.
395 // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
Alexander Richardson85e200e2018-06-25 16:49:20 +0000396 if (T.isMIPS())
Sean Eveson661e4fb2017-11-30 12:43:25 +0000397 DebugSecType = ELF::SHT_MIPS_DWARF;
398
399 // Debug Info Sections.
400 DwarfAbbrevSection =
401 Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);
402 DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0);
403 DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0);
Paul Robinson1f900292018-02-06 20:29:21 +0000404 DwarfLineStrSection =
405 Ctx->getELFSection(".debug_line_str", DebugSecType,
406 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000407 DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0);
408 DwarfPubNamesSection =
409 Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);
410 DwarfPubTypesSection =
411 Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);
412 DwarfGnuPubNamesSection =
413 Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);
414 DwarfGnuPubTypesSection =
415 Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);
416 DwarfStrSection =
417 Ctx->getELFSection(".debug_str", DebugSecType,
418 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
419 DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0);
420 DwarfARangesSection =
421 Ctx->getELFSection(".debug_aranges", DebugSecType, 0);
422 DwarfRangesSection =
423 Ctx->getELFSection(".debug_ranges", DebugSecType, 0);
424 DwarfMacinfoSection =
425 Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);
426
427 // DWARF5 Experimental Debug Info
428
429 // Accelerator Tables
Pavel Labath6088c232018-04-04 14:42:14 +0000430 DwarfDebugNamesSection =
431 Ctx->getELFSection(".debug_names", ELF::SHT_PROGBITS, 0);
Sean Eveson661e4fb2017-11-30 12:43:25 +0000432 DwarfAccelNamesSection =
433 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);
434 DwarfAccelObjCSection =
435 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);
436 DwarfAccelNamespaceSection =
437 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);
438 DwarfAccelTypesSection =
439 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);
440
441 // String Offset and Address Sections
442 DwarfStrOffSection =
443 Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);
444 DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);
Wolfgang Piebfcf38102018-07-12 18:18:21 +0000445 DwarfRnglistsSection = Ctx->getELFSection(".debug_rnglists", DebugSecType, 0);
George Rimar088d96b2018-10-26 11:25:12 +0000446 DwarfLoclistsSection = Ctx->getELFSection(".debug_loclists", DebugSecType, 0);
Sean Eveson661e4fb2017-11-30 12:43:25 +0000447
448 // Fission Sections
449 DwarfInfoDWOSection =
George Rimarce95ac62018-09-22 07:36:20 +0000450 Ctx->getELFSection(".debug_info.dwo", DebugSecType, ELF::SHF_EXCLUDE);
Sean Eveson661e4fb2017-11-30 12:43:25 +0000451 DwarfTypesDWOSection =
George Rimarce95ac62018-09-22 07:36:20 +0000452 Ctx->getELFSection(".debug_types.dwo", DebugSecType, ELF::SHF_EXCLUDE);
Sean Eveson661e4fb2017-11-30 12:43:25 +0000453 DwarfAbbrevDWOSection =
George Rimarce95ac62018-09-22 07:36:20 +0000454 Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, ELF::SHF_EXCLUDE);
455 DwarfStrDWOSection = Ctx->getELFSection(
456 ".debug_str.dwo", DebugSecType,
457 ELF::SHF_MERGE | ELF::SHF_STRINGS | ELF::SHF_EXCLUDE, 1, "");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000458 DwarfLineDWOSection =
George Rimarce95ac62018-09-22 07:36:20 +0000459 Ctx->getELFSection(".debug_line.dwo", DebugSecType, ELF::SHF_EXCLUDE);
Sean Eveson661e4fb2017-11-30 12:43:25 +0000460 DwarfLocDWOSection =
George Rimarce95ac62018-09-22 07:36:20 +0000461 Ctx->getELFSection(".debug_loc.dwo", DebugSecType, ELF::SHF_EXCLUDE);
462 DwarfStrOffDWOSection = Ctx->getELFSection(".debug_str_offsets.dwo",
463 DebugSecType, ELF::SHF_EXCLUDE);
Wolfgang Piebfcf38102018-07-12 18:18:21 +0000464 DwarfRnglistsDWOSection =
George Rimarce95ac62018-09-22 07:36:20 +0000465 Ctx->getELFSection(".debug_rnglists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
Sourabh Singh Tomar3f3d0f42019-11-11 12:53:19 +0530466 DwarfMacinfoDWOSection =
467 Ctx->getELFSection(".debug_macinfo.dwo", DebugSecType, ELF::SHF_EXCLUDE);
Sean Eveson661e4fb2017-11-30 12:43:25 +0000468
Sourabh Singh Tomar0e029772019-11-23 20:04:36 +0530469 DwarfLoclistsDWOSection =
470 Ctx->getELFSection(".debug_loclists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
471
Sean Eveson661e4fb2017-11-30 12:43:25 +0000472 // DWP Sections
473 DwarfCUIndexSection =
474 Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);
475 DwarfTUIndexSection =
476 Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);
477
478 StackMapSection =
479 Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
480
481 FaultMapSection =
482 Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
483
484 EHFrameSection =
485 Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
Sean Evesona6bcd532017-11-30 13:05:14 +0000486
487 StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);
Sean Eveson661e4fb2017-11-30 12:43:25 +0000488}
489
490void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
Martin Storsjo1aa7e902018-12-03 20:02:05 +0000491 EHFrameSection =
492 Ctx->getCOFFSection(".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
493 COFF::IMAGE_SCN_MEM_READ,
494 SectionKind::getData());
Sean Eveson661e4fb2017-11-30 12:43:25 +0000495
496 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
497 // used to indicate to the linker that the text segment contains thumb instructions
498 // and to set the ISA selection bit for calls accordingly.
499 const bool IsThumb = T.getArch() == Triple::thumb;
500
501 CommDirectiveSupportsAlignment = true;
502
503 // COFF
504 BSSSection = Ctx->getCOFFSection(
505 ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
506 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
507 SectionKind::getBSS());
508 TextSection = Ctx->getCOFFSection(
509 ".text",
510 (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |
511 COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
512 COFF::IMAGE_SCN_MEM_READ,
513 SectionKind::getText());
514 DataSection = Ctx->getCOFFSection(
515 ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
516 COFF::IMAGE_SCN_MEM_WRITE,
517 SectionKind::getData());
518 ReadOnlySection = Ctx->getCOFFSection(
519 ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
520 SectionKind::getReadOnly());
521
Martin Storsjo8f0cb9c2018-12-18 08:32:37 +0000522 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64) {
Sean Eveson661e4fb2017-11-30 12:43:25 +0000523 // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
524 LSDASection = nullptr;
525 } else {
526 LSDASection = Ctx->getCOFFSection(".gcc_except_table",
527 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
528 COFF::IMAGE_SCN_MEM_READ,
529 SectionKind::getReadOnly());
530 }
531
532 // Debug info.
533 COFFDebugSymbolsSection =
534 Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
535 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
536 COFF::IMAGE_SCN_MEM_READ),
537 SectionKind::getMetadata());
538 COFFDebugTypesSection =
539 Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
540 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
541 COFF::IMAGE_SCN_MEM_READ),
542 SectionKind::getMetadata());
Zachary Turner048f8f92017-12-13 22:33:58 +0000543 COFFGlobalTypeHashesSection = Ctx->getCOFFSection(
544 ".debug$H",
545 (COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
546 COFF::IMAGE_SCN_MEM_READ),
547 SectionKind::getMetadata());
Sean Eveson661e4fb2017-11-30 12:43:25 +0000548
549 DwarfAbbrevSection = Ctx->getCOFFSection(
550 ".debug_abbrev",
551 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
552 COFF::IMAGE_SCN_MEM_READ,
553 SectionKind::getMetadata(), "section_abbrev");
554 DwarfInfoSection = Ctx->getCOFFSection(
555 ".debug_info",
556 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
557 COFF::IMAGE_SCN_MEM_READ,
558 SectionKind::getMetadata(), "section_info");
559 DwarfLineSection = Ctx->getCOFFSection(
560 ".debug_line",
561 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
562 COFF::IMAGE_SCN_MEM_READ,
563 SectionKind::getMetadata(), "section_line");
Paul Robinson1f900292018-02-06 20:29:21 +0000564 DwarfLineStrSection = Ctx->getCOFFSection(
565 ".debug_line_str",
566 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
567 COFF::IMAGE_SCN_MEM_READ,
568 SectionKind::getMetadata(), "section_line_str");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000569 DwarfFrameSection = Ctx->getCOFFSection(
570 ".debug_frame",
571 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
572 COFF::IMAGE_SCN_MEM_READ,
573 SectionKind::getMetadata());
574 DwarfPubNamesSection = Ctx->getCOFFSection(
575 ".debug_pubnames",
576 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
577 COFF::IMAGE_SCN_MEM_READ,
578 SectionKind::getMetadata());
579 DwarfPubTypesSection = Ctx->getCOFFSection(
580 ".debug_pubtypes",
581 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
582 COFF::IMAGE_SCN_MEM_READ,
583 SectionKind::getMetadata());
584 DwarfGnuPubNamesSection = Ctx->getCOFFSection(
585 ".debug_gnu_pubnames",
586 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
587 COFF::IMAGE_SCN_MEM_READ,
588 SectionKind::getMetadata());
589 DwarfGnuPubTypesSection = Ctx->getCOFFSection(
590 ".debug_gnu_pubtypes",
591 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
592 COFF::IMAGE_SCN_MEM_READ,
593 SectionKind::getMetadata());
594 DwarfStrSection = Ctx->getCOFFSection(
595 ".debug_str",
596 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
597 COFF::IMAGE_SCN_MEM_READ,
598 SectionKind::getMetadata(), "info_string");
599 DwarfStrOffSection = Ctx->getCOFFSection(
600 ".debug_str_offsets",
601 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
602 COFF::IMAGE_SCN_MEM_READ,
603 SectionKind::getMetadata(), "section_str_off");
604 DwarfLocSection = Ctx->getCOFFSection(
605 ".debug_loc",
606 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
607 COFF::IMAGE_SCN_MEM_READ,
608 SectionKind::getMetadata(), "section_debug_loc");
609 DwarfARangesSection = Ctx->getCOFFSection(
610 ".debug_aranges",
611 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
612 COFF::IMAGE_SCN_MEM_READ,
613 SectionKind::getMetadata());
614 DwarfRangesSection = Ctx->getCOFFSection(
615 ".debug_ranges",
616 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
617 COFF::IMAGE_SCN_MEM_READ,
618 SectionKind::getMetadata(), "debug_range");
619 DwarfMacinfoSection = Ctx->getCOFFSection(
620 ".debug_macinfo",
621 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
622 COFF::IMAGE_SCN_MEM_READ,
623 SectionKind::getMetadata(), "debug_macinfo");
624 DwarfInfoDWOSection = Ctx->getCOFFSection(
625 ".debug_info.dwo",
626 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
627 COFF::IMAGE_SCN_MEM_READ,
628 SectionKind::getMetadata(), "section_info_dwo");
629 DwarfTypesDWOSection = Ctx->getCOFFSection(
630 ".debug_types.dwo",
631 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
632 COFF::IMAGE_SCN_MEM_READ,
633 SectionKind::getMetadata(), "section_types_dwo");
634 DwarfAbbrevDWOSection = Ctx->getCOFFSection(
635 ".debug_abbrev.dwo",
636 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
637 COFF::IMAGE_SCN_MEM_READ,
638 SectionKind::getMetadata(), "section_abbrev_dwo");
639 DwarfStrDWOSection = Ctx->getCOFFSection(
640 ".debug_str.dwo",
641 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
642 COFF::IMAGE_SCN_MEM_READ,
643 SectionKind::getMetadata(), "skel_string");
644 DwarfLineDWOSection = Ctx->getCOFFSection(
645 ".debug_line.dwo",
646 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
647 COFF::IMAGE_SCN_MEM_READ,
648 SectionKind::getMetadata());
649 DwarfLocDWOSection = Ctx->getCOFFSection(
650 ".debug_loc.dwo",
651 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
652 COFF::IMAGE_SCN_MEM_READ,
653 SectionKind::getMetadata(), "skel_loc");
654 DwarfStrOffDWOSection = Ctx->getCOFFSection(
655 ".debug_str_offsets.dwo",
656 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
657 COFF::IMAGE_SCN_MEM_READ,
658 SectionKind::getMetadata(), "section_str_off_dwo");
659 DwarfAddrSection = Ctx->getCOFFSection(
660 ".debug_addr",
661 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
662 COFF::IMAGE_SCN_MEM_READ,
663 SectionKind::getMetadata(), "addr_sec");
664 DwarfCUIndexSection = Ctx->getCOFFSection(
665 ".debug_cu_index",
666 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
667 COFF::IMAGE_SCN_MEM_READ,
668 SectionKind::getMetadata());
669 DwarfTUIndexSection = Ctx->getCOFFSection(
670 ".debug_tu_index",
671 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
672 COFF::IMAGE_SCN_MEM_READ,
673 SectionKind::getMetadata());
Pavel Labath6088c232018-04-04 14:42:14 +0000674 DwarfDebugNamesSection = Ctx->getCOFFSection(
675 ".debug_names",
676 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
677 COFF::IMAGE_SCN_MEM_READ,
678 SectionKind::getMetadata(), "debug_names_begin");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000679 DwarfAccelNamesSection = Ctx->getCOFFSection(
680 ".apple_names",
681 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
682 COFF::IMAGE_SCN_MEM_READ,
683 SectionKind::getMetadata(), "names_begin");
684 DwarfAccelNamespaceSection = Ctx->getCOFFSection(
685 ".apple_namespaces",
686 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
687 COFF::IMAGE_SCN_MEM_READ,
688 SectionKind::getMetadata(), "namespac_begin");
689 DwarfAccelTypesSection = Ctx->getCOFFSection(
690 ".apple_types",
691 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
692 COFF::IMAGE_SCN_MEM_READ,
693 SectionKind::getMetadata(), "types_begin");
694 DwarfAccelObjCSection = Ctx->getCOFFSection(
695 ".apple_objc",
696 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
697 COFF::IMAGE_SCN_MEM_READ,
698 SectionKind::getMetadata(), "objc_begin");
699
700 DrectveSection = Ctx->getCOFFSection(
701 ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
702 SectionKind::getMetadata());
703
704 PDataSection = Ctx->getCOFFSection(
705 ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
706 SectionKind::getData());
707
708 XDataSection = Ctx->getCOFFSection(
709 ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
710 SectionKind::getData());
711
712 SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO,
713 SectionKind::getMetadata());
714
Adrian McCarthydb2736d2018-01-09 23:49:30 +0000715 GFIDsSection = Ctx->getCOFFSection(".gfids$y",
716 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
717 COFF::IMAGE_SCN_MEM_READ,
718 SectionKind::getMetadata());
719
Andrew Paverdd157a9b2019-10-28 13:22:19 +0000720 GLJMPSection = Ctx->getCOFFSection(".gljmp$y",
721 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
722 COFF::IMAGE_SCN_MEM_READ,
723 SectionKind::getMetadata());
724
Sean Eveson661e4fb2017-11-30 12:43:25 +0000725 TLSDataSection = Ctx->getCOFFSection(
726 ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
727 COFF::IMAGE_SCN_MEM_WRITE,
728 SectionKind::getData());
729
730 StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
731 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
732 COFF::IMAGE_SCN_MEM_READ,
733 SectionKind::getReadOnly());
734}
735
736void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
Sean Eveson661e4fb2017-11-30 12:43:25 +0000737 TextSection = Ctx->getWasmSection(".text", SectionKind::getText());
738 DataSection = Ctx->getWasmSection(".data", SectionKind::getData());
739
Sam Cleggb210c642018-05-10 17:38:35 +0000740 DwarfLineSection =
741 Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());
Paul Robinson1f900292018-02-06 20:29:21 +0000742 DwarfLineStrSection =
743 Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata());
Sam Cleggb210c642018-05-10 17:38:35 +0000744 DwarfStrSection =
745 Ctx->getWasmSection(".debug_str", SectionKind::getMetadata());
746 DwarfLocSection =
747 Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());
748 DwarfAbbrevSection =
749 Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata());
Sean Eveson661e4fb2017-11-30 12:43:25 +0000750 DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());
Sam Cleggb210c642018-05-10 17:38:35 +0000751 DwarfRangesSection =
752 Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata());
753 DwarfMacinfoSection =
754 Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata());
Sean Eveson661e4fb2017-11-30 12:43:25 +0000755 DwarfAddrSection = Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata());
756 DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
757 DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
Sam Cleggb210c642018-05-10 17:38:35 +0000758 DwarfInfoSection =
759 Ctx->getWasmSection(".debug_info", SectionKind::getMetadata());
Sean Eveson661e4fb2017-11-30 12:43:25 +0000760 DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());
761 DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
762 DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
763
Heejin Ahn24faf852018-10-25 23:55:10 +0000764 // Wasm use data section for LSDA.
765 // TODO Consider putting each function's exception table in a separate
766 // section, as in -function-sections, to facilitate lld's --gc-section.
767 LSDASection = Ctx->getWasmSection(".rodata.gcc_except_table",
768 SectionKind::getReadOnlyWithRel());
769
Sean Eveson661e4fb2017-11-30 12:43:25 +0000770 // TODO: Define more sections.
771}
772
Sean Fertilef09d54e2019-07-09 19:21:01 +0000773void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) {
774 // The default csect for program code. Functions without a specified section
775 // get placed into this csect. The choice of csect name is not a property of
776 // the ABI or object file format. For example, the XL compiler uses an unnamed
777 // csect for program code.
Sean Fertile1e46d4c2019-08-20 22:03:18 +0000778 TextSection = Ctx->getXCOFFSection(
779 ".text", XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD,
780 XCOFF::C_HIDEXT, SectionKind::getText());
Xing Xueef039a32019-08-25 15:17:25 +0000781
782 DataSection = Ctx->getXCOFFSection(
783 ".data", XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD,
784 XCOFF::C_HIDEXT, SectionKind::getData());
diggerlin3dfa9752019-11-15 11:30:19 -0500785
786 ReadOnlySection = Ctx->getXCOFFSection(
787 ".rodata", XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD,
788 XCOFF::C_HIDEXT, SectionKind::getReadOnly());
Sean Fertilef09d54e2019-07-09 19:21:01 +0000789}
790
Sean Eveson661e4fb2017-11-30 12:43:25 +0000791void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
792 MCContext &ctx,
793 bool LargeCodeModel) {
794 PositionIndependent = PIC;
795 Ctx = &ctx;
796
797 // Common.
798 CommDirectiveSupportsAlignment = true;
799 SupportsWeakOmittedEHFrame = true;
800 SupportsCompactUnwindWithoutEHFrame = false;
801 OmitDwarfIfHaveCompactUnwind = false;
802
Reid Klecknerfce7f732018-08-09 22:24:04 +0000803 FDECFIEncoding = dwarf::DW_EH_PE_absptr;
Sean Eveson661e4fb2017-11-30 12:43:25 +0000804
805 CompactUnwindDwarfEHFrameOnly = 0;
806
807 EHFrameSection = nullptr; // Created on demand.
808 CompactUnwindSection = nullptr; // Used only by selected targets.
809 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
810 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
811 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
812 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
813
814 TT = TheTriple;
815
816 switch (TT.getObjectFormat()) {
817 case Triple::MachO:
818 Env = IsMachO;
819 initMachOMCObjectFileInfo(TT);
820 break;
821 case Triple::COFF:
822 if (!TT.isOSWindows())
823 report_fatal_error(
824 "Cannot initialize MC for non-Windows COFF object files.");
825
826 Env = IsCOFF;
827 initCOFFMCObjectFileInfo(TT);
828 break;
829 case Triple::ELF:
830 Env = IsELF;
831 initELFMCObjectFileInfo(TT, LargeCodeModel);
832 break;
833 case Triple::Wasm:
834 Env = IsWasm;
835 initWasmMCObjectFileInfo(TT);
836 break;
Jason Liua03ae732019-03-12 22:01:10 +0000837 case Triple::XCOFF:
838 Env = IsXCOFF;
Sean Fertilef09d54e2019-07-09 19:21:01 +0000839 initXCOFFMCObjectFileInfo(TT);
Jason Liua03ae732019-03-12 22:01:10 +0000840 break;
Sean Eveson661e4fb2017-11-30 12:43:25 +0000841 case Triple::UnknownObjectFormat:
842 report_fatal_error("Cannot initialize MC for unknown object file format.");
843 break;
844 }
845}
846
Paul Robinsonddbde9a2018-11-09 19:06:09 +0000847MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
848 uint64_t Hash) const {
Jonas Devlieghere8acb74e2018-08-01 12:53:06 +0000849 switch (TT.getObjectFormat()) {
850 case Triple::ELF:
Paul Robinsonddbde9a2018-11-09 19:06:09 +0000851 return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0,
852 utostr(Hash));
Jonas Devlieghere8acb74e2018-08-01 12:53:06 +0000853 case Triple::MachO:
854 case Triple::COFF:
855 case Triple::Wasm:
Jason Liua03ae732019-03-12 22:01:10 +0000856 case Triple::XCOFF:
Jonas Devlieghere8acb74e2018-08-01 12:53:06 +0000857 case Triple::UnknownObjectFormat:
Paul Robinsonddbde9a2018-11-09 19:06:09 +0000858 report_fatal_error("Cannot get DWARF comdat section for this object file "
Jonas Devlieghere8acb74e2018-08-01 12:53:06 +0000859 "format: not implemented.");
860 break;
861 }
Simon Pilgrim25b15f12018-08-01 13:00:11 +0000862 llvm_unreachable("Unknown ObjectFormatType");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000863}
George Rimardcf59c52018-06-22 10:53:47 +0000864
865MCSection *
866MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const {
867 if (Env != IsELF)
868 return StackSizesSection;
869
870 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
871 unsigned Flags = ELF::SHF_LINK_ORDER;
872 StringRef GroupName;
873 if (const MCSymbol *Group = ElfSec.getGroup()) {
874 GroupName = Group->getName();
875 Flags |= ELF::SHF_GROUP;
876 }
877
878 const MCSymbol *Link = TextSec.getBeginSymbol();
879 auto It = StackSizesUniquing.insert({Link, StackSizesUniquing.size()});
880 unsigned UniqueID = It.first->second;
881
882 return Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, Flags, 0,
883 GroupName, UniqueID, cast<MCSymbolELF>(Link));
884}