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