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