blob: c99f2521f8f5f31be0a8146f35946a36846e25c7 [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
17#include "llvm/ADT/Triple.h"
18#include "llvm/Support/CodeGen.h"
19
20namespace llvm {
21class MCContext;
22class MCSection;
23
24class MCObjectFileInfo {
25protected:
26 /// True if .comm supports alignment. This is a hack for as long as we
27 /// support 10.4 Tiger, whose assembler doesn't support alignment on comm.
28 bool CommDirectiveSupportsAlignment;
29
30 /// True if target object file supports a weak_definition of constant 0 for an
31 /// omitted EH frame.
32 bool SupportsWeakOmittedEHFrame;
33
34 /// True if the target object file supports emitting a compact unwind section
35 /// without an associated EH frame section.
36 bool SupportsCompactUnwindWithoutEHFrame;
37
38 /// OmitDwarfIfHaveCompactUnwind - True if the target object file
39 /// supports having some functions with compact unwind and other with
40 /// dwarf unwind.
41 bool OmitDwarfIfHaveCompactUnwind;
42
43 /// PersonalityEncoding, LSDAEncoding, TTypeEncoding - Some encoding values
44 /// for EH.
45 unsigned PersonalityEncoding;
46 unsigned LSDAEncoding;
47 unsigned FDECFIEncoding;
48 unsigned TTypeEncoding;
49
50 /// Compact unwind encoding indicating that we should emit only an EH frame.
51 unsigned CompactUnwindDwarfEHFrameOnly;
52
53 /// Section directive for standard text.
54 MCSection *TextSection;
55
56 /// Section directive for standard data.
57 MCSection *DataSection;
58
59 /// Section that is default initialized to zero.
60 MCSection *BSSSection;
61
62 /// Section that is readonly and can contain arbitrary initialized data.
63 /// Targets are not required to have a readonly section. If they don't,
64 /// various bits of code will fall back to using the data section for
65 /// constants.
66 MCSection *ReadOnlySection;
67
68 /// If exception handling is supported by the target, this is the section the
69 /// Language Specific Data Area information is emitted to.
70 MCSection *LSDASection;
71
72 /// If exception handling is supported by the target and the target can
73 /// support a compact representation of the CIE and FDE, this is the section
74 /// to emit them into.
75 MCSection *CompactUnwindSection;
76
77 // Dwarf sections for debug info. If a target supports debug info, these must
78 // be set.
79 MCSection *DwarfAbbrevSection;
80 MCSection *DwarfInfoSection;
81 MCSection *DwarfLineSection;
82 MCSection *DwarfLineStrSection;
83 MCSection *DwarfFrameSection;
84 MCSection *DwarfPubTypesSection;
85 const MCSection *DwarfDebugInlineSection;
86 MCSection *DwarfStrSection;
87 MCSection *DwarfLocSection;
88 MCSection *DwarfARangesSection;
89 MCSection *DwarfRangesSection;
90 MCSection *DwarfMacinfoSection;
91 // The pubnames section is no longer generated by default. The generation
92 // can be enabled by a compiler flag.
93 MCSection *DwarfPubNamesSection;
94
95 /// DWARF5 Experimental Debug Info Sections
96 /// DwarfAccelNamesSection, DwarfAccelObjCSection,
97 /// DwarfAccelNamespaceSection, DwarfAccelTypesSection -
98 /// If we use the DWARF accelerated hash tables then we want to emit these
99 /// sections.
100 MCSection *DwarfAccelNamesSection;
101 MCSection *DwarfAccelObjCSection;
102 MCSection *DwarfAccelNamespaceSection;
103 MCSection *DwarfAccelTypesSection;
104
105 // These are used for the Fission separate debug information files.
106 MCSection *DwarfInfoDWOSection;
107 MCSection *DwarfTypesDWOSection;
108 MCSection *DwarfAbbrevDWOSection;
109 MCSection *DwarfStrDWOSection;
110 MCSection *DwarfLineDWOSection;
111 MCSection *DwarfLocDWOSection;
112 MCSection *DwarfStrOffDWOSection;
113
114 /// The DWARF v5 string offset and address table sections.
115 MCSection *DwarfStrOffSection;
116 MCSection *DwarfAddrSection;
117
118 // These are for Fission DWP files.
119 MCSection *DwarfCUIndexSection;
120 MCSection *DwarfTUIndexSection;
121
122 /// Section for newer gnu pubnames.
123 MCSection *DwarfGnuPubNamesSection;
124 /// Section for newer gnu pubtypes.
125 MCSection *DwarfGnuPubTypesSection;
126
127 // Section for Swift AST
128 MCSection *DwarfSwiftASTSection;
129
130 MCSection *COFFDebugSymbolsSection;
131 MCSection *COFFDebugTypesSection;
132 MCSection *COFFGlobalTypeHashesSection;
133
134 /// Extra TLS Variable Data section.
135 ///
136 /// If the target needs to put additional information for a TLS variable,
137 /// it'll go here.
138 MCSection *TLSExtraDataSection;
139
140 /// Section directive for Thread Local data. ELF, MachO, COFF, and Wasm.
141 MCSection *TLSDataSection; // Defaults to ".tdata".
142
143 /// Section directive for Thread Local uninitialized data.
144 ///
145 /// Null if this target doesn't support a BSS section. ELF and MachO only.
146 MCSection *TLSBSSSection; // Defaults to ".tbss".
147
148 /// StackMap section.
149 MCSection *StackMapSection;
150
151 /// FaultMap section.
152 MCSection *FaultMapSection;
153
154 /// EH frame section.
155 ///
156 /// It is initialized on demand so it can be overwritten (with uniquing).
157 MCSection *EHFrameSection;
158
159 /// Section containing metadata on function stack sizes.
160 MCSection *StackSizesSection;
161
162 // ELF specific sections.
163 MCSection *DataRelROSection;
164 MCSection *MergeableConst4Section;
165 MCSection *MergeableConst8Section;
166 MCSection *MergeableConst16Section;
167 MCSection *MergeableConst32Section;
168
169 // MachO specific sections.
170
171 /// Section for thread local structure information.
172 ///
173 /// Contains the source code name of the variable, visibility and a pointer to
174 /// the initial value (.tdata or .tbss).
175 MCSection *TLSTLVSection; // Defaults to ".tlv".
176
177 /// Section for thread local data initialization functions.
178 const MCSection *TLSThreadInitSection; // Defaults to ".thread_init_func".
179
180 MCSection *CStringSection;
181 MCSection *UStringSection;
182 MCSection *TextCoalSection;
183 MCSection *ConstTextCoalSection;
184 MCSection *ConstDataSection;
185 MCSection *DataCoalSection;
186 MCSection *DataCommonSection;
187 MCSection *DataBSSSection;
188 MCSection *FourByteConstantSection;
189 MCSection *EightByteConstantSection;
190 MCSection *SixteenByteConstantSection;
191 MCSection *LazySymbolPointerSection;
192 MCSection *NonLazySymbolPointerSection;
193 MCSection *ThreadLocalPointerSection;
194
195 /// COFF specific sections.
196 MCSection *DrectveSection;
197 MCSection *PDataSection;
198 MCSection *XDataSection;
199 MCSection *SXDataSection;
200 MCSection *GFIDsSection;
201
202public:
203 void InitMCObjectFileInfo(const Triple &TT, bool PIC, MCContext &ctx,
204 bool LargeCodeModel = false);
205
206 bool getSupportsWeakOmittedEHFrame() const {
207 return SupportsWeakOmittedEHFrame;
208 }
209 bool getSupportsCompactUnwindWithoutEHFrame() const {
210 return SupportsCompactUnwindWithoutEHFrame;
211 }
212 bool getOmitDwarfIfHaveCompactUnwind() const {
213 return OmitDwarfIfHaveCompactUnwind;
214 }
215
216 bool getCommDirectiveSupportsAlignment() const {
217 return CommDirectiveSupportsAlignment;
218 }
219
220 unsigned getPersonalityEncoding() const { return PersonalityEncoding; }
221 unsigned getLSDAEncoding() const { return LSDAEncoding; }
222 unsigned getFDEEncoding() const { return FDECFIEncoding; }
223 unsigned getTTypeEncoding() const { return TTypeEncoding; }
224
225 unsigned getCompactUnwindDwarfEHFrameOnly() const {
226 return CompactUnwindDwarfEHFrameOnly;
227 }
228
229 MCSection *getTextSection() const { return TextSection; }
230 MCSection *getDataSection() const { return DataSection; }
231 MCSection *getBSSSection() const { return BSSSection; }
232 MCSection *getReadOnlySection() const { return ReadOnlySection; }
233 MCSection *getLSDASection() const { return LSDASection; }
234 MCSection *getCompactUnwindSection() const { return CompactUnwindSection; }
235 MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
236 MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
237 MCSection *getDwarfLineSection() const { return DwarfLineSection; }
238 MCSection *getDwarfLineStrSection() const { return DwarfLineStrSection; }
239 MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
240 MCSection *getDwarfPubNamesSection() const { return DwarfPubNamesSection; }
241 MCSection *getDwarfPubTypesSection() const { return DwarfPubTypesSection; }
242 MCSection *getDwarfGnuPubNamesSection() const {
243 return DwarfGnuPubNamesSection;
244 }
245 MCSection *getDwarfGnuPubTypesSection() const {
246 return DwarfGnuPubTypesSection;
247 }
248 const MCSection *getDwarfDebugInlineSection() const {
249 return DwarfDebugInlineSection;
250 }
251 MCSection *getDwarfStrSection() const { return DwarfStrSection; }
252 MCSection *getDwarfLocSection() const { return DwarfLocSection; }
253 MCSection *getDwarfARangesSection() const { return DwarfARangesSection; }
254 MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
255 MCSection *getDwarfMacinfoSection() const { return DwarfMacinfoSection; }
256
257 // DWARF5 Experimental Debug Info Sections
258 MCSection *getDwarfAccelNamesSection() const {
259 return DwarfAccelNamesSection;
260 }
261 MCSection *getDwarfAccelObjCSection() const { return DwarfAccelObjCSection; }
262 MCSection *getDwarfAccelNamespaceSection() const {
263 return DwarfAccelNamespaceSection;
264 }
265 MCSection *getDwarfAccelTypesSection() const {
266 return DwarfAccelTypesSection;
267 }
268 MCSection *getDwarfInfoDWOSection() const { return DwarfInfoDWOSection; }
269 MCSection *getDwarfTypesSection(uint64_t Hash) const;
270 MCSection *getDwarfTypesDWOSection() const { return DwarfTypesDWOSection; }
271 MCSection *getDwarfAbbrevDWOSection() const { return DwarfAbbrevDWOSection; }
272 MCSection *getDwarfStrDWOSection() const { return DwarfStrDWOSection; }
273 MCSection *getDwarfLineDWOSection() const { return DwarfLineDWOSection; }
274 MCSection *getDwarfLocDWOSection() const { return DwarfLocDWOSection; }
275 MCSection *getDwarfStrOffDWOSection() const { return DwarfStrOffDWOSection; }
276 MCSection *getDwarfStrOffSection() const { return DwarfStrOffSection; }
277 MCSection *getDwarfAddrSection() const { return DwarfAddrSection; }
278 MCSection *getDwarfCUIndexSection() const { return DwarfCUIndexSection; }
279 MCSection *getDwarfTUIndexSection() const { return DwarfTUIndexSection; }
280 MCSection *getDwarfSwiftASTSection() const { return DwarfSwiftASTSection; }
281
282 MCSection *getCOFFDebugSymbolsSection() const {
283 return COFFDebugSymbolsSection;
284 }
285 MCSection *getCOFFDebugTypesSection() const {
286 return COFFDebugTypesSection;
287 }
288 MCSection *getCOFFGlobalTypeHashesSection() const {
289 return COFFGlobalTypeHashesSection;
290 }
291
292 MCSection *getTLSExtraDataSection() const { return TLSExtraDataSection; }
293 const MCSection *getTLSDataSection() const { return TLSDataSection; }
294 MCSection *getTLSBSSSection() const { return TLSBSSSection; }
295
296 MCSection *getStackMapSection() const { return StackMapSection; }
297 MCSection *getFaultMapSection() const { return FaultMapSection; }
298
299 MCSection *getStackSizesSection() const { return StackSizesSection; }
300
301 // ELF specific sections.
302 MCSection *getDataRelROSection() const { return DataRelROSection; }
303 const MCSection *getMergeableConst4Section() const {
304 return MergeableConst4Section;
305 }
306 const MCSection *getMergeableConst8Section() const {
307 return MergeableConst8Section;
308 }
309 const MCSection *getMergeableConst16Section() const {
310 return MergeableConst16Section;
311 }
312 const MCSection *getMergeableConst32Section() const {
313 return MergeableConst32Section;
314 }
315
316 // MachO specific sections.
317 const MCSection *getTLSTLVSection() const { return TLSTLVSection; }
318 const MCSection *getTLSThreadInitSection() const {
319 return TLSThreadInitSection;
320 }
321 const MCSection *getCStringSection() const { return CStringSection; }
322 const MCSection *getUStringSection() const { return UStringSection; }
323 MCSection *getTextCoalSection() const { return TextCoalSection; }
324 const MCSection *getConstTextCoalSection() const {
325 return ConstTextCoalSection;
326 }
327 const MCSection *getConstDataSection() const { return ConstDataSection; }
328 const MCSection *getDataCoalSection() const { return DataCoalSection; }
329 const MCSection *getDataCommonSection() const { return DataCommonSection; }
330 MCSection *getDataBSSSection() const { return DataBSSSection; }
331 const MCSection *getFourByteConstantSection() const {
332 return FourByteConstantSection;
333 }
334 const MCSection *getEightByteConstantSection() const {
335 return EightByteConstantSection;
336 }
337 const MCSection *getSixteenByteConstantSection() const {
338 return SixteenByteConstantSection;
339 }
340 MCSection *getLazySymbolPointerSection() const {
341 return LazySymbolPointerSection;
342 }
343 MCSection *getNonLazySymbolPointerSection() const {
344 return NonLazySymbolPointerSection;
345 }
346 MCSection *getThreadLocalPointerSection() const {
347 return ThreadLocalPointerSection;
348 }
349
350 // COFF specific sections.
351 MCSection *getDrectveSection() const { return DrectveSection; }
352 MCSection *getPDataSection() const { return PDataSection; }
353 MCSection *getXDataSection() const { return XDataSection; }
354 MCSection *getSXDataSection() const { return SXDataSection; }
355 MCSection *getGFIDsSection() const { return GFIDsSection; }
356
357 MCSection *getEHFrameSection() {
358 return EHFrameSection;
359 }
360
361 enum Environment { IsMachO, IsELF, IsCOFF, IsWasm };
362 Environment getObjectFileType() const { return Env; }
363
364 bool isPositionIndependent() const { return PositionIndependent; }
365
366private:
367 Environment Env;
368 bool PositionIndependent;
369 MCContext *Ctx;
370 Triple TT;
371
372 void initMachOMCObjectFileInfo(const Triple &T);
373 void initELFMCObjectFileInfo(const Triple &T, bool Large);
374 void initCOFFMCObjectFileInfo(const Triple &T);
375 void initWasmMCObjectFileInfo(const Triple &T);
376
377public:
378 const Triple &getTargetTriple() const { return TT; }
379};
380
381} // end namespace llvm
382
383#endif