LLVM API Documentation

MCObjectFileInfo.h
Go to the documentation of this file.
00001 //===-- llvm/MC/MCObjectFileInfo.h - Object File Info -----------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file describes common object file formats.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_MC_MCBJECTFILEINFO_H
00015 #define LLVM_MC_MCBJECTFILEINFO_H
00016 
00017 #include "llvm/Support/CodeGen.h"
00018 
00019 namespace llvm {
00020   class MCContext;
00021   class MCSection;
00022   class StringRef;
00023   class Triple;
00024 
00025 class MCObjectFileInfo {
00026 protected:
00027   /// CommDirectiveSupportsAlignment - True if .comm supports alignment.  This
00028   /// is a hack for as long as we support 10.4 Tiger, whose assembler doesn't
00029   /// support alignment on comm.
00030   bool CommDirectiveSupportsAlignment;
00031 
00032   /// SupportsWeakEmptyEHFrame - True if target object file supports a
00033   /// weak_definition of constant 0 for an omitted EH frame.
00034   bool SupportsWeakOmittedEHFrame;
00035 
00036   /// IsFunctionEHFrameSymbolPrivate - This flag is set to true if the
00037   /// "EH_frame" symbol for EH information should be an assembler temporary (aka
00038   /// private linkage, aka an L or .L label) or false if it should be a normal
00039   /// non-.globl label.  This defaults to true.
00040   bool IsFunctionEHFrameSymbolPrivate;
00041 
00042   /// PersonalityEncoding, LSDAEncoding, FDEEncoding, TTypeEncoding - Some
00043   /// encoding values for EH.
00044   unsigned PersonalityEncoding;
00045   unsigned LSDAEncoding;
00046   unsigned FDEEncoding;
00047   unsigned FDECFIEncoding;
00048   unsigned TTypeEncoding;
00049 
00050   /// Section flags for eh_frame
00051   unsigned EHSectionType;
00052   unsigned EHSectionFlags;
00053 
00054   /// CompactUnwindDwarfEHFrameOnly - Compact unwind encoding indicating that we
00055   /// should emit only an EH frame.
00056   unsigned CompactUnwindDwarfEHFrameOnly;
00057 
00058   /// TextSection - Section directive for standard text.
00059   ///
00060   const MCSection *TextSection;
00061 
00062   /// DataSection - Section directive for standard data.
00063   ///
00064   const MCSection *DataSection;
00065 
00066   /// BSSSection - Section that is default initialized to zero.
00067   const MCSection *BSSSection;
00068 
00069   /// ReadOnlySection - Section that is readonly and can contain arbitrary
00070   /// initialized data.  Targets are not required to have a readonly section.
00071   /// If they don't, various bits of code will fall back to using the data
00072   /// section for constants.
00073   const MCSection *ReadOnlySection;
00074 
00075   /// StaticCtorSection - This section contains the static constructor pointer
00076   /// list.
00077   const MCSection *StaticCtorSection;
00078 
00079   /// StaticDtorSection - This section contains the static destructor pointer
00080   /// list.
00081   const MCSection *StaticDtorSection;
00082 
00083   /// LSDASection - If exception handling is supported by the target, this is
00084   /// the section the Language Specific Data Area information is emitted to.
00085   const MCSection *LSDASection;
00086 
00087   /// CompactUnwindSection - If exception handling is supported by the target
00088   /// and the target can support a compact representation of the CIE and FDE,
00089   /// this is the section to emit them into.
00090   const MCSection *CompactUnwindSection;
00091 
00092   // Dwarf sections for debug info.  If a target supports debug info, these must
00093   // be set.
00094   const MCSection *DwarfAbbrevSection;
00095   const MCSection *DwarfInfoSection;
00096   const MCSection *DwarfLineSection;
00097   const MCSection *DwarfFrameSection;
00098   const MCSection *DwarfPubTypesSection;
00099   const MCSection *DwarfDebugInlineSection;
00100   const MCSection *DwarfStrSection;
00101   const MCSection *DwarfLocSection;
00102   const MCSection *DwarfARangesSection;
00103   const MCSection *DwarfRangesSection;
00104   const MCSection *DwarfMacroInfoSection;
00105   // The pubnames section is no longer generated by default.  The generation
00106   // can be enabled by a compiler flag.
00107   const MCSection *DwarfPubNamesSection;
00108 
00109   // DWARF5 Experimental Debug Info Sections
00110   /// DwarfAccelNamesSection, DwarfAccelObjCSection,
00111   /// DwarfAccelNamespaceSection, DwarfAccelTypesSection -
00112   /// If we use the DWARF accelerated hash tables then we want to emit these
00113   /// sections.
00114   const MCSection *DwarfAccelNamesSection;
00115   const MCSection *DwarfAccelObjCSection;
00116   const MCSection *DwarfAccelNamespaceSection;
00117   const MCSection *DwarfAccelTypesSection;
00118 
00119   /// These are used for the Fission separate debug information files.
00120   const MCSection *DwarfInfoDWOSection;
00121   const MCSection *DwarfAbbrevDWOSection;
00122   const MCSection *DwarfStrDWOSection;
00123   const MCSection *DwarfLineDWOSection;
00124   const MCSection *DwarfLocDWOSection;
00125   const MCSection *DwarfStrOffDWOSection;
00126   const MCSection *DwarfAddrSection;
00127 
00128   // Extra TLS Variable Data section.  If the target needs to put additional
00129   // information for a TLS variable, it'll go here.
00130   const MCSection *TLSExtraDataSection;
00131 
00132   /// TLSDataSection - Section directive for Thread Local data.
00133   /// ELF, MachO and COFF.
00134   const MCSection *TLSDataSection;        // Defaults to ".tdata".
00135 
00136   /// TLSBSSSection - Section directive for Thread Local uninitialized data.
00137   /// Null if this target doesn't support a BSS section.
00138   /// ELF and MachO only.
00139   const MCSection *TLSBSSSection;         // Defaults to ".tbss".
00140 
00141 
00142   /// EHFrameSection - EH frame section. It is initialized on demand so it
00143   /// can be overwritten (with uniquing).
00144   const MCSection *EHFrameSection;
00145 
00146   /// ELF specific sections.
00147   ///
00148   const MCSection *DataRelSection;
00149   const MCSection *DataRelLocalSection;
00150   const MCSection *DataRelROSection;
00151   const MCSection *DataRelROLocalSection;
00152   const MCSection *MergeableConst4Section;
00153   const MCSection *MergeableConst8Section;
00154   const MCSection *MergeableConst16Section;
00155 
00156   /// MachO specific sections.
00157   ///
00158 
00159   /// TLSTLVSection - Section for thread local structure information.
00160   /// Contains the source code name of the variable, visibility and a pointer
00161   /// to the initial value (.tdata or .tbss).
00162   const MCSection *TLSTLVSection;         // Defaults to ".tlv".
00163 
00164   /// TLSThreadInitSection - Section for thread local data initialization
00165   /// functions.
00166   const MCSection *TLSThreadInitSection;  // Defaults to ".thread_init_func".
00167 
00168   const MCSection *CStringSection;
00169   const MCSection *UStringSection;
00170   const MCSection *TextCoalSection;
00171   const MCSection *ConstTextCoalSection;
00172   const MCSection *ConstDataSection;
00173   const MCSection *DataCoalSection;
00174   const MCSection *DataCommonSection;
00175   const MCSection *DataBSSSection;
00176   const MCSection *FourByteConstantSection;
00177   const MCSection *EightByteConstantSection;
00178   const MCSection *SixteenByteConstantSection;
00179   const MCSection *LazySymbolPointerSection;
00180   const MCSection *NonLazySymbolPointerSection;
00181 
00182   /// COFF specific sections.
00183   ///
00184   const MCSection *DrectveSection;
00185   const MCSection *PDataSection;
00186   const MCSection *XDataSection;
00187 
00188 public:
00189   void InitMCObjectFileInfo(StringRef TT, Reloc::Model RM, CodeModel::Model CM,
00190                             MCContext &ctx);
00191 
00192   bool isFunctionEHFrameSymbolPrivate() const {
00193     return IsFunctionEHFrameSymbolPrivate;
00194   }
00195   bool getSupportsWeakOmittedEHFrame() const {
00196     return SupportsWeakOmittedEHFrame;
00197   }
00198   bool getCommDirectiveSupportsAlignment() const {
00199     return CommDirectiveSupportsAlignment;
00200   }
00201 
00202   unsigned getPersonalityEncoding() const { return PersonalityEncoding; }
00203   unsigned getLSDAEncoding() const { return LSDAEncoding; }
00204   unsigned getFDEEncoding(bool CFI) const {
00205     return CFI ? FDECFIEncoding : FDEEncoding;
00206   }
00207   unsigned getTTypeEncoding() const { return TTypeEncoding; }
00208 
00209   unsigned getCompactUnwindDwarfEHFrameOnly() const {
00210     return CompactUnwindDwarfEHFrameOnly;
00211   }
00212 
00213   const MCSection *getTextSection() const { return TextSection; }
00214   const MCSection *getDataSection() const { return DataSection; }
00215   const MCSection *getBSSSection() const { return BSSSection; }
00216   const MCSection *getLSDASection() const { return LSDASection; }
00217   const MCSection *getCompactUnwindSection() const{
00218     return CompactUnwindSection;
00219   }
00220   const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
00221   const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
00222   const MCSection *getDwarfLineSection() const { return DwarfLineSection; }
00223   const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
00224   const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;}
00225   const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;}
00226   const MCSection *getDwarfDebugInlineSection() const {
00227     return DwarfDebugInlineSection;
00228   }
00229   const MCSection *getDwarfStrSection() const { return DwarfStrSection; }
00230   const MCSection *getDwarfLocSection() const { return DwarfLocSection; }
00231   const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;}
00232   const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
00233   const MCSection *getDwarfMacroInfoSection() const {
00234     return DwarfMacroInfoSection;
00235   }
00236 
00237   // DWARF5 Experimental Debug Info Sections
00238   const MCSection *getDwarfAccelNamesSection() const {
00239     return DwarfAccelNamesSection;
00240   }
00241   const MCSection *getDwarfAccelObjCSection() const {
00242     return DwarfAccelObjCSection;
00243   }
00244   const MCSection *getDwarfAccelNamespaceSection() const {
00245     return DwarfAccelNamespaceSection;
00246   }
00247   const MCSection *getDwarfAccelTypesSection() const {
00248     return DwarfAccelTypesSection;
00249   }
00250   const MCSection *getDwarfInfoDWOSection() const {
00251     return DwarfInfoDWOSection;
00252   }
00253   const MCSection *getDwarfAbbrevDWOSection() const {
00254     return DwarfAbbrevDWOSection;
00255   }
00256   const MCSection *getDwarfStrDWOSection() const {
00257     return DwarfStrDWOSection;
00258   }
00259   const MCSection *getDwarfLineDWOSection() const {
00260     return DwarfLineDWOSection;
00261   }
00262   const MCSection *getDwarfLocDWOSection() const {
00263     return DwarfLocDWOSection;
00264   }
00265   const MCSection *getDwarfStrOffDWOSection() const {
00266     return DwarfStrOffDWOSection;
00267   }
00268   const MCSection *getDwarfAddrSection() const {
00269     return DwarfAddrSection;
00270   }
00271 
00272   const MCSection *getTLSExtraDataSection() const {
00273     return TLSExtraDataSection;
00274   }
00275   const MCSection *getTLSDataSection() const { return TLSDataSection; }
00276   const MCSection *getTLSBSSSection() const { return TLSBSSSection; }
00277 
00278   /// ELF specific sections.
00279   ///
00280   const MCSection *getDataRelSection() const { return DataRelSection; }
00281   const MCSection *getDataRelLocalSection() const {
00282     return DataRelLocalSection;
00283   }
00284   const MCSection *getDataRelROSection() const { return DataRelROSection; }
00285   const MCSection *getDataRelROLocalSection() const {
00286     return DataRelROLocalSection;
00287   }
00288   const MCSection *getMergeableConst4Section() const {
00289     return MergeableConst4Section;
00290   }
00291   const MCSection *getMergeableConst8Section() const {
00292     return MergeableConst8Section;
00293   }
00294   const MCSection *getMergeableConst16Section() const {
00295     return MergeableConst16Section;
00296   }
00297 
00298   /// MachO specific sections.
00299   ///
00300   const MCSection *getTLSTLVSection() const { return TLSTLVSection; }
00301   const MCSection *getTLSThreadInitSection() const {
00302     return TLSThreadInitSection;
00303   }
00304   const MCSection *getCStringSection() const { return CStringSection; }
00305   const MCSection *getUStringSection() const { return UStringSection; }
00306   const MCSection *getTextCoalSection() const { return TextCoalSection; }
00307   const MCSection *getConstTextCoalSection() const {
00308     return ConstTextCoalSection;
00309   }
00310   const MCSection *getConstDataSection() const { return ConstDataSection; }
00311   const MCSection *getDataCoalSection() const { return DataCoalSection; }
00312   const MCSection *getDataCommonSection() const { return DataCommonSection; }
00313   const MCSection *getDataBSSSection() const { return DataBSSSection; }
00314   const MCSection *getFourByteConstantSection() const {
00315     return FourByteConstantSection;
00316   }
00317   const MCSection *getEightByteConstantSection() const {
00318     return EightByteConstantSection;
00319   }
00320   const MCSection *getSixteenByteConstantSection() const {
00321     return SixteenByteConstantSection;
00322   }
00323   const MCSection *getLazySymbolPointerSection() const {
00324     return LazySymbolPointerSection;
00325   }
00326   const MCSection *getNonLazySymbolPointerSection() const {
00327     return NonLazySymbolPointerSection;
00328   }
00329 
00330   /// COFF specific sections.
00331   ///
00332   const MCSection *getDrectveSection() const { return DrectveSection; }
00333   const MCSection *getPDataSection() const { return PDataSection; }
00334   const MCSection *getXDataSection() const { return XDataSection; }
00335 
00336   const MCSection *getEHFrameSection() {
00337     if (!EHFrameSection)
00338       InitEHFrameSection();
00339     return EHFrameSection;
00340   }
00341 
00342 private:
00343   enum Environment { IsMachO, IsELF, IsCOFF };
00344   Environment Env;
00345   Reloc::Model RelocM;
00346   CodeModel::Model CMModel;
00347   MCContext *Ctx;
00348 
00349   void InitMachOMCObjectFileInfo(Triple T);
00350   void InitELFMCObjectFileInfo(Triple T);
00351   void InitCOFFMCObjectFileInfo(Triple T);
00352 
00353   /// InitEHFrameSection - Initialize EHFrameSection on demand.
00354   ///
00355   void InitEHFrameSection();
00356 };
00357 
00358 } // end namespace llvm
00359 
00360 #endif