Home | History | Annotate | Download | only in MC
      1 //===-- llvm/MC/MCObjectFileInfo.h - Object File Info -----------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file describes common object file formats.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef LLVM_MC_MCBJECTFILEINFO_H
     15 #define LLVM_MC_MCBJECTFILEINFO_H
     16 
     17 #include "llvm/Support/CodeGen.h"
     18 
     19 namespace llvm {
     20   class MCContext;
     21   class MCSection;
     22   class StringRef;
     23   class Triple;
     24 
     25 class MCObjectFileInfo {
     26 protected:
     27   /// CommDirectiveSupportsAlignment - True if .comm supports alignment.  This
     28   /// is a hack for as long as we support 10.4 Tiger, whose assembler doesn't
     29   /// support alignment on comm.
     30   bool CommDirectiveSupportsAlignment;
     31 
     32   /// SupportsWeakEmptyEHFrame - True if target object file supports a
     33   /// weak_definition of constant 0 for an omitted EH frame.
     34   bool SupportsWeakOmittedEHFrame;
     35 
     36   /// IsFunctionEHFrameSymbolPrivate - This flag is set to true if the
     37   /// "EH_frame" symbol for EH information should be an assembler temporary (aka
     38   /// private linkage, aka an L or .L label) or false if it should be a normal
     39   /// non-.globl label.  This defaults to true.
     40   bool IsFunctionEHFrameSymbolPrivate;
     41 
     42   /// PersonalityEncoding, LSDAEncoding, FDEEncoding, TTypeEncoding - Some
     43   /// encoding values for EH.
     44   unsigned PersonalityEncoding;
     45   unsigned LSDAEncoding;
     46   unsigned FDEEncoding;
     47   unsigned FDECFIEncoding;
     48   unsigned TTypeEncoding;
     49   // Section flags for eh_frame
     50   unsigned EHSectionType;
     51   unsigned EHSectionFlags;
     52 
     53   /// TextSection - Section directive for standard text.
     54   ///
     55   const MCSection *TextSection;
     56 
     57   /// DataSection - Section directive for standard data.
     58   ///
     59   const MCSection *DataSection;
     60 
     61   /// BSSSection - Section that is default initialized to zero.
     62   const MCSection *BSSSection;
     63 
     64   /// ReadOnlySection - Section that is readonly and can contain arbitrary
     65   /// initialized data.  Targets are not required to have a readonly section.
     66   /// If they don't, various bits of code will fall back to using the data
     67   /// section for constants.
     68   const MCSection *ReadOnlySection;
     69 
     70   /// StaticCtorSection - This section contains the static constructor pointer
     71   /// list.
     72   const MCSection *StaticCtorSection;
     73 
     74   /// StaticDtorSection - This section contains the static destructor pointer
     75   /// list.
     76   const MCSection *StaticDtorSection;
     77 
     78   /// LSDASection - If exception handling is supported by the target, this is
     79   /// the section the Language Specific Data Area information is emitted to.
     80   const MCSection *LSDASection;
     81 
     82   /// CompactUnwindSection - If exception handling is supported by the target
     83   /// and the target can support a compact representation of the CIE and FDE,
     84   /// this is the section to emit them into.
     85   const MCSection *CompactUnwindSection;
     86 
     87   // Dwarf sections for debug info.  If a target supports debug info, these must
     88   // be set.
     89   const MCSection *DwarfAbbrevSection;
     90   const MCSection *DwarfInfoSection;
     91   const MCSection *DwarfLineSection;
     92   const MCSection *DwarfFrameSection;
     93   const MCSection *DwarfPubTypesSection;
     94   const MCSection *DwarfDebugInlineSection;
     95   const MCSection *DwarfStrSection;
     96   const MCSection *DwarfLocSection;
     97   const MCSection *DwarfARangesSection;
     98   const MCSection *DwarfRangesSection;
     99   const MCSection *DwarfMacroInfoSection;
    100   // The pubnames section is no longer generated by default.  The generation
    101   // can be enabled by a compiler flag.
    102   const MCSection *DwarfPubNamesSection;
    103 
    104   // DWARF5 Experimental Debug Info Sections
    105   /// DwarfAccelNamesSection, DwarfAccelObjCSection,
    106   /// DwarfAccelNamespaceSection, DwarfAccelTypesSection -
    107   /// If we use the DWARF accelerated hash tables then we want to emit these
    108   /// sections.
    109   const MCSection *DwarfAccelNamesSection;
    110   const MCSection *DwarfAccelObjCSection;
    111   const MCSection *DwarfAccelNamespaceSection;
    112   const MCSection *DwarfAccelTypesSection;
    113 
    114   /// These are used for the Fission separate debug information files.
    115   const MCSection *DwarfInfoDWOSection;
    116   const MCSection *DwarfAbbrevDWOSection;
    117   const MCSection *DwarfStrDWOSection;
    118   const MCSection *DwarfLineDWOSection;
    119   const MCSection *DwarfLocDWOSection;
    120   const MCSection *DwarfStrOffDWOSection;
    121   const MCSection *DwarfAddrSection;
    122 
    123   // Extra TLS Variable Data section.  If the target needs to put additional
    124   // information for a TLS variable, it'll go here.
    125   const MCSection *TLSExtraDataSection;
    126 
    127   /// TLSDataSection - Section directive for Thread Local data.
    128   /// ELF, MachO and COFF.
    129   const MCSection *TLSDataSection;        // Defaults to ".tdata".
    130 
    131   /// TLSBSSSection - Section directive for Thread Local uninitialized data.
    132   /// Null if this target doesn't support a BSS section.
    133   /// ELF and MachO only.
    134   const MCSection *TLSBSSSection;         // Defaults to ".tbss".
    135 
    136 
    137   /// EHFrameSection - EH frame section. It is initialized on demand so it
    138   /// can be overwritten (with uniquing).
    139   const MCSection *EHFrameSection;
    140 
    141   /// ELF specific sections.
    142   ///
    143   const MCSection *DataRelSection;
    144   const MCSection *DataRelLocalSection;
    145   const MCSection *DataRelROSection;
    146   const MCSection *DataRelROLocalSection;
    147   const MCSection *MergeableConst4Section;
    148   const MCSection *MergeableConst8Section;
    149   const MCSection *MergeableConst16Section;
    150 
    151   /// MachO specific sections.
    152   ///
    153 
    154   /// TLSTLVSection - Section for thread local structure information.
    155   /// Contains the source code name of the variable, visibility and a pointer
    156   /// to the initial value (.tdata or .tbss).
    157   const MCSection *TLSTLVSection;         // Defaults to ".tlv".
    158 
    159   /// TLSThreadInitSection - Section for thread local data initialization
    160   /// functions.
    161   const MCSection *TLSThreadInitSection;  // Defaults to ".thread_init_func".
    162 
    163   const MCSection *CStringSection;
    164   const MCSection *UStringSection;
    165   const MCSection *TextCoalSection;
    166   const MCSection *ConstTextCoalSection;
    167   const MCSection *ConstDataSection;
    168   const MCSection *DataCoalSection;
    169   const MCSection *DataCommonSection;
    170   const MCSection *DataBSSSection;
    171   const MCSection *FourByteConstantSection;
    172   const MCSection *EightByteConstantSection;
    173   const MCSection *SixteenByteConstantSection;
    174   const MCSection *LazySymbolPointerSection;
    175   const MCSection *NonLazySymbolPointerSection;
    176 
    177   /// COFF specific sections.
    178   ///
    179   const MCSection *DrectveSection;
    180   const MCSection *PDataSection;
    181   const MCSection *XDataSection;
    182 
    183 public:
    184   void InitMCObjectFileInfo(StringRef TT, Reloc::Model RM, CodeModel::Model CM,
    185                             MCContext &ctx);
    186 
    187   bool isFunctionEHFrameSymbolPrivate() const {
    188     return IsFunctionEHFrameSymbolPrivate;
    189   }
    190   bool getSupportsWeakOmittedEHFrame() const {
    191     return SupportsWeakOmittedEHFrame;
    192   }
    193   bool getCommDirectiveSupportsAlignment() const {
    194     return CommDirectiveSupportsAlignment;
    195   }
    196 
    197   unsigned getPersonalityEncoding() const { return PersonalityEncoding; }
    198   unsigned getLSDAEncoding() const { return LSDAEncoding; }
    199   unsigned getFDEEncoding(bool CFI) const {
    200     return CFI ? FDECFIEncoding : FDEEncoding;
    201   }
    202   unsigned getTTypeEncoding() const { return TTypeEncoding; }
    203 
    204   const MCSection *getTextSection() const { return TextSection; }
    205   const MCSection *getDataSection() const { return DataSection; }
    206   const MCSection *getBSSSection() const { return BSSSection; }
    207   const MCSection *getLSDASection() const { return LSDASection; }
    208   const MCSection *getCompactUnwindSection() const{
    209     return CompactUnwindSection;
    210   }
    211   const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
    212   const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
    213   const MCSection *getDwarfLineSection() const { return DwarfLineSection; }
    214   const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
    215   const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;}
    216   const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;}
    217   const MCSection *getDwarfDebugInlineSection() const {
    218     return DwarfDebugInlineSection;
    219   }
    220   const MCSection *getDwarfStrSection() const { return DwarfStrSection; }
    221   const MCSection *getDwarfLocSection() const { return DwarfLocSection; }
    222   const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;}
    223   const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
    224   const MCSection *getDwarfMacroInfoSection() const {
    225     return DwarfMacroInfoSection;
    226   }
    227 
    228   // DWARF5 Experimental Debug Info Sections
    229   const MCSection *getDwarfAccelNamesSection() const {
    230     return DwarfAccelNamesSection;
    231   }
    232   const MCSection *getDwarfAccelObjCSection() const {
    233     return DwarfAccelObjCSection;
    234   }
    235   const MCSection *getDwarfAccelNamespaceSection() const {
    236     return DwarfAccelNamespaceSection;
    237   }
    238   const MCSection *getDwarfAccelTypesSection() const {
    239     return DwarfAccelTypesSection;
    240   }
    241   const MCSection *getDwarfInfoDWOSection() const {
    242     return DwarfInfoDWOSection;
    243   }
    244   const MCSection *getDwarfAbbrevDWOSection() const {
    245     return DwarfAbbrevDWOSection;
    246   }
    247   const MCSection *getDwarfStrDWOSection() const {
    248     return DwarfStrDWOSection;
    249   }
    250   const MCSection *getDwarfLineDWOSection() const {
    251     return DwarfLineDWOSection;
    252   }
    253   const MCSection *getDwarfLocDWOSection() const {
    254     return DwarfLocDWOSection;
    255   }
    256   const MCSection *getDwarfStrOffDWOSection() const {
    257     return DwarfStrOffDWOSection;
    258   }
    259   const MCSection *getDwarfAddrSection() const {
    260     return DwarfAddrSection;
    261   }
    262 
    263   const MCSection *getTLSExtraDataSection() const {
    264     return TLSExtraDataSection;
    265   }
    266   const MCSection *getTLSDataSection() const { return TLSDataSection; }
    267   const MCSection *getTLSBSSSection() const { return TLSBSSSection; }
    268 
    269   /// ELF specific sections.
    270   ///
    271   const MCSection *getDataRelSection() const { return DataRelSection; }
    272   const MCSection *getDataRelLocalSection() const {
    273     return DataRelLocalSection;
    274   }
    275   const MCSection *getDataRelROSection() const { return DataRelROSection; }
    276   const MCSection *getDataRelROLocalSection() const {
    277     return DataRelROLocalSection;
    278   }
    279   const MCSection *getMergeableConst4Section() const {
    280     return MergeableConst4Section;
    281   }
    282   const MCSection *getMergeableConst8Section() const {
    283     return MergeableConst8Section;
    284   }
    285   const MCSection *getMergeableConst16Section() const {
    286     return MergeableConst16Section;
    287   }
    288 
    289   /// MachO specific sections.
    290   ///
    291   const MCSection *getTLSTLVSection() const { return TLSTLVSection; }
    292   const MCSection *getTLSThreadInitSection() const {
    293     return TLSThreadInitSection;
    294   }
    295   const MCSection *getCStringSection() const { return CStringSection; }
    296   const MCSection *getUStringSection() const { return UStringSection; }
    297   const MCSection *getTextCoalSection() const { return TextCoalSection; }
    298   const MCSection *getConstTextCoalSection() const {
    299     return ConstTextCoalSection;
    300   }
    301   const MCSection *getConstDataSection() const { return ConstDataSection; }
    302   const MCSection *getDataCoalSection() const { return DataCoalSection; }
    303   const MCSection *getDataCommonSection() const { return DataCommonSection; }
    304   const MCSection *getDataBSSSection() const { return DataBSSSection; }
    305   const MCSection *getFourByteConstantSection() const {
    306     return FourByteConstantSection;
    307   }
    308   const MCSection *getEightByteConstantSection() const {
    309     return EightByteConstantSection;
    310   }
    311   const MCSection *getSixteenByteConstantSection() const {
    312     return SixteenByteConstantSection;
    313   }
    314   const MCSection *getLazySymbolPointerSection() const {
    315     return LazySymbolPointerSection;
    316   }
    317   const MCSection *getNonLazySymbolPointerSection() const {
    318     return NonLazySymbolPointerSection;
    319   }
    320 
    321   /// COFF specific sections.
    322   ///
    323   const MCSection *getDrectveSection() const { return DrectveSection; }
    324   const MCSection *getPDataSection() const { return PDataSection; }
    325   const MCSection *getXDataSection() const { return XDataSection; }
    326 
    327   const MCSection *getEHFrameSection() {
    328     if (!EHFrameSection)
    329       InitEHFrameSection();
    330     return EHFrameSection;
    331   }
    332 
    333 private:
    334   enum Environment { IsMachO, IsELF, IsCOFF };
    335   Environment Env;
    336   Reloc::Model RelocM;
    337   CodeModel::Model CMModel;
    338   MCContext *Ctx;
    339 
    340   void InitMachOMCObjectFileInfo(Triple T);
    341   void InitELFMCObjectFileInfo(Triple T);
    342   void InitCOFFMCObjectFileInfo(Triple T);
    343 
    344   /// InitEHFrameSection - Initialize EHFrameSection on demand.
    345   ///
    346   void InitEHFrameSection();
    347 };
    348 
    349 } // end namespace llvm
    350 
    351 #endif
    352