Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/MC/MCObjectFileInfo.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- MCObjectFileInfo.cpp - Object File Information --------------------===//
2
//
3
// 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
6
//
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"
21
#include "llvm/MC/MCSectionXCOFF.h"
22
23
using namespace llvm;
24
25
16.9k
static bool useCompactUnwind(const Triple &T) {
26
16.9k
  // Only on darwin.
27
16.9k
  if (!T.isOSDarwin())
28
866
    return false;
29
16.0k
30
16.0k
  // aarch64 always has it.
31
16.0k
  if (T.getArch() == Triple::aarch64)
32
7.67k
    return true;
33
8.38k
34
8.38k
  // armv7k always has it.
35
8.38k
  if (T.isWatchABI())
36
689
    return true;
37
7.69k
38
7.69k
  // Use it on newer version of OS X.
39
7.69k
  if (T.isMacOSX() && 
!T.isMacOSXVersionLT(10, 6)5.55k
)
40
3.16k
    return true;
41
4.52k
42
4.52k
  // And the iOS simulator.
43
4.52k
  if (T.isiOS() &&
44
4.52k
      
(2.13k
T.getArch() == Triple::x86_642.13k
||
T.getArch() == Triple::x861.62k
))
45
869
    return true;
46
3.65k
47
3.65k
  return false;
48
3.65k
}
49
50
16.9k
void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
51
16.9k
  // MachO
52
16.9k
  SupportsWeakOmittedEHFrame = false;
53
16.9k
54
16.9k
  EHFrameSection = Ctx->getMachOSection(
55
16.9k
      "__TEXT", "__eh_frame",
56
16.9k
      MachO::S_COALESCED | MachO::S_ATTR_NO_TOC |
57
16.9k
          MachO::S_ATTR_STRIP_STATIC_SYMS | MachO::S_ATTR_LIVE_SUPPORT,
58
16.9k
      SectionKind::getReadOnly());
59
16.9k
60
16.9k
  if (T.isOSDarwin() && 
T.getArch() == Triple::aarch6416.0k
)
61
7.67k
    SupportsCompactUnwindWithoutEHFrame = true;
62
16.9k
63
16.9k
  if (T.isWatchABI())
64
689
    OmitDwarfIfHaveCompactUnwind = true;
65
16.9k
66
16.9k
  FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
67
16.9k
68
16.9k
  // .comm doesn't support alignment before Leopard.
69
16.9k
  if (T.isMacOSX() && 
T.isMacOSXVersionLT(10, 5)5.74k
)
70
1.70k
    CommDirectiveSupportsAlignment = false;
71
16.9k
72
16.9k
  TextSection // .text
73
16.9k
    = Ctx->getMachOSection("__TEXT", "__text",
74
16.9k
                           MachO::S_ATTR_PURE_INSTRUCTIONS,
75
16.9k
                           SectionKind::getText());
76
16.9k
  DataSection // .data
77
16.9k
      = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
78
16.9k
79
16.9k
  // BSSSection might not be expected initialized on msvc.
80
16.9k
  BSSSection = nullptr;
81
16.9k
82
16.9k
  TLSDataSection // .tdata
83
16.9k
      = Ctx->getMachOSection("__DATA", "__thread_data",
84
16.9k
                             MachO::S_THREAD_LOCAL_REGULAR,
85
16.9k
                             SectionKind::getData());
86
16.9k
  TLSBSSSection // .tbss
87
16.9k
    = Ctx->getMachOSection("__DATA", "__thread_bss",
88
16.9k
                           MachO::S_THREAD_LOCAL_ZEROFILL,
89
16.9k
                           SectionKind::getThreadBSS());
90
16.9k
91
16.9k
  // TODO: Verify datarel below.
92
16.9k
  TLSTLVSection // .tlv
93
16.9k
      = Ctx->getMachOSection("__DATA", "__thread_vars",
94
16.9k
                             MachO::S_THREAD_LOCAL_VARIABLES,
95
16.9k
                             SectionKind::getData());
96
16.9k
97
16.9k
  TLSThreadInitSection = Ctx->getMachOSection(
98
16.9k
      "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
99
16.9k
      SectionKind::getData());
100
16.9k
101
16.9k
  CStringSection // .cstring
102
16.9k
    = Ctx->getMachOSection("__TEXT", "__cstring",
103
16.9k
                           MachO::S_CSTRING_LITERALS,
104
16.9k
                           SectionKind::getMergeable1ByteCString());
105
16.9k
  UStringSection
106
16.9k
    = Ctx->getMachOSection("__TEXT","__ustring", 0,
107
16.9k
                           SectionKind::getMergeable2ByteCString());
108
16.9k
  FourByteConstantSection // .literal4
109
16.9k
    = Ctx->getMachOSection("__TEXT", "__literal4",
110
16.9k
                           MachO::S_4BYTE_LITERALS,
111
16.9k
                           SectionKind::getMergeableConst4());
112
16.9k
  EightByteConstantSection // .literal8
113
16.9k
    = Ctx->getMachOSection("__TEXT", "__literal8",
114
16.9k
                           MachO::S_8BYTE_LITERALS,
115
16.9k
                           SectionKind::getMergeableConst8());
116
16.9k
117
16.9k
  SixteenByteConstantSection // .literal16
118
16.9k
      = Ctx->getMachOSection("__TEXT", "__literal16",
119
16.9k
                             MachO::S_16BYTE_LITERALS,
120
16.9k
                             SectionKind::getMergeableConst16());
