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