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