121
16.9k
122
16.9k
  ReadOnlySection  // .const
123
16.9k
    = Ctx->getMachOSection("__TEXT", "__const", 0,
124
16.9k
                           SectionKind::getReadOnly());
125
16.9k
126
16.9k
  // If the target is not powerpc, map the coal sections to the non-coal
127
16.9k
  // sections.
128
16.9k
  //
129
16.9k
  // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
130
16.9k
  // "__TEXT/__const_coal"  => section "__TEXT/__const"
131
16.9k
  // "__DATA/__datacoal_nt" => section "__DATA/__data"
132
16.9k
  Triple::ArchType ArchTy = T.getArch();
133
16.9k
134
16.9k
  ConstDataSection  // .const_data
135
16.9k
    = Ctx->getMachOSection("__DATA", "__const", 0,
136
16.9k
                           SectionKind::getReadOnlyWithRel());
137
16.9k
138
16.9k
  if (ArchTy == Triple::ppc || 
ArchTy == Triple::ppc6416.9k
) {
139
4
    TextCoalSection
140
4
      = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
141
4
                             MachO::S_COALESCED |
142
4
                             MachO::S_ATTR_PURE_INSTRUCTIONS,
143
4
                             SectionKind::getText());
144
4
    ConstTextCoalSection
145
4
      = Ctx->getMachOSection("__TEXT", "__const_coal",
146
4
                             MachO::S_COALESCED,
147
4
                             SectionKind::getReadOnly());
148
4
    DataCoalSection = Ctx->getMachOSection(
149
4
        "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());
150
4
    ConstDataCoalSection = DataCoalSection;
151
16.9k
  } else {
152
16.9k
    TextCoalSection = TextSection;
153
16.9k
    ConstTextCoalSection = ReadOnlySection;
154
16.9k
    DataCoalSection = DataSection;
155
16.9k
    ConstDataCoalSection = ConstDataSection;
156
16.9k
  }
157
16.9k
158
16.9k
  DataCommonSection
159
16.9k
    = Ctx->getMachOSection("__DATA","__common",
160
16.9k
                           MachO::S_ZEROFILL,
161
16.9k
                           SectionKind::getBSS());
162
16.9k
  DataBSSSection
163
16.9k
    = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
164
16.9k
                           SectionKind::getBSS());
165
16.9k
166
16.9k
167
16.9k
  LazySymbolPointerSection
168
16.9k
    = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
169
16.9k
                           MachO::S_LAZY_SYMBOL_POINTERS,
170
16.9k
                           SectionKind::getMetadata());
171
16.9k
  NonLazySymbolPointerSection
172
16.9k
    = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
173
16.9k
                           MachO::S_NON_LAZY_SYMBOL_POINTERS,
174
16.9k
                           SectionKind::getMetadata());
175
16.9k
176
16.9k
  ThreadLocalPointerSection
177
16.9k
    = Ctx->getMachOSection("__DATA", "__thread_ptr",
178
16.9k
                           MachO::S_THREAD_LOCAL_VARIABLE_POINTERS,
179
16.9k
                           SectionKind::getMetadata());
180
16.9k
181
16.9k
  // Exception Handling.
182
16.9k
  LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
183
16.9k
                                     SectionKind::getReadOnlyWithRel());
184
16.9k
185
16.9k
  COFFDebugSymbolsSection = nullptr;
186
16.9k
  COFFDebugTypesSection = nullptr;
187
16.9k
  COFFGlobalTypeHashesSection = nullptr;
188
16.9k
189
16.9k
  if (useCompactUnwind(T)) {
190
12.4k
    CompactUnwindSection =
191
12.4k
        Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
192
12.4k
                             SectionKind::getReadOnly());
193
12.4k
194
12.4k
    if (T.getArch() == Triple::x86_64 || 
T.getArch() == Triple::x869.69k
)
195
3.52k
      CompactUnwindDwarfEHFrameOnly = 0x04000000;  // UNWIND_X86_64_MODE_DWARF
196
8.88k
    else if (T.getArch() == Triple::aarch64)
197
7.67k
      CompactUnwindDwarfEHFrameOnly = 0x03000000;  // UNWIND_ARM64_MODE_DWARF
198
1.20k
    else if (T.getArch() == Triple::arm || 
T.getArch() == Triple::thumb872
)
199
1.20k
      CompactUnwindDwarfEHFrameOnly = 0x04000000;  // UNWIND_ARM_MODE_DWARF
200
12.4k
  }
201
16.9k
202
16.9k
  // Debug Information.
203
16.9k
  DwarfDebugNamesSection =
204
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG,
205
16.9k
                           SectionKind::getMetadata(), "debug_names_begin");
206
16.9k
  DwarfAccelNamesSection =
207
16.9k
      Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
208
16.9k
                           SectionKind::getMetadata(), "names_begin");
209
16.9k
  DwarfAccelObjCSection =
210
16.9k
      Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
211
16.9k
                           SectionKind::getMetadata(), "objc_begin");
212
16.9k
  // 16 character section limit...
213
16.9k
  DwarfAccelNamespaceSection =
214
16.9k
      Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
215
16.9k
                           SectionKind::getMetadata(), "namespac_begin");
216
16.9k
  DwarfAccelTypesSection =
217
16.9k
      Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
