• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   /// PersonalityEncoding, LSDAEncoding, FDEEncoding, TTypeEncoding - Some
43   /// encoding values for EH.
44   unsigned PersonalityEncoding;
45   unsigned LSDAEncoding;
46   unsigned FDEEncoding;
47   unsigned FDECFIEncoding;
48   unsigned TTypeEncoding;
49   // Section flags for eh_frame
50   unsigned EHSectionType;
51   unsigned EHSectionFlags;
52 
53   /// TextSection - Section directive for standard text.
54   ///
55   const MCSection *TextSection;
56 
57   /// DataSection - Section directive for standard data.
58   ///
59   const MCSection *DataSection;
60 
61   /// BSSSection - Section that is default initialized to zero.
62   const MCSection *BSSSection;
63 
64   /// ReadOnlySection - Section that is readonly and can contain arbitrary
65   /// initialized data.  Targets are not required to have a readonly section.
66   /// If they don't, various bits of code will fall back to using the data
67   /// section for constants.
68   const MCSection *ReadOnlySection;
69 
70   /// StaticCtorSection - This section contains the static constructor pointer
71   /// list.
72   const MCSection *StaticCtorSection;
73 
74   /// StaticDtorSection - This section contains the static destructor pointer
75   /// list.
76   const MCSection *StaticDtorSection;
77 
78   /// LSDASection - If exception handling is supported by the target, this is
79   /// the section the Language Specific Data Area information is emitted to.
80   const MCSection *LSDASection;
81 
82   /// CompactUnwindSection - If exception handling is supported by the target
83   /// and the target can support a compact representation of the CIE and FDE,
84   /// this is the section to emit them into.
85   const MCSection *CompactUnwindSection;
86 
87   /// DwarfAccelNamesSection, DwarfAccelObjCSection
88   /// If we use the DWARF accelerated hash tables then we want toe emit these
89   /// sections.
90   const MCSection *DwarfAccelNamesSection;
91   const MCSection *DwarfAccelObjCSection;
92   const MCSection *DwarfAccelNamespaceSection;
93   const MCSection *DwarfAccelTypesSection;
94 
95   // Dwarf sections for debug info.  If a target supports debug info, these must
96   // be set.
97   const MCSection *DwarfAbbrevSection;
98   const MCSection *DwarfInfoSection;
99   const MCSection *DwarfLineSection;
100   const MCSection *DwarfFrameSection;
101   const MCSection *DwarfPubTypesSection;
102   const MCSection *DwarfDebugInlineSection;
103   const MCSection *DwarfStrSection;
104   const MCSection *DwarfLocSection;
105   const MCSection *DwarfARangesSection;
106   const MCSection *DwarfRangesSection;
107   const MCSection *DwarfMacroInfoSection;
108 
109   // Extra TLS Variable Data section.  If the target needs to put additional
110   // information for a TLS variable, it'll go here.
111   const MCSection *TLSExtraDataSection;
112 
113   /// TLSDataSection - Section directive for Thread Local data.
114   /// ELF, MachO and COFF.
115   const MCSection *TLSDataSection;        // Defaults to ".tdata".
116 
117   /// TLSBSSSection - Section directive for Thread Local uninitialized data.
118   /// Null if this target doesn't support a BSS section.
119   /// ELF and MachO only.
120   const MCSection *TLSBSSSection;         // Defaults to ".tbss".
121 
122 
123   /// EHFrameSection - EH frame section. It is initialized on demand so it
124   /// can be overwritten (with uniquing).
125   const MCSection *EHFrameSection;
126 
127   /// ELF specific sections.
128   ///
129   const MCSection *DataRelSection;
130   const MCSection *DataRelLocalSection;
131   const MCSection *DataRelROSection;
132   const MCSection *DataRelROLocalSection;
133   const MCSection *MergeableConst4Section;
134   const MCSection *MergeableConst8Section;
135   const MCSection *MergeableConst16Section;
136 
137   /// MachO specific sections.
138   ///
139 
140   /// TLSTLVSection - Section for thread local structure information.
141   /// Contains the source code name of the variable, visibility and a pointer
142   /// to the initial value (.tdata or .tbss).
143   const MCSection *TLSTLVSection;         // Defaults to ".tlv".
144 
145   /// TLSThreadInitSection - Section for thread local data initialization
146   /// functions.
147   const MCSection *TLSThreadInitSection;  // Defaults to ".thread_init_func".
148 
149   const MCSection *CStringSection;
150   const MCSection *UStringSection;
151   const MCSection *TextCoalSection;
152   const MCSection *ConstTextCoalSection;
153   const MCSection *ConstDataSection;
154   const MCSection *DataCoalSection;
155   const MCSection *DataCommonSection;
156   const MCSection *DataBSSSection;
157   const MCSection *FourByteConstantSection;
158   const MCSection *EightByteConstantSection;
159   const MCSection *SixteenByteConstantSection;
160   const MCSection *LazySymbolPointerSection;
161   const MCSection *NonLazySymbolPointerSection;
162 
163   /// COFF specific sections.
164   ///
165   const MCSection *DrectveSection;
166   const MCSection *PDataSection;
167   const MCSection *XDataSection;
168 
169 public:
170   void InitMCObjectFileInfo(StringRef TT, Reloc::Model RM, CodeModel::Model CM,
171                             MCContext &ctx);
172 
isFunctionEHFrameSymbolPrivate()173   bool isFunctionEHFrameSymbolPrivate() const {
174     return IsFunctionEHFrameSymbolPrivate;
175   }
getSupportsWeakOmittedEHFrame()176   bool getSupportsWeakOmittedEHFrame() const {
177     return SupportsWeakOmittedEHFrame;
178   }
getCommDirectiveSupportsAlignment()179   bool getCommDirectiveSupportsAlignment() const {
180     return CommDirectiveSupportsAlignment;
181   }
182 
getPersonalityEncoding()183   unsigned getPersonalityEncoding() const { return PersonalityEncoding; }
getLSDAEncoding()184   unsigned getLSDAEncoding() const { return LSDAEncoding; }
getFDEEncoding(bool CFI)185   unsigned getFDEEncoding(bool CFI) const {
186     return CFI ? FDECFIEncoding : FDEEncoding;
187   }
getTTypeEncoding()188   unsigned getTTypeEncoding() const { return TTypeEncoding; }
189 
getTextSection()190   const MCSection *getTextSection() const { return TextSection; }
getDataSection()191   const MCSection *getDataSection() const { return DataSection; }
getBSSSection()192   const MCSection *getBSSSection() const { return BSSSection; }
getLSDASection()193   const MCSection *getLSDASection() const { return LSDASection; }
getCompactUnwindSection()194   const MCSection *getCompactUnwindSection() const{
195     return CompactUnwindSection;
196   }
getDwarfAccelNamesSection()197   const MCSection *getDwarfAccelNamesSection() const {
198     return DwarfAccelNamesSection;
199   }
getDwarfAccelObjCSection()200   const MCSection *getDwarfAccelObjCSection() const {
201     return DwarfAccelObjCSection;
202   }
getDwarfAccelNamespaceSection()203   const MCSection *getDwarfAccelNamespaceSection() const {
204     return DwarfAccelNamespaceSection;
205   }
getDwarfAccelTypesSection()206   const MCSection *getDwarfAccelTypesSection() const {
207     return DwarfAccelTypesSection;
208   }
getDwarfAbbrevSection()209   const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
getDwarfInfoSection()210   const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
getDwarfLineSection()211   const MCSection *getDwarfLineSection() const { return DwarfLineSection; }
getDwarfFrameSection()212   const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
getDwarfPubTypesSection()213   const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;}
getDwarfDebugInlineSection()214   const MCSection *getDwarfDebugInlineSection() const {
215     return DwarfDebugInlineSection;
216   }
getDwarfStrSection()217   const MCSection *getDwarfStrSection() const { return DwarfStrSection; }
getDwarfLocSection()218   const MCSection *getDwarfLocSection() const { return DwarfLocSection; }
getDwarfARangesSection()219   const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;}
getDwarfRangesSection()220   const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
getDwarfMacroInfoSection()221   const MCSection *getDwarfMacroInfoSection() const {
222     return DwarfMacroInfoSection;
223   }
getTLSExtraDataSection()224   const MCSection *getTLSExtraDataSection() const {
225     return TLSExtraDataSection;
226   }
getTLSDataSection()227   const MCSection *getTLSDataSection() const { return TLSDataSection; }
getTLSBSSSection()228   const MCSection *getTLSBSSSection() const { return TLSBSSSection; }
229 
230   /// ELF specific sections.
231   ///
getDataRelSection()232   const MCSection *getDataRelSection() const { return DataRelSection; }
getDataRelLocalSection()233   const MCSection *getDataRelLocalSection() const {
234     return DataRelLocalSection;
235   }
getDataRelROSection()236   const MCSection *getDataRelROSection() const { return DataRelROSection; }
getDataRelROLocalSection()237   const MCSection *getDataRelROLocalSection() const {
238     return DataRelROLocalSection;
239   }
getMergeableConst4Section()240   const MCSection *getMergeableConst4Section() const {
241     return MergeableConst4Section;
242   }
getMergeableConst8Section()243   const MCSection *getMergeableConst8Section() const {
244     return MergeableConst8Section;
245   }
getMergeableConst16Section()246   const MCSection *getMergeableConst16Section() const {
247     return MergeableConst16Section;
248   }
249 
250   /// MachO specific sections.
251   ///
getTLSTLVSection()252   const MCSection *getTLSTLVSection() const { return TLSTLVSection; }
getTLSThreadInitSection()253   const MCSection *getTLSThreadInitSection() const {
254     return TLSThreadInitSection;
255   }
getCStringSection()256   const MCSection *getCStringSection() const { return CStringSection; }
getUStringSection()257   const MCSection *getUStringSection() const { return UStringSection; }
getTextCoalSection()258   const MCSection *getTextCoalSection() const { return TextCoalSection; }
getConstTextCoalSection()259   const MCSection *getConstTextCoalSection() const {
260     return ConstTextCoalSection;
261   }
getConstDataSection()262   const MCSection *getConstDataSection() const { return ConstDataSection; }
getDataCoalSection()263   const MCSection *getDataCoalSection() const { return DataCoalSection; }
getDataCommonSection()264   const MCSection *getDataCommonSection() const { return DataCommonSection; }
getDataBSSSection()265   const MCSection *getDataBSSSection() const { return DataBSSSection; }
getFourByteConstantSection()266   const MCSection *getFourByteConstantSection() const {
267     return FourByteConstantSection;
268   }
getEightByteConstantSection()269   const MCSection *getEightByteConstantSection() const {
270     return EightByteConstantSection;
271   }
getSixteenByteConstantSection()272   const MCSection *getSixteenByteConstantSection() const {
273     return SixteenByteConstantSection;
274   }
getLazySymbolPointerSection()275   const MCSection *getLazySymbolPointerSection() const {
276     return LazySymbolPointerSection;
277   }
getNonLazySymbolPointerSection()278   const MCSection *getNonLazySymbolPointerSection() const {
279     return NonLazySymbolPointerSection;
280   }
281 
282   /// COFF specific sections.
283   ///
getDrectveSection()284   const MCSection *getDrectveSection() const { return DrectveSection; }
getPDataSection()285   const MCSection *getPDataSection() const { return PDataSection; }
getXDataSection()286   const MCSection *getXDataSection() const { return XDataSection; }
287 
getEHFrameSection()288   const MCSection *getEHFrameSection() {
289     if (!EHFrameSection)
290       InitEHFrameSection();
291     return EHFrameSection;
292   }
293 
294 private:
295   enum Environment { IsMachO, IsELF, IsCOFF };
296   Environment Env;
297   Reloc::Model RelocM;
298   CodeModel::Model CMModel;
299   MCContext *Ctx;
300 
301   void InitMachOMCObjectFileInfo(Triple T);
302   void InitELFMCObjectFileInfo(Triple T);
303   void InitCOFFMCObjectFileInfo(Triple T);
304 
305   /// InitEHFrameSection - Initialize EHFrameSection on demand.
306   ///
307   void InitEHFrameSection();
308 };
309 
310 } // end namespace llvm
311 
312 #endif
313