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