218
16.9k
                           SectionKind::getMetadata(), "types_begin");
219
16.9k
220
16.9k
  DwarfSwiftASTSection =
221
16.9k
      Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG,
222
16.9k
                           SectionKind::getMetadata());
223
16.9k
224
16.9k
  DwarfAbbrevSection =
225
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
226
16.9k
                           SectionKind::getMetadata(), "section_abbrev");
227
16.9k
  DwarfInfoSection =
228
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
229
16.9k
                           SectionKind::getMetadata(), "section_info");
230
16.9k
  DwarfLineSection =
231
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
232
16.9k
                           SectionKind::getMetadata(), "section_line");
233
16.9k
  DwarfLineStrSection =
234
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,
235
16.9k
                           SectionKind::getMetadata(), "section_line_str");
236
16.9k
  DwarfFrameSection =
237
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
238
16.9k
                           SectionKind::getMetadata());
239
16.9k
  DwarfPubNamesSection =
240
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
241
16.9k
                           SectionKind::getMetadata());
242
16.9k
  DwarfPubTypesSection =
243
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
244
16.9k
                           SectionKind::getMetadata());
245
16.9k
  DwarfGnuPubNamesSection =
246
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
247
16.9k
                           SectionKind::getMetadata());
248
16.9k
  DwarfGnuPubTypesSection =
249
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
250
16.9k
                           SectionKind::getMetadata());
251
16.9k
  DwarfStrSection =
252
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
253
16.9k
                           SectionKind::getMetadata(), "info_string");
254
16.9k
  DwarfStrOffSection =
255
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG,
256
16.9k
                           SectionKind::getMetadata(), "section_str_off");
257
16.9k
  DwarfAddrSection =
258
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_addr", MachO::S_ATTR_DEBUG,
259
16.9k
                           SectionKind::getMetadata(), "section_info");
260
16.9k
  DwarfLocSection =
261
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
262
16.9k
                           SectionKind::getMetadata(), "section_debug_loc");
263
16.9k
  DwarfLoclistsSection =
264
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_loclists", MachO::S_ATTR_DEBUG,
265
16.9k
                           SectionKind::getMetadata(), "section_debug_loc");
266
16.9k
267
16.9k
  DwarfARangesSection =
268
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
269
16.9k
                           SectionKind::getMetadata());
270
16.9k
  DwarfRangesSection =
271
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
272
16.9k
                           SectionKind::getMetadata(), "debug_range");
273
16.9k
  DwarfRnglistsSection =
274
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_rnglists", MachO::S_ATTR_DEBUG,
275
16.9k
                           SectionKind::getMetadata(), "debug_range");
276
16.9k
  DwarfMacinfoSection =
277
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG,
278
16.9k
                           SectionKind::getMetadata(), "debug_macinfo");
279
16.9k
  DwarfDebugInlineSection =
280
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
281
16.9k
                           SectionKind::getMetadata());
282
16.9k
  DwarfCUIndexSection =
283
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,
284
16.9k
                           SectionKind::getMetadata());
285
16.9k
  DwarfTUIndexSection =
286
16.9k
      Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG,
287
16.9k
                           SectionKind::getMetadata());
288
16.9k
  StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
289
16.9k
                                         0, SectionKind::getMetadata());
290
16.9k
291
16.9k
  FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
292
16.9k
                                         0, SectionKind::getMetadata());
293
16.9k
294
16.9k
  RemarksSection = Ctx->getMachOSection(
295
16.9k
      "__LLVM", "__remarks", MachO::S_ATTR_DEBUG, SectionKind::getMetadata());
296
16.9k
297
16.9k
  TLSExtraDataSection = TLSTLVSection;
298
16.9k
}
299
300
31.9k
void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
301
31.9k
  switch (T.getArch()) {
302
31.9k
  case Triple::mips:
303
3.32k
  case Triple::mipsel:
304
3.32k
  case Triple::mips64:
305
3.32k
  case Triple::mips64el:
306
3.32k
    FDECFIEncoding = Ctx->getAsmInfo()->getCodePointerSize() == 4
307
3.32k
                         ? 
dwarf::DW_EH_PE_sdata42.31k
308
3.32k
                         : 
dwarf::DW_EH_PE_sdata81.01k
;
309
3.32k
    break;
310
9.60k
  case Triple::ppc64:
311
9.60k
  case Triple::ppc64le:
312
9.60k
  case Triple::x86_64:
313
9.60k
    FDECFIEncoding = dwarf::DW_EH_PE_pcrel |
314
9.60k
                     (Large ? 
dwarf::DW_EH_PE_sdata840
:
dwarf::DW_EH_PE_sdata49.56k
);
315
9.60k
    break;
316
9.60k
  case Triple::bpfel:
317
225
  case Triple::bpfeb:
318
225
    FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
319
225
    break;
320
1.15k
  case Triple::hexagon:
321
1.15k
    FDECFIEncoding =
322
1.15k
        PositionIndependent ? 
dwarf::DW_EH_PE_pcrel18
:
dwarf::DW_EH_PE_absptr1.13k
;
323
1.15k
    break;
324
17.6k
  default:
325
17.6k
    FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
326
17.6k
    break;
327
31.9k
  }
328
31.9k
329
31.9k
  unsigned EHSectionType = T.getArch() == Triple::x86_64
330
31.9k
                               ? 
ELF::SHT_X86_64_UNWIND7.89k
331
31.9k
                               : 
