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   /// SupportsCompactUnwindWithoutEHFrame - True if the target object file
00043   /// supports emitting a compact unwind section without an associated EH frame
00044   /// section.
00045   bool SupportsCompactUnwindWithoutEHFrame;
00046 
00047   /// PersonalityEncoding, LSDAEncoding, FDEEncoding, TTypeEncoding - Some
00048   /// encoding values for EH.
00049   unsigned PersonalityEncoding;
00050   unsigned LSDAEncoding;
00051   unsigned FDEEncoding;
00052   unsigned FDECFIEncoding;
00053   unsigned TTypeEncoding;
00054 
00055   /// Section flags for eh_frame
00056   unsigned EHSectionType;
00057   unsigned EHSectionFlags;
00058 
00059   /// CompactUnwindDwarfEHFrameOnly - Compact unwind encoding indicating that we
00060   /// should emit only an EH frame.
00061   unsigned CompactUnwindDwarfEHFrameOnly;
00062 
00063   /// TextSection - Section directive for standard text.
00064   ///
00065   const MCSection *TextSection;
00066 
00067   /// DataSection - Section directive for standard data.
00068   ///
00069   const MCSection *DataSection;
00070 
00071   /// BSSSection - Section that is default initialized to zero.
00072   const MCSection *BSSSection;
00073 
00074   /// ReadOnlySection - Section that is readonly and can contain arbitrary
00075   /// initialized data.  Targets are not required to have a readonly section.
00076   /// If they don't, various bits of code will fall back to using the data
00077   /// section for constants.
00078   const MCSection *ReadOnlySection;
00079 
00080   /// StaticCtorSection - This section contains the static constructor pointer
00081   /// list.
00082   const MCSection *StaticCtorSection;
00083 
00084   /// StaticDtorSection - This section contains the static destructor pointer
00085   /// list.
00086   const MCSection *StaticDtorSection;
00087 
00088   /// LSDASection - If exception handling is supported by the target, this is
00089   /// the section the Language Specific Data Area information is emitted to.
00090   const MCSection *LSDASection;
00091 
00092   /// CompactUnwindSection - If exception handling is supported by the target
00093   /// and the target can support a compact representation of the CIE and FDE,
00094   /// this is the section to emit them into.
00095   const MCSection *CompactUnwindSection;
00096 
00097   // Dwarf sections for debug info.  If a target supports debug info, these must
00098   // be set.
00099   const MCSection *DwarfAbbrevSection;
00100   const MCSection *DwarfInfoSection;
00101   const MCSection *DwarfLineSection;
00102   const MCSection *DwarfFrameSection;
00103   const MCSection *DwarfPubTypesSection;
00104   const MCSection *DwarfDebugInlineSection;
00105   const MCSection *DwarfStrSection;
00106   const MCSection *DwarfLocSection;
00107   const MCSection *DwarfARangesSection;
00108   const MCSection *DwarfRangesSection;
00109   const MCSection *DwarfMacroInfoSection;
00110   // The pubnames section is no longer generated by default.  The generation
00111   // can be enabled by a compiler flag.
00112   const MCSection *DwarfPubNamesSection;
00113 
00114   // DWARF5 Experimental Debug Info Sections
00115   /// DwarfAccelNamesSection, DwarfAccelObjCSection,
00116   /// DwarfAccelNamespaceSection, DwarfAccelTypesSection -
00117   /// If we use the DWARF accelerated hash tables then we want to emit these
00118   /// sections.
00119   const MCSection *DwarfAccelNamesSection;
00120   const MCSection *DwarfAccelObjCSection;
00121   const MCSection *DwarfAccelNamespaceSection;
00122   const MCSection *DwarfAccelTypesSection;
00123 
00124   /// These are used for the Fission separate debug information files.
00125   const MCSection *DwarfInfoDWOSection;
00126   const MCSection *DwarfAbbrevDWOSection;
00127   const MCSection *DwarfStrDWOSection;
00128   const MCSection *DwarfLineDWOSection;
00129   const MCSection *DwarfLocDWOSection;
00130   const MCSection *DwarfStrOffDWOSection;
00131   const MCSection *DwarfAddrSection;
00132 
00133   /// Sections for newer gnu pubnames and pubtypes.
00134   const MCSection *DwarfGnuPubNamesSection;
00135   const MCSection *DwarfGnuPubTypesSection;
00136 
00137   const MCSection *COFFDebugSymbolsSection;
00138 
00139   // Extra TLS Variable Data section.  If the target needs to put additional
00140   // information for a TLS variable, it'll go here.
00141   const MCSection *TLSExtraDataSection;
00142 
00143   /// TLSDataSection - Section directive for Thread Local data.
00144   /// ELF, MachO and COFF.
00145   const MCSection *TLSDataSection;        // Defaults to ".tdata".
00146 
00147   /// TLSBSSSection - Section directive for Thread Local uninitialized data.
00148   /// Null if this target doesn't support a BSS section.
00149   /// ELF and MachO only.
00150   const MCSection *TLSBSSSection;         // Defaults to ".tbss".
00151 
00152   /// StackMap section.
00153   const MCSection *StackMapSection;
00154 
00155   /// EHFrameSection - EH frame section. It is initialized on demand so it
00156   /// can be overwritten (with uniquing).
00157   const MCSection *EHFrameSection;
00158 
00159   /// ELF specific sections.
00160   ///
00161   const MCSection *DataRelSection;
00162   const MCSection *DataRelLocalSection;
00163   const MCSection *DataRelROSection;
00164   const MCSection *DataRelROLocalSection;
00165   const MCSection *MergeableConst4Section;
00166   const MCSection *MergeableConst8Section;
00167   const MCSection *MergeableConst16Section;
00168 
00169   /// MachO specific sections.
00170   ///
00171 
00172   /// TLSTLVSection - Section for thread local structure information.
00173   /// Contains the source code name of the variable, visibility and a pointer
00174   /// to the initial value (.tdata or .tbss).
00175   const MCSection *TLSTLVSection;         // Defaults to ".tlv".
00176 
00177   /// TLSThreadInitSection - Section for thread local data initialization
00178   /// functions.
00179   const MCSection *TLSThreadInitSection;  // Defaults to ".thread_init_func".
00180 
00181   const MCSection *CStringSection;
00182   const MCSection *UStringSection;
00183   const MCSection *TextCoalSection;
00184   const MCSection *ConstTextCoalSection;
00185   const MCSection *ConstDataSection;
00186   const MCSection *DataCoalSection;
00187   const MCSection *DataCommonSection;
00188   const MCSection *DataBSSSection;
00189   const MCSection *FourByteConstantSection;
00190   const MCSection *EightByteConstantSection;
00191   const MCSection *SixteenByteConstantSection;
00192   const MCSection *LazySymbolPointerSection;
00193   const MCSection *NonLazySymbolPointerSection;
00194 
00195   /// COFF specific sections.
00196   ///
00197   const MCSection *DrectveSection;
00198   const MCSection *PDataSection;
00199   const MCSection *XDataSection;
00200 
00201 public:
00202   void InitMCObjectFileInfo(StringRef TT, Reloc::Model RM, CodeModel::Model CM,
00203                             MCContext &ctx);
00204 
00205   bool isFunctionEHFrameSymbolPrivate() const {
00206     return IsFunctionEHFrameSymbolPrivate;
00207   }
00208   bool getSupportsWeakOmittedEHFrame() const {
00209     return SupportsWeakOmittedEHFrame;
00210   }
00211   bool getSupportsCompactUnwindWithoutEHFrame() const {
00212     return SupportsCompactUnwindWithoutEHFrame;
00213   }
00214   bool getCommDirectiveSupportsAlignment() const {
00215     return CommDirectiveSupportsAlignment;
00216   }
00217 
00218   unsigned getPersonalityEncoding() const { return PersonalityEncoding; }
00219   unsigned getLSDAEncoding() const { return LSDAEncoding; }
00220   unsigned getFDEEncoding(bool CFI) const {
00221     return CFI ? FDECFIEncoding : FDEEncoding;
00222   }
00223   unsigned getTTypeEncoding() const { return TTypeEncoding; }
00224 
00225   unsigned getCompactUnwindDwarfEHFrameOnly() const {
00226     return CompactUnwindDwarfEHFrameOnly;
00227   }
00228 
00229   const MCSection *getTextSection() const { return TextSection; }
00230   const MCSection *getDataSection() const { return DataSection; }
00231   const MCSection *getBSSSection() const { return BSSSection; }
00232   const MCSection *getLSDASection() const { return LSDASection; }
00233   const MCSection *getCompactUnwindSection() const{
00234     return CompactUnwindSection;
00235   }
00236   const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
00237   const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
00238   const MCSection *getDwarfLineSection() const { return DwarfLineSection; }
00239   const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
00240   const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;}
00241   const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;}
00242   const MCSection *getDwarfGnuPubNamesSection() const {
00243     return DwarfGnuPubNamesSection;
00244   }
00245   const MCSection *getDwarfGnuPubTypesSection() const {
00246     return DwarfGnuPubTypesSection;
00247   }
00248   const MCSection *getDwarfDebugInlineSection() const {
00249     return DwarfDebugInlineSection;
00250   }
00251   const MCSection *getDwarfStrSection() const { return DwarfStrSection; }
00252   const MCSection *getDwarfLocSection() const { return DwarfLocSection; }
00253   const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;}
00254   const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
00255   const MCSection *getDwarfMacroInfoSection() const {
00256     return DwarfMacroInfoSection;
00257   }
00258 
00259   // DWARF5 Experimental Debug Info Sections
00260   const MCSection *getDwarfAccelNamesSection() const {
00261     return DwarfAccelNamesSection;
00262   }
00263   const MCSection *getDwarfAccelObjCSection() const {
00264     return DwarfAccelObjCSection;
00265   }
00266   const MCSection *getDwarfAccelNamespaceSection() const {
00267     return DwarfAccelNamespaceSection;
00268   }
00269   const MCSection *getDwarfAccelTypesSection() const {
00270     return DwarfAccelTypesSection;
00271   }
00272   const MCSection *getDwarfInfoDWOSection() const {
00273     return DwarfInfoDWOSection;
00274   }
00275   const MCSection *getDwarfTypesSection(uint64_t Hash) const;
00276   const MCSection *getDwarfTypesDWOSection(uint64_t Hash) const;
00277   const MCSection *getDwarfAbbrevDWOSection() const {
00278     return DwarfAbbrevDWOSection;
00279   }
00280   const MCSection *getDwarfStrDWOSection() const {
00281     return DwarfStrDWOSection;
00282   }
00283   const MCSection *getDwarfLineDWOSection() const {
00284     return DwarfLineDWOSection;
00285   }
00286   const MCSection *getDwarfLocDWOSection() const {
00287     return DwarfLocDWOSection;
00288   }
00289   const MCSection *getDwarfStrOffDWOSection() const {
00290     return DwarfStrOffDWOSection;
00291   }
00292   const MCSection *getDwarfAddrSection() const {
00293     return DwarfAddrSection;
00294   }
00295 
00296   const MCSection *getCOFFDebugSymbolsSection() const {
00297     return COFFDebugSymbolsSection;
00298   }
00299 
00300   const MCSection *getTLSExtraDataSection() const {
00301     return TLSExtraDataSection;
00302   }
00303   const MCSection *getTLSDataSection() const { return TLSDataSection; }
00304   const MCSection *getTLSBSSSection() const { return TLSBSSSection; }
00305 
00306   const MCSection *getStackMapSection() const { return StackMapSection; }
00307 
00308   /// ELF specific sections.
00309   ///
00310   const MCSection *getDataRelSection() const { return DataRelSection; }
00311   const MCSection *getDataRelLocalSection() const {
00312     return DataRelLocalSection;
00313   }
00314   const MCSection *getDataRelROSection() const { return DataRelROSection; }
00315   const MCSection *getDataRelROLocalSection() const {
00316     return DataRelROLocalSection;
00317   }
00318   const MCSection *getMergeableConst4Section() const {
00319     return MergeableConst4Section;
00320   }
00321   const MCSection *getMergeableConst8Section() const {
00322     return MergeableConst8Section;
00323   }
00324   const MCSection *getMergeableConst16Section() const {
00325     return MergeableConst16Section;
00326   }
00327 
00328   /// MachO specific sections.
00329   ///
00330   const MCSection *getTLSTLVSection() const { return TLSTLVSection; }
00331   const MCSection *getTLSThreadInitSection() const {
00332     return TLSThreadInitSection;
00333   }
00334   const MCSection *getCStringSection() const { return CStringSection; }
00335   const MCSection *getUStringSection() const { return UStringSection; }
00336   const MCSection *getTextCoalSection() const { return TextCoalSection; }
00337   const MCSection *getConstTextCoalSection() const {
00338     return ConstTextCoalSection;
00339   }
00340   const MCSection *getConstDataSection() const { return ConstDataSection; }
00341   const MCSection *getDataCoalSection() const { return DataCoalSection; }
00342   const MCSection *getDataCommonSection() const { return DataCommonSection; }
00343   const MCSection *getDataBSSSection() const { return DataBSSSection; }
00344   const MCSection *getFourByteConstantSection() const {
00345     return FourByteConstantSection;
00346   }
00347   const MCSection *getEightByteConstantSection() const {
00348     return EightByteConstantSection;
00349   }
00350   const MCSection *getSixteenByteConstantSection() const {
00351     return SixteenByteConstantSection;
00352   }
00353   const MCSection *getLazySymbolPointerSection() const {
00354     return LazySymbolPointerSection;
00355   }
00356   const MCSection *getNonLazySymbolPointerSection() const {
00357     return NonLazySymbolPointerSection;
00358   }
00359 
00360   /// COFF specific sections.
00361   ///
00362   const MCSection *getDrectveSection() const { return DrectveSection; }
00363   const MCSection *getPDataSection() const { return PDataSection; }
00364   const MCSection *getXDataSection() const { return XDataSection; }
00365 
00366   const MCSection *getEHFrameSection() {
00367     if (!EHFrameSection)
00368       InitEHFrameSection();
00369     return EHFrameSection;
00370   }
00371 
00372   enum Environment { IsMachO, IsELF, IsCOFF };
00373   Environment getObjectFileType() const {
00374     return Env;
00375   }
00376 
00377   Reloc::Model getRelocM() const {
00378     return RelocM;
00379   }
00380 
00381 private:
00382   Environment Env;
00383   Reloc::Model RelocM;
00384   CodeModel::Model CMModel;
00385   MCContext *Ctx;
00386 
00387   void InitMachOMCObjectFileInfo(Triple T);
00388   void InitELFMCObjectFileInfo(Triple T);
00389   void InitCOFFMCObjectFileInfo(Triple T);
00390 
00391   /// InitEHFrameSection - Initialize EHFrameSection on demand.
00392   ///
00393   void InitEHFrameSection();
00394 };
00395 
00396 } // end namespace llvm
00397 
00398 #endif