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