ELF::SHT_PROGBITS24.0k
;
332
31.9k
333
31.9k
  // Solaris requires different flags for .eh_frame to seemingly every other
334
31.9k
  // platform.
335
31.9k
  unsigned EHSectionFlags = ELF::SHF_ALLOC;
336
31.9k
  if (T.isOSSolaris() && 
T.getArch() != Triple::x86_6411
)
337
7
    EHSectionFlags |= ELF::SHF_WRITE;
338
31.9k
339
31.9k
  // ELF
340
31.9k
  BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
341
31.9k
                                  ELF::SHF_WRITE | ELF::SHF_ALLOC);
342
31.9k
343
31.9k
  TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
344
31.9k
                                   ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
345
31.9k
346
31.9k
  DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
347
31.9k
                                   ELF::SHF_WRITE | ELF::SHF_ALLOC);
348
31.9k
349
31.9k
  ReadOnlySection =
350
31.9k
      Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
351
31.9k
352
31.9k
  TLSDataSection =
353
31.9k
      Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
354
31.9k
                         ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
355
31.9k
356
31.9k
  TLSBSSSection = Ctx->getELFSection(
357
31.9k
      ".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
358
31.9k
359
31.9k
  DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
360
31.9k
                                        ELF::SHF_ALLOC | ELF::SHF_WRITE);
361
31.9k
362
31.9k
  MergeableConst4Section =
363
31.9k
      Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
364
31.9k
                         ELF::SHF_ALLOC | ELF::SHF_MERGE, 4, "");
365
31.9k
366
31.9k
  MergeableConst8Section =
367
31.9k
      Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
368
31.9k
                         ELF::SHF_ALLOC | ELF::SHF_MERGE, 8, "");
369
31.9k
370
31.9k
  MergeableConst16Section =
371
31.9k
      Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
372
31.9k
                         ELF::SHF_ALLOC | ELF::SHF_MERGE, 16, "");
373
31.9k
374
31.9k
  MergeableConst32Section =
375
31.9k
      Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS,
376
31.9k
                         ELF::SHF_ALLOC | ELF::SHF_MERGE, 32, "");
377
31.9k
378
31.9k
  // Exception Handling Sections.
379
31.9k
380
31.9k
  // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
381
31.9k
  // it contains relocatable pointers.  In PIC mode, this is probably a big
382
31.9k
  // runtime hit for C++ apps.  Either the contents of the LSDA need to be
383
31.9k
  // adjusted or this should be a data section.
384
31.9k
  LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
385
31.9k
                                   ELF::SHF_ALLOC);
386
31.9k
387
31.9k
  COFFDebugSymbolsSection = nullptr;
388
31.9k
  COFFDebugTypesSection = nullptr;
389
31.9k
390
31.9k
  unsigned DebugSecType = ELF::SHT_PROGBITS;
391
31.9k
392
31.9k
  // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
393
31.9k
  // to distinguish among sections contain DWARF and ECOFF debug formats.
394
31.9k
  // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
395
31.9k
  if (T.isMIPS())
396
3.32k
    DebugSecType = ELF::SHT_MIPS_DWARF;
397
31.9k
398
31.9k
  // Debug Info Sections.
399
31.9k
  DwarfAbbrevSection =
400
31.9k
      Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);
401
31.9k
  DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0);
402
31.9k
  DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0);
403
31.9k
  DwarfLineStrSection =
404
31.9k
      Ctx->getELFSection(".debug_line_str", DebugSecType,
405
31.9k
                         ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
406
31.9k
  DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0);
407
31.9k
  DwarfPubNamesSection =
408
31.9k
      Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);
409
31.9k
  DwarfPubTypesSection =
410
31.9k
      Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);
411
31.9k
  DwarfGnuPubNamesSection =
412
31.9k
      Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);
413
31.9k
  DwarfGnuPubTypesSection =
414
31.9k
      Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);
415
31.9k
  DwarfStrSection =
416
31.9k
      Ctx->getELFSection(".debug_str", DebugSecType,
417
31.9k
                         ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
418
31.9k
  DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0);
419
31.9k
  DwarfARangesSection =
420
31.9k
      Ctx->getELFSection(".debug_aranges", DebugSecType, 0);
421
31.9k
  DwarfRangesSection =
422
31.9k
      Ctx->getELFSection(".debug_ranges", DebugSecType, 0);
423
31.9k
  DwarfMacinfoSection =
424
31.9k
      Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);
425
31.9k
426
31.9k
  // DWARF5 Experimental Debug Info
427
31.9k
428
31.9k
  // Accelerator Tables
429
31.9k
  DwarfDebugNamesSection =
430
31.9k
      Ctx->getELFSection(".debug_names", ELF::SHT_PROGBITS, 0);
431
31.9k
  DwarfAccelNamesSection =
432
31.9k
      Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);
433
31.9k
  DwarfAccelObjCSection =
434
31.9k
      Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);
435
31.9k
  DwarfAccelNamespaceSection =
436
31.9k
      Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);
437
31.9k
  DwarfAccelTypesSection =
438
31.9k
      Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);
439
31.9k
440
31.9k
  // String Offset and Address Sections
441
31.9k
  DwarfStrOffSection =
442
31.9k
      Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);
443
31.9k
  DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);
444
31.9k
  DwarfRnglistsSection = Ctx->getELFSection(".debug_rnglists", DebugSecType, 0);
445
31.9k
  DwarfLoclistsSection = Ctx->getELFSection(".debug_loclists", DebugSecType, 0);
