blob: 29fbda2be82b603a3703f1652a8179028c6b72bf [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.
Jim Linab1bcda2020-01-07 17:32:39 +080043 if (T.isiOS() && T.isX86())
Sean Eveson661e4fb2017-11-30 12:43:25 +000044 return true;
45
46 return false;
47}
48
49void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
50 // MachO
51 SupportsWeakOmittedEHFrame = false;
52
53 EHFrameSection = Ctx->getMachOSection(
54 "__TEXT", "__eh_frame",
55 MachO::S_COALESCED | MachO::S_ATTR_NO_TOC |
56 MachO::S_ATTR_STRIP_STATIC_SYMS | MachO::S_ATTR_LIVE_SUPPORT,
57 SectionKind::getReadOnly());
58
Tim Northoverf1c28922019-09-12 10:22:23 +000059 if (T.isOSDarwin() &&
60 (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32))
Sean Eveson661e4fb2017-11-30 12:43:25 +000061 SupportsCompactUnwindWithoutEHFrame = true;
62
63 if (T.isWatchABI())
64 OmitDwarfIfHaveCompactUnwind = true;
65
Reid Klecknerfce7f732018-08-09 22:24:04 +000066 FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
Sean Eveson661e4fb2017-11-30 12:43:25 +000067
68 // .comm doesn't support alignment before Leopard.
69 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
70 CommDirectiveSupportsAlignment = false;
71
72 TextSection // .text
73 = Ctx->getMachOSection("__TEXT", "__text",
74 MachO::S_ATTR_PURE_INSTRUCTIONS,
75 SectionKind::getText());
76 DataSection // .data
77 = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
78
79 // BSSSection might not be expected initialized on msvc.
80 BSSSection = nullptr;
81
82 TLSDataSection // .tdata
83 = Ctx->getMachOSection("__DATA", "__thread_data",
84 MachO::S_THREAD_LOCAL_REGULAR,
85 SectionKind::getData());
86 TLSBSSSection // .tbss
87 = Ctx->getMachOSection("__DATA", "__thread_bss",
88 MachO::S_THREAD_LOCAL_ZEROFILL,
89 SectionKind::getThreadBSS());
90
91 // TODO: Verify datarel below.
92 TLSTLVSection // .tlv
93 = Ctx->getMachOSection("__DATA", "__thread_vars",
94 MachO::S_THREAD_LOCAL_VARIABLES,
95 SectionKind::getData());
96
97 TLSThreadInitSection = Ctx->getMachOSection(
98 "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
99 SectionKind::getData());
100
101 CStringSection // .cstring
102 = Ctx->getMachOSection("__TEXT", "__cstring",
103 MachO::S_CSTRING_LITERALS,
104 SectionKind::getMergeable1ByteCString());
105 UStringSection
106 = Ctx->getMachOSection("__TEXT","__ustring", 0,
107 SectionKind::getMergeable2ByteCString());
108 FourByteConstantSection // .literal4
109 = Ctx->getMachOSection("__TEXT", "__literal4",
110 MachO::S_4BYTE_LITERALS,
111 SectionKind::getMergeableConst4());
112 EightByteConstantSection // .literal8
113 = Ctx->getMachOSection("__TEXT", "__literal8",
114 MachO::S_8BYTE_LITERALS,
115 SectionKind::getMergeableConst8());
116
117 SixteenByteConstantSection // .literal16
118 = Ctx->getMachOSection("__TEXT", "__literal16",
119 MachO::S_16BYTE_LITERALS,
120 SectionKind::getMergeableConst16());
121
122 ReadOnlySection // .const
123 = Ctx->getMachOSection("__TEXT", "__const", 0,
124 SectionKind::getReadOnly());
125
126 // If the target is not powerpc, map the coal sections to the non-coal
127 // sections.
128 //
129 // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
130 // "__TEXT/__const_coal" => section "__TEXT/__const"
131 // "__DATA/__datacoal_nt" => section "__DATA/__data"
132 Triple::ArchType ArchTy = T.getArch();
133
Steven Wud0804aa2018-04-10 20:16:35 +0000134 ConstDataSection // .const_data
135 = Ctx->getMachOSection("__DATA", "__const", 0,
136 SectionKind::getReadOnlyWithRel());
137
Sean Eveson661e4fb2017-11-30 12:43:25 +0000138 if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
139 TextCoalSection
140 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
141 MachO::S_COALESCED |
142 MachO::S_ATTR_PURE_INSTRUCTIONS,
143 SectionKind::getText());
144 ConstTextCoalSection
145 = Ctx->getMachOSection("__TEXT", "__const_coal",
146 MachO::S_COALESCED,
147 SectionKind::getReadOnly());
148 DataCoalSection = Ctx->getMachOSection(
149 "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());
Steven Wud0804aa2018-04-10 20:16:35 +0000150 ConstDataCoalSection = DataCoalSection;
Sean Eveson661e4fb2017-11-30 12:43:25 +0000151 } else {
152 TextCoalSection = TextSection;
153 ConstTextCoalSection = ReadOnlySection;
154 DataCoalSection = DataSection;
Steven Wud0804aa2018-04-10 20:16:35 +0000155 ConstDataCoalSection = ConstDataSection;
Sean Eveson661e4fb2017-11-30 12:43:25 +0000156 }
157
Sean Eveson661e4fb2017-11-30 12:43:25 +0000158 DataCommonSection
159 = Ctx->getMachOSection("__DATA","__common",
160 MachO::S_ZEROFILL,
161 SectionKind::getBSS());
162 DataBSSSection
163 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
164 SectionKind::getBSS());
165
166
167 LazySymbolPointerSection
168 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
169 MachO::S_LAZY_SYMBOL_POINTERS,
170 SectionKind::getMetadata());
171 NonLazySymbolPointerSection
172 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
173 MachO::S_NON_LAZY_SYMBOL_POINTERS,
174 SectionKind::getMetadata());
175
176 ThreadLocalPointerSection
177 = Ctx->getMachOSection("__DATA", "__thread_ptr",
178 MachO::S_THREAD_LOCAL_VARIABLE_POINTERS,
179 SectionKind::getMetadata());
180
181 // Exception Handling.
182 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
183 SectionKind::getReadOnlyWithRel());
184
185 COFFDebugSymbolsSection = nullptr;
186 COFFDebugTypesSection = nullptr;
Zachary Turner048f8f92017-12-13 22:33:58 +0000187 COFFGlobalTypeHashesSection = nullptr;
Sean Eveson661e4fb2017-11-30 12:43:25 +0000188
189 if (useCompactUnwind(T)) {
190 CompactUnwindSection =
191 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
192 SectionKind::getReadOnly());
193
Jim Linab1bcda2020-01-07 17:32:39 +0800194 if (T.isX86())
Sean Eveson661e4fb2017-11-30 12:43:25 +0000195 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF
Tim Northoverf1c28922019-09-12 10:22:23 +0000196 else if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)
Sean Eveson661e4fb2017-11-30 12:43:25 +0000197 CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF
198 else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
199 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF
200 }
201
202 // Debug Information.
Pavel Labath6088c232018-04-04 14:42:14 +0000203 DwarfDebugNamesSection =
204 Ctx->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG,
205 SectionKind::getMetadata(), "debug_names_begin");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000206 DwarfAccelNamesSection =
207 Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
208 SectionKind::getMetadata(), "names_begin");
209 DwarfAccelObjCSection =
210 Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
211 SectionKind::getMetadata(), "objc_begin");
212 // 16 character section limit...
213 DwarfAccelNamespaceSection =
214 Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
215 SectionKind::getMetadata(), "namespac_begin");
216 DwarfAccelTypesSection =
217 Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
218 SectionKind::getMetadata(), "types_begin");
219
220 DwarfSwiftASTSection =
221 Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG,
222 SectionKind::getMetadata());
223
224 DwarfAbbrevSection =
225 Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
226 SectionKind::getMetadata(), "section_abbrev");
227 DwarfInfoSection =
228 Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
229 SectionKind::getMetadata(), "section_info");
230 DwarfLineSection =
231 Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
232 SectionKind::getMetadata(), "section_line");
Paul Robinson1f900292018-02-06 20:29:21 +0000233 DwarfLineStrSection =
234 Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,
235 SectionKind::getMetadata(), "section_line_str");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000236 DwarfFrameSection =
237 Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
238 SectionKind::getMetadata());
239 DwarfPubNamesSection =
240 Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
241 SectionKind::getMetadata());
242 DwarfPubTypesSection =
243 Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
244 SectionKind::getMetadata());
245 DwarfGnuPubNamesSection =
246 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
247 SectionKind::getMetadata());
248 DwarfGnuPubTypesSection =
249 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
250 SectionKind::getMetadata());
251 DwarfStrSection =
252 Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
253 SectionKind::getMetadata(), "info_string");
254 DwarfStrOffSection =
255 Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG,
256 SectionKind::getMetadata(), "section_str_off");
David Blaikied0e5eca2018-10-20 08:55:51 +0000257 DwarfAddrSection =
258 Ctx->getMachOSection("__DWARF", "__debug_addr", MachO::S_ATTR_DEBUG,
259 SectionKind::getMetadata(), "section_info");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000260 DwarfLocSection =
261 Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
262 SectionKind::getMetadata(), "section_debug_loc");
George Rimar088d96b2018-10-26 11:25:12 +0000263 DwarfLoclistsSection =
264 Ctx->getMachOSection("__DWARF", "__debug_loclists", MachO::S_ATTR_DEBUG,
265 SectionKind::getMetadata(), "section_debug_loc");
266
Sean Eveson661e4fb2017-11-30 12:43:25 +0000267 DwarfARangesSection =
268 Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
269 SectionKind::getMetadata());
270 DwarfRangesSection =
271 Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
272 SectionKind::getMetadata(), "debug_range");
Wolfgang Piebfcf38102018-07-12 18:18:21 +0000273 DwarfRnglistsSection =
274 Ctx->getMachOSection("__DWARF", "__debug_rnglists", MachO::S_ATTR_DEBUG,
275 SectionKind::getMetadata(), "debug_range");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000276 DwarfMacinfoSection =
277 Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG,
278 SectionKind::getMetadata(), "debug_macinfo");
279 DwarfDebugInlineSection =
280 Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
281 SectionKind::getMetadata());
282 DwarfCUIndexSection =
283 Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,
284 SectionKind::getMetadata());
285 DwarfTUIndexSection =
286 Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG,
287 SectionKind::getMetadata());
288 StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
289 0, SectionKind::getMetadata());
290
291 FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
292 0, SectionKind::getMetadata());
293
Francis Visoiu Mistrihee1a6e72019-03-27 01:13:59 +0000294 RemarksSection = Ctx->getMachOSection(
295 "__LLVM", "__remarks", MachO::S_ATTR_DEBUG, SectionKind::getMetadata());
296
Sean Eveson661e4fb2017-11-30 12:43:25 +0000297 TLSExtraDataSection = TLSTLVSection;
298}
299
300void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
301 switch (T.getArch()) {
302 case Triple::mips:
303 case Triple::mipsel:
Sean Eveson661e4fb2017-11-30 12:43:25 +0000304 case Triple::mips64:
305 case Triple::mips64el:
Simon Atanasyan4d6f4252018-10-09 11:29:51 +0000306 FDECFIEncoding = Ctx->getAsmInfo()->getCodePointerSize() == 4
307 ? dwarf::DW_EH_PE_sdata4
308 : dwarf::DW_EH_PE_sdata8;
Sean Eveson661e4fb2017-11-30 12:43:25 +0000309 break;
Eric Christopherfe6e6d92018-03-24 00:07:38 +0000310 case Triple::ppc64:
311 case Triple::ppc64le:
Sean Eveson661e4fb2017-11-30 12:43:25 +0000312 case Triple::x86_64:
313 FDECFIEncoding = dwarf::DW_EH_PE_pcrel |
314 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
315 break;
316 case Triple::bpfel:
317 case Triple::bpfeb:
318 FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
319 break;
Reid Klecknerfce7f732018-08-09 22:24:04 +0000320 case Triple::hexagon:
321 FDECFIEncoding =
322 PositionIndependent ? dwarf::DW_EH_PE_pcrel : dwarf::DW_EH_PE_absptr;
Simon Pilgrim3640d852018-08-10 11:02:44 +0000323 break;
Sean Eveson661e4fb2017-11-30 12:43:25 +0000324 default:
325 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
326 break;
327 }
328
Sean Eveson661e4fb2017-11-30 12:43:25 +0000329 unsigned EHSectionType = T.getArch() == Triple::x86_64
330 ? ELF::SHT_X86_64_UNWIND
331 : ELF::SHT_PROGBITS;
332
333 // Solaris requires different flags for .eh_frame to seemingly every other
334 // platform.
335 unsigned EHSectionFlags = ELF::SHF_ALLOC;
336 if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
337 EHSectionFlags |= ELF::SHF_WRITE;
338
339 // ELF
340 BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
341 ELF::SHF_WRITE | ELF::SHF_ALLOC);
342
343 TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
344 ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
345
346 DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
347 ELF::SHF_WRITE | ELF::SHF_ALLOC);
348
349 ReadOnlySection =
350 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
351
352 TLSDataSection =
353 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
354 ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
355
356 TLSBSSSection = Ctx->getELFSection(
357 ".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
358
359 DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
360 ELF::SHF_ALLOC | ELF::SHF_WRITE);
361
362 MergeableConst4Section =
363 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
364 ELF::SHF_ALLOC | ELF::SHF_MERGE, 4, "");
365
366 MergeableConst8Section =
367 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
368 ELF::SHF_ALLOC | ELF::SHF_MERGE, 8, "");
369
370 MergeableConst16Section =
371 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
372 ELF::SHF_ALLOC | ELF::SHF_MERGE, 16, "");
373
374 MergeableConst32Section =
375 Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS,
376 ELF::SHF_ALLOC | ELF::SHF_MERGE, 32, "");
377
378 // Exception Handling Sections.
379
380 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
381 // it contains relocatable pointers. In PIC mode, this is probably a big
382 // runtime hit for C++ apps. Either the contents of the LSDA need to be
383 // adjusted or this should be a data section.
384 LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
385 ELF::SHF_ALLOC);
386
387 COFFDebugSymbolsSection = nullptr;
388 COFFDebugTypesSection = nullptr;
389
390 unsigned DebugSecType = ELF::SHT_PROGBITS;
391
392 // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
393 // to distinguish among sections contain DWARF and ECOFF debug formats.
394 // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
Alexander Richardson85e200e2018-06-25 16:49:20 +0000395 if (T.isMIPS())
Sean Eveson661e4fb2017-11-30 12:43:25 +0000396 DebugSecType = ELF::SHT_MIPS_DWARF;
397
398 // Debug Info Sections.
399 DwarfAbbrevSection =
400 Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);
401 DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0);
402 DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0);
Paul Robinson1f900292018-02-06 20:29:21 +0000403 DwarfLineStrSection =
404 Ctx->getELFSection(".debug_line_str", DebugSecType,
405 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000406 DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0);
407 DwarfPubNamesSection =
408 Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);
409 DwarfPubTypesSection =
410 Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);
411 DwarfGnuPubNamesSection =
412 Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);
413 DwarfGnuPubTypesSection =
414 Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);
415 DwarfStrSection =
416 Ctx->getELFSection(".debug_str", DebugSecType,
417 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
418 DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0);
419 DwarfARangesSection =
420 Ctx->getELFSection(".debug_aranges", DebugSecType, 0);
421 DwarfRangesSection =
422 Ctx->getELFSection(".debug_ranges", DebugSecType, 0);
423 DwarfMacinfoSection =
424 Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);
425
426 // DWARF5 Experimental Debug Info
427
428 // Accelerator Tables
Pavel Labath6088c232018-04-04 14:42:14 +0000429 DwarfDebugNamesSection =
430 Ctx->getELFSection(".debug_names", ELF::SHT_PROGBITS, 0);
Sean Eveson661e4fb2017-11-30 12:43:25 +0000431 DwarfAccelNamesSection =
432 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);
433 DwarfAccelObjCSection =
434 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);
435 DwarfAccelNamespaceSection =
436 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);
437 DwarfAccelTypesSection =
438 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);
439
440 // String Offset and Address Sections
441 DwarfStrOffSection =
442 Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);
443 DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);
Wolfgang Piebfcf38102018-07-12 18:18:21 +0000444 DwarfRnglistsSection = Ctx->getELFSection(".debug_rnglists", DebugSecType, 0);
George Rimar088d96b2018-10-26 11:25:12 +0000445 DwarfLoclistsSection = Ctx->getELFSection(".debug_loclists", DebugSecType, 0);
Sean Eveson661e4fb2017-11-30 12:43:25 +0000446
447 // Fission Sections
448 DwarfInfoDWOSection =
George Rimarce95ac62018-09-22 07:36:20 +0000449 Ctx->getELFSection(".debug_info.dwo", DebugSecType, ELF::SHF_EXCLUDE);
Sean Eveson661e4fb2017-11-30 12:43:25 +0000450 DwarfTypesDWOSection =
George Rimarce95ac62018-09-22 07:36:20 +0000451 Ctx->getELFSection(".debug_types.dwo", DebugSecType, ELF::SHF_EXCLUDE);
Sean Eveson661e4fb2017-11-30 12:43:25 +0000452 DwarfAbbrevDWOSection =
George Rimarce95ac62018-09-22 07:36:20 +0000453 Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, ELF::SHF_EXCLUDE);
454 DwarfStrDWOSection = Ctx->getELFSection(
455 ".debug_str.dwo", DebugSecType,
456 ELF::SHF_MERGE | ELF::SHF_STRINGS | ELF::SHF_EXCLUDE, 1, "");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000457 DwarfLineDWOSection =
George Rimarce95ac62018-09-22 07:36:20 +0000458 Ctx->getELFSection(".debug_line.dwo", DebugSecType, ELF::SHF_EXCLUDE);
Sean Eveson661e4fb2017-11-30 12:43:25 +0000459 DwarfLocDWOSection =
George Rimarce95ac62018-09-22 07:36:20 +0000460 Ctx->getELFSection(".debug_loc.dwo", DebugSecType, ELF::SHF_EXCLUDE);
461 DwarfStrOffDWOSection = Ctx->getELFSection(".debug_str_offsets.dwo",
462 DebugSecType, ELF::SHF_EXCLUDE);
Wolfgang Piebfcf38102018-07-12 18:18:21 +0000463 DwarfRnglistsDWOSection =
George Rimarce95ac62018-09-22 07:36:20 +0000464 Ctx->getELFSection(".debug_rnglists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
Sourabh Singh Tomar3f3d0f42019-11-11 12:53:19 +0530465 DwarfMacinfoDWOSection =
466 Ctx->getELFSection(".debug_macinfo.dwo", DebugSecType, ELF::SHF_EXCLUDE);
Sean Eveson661e4fb2017-11-30 12:43:25 +0000467
Sourabh Singh Tomar0e029772019-11-23 20:04:36 +0530468 DwarfLoclistsDWOSection =
469 Ctx->getELFSection(".debug_loclists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
470
Sean Eveson661e4fb2017-11-30 12:43:25 +0000471 // DWP Sections
472 DwarfCUIndexSection =
473 Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);
474 DwarfTUIndexSection =
475 Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);
476
477 StackMapSection =
478 Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
479
480 FaultMapSection =
481 Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
482
483 EHFrameSection =
484 Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
Sean Evesona6bcd532017-11-30 13:05:14 +0000485
486 StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);
Sean Eveson661e4fb2017-11-30 12:43:25 +0000487}
488
489void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
Martin Storsjo1aa7e902018-12-03 20:02:05 +0000490 EHFrameSection =
491 Ctx->getCOFFSection(".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
492 COFF::IMAGE_SCN_MEM_READ,
493 SectionKind::getData());
Sean Eveson661e4fb2017-11-30 12:43:25 +0000494
495 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
496 // used to indicate to the linker that the text segment contains thumb instructions
497 // and to set the ISA selection bit for calls accordingly.
498 const bool IsThumb = T.getArch() == Triple::thumb;
499
500 CommDirectiveSupportsAlignment = true;
501
502 // COFF
503 BSSSection = Ctx->getCOFFSection(
504 ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
505 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
506 SectionKind::getBSS());
507 TextSection = Ctx->getCOFFSection(
508 ".text",
509 (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |
510 COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
511 COFF::IMAGE_SCN_MEM_READ,
512 SectionKind::getText());
513 DataSection = Ctx->getCOFFSection(
514 ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
515 COFF::IMAGE_SCN_MEM_WRITE,
516 SectionKind::getData());
517 ReadOnlySection = Ctx->getCOFFSection(
518 ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
519 SectionKind::getReadOnly());
520
Martin Storsjo8f0cb9c2018-12-18 08:32:37 +0000521 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64) {
Sean Eveson661e4fb2017-11-30 12:43:25 +0000522 // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
523 LSDASection = nullptr;
524 } else {
525 LSDASection = Ctx->getCOFFSection(".gcc_except_table",
526 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
527 COFF::IMAGE_SCN_MEM_READ,
528 SectionKind::getReadOnly());
529 }
530
531 // Debug info.
532 COFFDebugSymbolsSection =
533 Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
534 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
535 COFF::IMAGE_SCN_MEM_READ),
536 SectionKind::getMetadata());
537 COFFDebugTypesSection =
538 Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
539 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
540 COFF::IMAGE_SCN_MEM_READ),
541 SectionKind::getMetadata());
Zachary Turner048f8f92017-12-13 22:33:58 +0000542 COFFGlobalTypeHashesSection = Ctx->getCOFFSection(
543 ".debug$H",
544 (COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
545 COFF::IMAGE_SCN_MEM_READ),
546 SectionKind::getMetadata());
Sean Eveson661e4fb2017-11-30 12:43:25 +0000547
548 DwarfAbbrevSection = Ctx->getCOFFSection(
549 ".debug_abbrev",
550 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
551 COFF::IMAGE_SCN_MEM_READ,
552 SectionKind::getMetadata(), "section_abbrev");
553 DwarfInfoSection = Ctx->getCOFFSection(
554 ".debug_info",
555 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
556 COFF::IMAGE_SCN_MEM_READ,
557 SectionKind::getMetadata(), "section_info");
558 DwarfLineSection = Ctx->getCOFFSection(
559 ".debug_line",
560 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
561 COFF::IMAGE_SCN_MEM_READ,
562 SectionKind::getMetadata(), "section_line");
Paul Robinson1f900292018-02-06 20:29:21 +0000563 DwarfLineStrSection = Ctx->getCOFFSection(
564 ".debug_line_str",
565 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
566 COFF::IMAGE_SCN_MEM_READ,
567 SectionKind::getMetadata(), "section_line_str");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000568 DwarfFrameSection = Ctx->getCOFFSection(
569 ".debug_frame",
570 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
571 COFF::IMAGE_SCN_MEM_READ,
572 SectionKind::getMetadata());
573 DwarfPubNamesSection = Ctx->getCOFFSection(
574 ".debug_pubnames",
575 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
576 COFF::IMAGE_SCN_MEM_READ,
577 SectionKind::getMetadata());
578 DwarfPubTypesSection = Ctx->getCOFFSection(
579 ".debug_pubtypes",
580 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
581 COFF::IMAGE_SCN_MEM_READ,
582 SectionKind::getMetadata());
583 DwarfGnuPubNamesSection = Ctx->getCOFFSection(
584 ".debug_gnu_pubnames",
585 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
586 COFF::IMAGE_SCN_MEM_READ,
587 SectionKind::getMetadata());
588 DwarfGnuPubTypesSection = Ctx->getCOFFSection(
589 ".debug_gnu_pubtypes",
590 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
591 COFF::IMAGE_SCN_MEM_READ,
592 SectionKind::getMetadata());
593 DwarfStrSection = Ctx->getCOFFSection(
594 ".debug_str",
595 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
596 COFF::IMAGE_SCN_MEM_READ,
597 SectionKind::getMetadata(), "info_string");
598 DwarfStrOffSection = Ctx->getCOFFSection(
599 ".debug_str_offsets",
600 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
601 COFF::IMAGE_SCN_MEM_READ,
602 SectionKind::getMetadata(), "section_str_off");
603 DwarfLocSection = Ctx->getCOFFSection(
604 ".debug_loc",
605 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
606 COFF::IMAGE_SCN_MEM_READ,
607 SectionKind::getMetadata(), "section_debug_loc");
608 DwarfARangesSection = Ctx->getCOFFSection(
609 ".debug_aranges",
610 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
611 COFF::IMAGE_SCN_MEM_READ,
612 SectionKind::getMetadata());
613 DwarfRangesSection = Ctx->getCOFFSection(
614 ".debug_ranges",
615 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
616 COFF::IMAGE_SCN_MEM_READ,
617 SectionKind::getMetadata(), "debug_range");
618 DwarfMacinfoSection = Ctx->getCOFFSection(
619 ".debug_macinfo",
620 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
621 COFF::IMAGE_SCN_MEM_READ,
622 SectionKind::getMetadata(), "debug_macinfo");
Sourabh Singh Tomar399273e2019-12-04 18:32:39 +0530623 DwarfMacinfoDWOSection = Ctx->getCOFFSection(
624 ".debug_macinfo.dwo",
625 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
626 COFF::IMAGE_SCN_MEM_READ,
627 SectionKind::getMetadata(), "debug_macinfo.dwo");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000628 DwarfInfoDWOSection = Ctx->getCOFFSection(
629 ".debug_info.dwo",
630 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
631 COFF::IMAGE_SCN_MEM_READ,
632 SectionKind::getMetadata(), "section_info_dwo");
633 DwarfTypesDWOSection = Ctx->getCOFFSection(
634 ".debug_types.dwo",
635 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
636 COFF::IMAGE_SCN_MEM_READ,
637 SectionKind::getMetadata(), "section_types_dwo");
638 DwarfAbbrevDWOSection = Ctx->getCOFFSection(
639 ".debug_abbrev.dwo",
640 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
641 COFF::IMAGE_SCN_MEM_READ,
642 SectionKind::getMetadata(), "section_abbrev_dwo");
643 DwarfStrDWOSection = Ctx->getCOFFSection(
644 ".debug_str.dwo",
645 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
646 COFF::IMAGE_SCN_MEM_READ,
647 SectionKind::getMetadata(), "skel_string");
648 DwarfLineDWOSection = Ctx->getCOFFSection(
649 ".debug_line.dwo",
650 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
651 COFF::IMAGE_SCN_MEM_READ,
652 SectionKind::getMetadata());
653 DwarfLocDWOSection = Ctx->getCOFFSection(
654 ".debug_loc.dwo",
655 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
656 COFF::IMAGE_SCN_MEM_READ,
657 SectionKind::getMetadata(), "skel_loc");
658 DwarfStrOffDWOSection = Ctx->getCOFFSection(
659 ".debug_str_offsets.dwo",
660 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
661 COFF::IMAGE_SCN_MEM_READ,
662 SectionKind::getMetadata(), "section_str_off_dwo");
663 DwarfAddrSection = Ctx->getCOFFSection(
664 ".debug_addr",
665 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
666 COFF::IMAGE_SCN_MEM_READ,
667 SectionKind::getMetadata(), "addr_sec");
668 DwarfCUIndexSection = Ctx->getCOFFSection(
669 ".debug_cu_index",
670 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
671 COFF::IMAGE_SCN_MEM_READ,
672 SectionKind::getMetadata());
673 DwarfTUIndexSection = Ctx->getCOFFSection(
674 ".debug_tu_index",
675 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
676 COFF::IMAGE_SCN_MEM_READ,
677 SectionKind::getMetadata());
Pavel Labath6088c232018-04-04 14:42:14 +0000678 DwarfDebugNamesSection = Ctx->getCOFFSection(
679 ".debug_names",
680 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
681 COFF::IMAGE_SCN_MEM_READ,
682 SectionKind::getMetadata(), "debug_names_begin");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000683 DwarfAccelNamesSection = Ctx->getCOFFSection(
684 ".apple_names",
685 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
686 COFF::IMAGE_SCN_MEM_READ,
687 SectionKind::getMetadata(), "names_begin");
688 DwarfAccelNamespaceSection = Ctx->getCOFFSection(
689 ".apple_namespaces",
690 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
691 COFF::IMAGE_SCN_MEM_READ,
692 SectionKind::getMetadata(), "namespac_begin");
693 DwarfAccelTypesSection = Ctx->getCOFFSection(
694 ".apple_types",
695 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
696 COFF::IMAGE_SCN_MEM_READ,
697 SectionKind::getMetadata(), "types_begin");
698 DwarfAccelObjCSection = Ctx->getCOFFSection(
699 ".apple_objc",
700 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
701 COFF::IMAGE_SCN_MEM_READ,
702 SectionKind::getMetadata(), "objc_begin");
703
704 DrectveSection = Ctx->getCOFFSection(
705 ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
706 SectionKind::getMetadata());
707
708 PDataSection = Ctx->getCOFFSection(
709 ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
710 SectionKind::getData());
711
712 XDataSection = Ctx->getCOFFSection(
713 ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
714 SectionKind::getData());
715
716 SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO,
717 SectionKind::getMetadata());
718
Adrian McCarthydb2736d2018-01-09 23:49:30 +0000719 GFIDsSection = Ctx->getCOFFSection(".gfids$y",
720 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
721 COFF::IMAGE_SCN_MEM_READ,
722 SectionKind::getMetadata());
723
Andrew Paverdd157a9b2019-10-28 13:22:19 +0000724 GLJMPSection = Ctx->getCOFFSection(".gljmp$y",
725 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
726 COFF::IMAGE_SCN_MEM_READ,
727 SectionKind::getMetadata());
728
Sean Eveson661e4fb2017-11-30 12:43:25 +0000729 TLSDataSection = Ctx->getCOFFSection(
730 ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
731 COFF::IMAGE_SCN_MEM_WRITE,
732 SectionKind::getData());
733
734 StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
735 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
736 COFF::IMAGE_SCN_MEM_READ,
737 SectionKind::getReadOnly());
738}
739
740void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
Sean Eveson661e4fb2017-11-30 12:43:25 +0000741 TextSection = Ctx->getWasmSection(".text", SectionKind::getText());
742 DataSection = Ctx->getWasmSection(".data", SectionKind::getData());
743
Sam Cleggb210c642018-05-10 17:38:35 +0000744 DwarfLineSection =
745 Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());
Paul Robinson1f900292018-02-06 20:29:21 +0000746 DwarfLineStrSection =
747 Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata());
Sam Cleggb210c642018-05-10 17:38:35 +0000748 DwarfStrSection =
749 Ctx->getWasmSection(".debug_str", SectionKind::getMetadata());
750 DwarfLocSection =
751 Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());
752 DwarfAbbrevSection =
753 Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata());
Sean Eveson661e4fb2017-11-30 12:43:25 +0000754 DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());
Sam Cleggb210c642018-05-10 17:38:35 +0000755 DwarfRangesSection =
756 Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata());
757 DwarfMacinfoSection =
758 Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata());
Sean Eveson661e4fb2017-11-30 12:43:25 +0000759 DwarfAddrSection = Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata());
760 DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
761 DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
Sam Cleggb210c642018-05-10 17:38:35 +0000762 DwarfInfoSection =
763 Ctx->getWasmSection(".debug_info", SectionKind::getMetadata());
Sean Eveson661e4fb2017-11-30 12:43:25 +0000764 DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());
765 DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
766 DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
767
Heejin Ahn24faf852018-10-25 23:55:10 +0000768 // Wasm use data section for LSDA.
769 // TODO Consider putting each function's exception table in a separate
770 // section, as in -function-sections, to facilitate lld's --gc-section.
771 LSDASection = Ctx->getWasmSection(".rodata.gcc_except_table",
772 SectionKind::getReadOnlyWithRel());
773
Sean Eveson661e4fb2017-11-30 12:43:25 +0000774 // TODO: Define more sections.
775}
776
Sean Fertilef09d54e2019-07-09 19:21:01 +0000777void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) {
778 // The default csect for program code. Functions without a specified section
779 // get placed into this csect. The choice of csect name is not a property of
780 // the ABI or object file format. For example, the XL compiler uses an unnamed
781 // csect for program code.
Sean Fertile1e46d4c2019-08-20 22:03:18 +0000782 TextSection = Ctx->getXCOFFSection(
783 ".text", XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD,
784 XCOFF::C_HIDEXT, SectionKind::getText());
Xing Xueef039a32019-08-25 15:17:25 +0000785
786 DataSection = Ctx->getXCOFFSection(
787 ".data", XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD,
788 XCOFF::C_HIDEXT, SectionKind::getData());
diggerlin3dfa9752019-11-15 11:30:19 -0500789
790 ReadOnlySection = Ctx->getXCOFFSection(
791 ".rodata", XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD,
792 XCOFF::C_HIDEXT, SectionKind::getReadOnly());
Sean Fertilef09d54e2019-07-09 19:21:01 +0000793}
794
Sean Eveson661e4fb2017-11-30 12:43:25 +0000795void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
796 MCContext &ctx,
797 bool LargeCodeModel) {
798 PositionIndependent = PIC;
799 Ctx = &ctx;
800
801 // Common.
802 CommDirectiveSupportsAlignment = true;
803 SupportsWeakOmittedEHFrame = true;
804 SupportsCompactUnwindWithoutEHFrame = false;
805 OmitDwarfIfHaveCompactUnwind = false;
806
Reid Klecknerfce7f732018-08-09 22:24:04 +0000807 FDECFIEncoding = dwarf::DW_EH_PE_absptr;
Sean Eveson661e4fb2017-11-30 12:43:25 +0000808
809 CompactUnwindDwarfEHFrameOnly = 0;
810
811 EHFrameSection = nullptr; // Created on demand.
812 CompactUnwindSection = nullptr; // Used only by selected targets.
813 DwarfAccelNamesSection = nullptr; // Used only by selected targets.
814 DwarfAccelObjCSection = nullptr; // Used only by selected targets.
815 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
816 DwarfAccelTypesSection = nullptr; // Used only by selected targets.
817
818 TT = TheTriple;
819
820 switch (TT.getObjectFormat()) {
821 case Triple::MachO:
822 Env = IsMachO;
823 initMachOMCObjectFileInfo(TT);
824 break;
825 case Triple::COFF:
826 if (!TT.isOSWindows())
827 report_fatal_error(
828 "Cannot initialize MC for non-Windows COFF object files.");
829
830 Env = IsCOFF;
831 initCOFFMCObjectFileInfo(TT);
832 break;
833 case Triple::ELF:
834 Env = IsELF;
835 initELFMCObjectFileInfo(TT, LargeCodeModel);
836 break;
837 case Triple::Wasm:
838 Env = IsWasm;
839 initWasmMCObjectFileInfo(TT);
840 break;
Jason Liua03ae732019-03-12 22:01:10 +0000841 case Triple::XCOFF:
842 Env = IsXCOFF;
Sean Fertilef09d54e2019-07-09 19:21:01 +0000843 initXCOFFMCObjectFileInfo(TT);
Jason Liua03ae732019-03-12 22:01:10 +0000844 break;
Sean Eveson661e4fb2017-11-30 12:43:25 +0000845 case Triple::UnknownObjectFormat:
846 report_fatal_error("Cannot initialize MC for unknown object file format.");
847 break;
848 }
849}
850
Paul Robinsonddbde9a2018-11-09 19:06:09 +0000851MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
852 uint64_t Hash) const {
Jonas Devlieghere8acb74e2018-08-01 12:53:06 +0000853 switch (TT.getObjectFormat()) {
854 case Triple::ELF:
Paul Robinsonddbde9a2018-11-09 19:06:09 +0000855 return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0,
856 utostr(Hash));
Jonas Devlieghere8acb74e2018-08-01 12:53:06 +0000857 case Triple::MachO:
858 case Triple::COFF:
859 case Triple::Wasm:
Jason Liua03ae732019-03-12 22:01:10 +0000860 case Triple::XCOFF:
Jonas Devlieghere8acb74e2018-08-01 12:53:06 +0000861 case Triple::UnknownObjectFormat:
Paul Robinsonddbde9a2018-11-09 19:06:09 +0000862 report_fatal_error("Cannot get DWARF comdat section for this object file "
Jonas Devlieghere8acb74e2018-08-01 12:53:06 +0000863 "format: not implemented.");
864 break;
865 }
Simon Pilgrim25b15f12018-08-01 13:00:11 +0000866 llvm_unreachable("Unknown ObjectFormatType");
Sean Eveson661e4fb2017-11-30 12:43:25 +0000867}
George Rimardcf59c52018-06-22 10:53:47 +0000868
869MCSection *
870MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const {
871 if (Env != IsELF)
872 return StackSizesSection;
873
874 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
875 unsigned Flags = ELF::SHF_LINK_ORDER;
876 StringRef GroupName;
877 if (const MCSymbol *Group = ElfSec.getGroup()) {
878 GroupName = Group->getName();
879 Flags |= ELF::SHF_GROUP;
880 }
881
882 const MCSymbol *Link = TextSec.getBeginSymbol();
883 auto It = StackSizesUniquing.insert({Link, StackSizesUniquing.size()});
884 unsigned UniqueID = It.first->second;
885
886 return Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, Flags, 0,
887 GroupName, UniqueID, cast<MCSymbolELF>(Link));
888}