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