446
31.9k
447
31.9k
  // Fission Sections
448
31.9k
  DwarfInfoDWOSection =
449
31.9k
      Ctx->getELFSection(".debug_info.dwo", DebugSecType, ELF::SHF_EXCLUDE);
450
31.9k
  DwarfTypesDWOSection =
451
31.9k
      Ctx->getELFSection(".debug_types.dwo", DebugSecType, ELF::SHF_EXCLUDE);
452
31.9k
  DwarfAbbrevDWOSection =
453
31.9k
      Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, ELF::SHF_EXCLUDE);
454
31.9k
  DwarfStrDWOSection = Ctx->getELFSection(
455
31.9k
      ".debug_str.dwo", DebugSecType,
456
31.9k
      ELF::SHF_MERGE | ELF::SHF_STRINGS | ELF::SHF_EXCLUDE, 1, "");
457
31.9k
  DwarfLineDWOSection =
458
31.9k
      Ctx->getELFSection(".debug_line.dwo", DebugSecType, ELF::SHF_EXCLUDE);
459
31.9k
  DwarfLocDWOSection =
460
31.9k
      Ctx->getELFSection(".debug_loc.dwo", DebugSecType, ELF::SHF_EXCLUDE);
461
31.9k
  DwarfStrOffDWOSection = Ctx->getELFSection(".debug_str_offsets.dwo",
462
31.9k
                                             DebugSecType, ELF::SHF_EXCLUDE);
463
31.9k
  DwarfRnglistsDWOSection =
464
31.9k
      Ctx->getELFSection(".debug_rnglists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
465
31.9k
466
31.9k
  // DWP Sections
467
31.9k
  DwarfCUIndexSection =
468
31.9k
      Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);
469
31.9k
  DwarfTUIndexSection =
470
31.9k
      Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);
471
31.9k
472
31.9k
  StackMapSection =
473
31.9k
      Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
474
31.9k
475
31.9k
  FaultMapSection =
476
31.9k
      Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
477
31.9k
478
31.9k
  EHFrameSection =
479
31.9k
      Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
480
31.9k
481
31.9k
  StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);
482
31.9k
483
31.9k
  RemarksSection =
484
31.9k
      Ctx->getELFSection(".remarks", ELF::SHT_PROGBITS, ELF::SHF_EXCLUDE);
485
31.9k
}
486
487
1.30k
void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
488
1.30k
  EHFrameSection =
489
1.30k
      Ctx->getCOFFSection(".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
490
1.30k
                                           COFF::IMAGE_SCN_MEM_READ,
491
1.30k
                          SectionKind::getData());
492
1.30k
493
1.30k
  // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode.  This is
494
1.30k
  // used to indicate to the linker that the text segment contains thumb instructions
495
1.30k
  // and to set the ISA selection bit for calls accordingly.
496
1.30k
  const bool IsThumb = T.getArch() == Triple::thumb;
497
1.30k
498
1.30k
  CommDirectiveSupportsAlignment = true;
499
1.30k
500
1.30k
  // COFF
501
1.30k
  BSSSection = Ctx->getCOFFSection(
502
1.30k
      ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
503
1.30k
                  COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
504
1.30k
      SectionKind::getBSS());
505
1.30k
  TextSection = Ctx->getCOFFSection(
506
1.30k
      ".text",
507
1.30k
      (IsThumb ? 
COFF::IMAGE_SCN_MEM_16BIT92
:
(COFF::SectionCharacteristics)01.21k
) |
508
1.30k
          COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
509
1.30k
          COFF::IMAGE_SCN_MEM_READ,
510
1.30k
      SectionKind::getText());
511
1.30k
  DataSection = Ctx->getCOFFSection(
512
1.30k
      ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
513
1.30k
                   COFF::IMAGE_SCN_MEM_WRITE,
514
1.30k
      SectionKind::getData());
515
1.30k
  ReadOnlySection = Ctx->getCOFFSection(
516
1.30k
      ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
517
1.30k
      SectionKind::getReadOnly());
518
1.30k
519
1.30k
  if (T.getArch() == Triple::x86_64 || 
T.getArch() == Triple::aarch64624
) {
520
769
    // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
521
769
    LSDASection = nullptr;
522
769
  } else {
523
533
    LSDASection = Ctx->getCOFFSection(".gcc_except_table",
524
533
                                      COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
525
533
                                          COFF::IMAGE_SCN_MEM_READ,
526
533
                                      SectionKind::getReadOnly());
527
533
  }
528
1.30k
529
1.30k
  // Debug info.
530
1.30k
  COFFDebugSymbolsSection =
531
1.30k
      Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
532
1.30k
                                       COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
533
1.30k
                                       COFF::IMAGE_SCN_MEM_READ),
534
1.30k
                          SectionKind::getMetadata());
535
1.30k
  COFFDebugTypesSection =
536
1.30k
      Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
537
1.30k
                                       COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
538
1.30k
                                       COFF::IMAGE_SCN_MEM_READ),
539
1.30k
                          SectionKind::getMetadata());
540
1.30k
  COFFGlobalTypeHashesSection = Ctx->getCOFFSection(
541
1.30k
      ".debug$H",
542
1.30k
      (COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
543
1.30k
       COFF::IMAGE_SCN_MEM_READ),
544
1.30k
      SectionKind::getMetadata());
