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