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