blob: 8cf9e1cc55a064d76190f953134d274e76ec5c2e [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===-- llvm/MC/MCObjectFileInfo.h - Object File Info -----------*- C++ -*-===//
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// This file describes common object file formats.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_MC_MCOBJECTFILEINFO_H
15#define LLVM_MC_MCOBJECTFILEINFO_H
16
Andrew Scullcdfcccc2018-10-05 20:58:37 +010017#include "llvm/ADT/DenseMap.h"
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010018#include "llvm/ADT/Triple.h"
Andrew Scullcdfcccc2018-10-05 20:58:37 +010019#include "llvm/MC/MCSymbol.h"
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010020#include "llvm/Support/CodeGen.h"
21
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;
120
121 /// The DWARF v5 range list section for fission.
122 MCSection *DwarfRnglistsDWOSection;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100123
124 // These are for Fission DWP files.
125 MCSection *DwarfCUIndexSection;
126 MCSection *DwarfTUIndexSection;
127
128 /// Section for newer gnu pubnames.
129 MCSection *DwarfGnuPubNamesSection;
130 /// Section for newer gnu pubtypes.
131 MCSection *DwarfGnuPubTypesSection;
132
133 // Section for Swift AST
134 MCSection *DwarfSwiftASTSection;
135
136 MCSection *COFFDebugSymbolsSection;
137 MCSection *COFFDebugTypesSection;
138 MCSection *COFFGlobalTypeHashesSection;
139
140 /// Extra TLS Variable Data section.
141 ///
142 /// If the target needs to put additional information for a TLS variable,
143 /// it'll go here.
144 MCSection *TLSExtraDataSection;
145
146 /// Section directive for Thread Local data. ELF, MachO, COFF, and Wasm.
147 MCSection *TLSDataSection; // Defaults to ".tdata".
148
149 /// Section directive for Thread Local uninitialized data.
150 ///
151 /// Null if this target doesn't support a BSS section. ELF and MachO only.
152 MCSection *TLSBSSSection; // Defaults to ".tbss".
153
154 /// StackMap section.
155 MCSection *StackMapSection;
156
157 /// FaultMap section.
158 MCSection *FaultMapSection;
159
160 /// EH frame section.
161 ///
162 /// It is initialized on demand so it can be overwritten (with uniquing).
163 MCSection *EHFrameSection;
164
165 /// Section containing metadata on function stack sizes.
166 MCSection *StackSizesSection;
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100167 mutable DenseMap<const MCSymbol *, unsigned> StackSizesUniquing;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100168
169 // ELF specific sections.
170 MCSection *DataRelROSection;
171 MCSection *MergeableConst4Section;
172 MCSection *MergeableConst8Section;
173 MCSection *MergeableConst16Section;
174 MCSection *MergeableConst32Section;
175
176 // MachO specific sections.
177
178 /// Section for thread local structure information.
179 ///
180 /// Contains the source code name of the variable, visibility and a pointer to
181 /// the initial value (.tdata or .tbss).
182 MCSection *TLSTLVSection; // Defaults to ".tlv".
183
184 /// Section for thread local data initialization functions.
185 const MCSection *TLSThreadInitSection; // Defaults to ".thread_init_func".
186
187 MCSection *CStringSection;
188 MCSection *UStringSection;
189 MCSection *TextCoalSection;
190 MCSection *ConstTextCoalSection;
191 MCSection *ConstDataSection;
192 MCSection *DataCoalSection;
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100193 MCSection *ConstDataCoalSection;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100194 MCSection *DataCommonSection;
195 MCSection *DataBSSSection;
196 MCSection *FourByteConstantSection;
197 MCSection *EightByteConstantSection;
198 MCSection *SixteenByteConstantSection;
199 MCSection *LazySymbolPointerSection;
200 MCSection *NonLazySymbolPointerSection;
201 MCSection *ThreadLocalPointerSection;
202
203 /// COFF specific sections.
204 MCSection *DrectveSection;
205 MCSection *PDataSection;
206 MCSection *XDataSection;
207 MCSection *SXDataSection;
208 MCSection *GFIDsSection;
209
210public:
211 void InitMCObjectFileInfo(const Triple &TT, bool PIC, MCContext &ctx,
212 bool LargeCodeModel = false);
213
214 bool getSupportsWeakOmittedEHFrame() const {
215 return SupportsWeakOmittedEHFrame;
216 }
217 bool getSupportsCompactUnwindWithoutEHFrame() const {
218 return SupportsCompactUnwindWithoutEHFrame;
219 }
220 bool getOmitDwarfIfHaveCompactUnwind() const {
221 return OmitDwarfIfHaveCompactUnwind;
222 }
223
224 bool getCommDirectiveSupportsAlignment() const {
225 return CommDirectiveSupportsAlignment;
226 }
227
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100228 unsigned getFDEEncoding() const { return FDECFIEncoding; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100229
230 unsigned getCompactUnwindDwarfEHFrameOnly() const {
231 return CompactUnwindDwarfEHFrameOnly;
232 }
233
234 MCSection *getTextSection() const { return TextSection; }
235 MCSection *getDataSection() const { return DataSection; }
236 MCSection *getBSSSection() const { return BSSSection; }
237 MCSection *getReadOnlySection() const { return ReadOnlySection; }
238 MCSection *getLSDASection() const { return LSDASection; }
239 MCSection *getCompactUnwindSection() const { return CompactUnwindSection; }
240 MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
241 MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
242 MCSection *getDwarfLineSection() const { return DwarfLineSection; }
243 MCSection *getDwarfLineStrSection() const { return DwarfLineStrSection; }
244 MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
245 MCSection *getDwarfPubNamesSection() const { return DwarfPubNamesSection; }
246 MCSection *getDwarfPubTypesSection() const { return DwarfPubTypesSection; }
247 MCSection *getDwarfGnuPubNamesSection() const {
248 return DwarfGnuPubNamesSection;
249 }
250 MCSection *getDwarfGnuPubTypesSection() const {
251 return DwarfGnuPubTypesSection;
252 }
253 const MCSection *getDwarfDebugInlineSection() const {
254 return DwarfDebugInlineSection;
255 }
256 MCSection *getDwarfStrSection() const { return DwarfStrSection; }
257 MCSection *getDwarfLocSection() const { return DwarfLocSection; }
258 MCSection *getDwarfARangesSection() const { return DwarfARangesSection; }
259 MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100260 MCSection *getDwarfRnglistsSection() const { return DwarfRnglistsSection; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100261 MCSection *getDwarfMacinfoSection() const { return DwarfMacinfoSection; }
262
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100263 MCSection *getDwarfDebugNamesSection() const {
264 return DwarfDebugNamesSection;
265 }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100266 MCSection *getDwarfAccelNamesSection() const {
267 return DwarfAccelNamesSection;
268 }
269 MCSection *getDwarfAccelObjCSection() const { return DwarfAccelObjCSection; }
270 MCSection *getDwarfAccelNamespaceSection() const {
271 return DwarfAccelNamespaceSection;
272 }
273 MCSection *getDwarfAccelTypesSection() const {
274 return DwarfAccelTypesSection;
275 }
276 MCSection *getDwarfInfoDWOSection() const { return DwarfInfoDWOSection; }
277 MCSection *getDwarfTypesSection(uint64_t Hash) const;
278 MCSection *getDwarfTypesDWOSection() const { return DwarfTypesDWOSection; }
279 MCSection *getDwarfAbbrevDWOSection() const { return DwarfAbbrevDWOSection; }
280 MCSection *getDwarfStrDWOSection() const { return DwarfStrDWOSection; }
281 MCSection *getDwarfLineDWOSection() const { return DwarfLineDWOSection; }
282 MCSection *getDwarfLocDWOSection() const { return DwarfLocDWOSection; }
283 MCSection *getDwarfStrOffDWOSection() const { return DwarfStrOffDWOSection; }
284 MCSection *getDwarfStrOffSection() const { return DwarfStrOffSection; }
285 MCSection *getDwarfAddrSection() const { return DwarfAddrSection; }
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100286 MCSection *getDwarfRnglistsDWOSection() const {
287 return DwarfRnglistsDWOSection;
288 }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100289 MCSection *getDwarfCUIndexSection() const { return DwarfCUIndexSection; }
290 MCSection *getDwarfTUIndexSection() const { return DwarfTUIndexSection; }
291 MCSection *getDwarfSwiftASTSection() const { return DwarfSwiftASTSection; }
292
293 MCSection *getCOFFDebugSymbolsSection() const {
294 return COFFDebugSymbolsSection;
295 }
296 MCSection *getCOFFDebugTypesSection() const {
297 return COFFDebugTypesSection;
298 }
299 MCSection *getCOFFGlobalTypeHashesSection() const {
300 return COFFGlobalTypeHashesSection;
301 }
302
303 MCSection *getTLSExtraDataSection() const { return TLSExtraDataSection; }
304 const MCSection *getTLSDataSection() const { return TLSDataSection; }
305 MCSection *getTLSBSSSection() const { return TLSBSSSection; }
306
307 MCSection *getStackMapSection() const { return StackMapSection; }
308 MCSection *getFaultMapSection() const { return FaultMapSection; }
309
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100310 MCSection *getStackSizesSection(const MCSection &TextSec) const;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100311
312 // ELF specific sections.
313 MCSection *getDataRelROSection() const { return DataRelROSection; }
314 const MCSection *getMergeableConst4Section() const {
315 return MergeableConst4Section;
316 }
317 const MCSection *getMergeableConst8Section() const {
318 return MergeableConst8Section;
319 }
320 const MCSection *getMergeableConst16Section() const {
321 return MergeableConst16Section;
322 }
323 const MCSection *getMergeableConst32Section() const {
324 return MergeableConst32Section;
325 }
326
327 // MachO specific sections.
328 const MCSection *getTLSTLVSection() const { return TLSTLVSection; }
329 const MCSection *getTLSThreadInitSection() const {
330 return TLSThreadInitSection;
331 }
332 const MCSection *getCStringSection() const { return CStringSection; }
333 const MCSection *getUStringSection() const { return UStringSection; }
334 MCSection *getTextCoalSection() const { return TextCoalSection; }
335 const MCSection *getConstTextCoalSection() const {
336 return ConstTextCoalSection;
337 }
338 const MCSection *getConstDataSection() const { return ConstDataSection; }
339 const MCSection *getDataCoalSection() const { return DataCoalSection; }
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100340 const MCSection *getConstDataCoalSection() const {
341 return ConstDataCoalSection;
342 }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100343 const MCSection *getDataCommonSection() const { return DataCommonSection; }
344 MCSection *getDataBSSSection() const { return DataBSSSection; }
345 const MCSection *getFourByteConstantSection() const {
346 return FourByteConstantSection;
347 }
348 const MCSection *getEightByteConstantSection() const {
349 return EightByteConstantSection;
350 }
351 const MCSection *getSixteenByteConstantSection() const {
352 return SixteenByteConstantSection;
353 }
354 MCSection *getLazySymbolPointerSection() const {
355 return LazySymbolPointerSection;
356 }
357 MCSection *getNonLazySymbolPointerSection() const {
358 return NonLazySymbolPointerSection;
359 }
360 MCSection *getThreadLocalPointerSection() const {
361 return ThreadLocalPointerSection;
362 }
363
364 // COFF specific sections.
365 MCSection *getDrectveSection() const { return DrectveSection; }
366 MCSection *getPDataSection() const { return PDataSection; }
367 MCSection *getXDataSection() const { return XDataSection; }
368 MCSection *getSXDataSection() const { return SXDataSection; }
369 MCSection *getGFIDsSection() const { return GFIDsSection; }
370
371 MCSection *getEHFrameSection() {
372 return EHFrameSection;
373 }
374
375 enum Environment { IsMachO, IsELF, IsCOFF, IsWasm };
376 Environment getObjectFileType() const { return Env; }
377
378 bool isPositionIndependent() const { return PositionIndependent; }
379
380private:
381 Environment Env;
382 bool PositionIndependent;
383 MCContext *Ctx;
384 Triple TT;
385
386 void initMachOMCObjectFileInfo(const Triple &T);
387 void initELFMCObjectFileInfo(const Triple &T, bool Large);
388 void initCOFFMCObjectFileInfo(const Triple &T);
389 void initWasmMCObjectFileInfo(const Triple &T);
390
391public:
392 const Triple &getTargetTriple() const { return TT; }
393};
394
395} // end namespace llvm
396
397#endif