• 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/MC/MCCodeGenInfo.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/MC/SectionKind.h"
20 
21 namespace llvm {
22 class MCContext;
23 class MCSection;
24 class Triple;
25 
26 class MCObjectFileInfo {
27 protected:
28   /// CommDirectiveSupportsAlignment - True if .comm supports alignment.  This
29   /// is a hack for as long as we support 10.4 Tiger, whose assembler doesn't
30   /// support alignment on comm.
31   bool CommDirectiveSupportsAlignment;
32 
33   /// SupportsWeakEmptyEHFrame - True if target object file supports a
34   /// weak_definition of constant 0 for an omitted EH frame.
35   bool SupportsWeakOmittedEHFrame;
36 
37   /// IsFunctionEHFrameSymbolPrivate - This flag is set to true if the
38   /// "EH_frame" symbol for EH information should be an assembler temporary (aka
39   /// private linkage, aka an L or .L label) or false if it should be a normal
40   /// non-.globl label.  This defaults to true.
41   bool IsFunctionEHFrameSymbolPrivate;
42 
43 
44   /// TextSection - Section directive for standard text.
45   ///
46   const MCSection *TextSection;
47 
48   /// DataSection - Section directive for standard data.
49   ///
50   const MCSection *DataSection;
51 
52   /// BSSSection - Section that is default initialized to zero.
53   const MCSection *BSSSection;
54 
55   /// ReadOnlySection - Section that is readonly and can contain arbitrary
56   /// initialized data.  Targets are not required to have a readonly section.
57   /// If they don't, various bits of code will fall back to using the data
58   /// section for constants.
59   const MCSection *ReadOnlySection;
60 
61   /// StaticCtorSection - This section contains the static constructor pointer
62   /// list.
63   const MCSection *StaticCtorSection;
64 
65   /// StaticDtorSection - This section contains the static destructor pointer
66   /// list.
67   const MCSection *StaticDtorSection;
68 
69   /// LSDASection - If exception handling is supported by the target, this is
70   /// the section the Language Specific Data Area information is emitted to.
71   const MCSection *LSDASection;
72 
73   /// CompactUnwindSection - If exception handling is supported by the target
74   /// and the target can support a compact representation of the CIE and FDE,
75   /// this is the section to emit them into.
76   const MCSection *CompactUnwindSection;
77 
78   // Dwarf sections for debug info.  If a target supports debug info, these must
79   // be set.
80   const MCSection *DwarfAbbrevSection;
81   const MCSection *DwarfInfoSection;
82   const MCSection *DwarfLineSection;
83   const MCSection *DwarfFrameSection;
84   const MCSection *DwarfPubNamesSection;
85   const MCSection *DwarfPubTypesSection;
86   const MCSection *DwarfDebugInlineSection;
87   const MCSection *DwarfStrSection;
88   const MCSection *DwarfLocSection;
89   const MCSection *DwarfARangesSection;
90   const MCSection *DwarfRangesSection;
91   const MCSection *DwarfMacroInfoSection;
92 
93   // Extra TLS Variable Data section.  If the target needs to put additional
94   // information for a TLS variable, it'll go here.
95   const MCSection *TLSExtraDataSection;
96 
97   /// TLSDataSection - Section directive for Thread Local data.
98   /// ELF and MachO only.
99   const MCSection *TLSDataSection;        // Defaults to ".tdata".
100 
101   /// TLSBSSSection - Section directive for Thread Local uninitialized data.
102   /// Null if this target doesn't support a BSS section.
103   /// ELF and MachO only.
104   const MCSection *TLSBSSSection;         // Defaults to ".tbss".
105 
106 
107   /// EHFrameSection - EH frame section. It is initialized on demand so it
108   /// can be overwritten (with uniquing).
109   const MCSection *EHFrameSection;
110 
111   /// ELF specific sections.
112   ///
113   const MCSection *DataRelSection;
114   const MCSection *DataRelLocalSection;
115   const MCSection *DataRelROSection;
116   const MCSection *DataRelROLocalSection;
117   const MCSection *MergeableConst4Section;
118   const MCSection *MergeableConst8Section;
119   const MCSection *MergeableConst16Section;
120 
121   /// MachO specific sections.
122   ///
123 
124   /// TLSTLVSection - Section for thread local structure information.
125   /// Contains the source code name of the variable, visibility and a pointer
126   /// to the initial value (.tdata or .tbss).
127   const MCSection *TLSTLVSection;         // Defaults to ".tlv".
128 
129   /// TLSThreadInitSection - Section for thread local data initialization
130   /// functions.
131   const MCSection *TLSThreadInitSection;  // Defaults to ".thread_init_func".
132 
133   const MCSection *CStringSection;
134   const MCSection *UStringSection;
135   const MCSection *TextCoalSection;
136   const MCSection *ConstTextCoalSection;
137   const MCSection *ConstDataSection;
138   const MCSection *DataCoalSection;
139   const MCSection *DataCommonSection;
140   const MCSection *DataBSSSection;
141   const MCSection *FourByteConstantSection;
142   const MCSection *EightByteConstantSection;
143   const MCSection *SixteenByteConstantSection;
144   const MCSection *LazySymbolPointerSection;
145   const MCSection *NonLazySymbolPointerSection;
146 
147   /// COFF specific sections.
148   ///
149   const MCSection *DrectveSection;
150   const MCSection *PDataSection;
151   const MCSection *XDataSection;
152 
153 public:
154   void InitMCObjectFileInfo(StringRef TT, Reloc::Model RM, MCContext &ctx);
155 
isFunctionEHFrameSymbolPrivate()156   bool isFunctionEHFrameSymbolPrivate() const {
157     return IsFunctionEHFrameSymbolPrivate;
158   }
getSupportsWeakOmittedEHFrame()159   bool getSupportsWeakOmittedEHFrame() const {
160     return SupportsWeakOmittedEHFrame;
161   }
getCommDirectiveSupportsAlignment()162   bool getCommDirectiveSupportsAlignment() const {
163     return CommDirectiveSupportsAlignment;
164   }
165 
getTextSection()166   const MCSection *getTextSection() const { return TextSection; }
getDataSection()167   const MCSection *getDataSection() const { return DataSection; }
getBSSSection()168   const MCSection *getBSSSection() const { return BSSSection; }
getStaticCtorSection()169   const MCSection *getStaticCtorSection() const { return StaticCtorSection; }
getStaticDtorSection()170   const MCSection *getStaticDtorSection() const { return StaticDtorSection; }
getLSDASection()171   const MCSection *getLSDASection() const { return LSDASection; }
getCompactUnwindSection()172   const MCSection *getCompactUnwindSection() const{
173     return CompactUnwindSection;
174   }
getDwarfAbbrevSection()175   const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
getDwarfInfoSection()176   const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
getDwarfLineSection()177   const MCSection *getDwarfLineSection() const { return DwarfLineSection; }
getDwarfFrameSection()178   const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
getDwarfPubNamesSection()179   const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;}
getDwarfPubTypesSection()180   const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;}
getDwarfDebugInlineSection()181   const MCSection *getDwarfDebugInlineSection() const {
182     return DwarfDebugInlineSection;
183   }
getDwarfStrSection()184   const MCSection *getDwarfStrSection() const { return DwarfStrSection; }
getDwarfLocSection()185   const MCSection *getDwarfLocSection() const { return DwarfLocSection; }
getDwarfARangesSection()186   const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;}
getDwarfRangesSection()187   const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
getDwarfMacroInfoSection()188   const MCSection *getDwarfMacroInfoSection() const {
189     return DwarfMacroInfoSection;
190   }
getTLSExtraDataSection()191   const MCSection *getTLSExtraDataSection() const {
192     return TLSExtraDataSection;
193   }
getTLSDataSection()194   const MCSection *getTLSDataSection() const { return TLSDataSection; }
getTLSBSSSection()195   const MCSection *getTLSBSSSection() const { return TLSBSSSection; }
196 
197   /// ELF specific sections.
198   ///
getDataRelSection()199   const MCSection *getDataRelSection() const { return DataRelSection; }
getDataRelLocalSection()200   const MCSection *getDataRelLocalSection() const {
201     return DataRelLocalSection;
202   }
getDataRelROSection()203   const MCSection *getDataRelROSection() const { return DataRelROSection; }
getDataRelROLocalSection()204   const MCSection *getDataRelROLocalSection() const {
205     return DataRelROLocalSection;
206   }
getMergeableConst4Section()207   const MCSection *getMergeableConst4Section() const {
208     return MergeableConst4Section;
209   }
getMergeableConst8Section()210   const MCSection *getMergeableConst8Section() const {
211     return MergeableConst8Section;
212   }
getMergeableConst16Section()213   const MCSection *getMergeableConst16Section() const {
214     return MergeableConst16Section;
215   }
216 
217   /// MachO specific sections.
218   ///
getTLSTLVSection()219   const MCSection *getTLSTLVSection() const { return TLSTLVSection; }
getTLSThreadInitSection()220   const MCSection *getTLSThreadInitSection() const {
221     return TLSThreadInitSection;
222   }
getCStringSection()223   const MCSection *getCStringSection() const { return CStringSection; }
getUStringSection()224   const MCSection *getUStringSection() const { return UStringSection; }
getTextCoalSection()225   const MCSection *getTextCoalSection() const { return TextCoalSection; }
getConstTextCoalSection()226   const MCSection *getConstTextCoalSection() const {
227     return ConstTextCoalSection;
228   }
getConstDataSection()229   const MCSection *getConstDataSection() const { return ConstDataSection; }
getDataCoalSection()230   const MCSection *getDataCoalSection() const { return DataCoalSection; }
getDataCommonSection()231   const MCSection *getDataCommonSection() const { return DataCommonSection; }
getDataBSSSection()232   const MCSection *getDataBSSSection() const { return DataBSSSection; }
getFourByteConstantSection()233   const MCSection *getFourByteConstantSection() const {
234     return FourByteConstantSection;
235   }
getEightByteConstantSection()236   const MCSection *getEightByteConstantSection() const {
237     return EightByteConstantSection;
238   }
getSixteenByteConstantSection()239   const MCSection *getSixteenByteConstantSection() const {
240     return SixteenByteConstantSection;
241   }
getLazySymbolPointerSection()242   const MCSection *getLazySymbolPointerSection() const {
243     return LazySymbolPointerSection;
244   }
getNonLazySymbolPointerSection()245   const MCSection *getNonLazySymbolPointerSection() const {
246     return NonLazySymbolPointerSection;
247   }
248 
249   /// COFF specific sections.
250   ///
getDrectveSection()251   const MCSection *getDrectveSection() const { return DrectveSection; }
getPDataSection()252   const MCSection *getPDataSection() const { return PDataSection; }
getXDataSection()253   const MCSection *getXDataSection() const { return XDataSection; }
254 
getEHFrameSection()255   const MCSection *getEHFrameSection() {
256     if (!EHFrameSection)
257       InitEHFrameSection();
258     return EHFrameSection;
259   }
260 
261 private:
262   enum Environment { IsMachO, IsELF, IsCOFF };
263   Environment Env;
264   Reloc::Model RelocM;
265   MCContext *Ctx;
266 
267   void InitMachOMCObjectFileInfo(Triple T);
268   void InitELFMCObjectFileInfo(Triple T);
269   void InitCOFFMCObjectFileInfo(Triple T);
270 
271   /// InitEHFrameSection - Initialize EHFrameSection on demand.
272   ///
273   void InitEHFrameSection();
274 };
275 
276 } // end namespace llvm
277 
278 #endif
279