545
1.30k
546
1.30k
  DwarfAbbrevSection = Ctx->getCOFFSection(
547
1.30k
      ".debug_abbrev",
548
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
549
1.30k
          COFF::IMAGE_SCN_MEM_READ,
550
1.30k
      SectionKind::getMetadata(), "section_abbrev");
551
1.30k
  DwarfInfoSection = Ctx->getCOFFSection(
552
1.30k
      ".debug_info",
553
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
554
1.30k
          COFF::IMAGE_SCN_MEM_READ,
555
1.30k
      SectionKind::getMetadata(), "section_info");
556
1.30k
  DwarfLineSection = Ctx->getCOFFSection(
557
1.30k
      ".debug_line",
558
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
559
1.30k
          COFF::IMAGE_SCN_MEM_READ,
560
1.30k
      SectionKind::getMetadata(), "section_line");
561
1.30k
  DwarfLineStrSection = Ctx->getCOFFSection(
562
1.30k
      ".debug_line_str",
563
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
564
1.30k
          COFF::IMAGE_SCN_MEM_READ,
565
1.30k
      SectionKind::getMetadata(), "section_line_str");
566
1.30k
  DwarfFrameSection = Ctx->getCOFFSection(
567
1.30k
      ".debug_frame",
568
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
569
1.30k
          COFF::IMAGE_SCN_MEM_READ,
570
1.30k
      SectionKind::getMetadata());
571
1.30k
  DwarfPubNamesSection = Ctx->getCOFFSection(
572
1.30k
      ".debug_pubnames",
573
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
574
1.30k
          COFF::IMAGE_SCN_MEM_READ,
575
1.30k
      SectionKind::getMetadata());
576
1.30k
  DwarfPubTypesSection = Ctx->getCOFFSection(
577
1.30k
      ".debug_pubtypes",
578
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
579
1.30k
          COFF::IMAGE_SCN_MEM_READ,
580
1.30k
      SectionKind::getMetadata());
581
1.30k
  DwarfGnuPubNamesSection = Ctx->getCOFFSection(
582
1.30k
      ".debug_gnu_pubnames",
583
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
584
1.30k
          COFF::IMAGE_SCN_MEM_READ,
585
1.30k
      SectionKind::getMetadata());
586
1.30k
  DwarfGnuPubTypesSection = Ctx->getCOFFSection(
587
1.30k
      ".debug_gnu_pubtypes",
588
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
589
1.30k
          COFF::IMAGE_SCN_MEM_READ,
590
1.30k
      SectionKind::getMetadata());
591
1.30k
  DwarfStrSection = Ctx->getCOFFSection(
592
1.30k
      ".debug_str",
593
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
594
1.30k
          COFF::IMAGE_SCN_MEM_READ,
595
1.30k
      SectionKind::getMetadata(), "info_string");
596
1.30k
  DwarfStrOffSection = Ctx->getCOFFSection(
597
1.30k
      ".debug_str_offsets",
598
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
599
1.30k
          COFF::IMAGE_SCN_MEM_READ,
600
1.30k
      SectionKind::getMetadata(), "section_str_off");
601
1.30k
  DwarfLocSection = Ctx->getCOFFSection(
602
1.30k
      ".debug_loc",
603
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
604
1.30k
          COFF::IMAGE_SCN_MEM_READ,
605
1.30k
      SectionKind::getMetadata(), "section_debug_loc");
606
1.30k
  DwarfARangesSection = Ctx->getCOFFSection(
607
1.30k
      ".debug_aranges",
608
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
609
1.30k
          COFF::IMAGE_SCN_MEM_READ,
610
1.30k
      SectionKind::getMetadata());
611
1.30k
  DwarfRangesSection = Ctx->getCOFFSection(
612
1.30k
      ".debug_ranges",
613
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
614
1.30k
          COFF::IMAGE_SCN_MEM_READ,
615
1.30k
      SectionKind::getMetadata(), "debug_range");
616
1.30k
  DwarfMacinfoSection = Ctx->getCOFFSection(
617
1.30k
      ".debug_macinfo",
618
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
619
1.30k
          COFF::IMAGE_SCN_MEM_READ,
620
1.30k
      SectionKind::getMetadata(), "debug_macinfo");
621
1.30k
  DwarfInfoDWOSection = Ctx->getCOFFSection(
622
1.30k
      ".debug_info.dwo",
623
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
624
1.30k
          COFF::IMAGE_SCN_MEM_READ,
625
1.30k
      SectionKind::getMetadata(), "section_info_dwo");
626
1.30k
  DwarfTypesDWOSection = Ctx->getCOFFSection(
627
1.30k
      ".debug_types.dwo",
628
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
629
1.30k
          COFF::IMAGE_SCN_MEM_READ,
630
1.30k
      SectionKind::getMetadata(), "section_types_dwo");
631
1.30k
  DwarfAbbrevDWOSection = Ctx->getCOFFSection(
632
1.30k
      ".debug_abbrev.dwo",
633
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
634
1.30k
          COFF::IMAGE_SCN_MEM_READ,
635
1.30k
      SectionKind::getMetadata(), "section_abbrev_dwo");
636
1.30k
  DwarfStrDWOSection = Ctx->getCOFFSection(
637
1.30k
      ".debug_str.dwo",
638
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
639
1.30k
          COFF::IMAGE_SCN_MEM_READ,
640
1.30k
      SectionKind::getMetadata(), "skel_string");
