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/MC/MCCodeGenInfo.h"
     18 #include "llvm/ADT/StringRef.h"
     19 #include "llvm/MC/SectionKind.h"
     20 
     21 namespace llvm {
     22 class MCContext;
     23 class MCSection;
     24 class Triple;
     25 
     26 class MCObjectFileInfo {
     27 protected:
     28   /// CommDirectiveSupportsAlignment - True if .comm supports alignment.  This
     29   /// is a hack for as long as we support 10.4 Tiger, whose assembler doesn't
     30   /// support alignment on comm.
     31   bool CommDirectiveSupportsAlignment;
     32 
     33   /// SupportsWeakEmptyEHFrame - True if target object file supports a
     34   /// weak_definition of constant 0 for an omitted EH frame.
     35   bool SupportsWeakOmittedEHFrame;
     36 
     37   /// IsFunctionEHFrameSymbolPrivate - This flag is set to true if the
     38   /// "EH_frame" symbol for EH information should be an assembler temporary (aka
     39   /// private linkage, aka an L or .L label) or false if it should be a normal
     40   /// non-.globl label.  This defaults to true.
     41   bool IsFunctionEHFrameSymbolPrivate;
     42 
     43   /// PersonalityEncoding, LSDAEncoding, FDEEncoding, TTypeEncoding - Some
     44   /// encoding values for EH.
     45   unsigned PersonalityEncoding;
     46   unsigned LSDAEncoding;
     47   unsigned FDEEncoding;
     48   unsigned FDECFIEncoding;
     49   unsigned TTypeEncoding;
     50 
     51   /// TextSection - Section directive for standard text.
     52   ///
     53   const MCSection *TextSection;
     54 
     55   /// DataSection - Section directive for standard data.
     56   ///
     57   const MCSection *DataSection;
     58 
     59   /// BSSSection - Section that is default initialized to zero.
     60   const MCSection *BSSSection;
     61 
     62   /// ReadOnlySection - Section that is readonly and can contain arbitrary
     63   /// initialized data.  Targets are not required to have a readonly section.
     64   /// If they don't, various bits of code will fall back to using the data
     65   /// section for constants.
     66   const MCSection *ReadOnlySection;
     67 
     68   /// StaticCtorSection - This section contains the static constructor pointer
     69   /// list.
     70   const MCSection *StaticCtorSection;
     71 
     72   /// StaticDtorSection - This section contains the static destructor pointer
     73   /// list.
     74   const MCSection *StaticDtorSection;
     75 
     76   /// LSDASection - If exception handling is supported by the target, this is
     77   /// the section the Language Specific Data Area information is emitted to.
     78   const MCSection *LSDASection;
     79 
     80   /// CompactUnwindSection - If exception handling is supported by the target
     81   /// and the target can support a compact representation of the CIE and FDE,
     82   /// this is the section to emit them into.
     83   const MCSection *CompactUnwindSection;
     84 
     85   // Dwarf sections for debug info.  If a target supports debug info, these must
     86   // be set.
     87   const MCSection *DwarfAbbrevSection;
     88   const MCSection *DwarfInfoSection;
     89   const MCSection *DwarfLineSection;
     90   const MCSection *DwarfFrameSection;
     91   const MCSection *DwarfPubNamesSection;
     92   const MCSection *DwarfPubTypesSection;
     93   const MCSection *DwarfDebugInlineSection;
     94   const MCSection *DwarfStrSection;
     95   const MCSection *DwarfLocSection;
     96   const MCSection *DwarfARangesSection;
     97   const MCSection *DwarfRangesSection;
     98   const MCSection *DwarfMacroInfoSection;
     99 
    100   // Extra TLS Variable Data section.  If the target needs to put additional
    101   // information for a TLS variable, it'll go here.
    102   const MCSection *TLSExtraDataSection;
    103 
    104   /// TLSDataSection - Section directive for Thread Local data.
    105   /// ELF and MachO only.
    106   const MCSection *TLSDataSection;        // Defaults to ".tdata".
    107 
    108   /// TLSBSSSection - Section directive for Thread Local uninitialized data.
    109   /// Null if this target doesn't support a BSS section.
    110   /// ELF and MachO only.
    111   const MCSection *TLSBSSSection;         // Defaults to ".tbss".
    112 
    113 
    114   /// EHFrameSection - EH frame section. It is initialized on demand so it
    115   /// can be overwritten (with uniquing).
    116   const MCSection *EHFrameSection;
    117 
    118   /// ELF specific sections.
    119   ///
    120   const MCSection *DataRelSection;
    121   const MCSection *DataRelLocalSection;
    122   const MCSection *DataRelROSection;
    123   const MCSection *DataRelROLocalSection;
    124   const MCSection *MergeableConst4Section;
    125   const MCSection *MergeableConst8Section;
    126   const MCSection *MergeableConst16Section;
    127 
    128   /// MachO specific sections.
    129   ///
    130 
    131   /// TLSTLVSection - Section for thread local structure information.
    132   /// Contains the source code name of the variable, visibility and a pointer
    133   /// to the initial value (.tdata or .tbss).
    134   const MCSection *TLSTLVSection;         // Defaults to ".tlv".
    135 
    136   /// TLSThreadInitSection - Section for thread local data initialization
    137   /// functions.
    138   const MCSection *TLSThreadInitSection;  // Defaults to ".thread_init_func".
    139 
    140   const MCSection *CStringSection;
    141   const MCSection *UStringSection;
    142   const MCSection *TextCoalSection;
    143   const MCSection *ConstTextCoalSection;
    144   const MCSection *ConstDataSection;
    145   const MCSection *DataCoalSection;
    146   const MCSection *DataCommonSection;
    147   const MCSection *DataBSSSection;
    148   const MCSection *FourByteConstantSection;
    149   const MCSection *EightByteConstantSection;
    150   const MCSection *SixteenByteConstantSection;
    151   const MCSection *LazySymbolPointerSection;
    152   const MCSection *NonLazySymbolPointerSection;
    153 
    154   /// COFF specific sections.
    155   ///
    156   const MCSection *DrectveSection;
    157   const MCSection *PDataSection;
    158   const MCSection *XDataSection;
    159 
    160 public:
    161   void InitMCObjectFileInfo(StringRef TT, Reloc::Model RM, CodeModel::Model CM,
    162                             MCContext &ctx);
    163 
    164   bool isFunctionEHFrameSymbolPrivate() const {
    165     return IsFunctionEHFrameSymbolPrivate;
    166   }
    167   bool getSupportsWeakOmittedEHFrame() const {
    168     return SupportsWeakOmittedEHFrame;
    169   }
    170   bool getCommDirectiveSupportsAlignment() const {
    171     return CommDirectiveSupportsAlignment;
    172   }
    173 
    174   unsigned getPersonalityEncoding() const { return PersonalityEncoding; }
    175   unsigned getLSDAEncoding() const { return LSDAEncoding; }
    176   unsigned getFDEEncoding(bool CFI) const {
    177     return CFI ? FDECFIEncoding : FDEEncoding;
    178   }
    179   unsigned getTTypeEncoding() const { return TTypeEncoding; }
    180 
    181   const MCSection *getTextSection() const { return TextSection; }
    182   const MCSection *getDataSection() const { return DataSection; }
    183   const MCSection *getBSSSection() const { return BSSSection; }
    184   const MCSection *getStaticCtorSection() const { return StaticCtorSection; }
    185   const MCSection *getStaticDtorSection() const { return StaticDtorSection; }
    186   const MCSection *getLSDASection() const { return LSDASection; }
    187   const MCSection *getCompactUnwindSection() const{
    188     return CompactUnwindSection;
    189   }
    190   const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
    191   const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
    192   const MCSection *getDwarfLineSection() const { return DwarfLineSection; }
    193   const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
    194   const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;}
    195   const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;}
    196   const MCSection *getDwarfDebugInlineSection() const {
    197     return DwarfDebugInlineSection;
    198   }
    199   const MCSection *getDwarfStrSection() const { return DwarfStrSection; }
    200   const MCSection *getDwarfLocSection() const { return DwarfLocSection; }
    201   const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;}
    202   const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
    203   const MCSection *getDwarfMacroInfoSection() const {
    204     return DwarfMacroInfoSection;
    205   }
    206   const MCSection *getTLSExtraDataSection() const {
    207     return TLSExtraDataSection;
    208   }
    209   const MCSection *getTLSDataSection() const { return TLSDataSection; }
    210   const MCSection *getTLSBSSSection() const { return TLSBSSSection; }
    211 
    212   /// ELF specific sections.
    213   ///
    214   const MCSection *getDataRelSection() const { return DataRelSection; }
    215   const MCSection *getDataRelLocalSection() const {
    216     return DataRelLocalSection;
    217   }
    218   const MCSection *getDataRelROSection() const { return DataRelROSection; }
    219   const MCSection *getDataRelROLocalSection() const {
    220     return DataRelROLocalSection;
    221   }
    222   const MCSection *getMergeableConst4Section() const {
    223     return MergeableConst4Section;
    224   }
    225   const MCSection *getMergeableConst8Section() const {
    226     return MergeableConst8Section;
    227   }
    228   const MCSection *getMergeableConst16Section() const {
    229     return MergeableConst16Section;
    230   }
    231 
    232   /// MachO specific sections.
    233   ///
    234   const MCSection *getTLSTLVSection() const { return TLSTLVSection; }
    235   const MCSection *getTLSThreadInitSection() const {
    236     return TLSThreadInitSection;
    237   }
    238   const MCSection *getCStringSection() const { return CStringSection; }
    239   const MCSection *getUStringSection() const { return UStringSection; }
    240   const MCSection *getTextCoalSection() const { return TextCoalSection; }
    241   const MCSection *getConstTextCoalSection() const {
    242     return ConstTextCoalSection;
    243   }
    244   const MCSection *getConstDataSection() const { return ConstDataSection; }
    245   const MCSection *getDataCoalSection() const { return DataCoalSection; }
    246   const MCSection *getDataCommonSection() const { return DataCommonSection; }
    247   const MCSection *getDataBSSSection() const { return DataBSSSection; }
    248   const MCSection *getFourByteConstantSection() const {
    249     return FourByteConstantSection;
    250   }
    251   const MCSection *getEightByteConstantSection() const {
    252     return EightByteConstantSection;
    253   }
    254   const MCSection *getSixteenByteConstantSection() const {
    255     return SixteenByteConstantSection;
    256   }
    257   const MCSection *getLazySymbolPointerSection() const {
    258     return LazySymbolPointerSection;
    259   }
    260   const MCSection *getNonLazySymbolPointerSection() const {
    261     return NonLazySymbolPointerSection;
    262   }
    263 
    264   /// COFF specific sections.
    265   ///
    266   const MCSection *getDrectveSection() const { return DrectveSection; }
    267   const MCSection *getPDataSection() const { return PDataSection; }
    268   const MCSection *getXDataSection() const { return XDataSection; }
    269 
    270   const MCSection *getEHFrameSection() {
    271     if (!EHFrameSection)
    272       InitEHFrameSection();
    273     return EHFrameSection;
    274   }
    275 
    276 private:
    277   enum Environment { IsMachO, IsELF, IsCOFF };
    278   Environment Env;
    279   Reloc::Model RelocM;
    280   CodeModel::Model CMModel;
    281   MCContext *Ctx;
    282 
    283   void InitMachOMCObjectFileInfo(Triple T);
    284   void InitELFMCObjectFileInfo(Triple T);
    285   void InitCOFFMCObjectFileInfo(Triple T);
    286 
    287   /// InitEHFrameSection - Initialize EHFrameSection on demand.
    288   ///
    289   void InitEHFrameSection();
    290 };
    291 
    292 } // end namespace llvm
    293 
    294 #endif
    295