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