641
1.30k
  DwarfLineDWOSection = Ctx->getCOFFSection(
642
1.30k
      ".debug_line.dwo",
643
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
644
1.30k
          COFF::IMAGE_SCN_MEM_READ,
645
1.30k
      SectionKind::getMetadata());
646
1.30k
  DwarfLocDWOSection = Ctx->getCOFFSection(
647
1.30k
      ".debug_loc.dwo",
648
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
649
1.30k
          COFF::IMAGE_SCN_MEM_READ,
650
1.30k
      SectionKind::getMetadata(), "skel_loc");
651
1.30k
  DwarfStrOffDWOSection = Ctx->getCOFFSection(
652
1.30k
      ".debug_str_offsets.dwo",
653
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
654
1.30k
          COFF::IMAGE_SCN_MEM_READ,
655
1.30k
      SectionKind::getMetadata(), "section_str_off_dwo");
656
1.30k
  DwarfAddrSection = Ctx->getCOFFSection(
657
1.30k
      ".debug_addr",
658
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
659
1.30k
          COFF::IMAGE_SCN_MEM_READ,
660
1.30k
      SectionKind::getMetadata(), "addr_sec");
661
1.30k
  DwarfCUIndexSection = Ctx->getCOFFSection(
662
1.30k
      ".debug_cu_index",
663
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
664
1.30k
          COFF::IMAGE_SCN_MEM_READ,
665
1.30k
      SectionKind::getMetadata());
666
1.30k
  DwarfTUIndexSection = Ctx->getCOFFSection(
667
1.30k
      ".debug_tu_index",
668
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
669
1.30k
          COFF::IMAGE_SCN_MEM_READ,
670
1.30k
      SectionKind::getMetadata());
671
1.30k
  DwarfDebugNamesSection = Ctx->getCOFFSection(
672
1.30k
      ".debug_names",
673
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
674
1.30k
          COFF::IMAGE_SCN_MEM_READ,
675
1.30k
      SectionKind::getMetadata(), "debug_names_begin");
676
1.30k
  DwarfAccelNamesSection = Ctx->getCOFFSection(
677
1.30k
      ".apple_names",
678
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
679
1.30k
          COFF::IMAGE_SCN_MEM_READ,
680
1.30k
      SectionKind::getMetadata(), "names_begin");
681
1.30k
  DwarfAccelNamespaceSection = Ctx->getCOFFSection(
682
1.30k
      ".apple_namespaces",
683
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
684
1.30k
          COFF::IMAGE_SCN_MEM_READ,
685
1.30k
      SectionKind::getMetadata(), "namespac_begin");
686
1.30k
  DwarfAccelTypesSection = Ctx->getCOFFSection(
687
1.30k
      ".apple_types",
688
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
689
1.30k
          COFF::IMAGE_SCN_MEM_READ,
690
1.30k
      SectionKind::getMetadata(), "types_begin");
691
1.30k
  DwarfAccelObjCSection = Ctx->getCOFFSection(
692
1.30k
      ".apple_objc",
693
1.30k
      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
694
1.30k
          COFF::IMAGE_SCN_MEM_READ,
695
1.30k
      SectionKind::getMetadata(), "objc_begin");
696
1.30k
697
1.30k
  DrectveSection = Ctx->getCOFFSection(
698
1.30k
      ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
699
1.30k
      SectionKind::getMetadata());
700
1.30k
701
1.30k
  PDataSection = Ctx->getCOFFSection(
702
1.30k
      ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
703
1.30k
      SectionKind::getData());
704
1.30k
705
1.30k
  XDataSection = Ctx->getCOFFSection(
706
1.30k
      ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
707
1.30k
      SectionKind::getData());
708
1.30k
709
1.30k
  SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO,
710
1.30k
                                      SectionKind::getMetadata());
711
1.30k
712
1.30k
  GFIDsSection = Ctx->getCOFFSection(".gfids$y",
713
1.30k
                                     COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
714
1.30k
                                         COFF::IMAGE_SCN_MEM_READ,
715
1.30k
                                     SectionKind::getMetadata());
716
1.30k
717
1.30k
  TLSDataSection = Ctx->getCOFFSection(
718
1.30k
      ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
719
1.30k
                   COFF::IMAGE_SCN_MEM_WRITE,
720
1.30k
      SectionKind::getData());
721
1.30k
722
1.30k
  StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
723
1.30k
                                        COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
724
1.30k
                                            COFF::IMAGE_SCN_MEM_READ,
725
1.30k
                                        SectionKind::getReadOnly());
726
1.30k
}
727
728
446
void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
729
446
  TextSection = Ctx->getWasmSection(".text", SectionKind::getText());
730
446
  DataSection = Ctx->getWasmSection(".data", SectionKind::getData());
731
446
732
446
  DwarfLineSection =
733
446
      Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());
734
446
  DwarfLineStrSection =
735
446
      Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata());
736
446
  DwarfStrSection =
737
446
      Ctx->getWasmSection(".debug_str", SectionKind::getMetadata());
738
446
  DwarfLocSection =
739
446
      Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());
740
446
  DwarfAbbrevSection =
741
446
      Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata());
742
446
  DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());
743
446
  DwarfRangesSection =
744
446
      Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata());
745
446
  DwarfMacinfoSection =
746
446
      Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata());
747
446
  DwarfAddrSection = Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata());
748
446
  DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
749
446
  DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
