Coverage Report

Created: 2017-10-03 07:32

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