blob: 0c1ade48fecc929f1be129eecdf9e852b79bdc82 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===-- llvm/MC/MCObjectFileInfo.h - Object File Info -----------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8//
9// This file describes common object file formats.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_MC_MCOBJECTFILEINFO_H
14#define LLVM_MC_MCOBJECTFILEINFO_H
15
Andrew Scullcdfcccc2018-10-05 20:58:37 +010016#include "llvm/ADT/DenseMap.h"
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010017#include "llvm/ADT/Triple.h"
Andrew Scullcdfcccc2018-10-05 20:58:37 +010018#include "llvm/MC/MCSymbol.h"
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010019#include "llvm/Support/CodeGen.h"
Andrew Walbran16937d02019-10-22 13:54:20 +010020#include "llvm/Support/VersionTuple.h"
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010021
22namespace llvm {
23class MCContext;
24class MCSection;
25
26class MCObjectFileInfo {
27protected:
28 /// True if .comm supports alignment. This is a hack for as long as we
29 /// support 10.4 Tiger, whose assembler doesn't support alignment on comm.
30 bool CommDirectiveSupportsAlignment;
31
32 /// True if target object file supports a weak_definition of constant 0 for an
33 /// omitted EH frame.
34 bool SupportsWeakOmittedEHFrame;
35
36 /// True if the target object file supports emitting a compact unwind section
37 /// without an associated EH frame section.
38 bool SupportsCompactUnwindWithoutEHFrame;
39
40 /// OmitDwarfIfHaveCompactUnwind - True if the target object file
41 /// supports having some functions with compact unwind and other with
42 /// dwarf unwind.
43 bool OmitDwarfIfHaveCompactUnwind;
44
Andrew Scullcdfcccc2018-10-05 20:58:37 +010045 /// FDE CFI encoding. Controls the encoding of the begin label in the
46 /// .eh_frame section. Unlike the LSDA encoding, personality encoding, and
47 /// type encodings, this is something that the assembler just "knows" about
48 /// its target
49 unsigned FDECFIEncoding = 0;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010050
51 /// Compact unwind encoding indicating that we should emit only an EH frame.
52 unsigned CompactUnwindDwarfEHFrameOnly;
53
54 /// Section directive for standard text.
55 MCSection *TextSection;
56
57 /// Section directive for standard data.
58 MCSection *DataSection;
59
60 /// Section that is default initialized to zero.
61 MCSection *BSSSection;
62
63 /// Section that is readonly and can contain arbitrary initialized data.
64 /// Targets are not required to have a readonly section. If they don't,
65 /// various bits of code will fall back to using the data section for
66 /// constants.
67 MCSection *ReadOnlySection;
68
69 /// If exception handling is supported by the target, this is the section the
70 /// Language Specific Data Area information is emitted to.
71 MCSection *LSDASection;
72
73 /// If exception handling is supported by the target and the target can
74 /// support a compact representation of the CIE and FDE, this is the section
75 /// to emit them into.
76 MCSection *CompactUnwindSection;
77
78 // Dwarf sections for debug info. If a target supports debug info, these must
79 // be set.
80 MCSection *DwarfAbbrevSection;
81 MCSection *DwarfInfoSection;
82 MCSection *DwarfLineSection;
83 MCSection *DwarfLineStrSection;
84 MCSection *DwarfFrameSection;
85 MCSection *DwarfPubTypesSection;
86 const MCSection *DwarfDebugInlineSection;
87 MCSection *DwarfStrSection;
88 MCSection *DwarfLocSection;
89 MCSection *DwarfARangesSection;
90 MCSection *DwarfRangesSection;
91 MCSection *DwarfMacinfoSection;
92 // The pubnames section is no longer generated by default. The generation
93 // can be enabled by a compiler flag.
94 MCSection *DwarfPubNamesSection;
95
Andrew Scullcdfcccc2018-10-05 20:58:37 +010096 /// Accelerator table sections. DwarfDebugNamesSection is the DWARF v5
97 /// accelerator table, while DwarfAccelNamesSection, DwarfAccelObjCSection,
98 /// DwarfAccelNamespaceSection, DwarfAccelTypesSection are pre-DWARF v5
99 /// extensions.
100 MCSection *DwarfDebugNamesSection;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100101 MCSection *DwarfAccelNamesSection;
102 MCSection *DwarfAccelObjCSection;
103 MCSection *DwarfAccelNamespaceSection;
104 MCSection *DwarfAccelTypesSection;
105
106 // These are used for the Fission separate debug information files.
107 MCSection *DwarfInfoDWOSection;
108 MCSection *DwarfTypesDWOSection;
109 MCSection *DwarfAbbrevDWOSection;
110 MCSection *DwarfStrDWOSection;
111 MCSection *DwarfLineDWOSection;
112 MCSection *DwarfLocDWOSection;
113 MCSection *DwarfStrOffDWOSection;
114
115 /// The DWARF v5 string offset and address table sections.
116 MCSection *DwarfStrOffSection;
117 MCSection *DwarfAddrSection;
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100118 /// The DWARF v5 range list section.
119 MCSection *DwarfRnglistsSection;
Andrew Walbran16937d02019-10-22 13:54:20 +0100120 /// The DWARF v5 locations list section.
121 MCSection *DwarfLoclistsSection;
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100122
123 /// The DWARF v5 range list section for fission.
124 MCSection *DwarfRnglistsDWOSection;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100125
126 // These are for Fission DWP files.
127 MCSection *DwarfCUIndexSection;
128 MCSection *DwarfTUIndexSection;
129
130 /// Section for newer gnu pubnames.
131 MCSection *DwarfGnuPubNamesSection;
132 /// Section for newer gnu pubtypes.
133 MCSection *DwarfGnuPubTypesSection;
134
135 // Section for Swift AST
136 MCSection *DwarfSwiftASTSection;
137
138 MCSection *COFFDebugSymbolsSection;
139 MCSection *COFFDebugTypesSection;
140 MCSection *COFFGlobalTypeHashesSection;
141
142 /// Extra TLS Variable Data section.
143 ///
144 /// If the target needs to put additional information for a TLS variable,
145 /// it'll go here.
146 MCSection *TLSExtraDataSection;
147
148 /// Section directive for Thread Local data. ELF, MachO, COFF, and Wasm.
149 MCSection *TLSDataSection; // Defaults to ".tdata".
150
151 /// Section directive for Thread Local uninitialized data.
152 ///
153 /// Null if this target doesn't support a BSS section. ELF and MachO only.
154 MCSection *TLSBSSSection; // Defaults to ".tbss".
155
156 /// StackMap section.
157 MCSection *StackMapSection;
158
159 /// FaultMap section.
160 MCSection *FaultMapSection;
161
162 /// EH frame section.
163 ///
164 /// It is initialized on demand so it can be overwritten (with uniquing).
165 MCSection *EHFrameSection;
166
167 /// Section containing metadata on function stack sizes.
168 MCSection *StackSizesSection;
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100169 mutable DenseMap<const MCSymbol *, unsigned> StackSizesUniquing;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100170
171 // ELF specific sections.
172 MCSection *DataRelROSection;
173 MCSection *MergeableConst4Section;
174 MCSection *MergeableConst8Section;
175 MCSection *MergeableConst16Section;
176 MCSection *MergeableConst32Section;
177
178 // MachO specific sections.
179
180 /// Section for thread local structure information.
181 ///
182 /// Contains the source code name of the variable, visibility and a pointer to
183 /// the initial value (.tdata or .tbss).
184 MCSection *TLSTLVSection; // Defaults to ".tlv".
185
186 /// Section for thread local data initialization functions.
187 const MCSection *TLSThreadInitSection; // Defaults to ".thread_init_func".
188
189 MCSection *CStringSection;
190 MCSection *UStringSection;
191 MCSection *TextCoalSection;
192 MCSection *ConstTextCoalSection;
193 MCSection *ConstDataSection;
194 MCSection *DataCoalSection;
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100195 MCSection *ConstDataCoalSection;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100196 MCSection *DataCommonSection;
197 MCSection *DataBSSSection;
198 MCSection *FourByteConstantSection;
199 MCSection *EightByteConstantSection;
200 MCSection *SixteenByteConstantSection;
201 MCSection *LazySymbolPointerSection;
202 MCSection *NonLazySymbolPointerSection;
203 MCSection *ThreadLocalPointerSection;
204
205 /// COFF specific sections.
206 MCSection *DrectveSection;
207 MCSection *PDataSection;
208 MCSection *XDataSection;
209 MCSection *SXDataSection;
210 MCSection *GFIDsSection;
211
212public:
213 void InitMCObjectFileInfo(const Triple &TT, bool PIC, MCContext &ctx,
214 bool LargeCodeModel = false);
215
216 bool getSupportsWeakOmittedEHFrame() const {
217 return SupportsWeakOmittedEHFrame;
218 }
219 bool getSupportsCompactUnwindWithoutEHFrame() const {
220 return SupportsCompactUnwindWithoutEHFrame;
221 }
222 bool getOmitDwarfIfHaveCompactUnwind() const {
223 return OmitDwarfIfHaveCompactUnwind;
224 }
225
226 bool getCommDirectiveSupportsAlignment() const {
227 return CommDirectiveSupportsAlignment;
228 }
229
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100230 unsigned getFDEEncoding() const { return FDECFIEncoding; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100231
232 unsigned getCompactUnwindDwarfEHFrameOnly() const {
233 return CompactUnwindDwarfEHFrameOnly;
234 }
235
236 MCSection *getTextSection() const { return TextSection; }
237 MCSection *getDataSection() const { return DataSection; }
238 MCSection *getBSSSection() const { return BSSSection; }
239 MCSection *getReadOnlySection() const { return ReadOnlySection; }
240 MCSection *getLSDASection() const { return LSDASection; }
241 MCSection *getCompactUnwindSection() const { return CompactUnwindSection; }
242 MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
243 MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
Andrew Walbran16937d02019-10-22 13:54:20 +0100244 MCSection *getDwarfInfoSection(uint64_t Hash) const {
245 return getDwarfComdatSection(".debug_info", Hash);
246 }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100247 MCSection *getDwarfLineSection() const { return DwarfLineSection; }
248 MCSection *getDwarfLineStrSection() const { return DwarfLineStrSection; }
249 MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
250 MCSection *getDwarfPubNamesSection() const { return DwarfPubNamesSection; }
251 MCSection *getDwarfPubTypesSection() const { return DwarfPubTypesSection; }
252 MCSection *getDwarfGnuPubNamesSection() const {
253 return DwarfGnuPubNamesSection;
254 }
255 MCSection *getDwarfGnuPubTypesSection() const {
256 return DwarfGnuPubTypesSection;
257 }
258 const MCSection *getDwarfDebugInlineSection() const {
259 return DwarfDebugInlineSection;
260 }
261 MCSection *getDwarfStrSection() const { return DwarfStrSection; }
262 MCSection *getDwarfLocSection() const { return DwarfLocSection; }
263 MCSection *getDwarfARangesSection() const { return DwarfARangesSection; }
264 MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100265 MCSection *getDwarfRnglistsSection() const { return DwarfRnglistsSection; }
Andrew Walbran16937d02019-10-22 13:54:20 +0100266 MCSection *getDwarfLoclistsSection() const { return DwarfLoclistsSection; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100267 MCSection *getDwarfMacinfoSection() const { return DwarfMacinfoSection; }
268
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100269 MCSection *getDwarfDebugNamesSection() const {
270 return DwarfDebugNamesSection;
271 }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100272 MCSection *getDwarfAccelNamesSection() const {
273 return DwarfAccelNamesSection;
274 }
275 MCSection *getDwarfAccelObjCSection() const { return DwarfAccelObjCSection; }
276 MCSection *getDwarfAccelNamespaceSection() const {
277 return DwarfAccelNamespaceSection;
278 }
279 MCSection *getDwarfAccelTypesSection() const {
280 return DwarfAccelTypesSection;
281 }
282 MCSection *getDwarfInfoDWOSection() const { return DwarfInfoDWOSection; }
Andrew Walbran16937d02019-10-22 13:54:20 +0100283 MCSection *getDwarfTypesSection(uint64_t Hash) const {
284 return getDwarfComdatSection(".debug_types", Hash);
285 }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100286 MCSection *getDwarfTypesDWOSection() const { return DwarfTypesDWOSection; }
287 MCSection *getDwarfAbbrevDWOSection() const { return DwarfAbbrevDWOSection; }
288 MCSection *getDwarfStrDWOSection() const { return DwarfStrDWOSection; }
289 MCSection *getDwarfLineDWOSection() const { return DwarfLineDWOSection; }
290 MCSection *getDwarfLocDWOSection() const { return DwarfLocDWOSection; }
291 MCSection *getDwarfStrOffDWOSection() const { return DwarfStrOffDWOSection; }
292 MCSection *getDwarfStrOffSection() const { return DwarfStrOffSection; }
293 MCSection *getDwarfAddrSection() const { return DwarfAddrSection; }
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100294 MCSection *getDwarfRnglistsDWOSection() const {
295 return DwarfRnglistsDWOSection;
296 }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100297 MCSection *getDwarfCUIndexSection() const { return DwarfCUIndexSection; }
298 MCSection *getDwarfTUIndexSection() const { return DwarfTUIndexSection; }
299 MCSection *getDwarfSwiftASTSection() const { return DwarfSwiftASTSection; }
300
301 MCSection *getCOFFDebugSymbolsSection() const {
302 return COFFDebugSymbolsSection;
303 }
304 MCSection *getCOFFDebugTypesSection() const {
305 return COFFDebugTypesSection;
306 }
307 MCSection *getCOFFGlobalTypeHashesSection() const {
308 return COFFGlobalTypeHashesSection;
309 }
310
311 MCSection *getTLSExtraDataSection() const { return TLSExtraDataSection; }
312 const MCSection *getTLSDataSection() const { return TLSDataSection; }
313 MCSection *getTLSBSSSection() const { return TLSBSSSection; }
314
315 MCSection *getStackMapSection() const { return StackMapSection; }
316 MCSection *getFaultMapSection() const { return FaultMapSection; }
317
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100318 MCSection *getStackSizesSection(const MCSection &TextSec) const;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100319
320 // ELF specific sections.
321 MCSection *getDataRelROSection() const { return DataRelROSection; }
322 const MCSection *getMergeableConst4Section() const {
323 return MergeableConst4Section;
324 }
325 const MCSection *getMergeableConst8Section() const {
326 return MergeableConst8Section;
327 }
328 const MCSection *getMergeableConst16Section() const {
329 return MergeableConst16Section;
330 }
331 const MCSection *getMergeableConst32Section() const {
332 return MergeableConst32Section;
333 }
334
335 // MachO specific sections.
336 const MCSection *getTLSTLVSection() const { return TLSTLVSection; }
337 const MCSection *getTLSThreadInitSection() const {
338 return TLSThreadInitSection;
339 }
340 const MCSection *getCStringSection() const { return CStringSection; }
341 const MCSection *getUStringSection() const { return UStringSection; }
342 MCSection *getTextCoalSection() const { return TextCoalSection; }
343 const MCSection *getConstTextCoalSection() const {
344 return ConstTextCoalSection;
345 }
346 const MCSection *getConstDataSection() const { return ConstDataSection; }
347 const MCSection *getDataCoalSection() const { return DataCoalSection; }
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100348 const MCSection *getConstDataCoalSection() const {
349 return ConstDataCoalSection;
350 }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100351 const MCSection *getDataCommonSection() const { return DataCommonSection; }
352 MCSection *getDataBSSSection() const { return DataBSSSection; }
353 const MCSection *getFourByteConstantSection() const {
354 return FourByteConstantSection;
355 }
356 const MCSection *getEightByteConstantSection() const {
357 return EightByteConstantSection;
358 }
359 const MCSection *getSixteenByteConstantSection() const {
360 return SixteenByteConstantSection;
361 }
362 MCSection *getLazySymbolPointerSection() const {
363 return LazySymbolPointerSection;
364 }
365 MCSection *getNonLazySymbolPointerSection() const {
366 return NonLazySymbolPointerSection;
367 }
368 MCSection *getThreadLocalPointerSection() const {
369 return ThreadLocalPointerSection;
370 }
371
372 // COFF specific sections.
373 MCSection *getDrectveSection() const { return DrectveSection; }
374 MCSection *getPDataSection() const { return PDataSection; }
375 MCSection *getXDataSection() const { return XDataSection; }
376 MCSection *getSXDataSection() const { return SXDataSection; }
377 MCSection *getGFIDsSection() const { return GFIDsSection; }
378
379 MCSection *getEHFrameSection() {
380 return EHFrameSection;
381 }
382
383 enum Environment { IsMachO, IsELF, IsCOFF, IsWasm };
384 Environment getObjectFileType() const { return Env; }
385
386 bool isPositionIndependent() const { return PositionIndependent; }
387
388private:
389 Environment Env;
390 bool PositionIndependent;
391 MCContext *Ctx;
392 Triple TT;
Andrew Walbran16937d02019-10-22 13:54:20 +0100393 VersionTuple SDKVersion;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100394
395 void initMachOMCObjectFileInfo(const Triple &T);
396 void initELFMCObjectFileInfo(const Triple &T, bool Large);
397 void initCOFFMCObjectFileInfo(const Triple &T);
398 void initWasmMCObjectFileInfo(const Triple &T);
Andrew Walbran16937d02019-10-22 13:54:20 +0100399 MCSection *getDwarfComdatSection(const char *Name, uint64_t Hash) const;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100400
401public:
402 const Triple &getTargetTriple() const { return TT; }
Andrew Walbran16937d02019-10-22 13:54:20 +0100403
404 void setSDKVersion(const VersionTuple &TheSDKVersion) {
405 SDKVersion = TheSDKVersion;
406 }
407
408 const VersionTuple &getSDKVersion() const { return SDKVersion; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100409};
410
411} // end namespace llvm
412
413#endif