750
446
  DwarfInfoSection =
751
446
      Ctx->getWasmSection(".debug_info", SectionKind::getMetadata());
752
446
  DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());
753
446
  DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
754
446
  DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
755
446
756
446
  // Wasm use data section for LSDA.
757
446
  // TODO Consider putting each function's exception table in a separate
758
446
  // section, as in -function-sections, to facilitate lld's --gc-section.
759
446
  LSDASection = Ctx->getWasmSection(".rodata.gcc_except_table",
760
446
                                    SectionKind::getReadOnlyWithRel());
761
446
762
446
  // TODO: Define more sections.
763
446
}
764
765
9
void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) {
766
9
  // The default csect for program code. Functions without a specified section
767
9
  // get placed into this csect. The choice of csect name is not a property of
768
9
  // the ABI or object file format. For example, the XL compiler uses an unnamed
769
9
  // csect for program code.
770
9
  TextSection =
771
9
      Ctx->getXCOFFSection(".text", XCOFF::StorageMappingClass::XMC_PR,
772
9
                           XCOFF::XTY_SD, SectionKind::getText());
773
9
}
774
775
void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
776
                                            MCContext &ctx,
777
50.6k
                                            bool LargeCodeModel) {
778
50.6k
  PositionIndependent = PIC;
779
50.6k
  Ctx = &ctx;
780
50.6k
781
50.6k
  // Common.
782
50.6k
  CommDirectiveSupportsAlignment = true;
783
50.6k
  SupportsWeakOmittedEHFrame = true;
784
50.6k
  SupportsCompactUnwindWithoutEHFrame = false;
785
50.6k
  OmitDwarfIfHaveCompactUnwind = false;
786
50.6k
787
50.6k
  FDECFIEncoding = dwarf::DW_EH_PE_absptr;
788
50.6k
789
50.6k
  CompactUnwindDwarfEHFrameOnly = 0;
790
50.6k
791
50.6k
  EHFrameSection = nullptr;             // Created on demand.
792
50.6k
  CompactUnwindSection = nullptr;       // Used only by selected targets.
793
50.6k
  DwarfAccelNamesSection = nullptr;     // Used only by selected targets.
794
50.6k
  DwarfAccelObjCSection = nullptr;      // Used only by selected targets.
795
50.6k
  DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
796
50.6k
  DwarfAccelTypesSection = nullptr;     // Used only by selected targets.
797
50.6k
798
50.6k
  TT = TheTriple;
799
50.6k
800
50.6k
  switch (TT.getObjectFormat()) {
801
50.6k
  case Triple::MachO:
802
16.9k
    Env = IsMachO;
803
16.9k
    initMachOMCObjectFileInfo(TT);
804
16.9k
    break;
805
50.6k
  case Triple::COFF:
806
1.30k
    if (!TT.isOSWindows())
807
0
      report_fatal_error(
808
0
          "Cannot initialize MC for non-Windows COFF object files.");
809
1.30k
810
1.30k
    Env = IsCOFF;
811
1.30k
    initCOFFMCObjectFileInfo(TT);
812
1.30k
    break;
813
31.9k
  case Triple::ELF:
814
31.9k
    Env = IsELF;
815
31.9k
    initELFMCObjectFileInfo(TT, LargeCodeModel);
816
31.9k
    break;
817
1.30k
  case Triple::Wasm:
818
446
    Env = IsWasm;
819
446
    initWasmMCObjectFileInfo(TT);
820
446
    break;
821
1.30k
  case Triple::XCOFF:
822
9
    Env = IsXCOFF;
823
9
    initXCOFFMCObjectFileInfo(TT);
824
9
    break;
825
1.30k
  case Triple::UnknownObjectFormat:
826
0
    report_fatal_error("Cannot initialize MC for unknown object file format.");
827
1.30k
    
break0
;
828
50.6k
  }
829
50.6k
}
830
831
MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
832
23
                                                   uint64_t Hash) const {
833
23
  switch (TT.getObjectFormat()) {
834
23
  case Triple::ELF:
835
23
    return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0,
836
23
                              utostr(Hash));
837
23
  case Triple::MachO:
838
0
  case Triple::COFF:
839
0
  case Triple::Wasm:
840
0
  case Triple::XCOFF:
841
0
  case Triple::UnknownObjectFormat:
842
0
    report_fatal_error("Cannot get DWARF comdat section for this object file "
843
0
                       "format: not implemented.");
844
0
    break;
845
0
  }
846
0
  llvm_unreachable("Unknown ObjectFormatType");
847
0
}
848
849
MCSection *
850
20
MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const {
851
20
  if (Env != IsELF)
852
0
    return StackSizesSection;
853
20
854
20
  const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
855
20
  unsigned Flags = ELF::SHF_LINK_ORDER;
856
20
  StringRef GroupName;
857
20
  if (const MCSymbol *Group = ElfSec.getGroup()) {
858
2
    GroupName = Group->getName();
859
2
    Flags |= ELF::SHF_GROUP;
860
2
  }
861
20
862
20
  const MCSymbol *Link = TextSec.getBeginSymbol();
863
20
  auto It = StackSizesUniquing.insert({Link, StackSizesUniquing.size()});
864
20
  unsigned UniqueID = It.first->second;
865
20
866
20
  return Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, Flags, 0,
867
20
                            GroupName, UniqueID, cast<MCSymbolELF>(Link));
868
20
}