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_MCOBJECTFILEINFO_H
     15 #define LLVM_MC_MCOBJECTFILEINFO_H
     16 
     17 #include "llvm/ADT/Triple.h"
     18 #include "llvm/Support/CodeGen.h"
     19 
     20 namespace llvm {
     21 class MCContext;
     22 class MCSection;
     23 
     24 class MCObjectFileInfo {
     25 protected:
     26   /// True if .comm supports alignment.  This is a hack for as long as we
     27   /// support 10.4 Tiger, whose assembler doesn't support alignment on comm.
     28   bool CommDirectiveSupportsAlignment;
     29 
     30   /// True if target object file supports a weak_definition of constant 0 for an
     31   /// omitted EH frame.
     32   bool SupportsWeakOmittedEHFrame;
     33 
     34   /// True if the target object file supports emitting a compact unwind section
     35   /// without an associated EH frame section.
     36   bool SupportsCompactUnwindWithoutEHFrame;
     37 
     38   /// OmitDwarfIfHaveCompactUnwind - True if the target object file
     39   /// supports having some functions with compact unwind and other with
     40   /// dwarf unwind.
     41   bool OmitDwarfIfHaveCompactUnwind;
     42 
     43   /// PersonalityEncoding, LSDAEncoding, TTypeEncoding - Some encoding values
     44   /// for EH.
     45   unsigned PersonalityEncoding;
     46   unsigned LSDAEncoding;
     47   unsigned FDECFIEncoding;
     48   unsigned TTypeEncoding;
     49 
     50   /// Compact unwind encoding indicating that we should emit only an EH frame.
     51   unsigned CompactUnwindDwarfEHFrameOnly;
     52 
     53   /// Section directive for standard text.
     54   MCSection *TextSection;
     55 
     56   /// Section directive for standard data.
     57   MCSection *DataSection;
     58 
     59   /// Section that is default initialized to zero.
     60   MCSection *BSSSection;
     61 
     62   /// Section that is readonly and can contain arbitrary initialized data.
     63   /// Targets are not required to have a readonly section. If they don't,
     64   /// various bits of code will fall back to using the data section for
     65   /// constants.
     66   MCSection *ReadOnlySection;
     67 
     68   /// If exception handling is supported by the target, this is the section the
     69   /// Language Specific Data Area information is emitted to.
     70   MCSection *LSDASection;
     71 
     72   /// If exception handling is supported by the target and the target can
     73   /// support a compact representation of the CIE and FDE, this is the section
     74   /// to emit them into.
     75   MCSection *CompactUnwindSection;
     76 
     77   // Dwarf sections for debug info.  If a target supports debug info, these must
     78   // be set.
     79   MCSection *DwarfAbbrevSection;
     80   MCSection *DwarfInfoSection;
     81   MCSection *DwarfLineSection;
     82   MCSection *DwarfFrameSection;
     83   MCSection *DwarfPubTypesSection;
     84   const MCSection *DwarfDebugInlineSection;
     85   MCSection *DwarfStrSection;
     86   MCSection *DwarfLocSection;
     87   MCSection *DwarfARangesSection;
     88   MCSection *DwarfRangesSection;
     89   MCSection *DwarfMacinfoSection;
     90   // The pubnames section is no longer generated by default.  The generation
     91   // can be enabled by a compiler flag.
     92   MCSection *DwarfPubNamesSection;
     93 
     94   /// DWARF5 Experimental Debug Info Sections
     95   /// DwarfAccelNamesSection, DwarfAccelObjCSection,
     96   /// DwarfAccelNamespaceSection, DwarfAccelTypesSection -
     97   /// If we use the DWARF accelerated hash tables then we want to emit these
     98   /// sections.
     99   MCSection *DwarfAccelNamesSection;
    100   MCSection *DwarfAccelObjCSection;
    101   MCSection *DwarfAccelNamespaceSection;
    102   MCSection *DwarfAccelTypesSection;
    103 
    104   // These are used for the Fission separate debug information files.
    105   MCSection *DwarfInfoDWOSection;
    106   MCSection *DwarfTypesDWOSection;
    107   MCSection *DwarfAbbrevDWOSection;
    108   MCSection *DwarfStrDWOSection;
    109   MCSection *DwarfLineDWOSection;
    110   MCSection *DwarfLocDWOSection;
    111   MCSection *DwarfStrOffDWOSection;
    112   MCSection *DwarfAddrSection;
    113 
    114   // These are for Fission DWP files.
    115   MCSection *DwarfCUIndexSection;
    116   MCSection *DwarfTUIndexSection;
    117 
    118   /// Section for newer gnu pubnames.
    119   MCSection *DwarfGnuPubNamesSection;
    120   /// Section for newer gnu pubtypes.
    121   MCSection *DwarfGnuPubTypesSection;
    122 
    123   MCSection *COFFDebugSymbolsSection;
    124   MCSection *COFFDebugTypesSection;
    125 
    126   /// Extra TLS Variable Data section.
    127   ///
    128   /// If the target needs to put additional information for a TLS variable,
    129   /// it'll go here.
    130   MCSection *TLSExtraDataSection;
    131 
    132   /// Section directive for Thread Local data. ELF, MachO, COFF, and Wasm.
    133   MCSection *TLSDataSection; // Defaults to ".tdata".
    134 
    135   /// Section directive for Thread Local uninitialized data.
    136   ///
    137   /// Null if this target doesn't support a BSS section. ELF and MachO only.
    138   MCSection *TLSBSSSection; // Defaults to ".tbss".
    139 
    140   /// StackMap section.
    141   MCSection *StackMapSection;
    142 
    143   /// FaultMap section.
    144   MCSection *FaultMapSection;
    145 
    146   /// EH frame section.
    147   ///
    148   /// It is initialized on demand so it can be overwritten (with uniquing).
    149   MCSection *EHFrameSection;
    150 
    151   // ELF specific sections.
    152   MCSection *DataRelROSection;
    153   MCSection *MergeableConst4Section;
    154   MCSection *MergeableConst8Section;
    155   MCSection *MergeableConst16Section;
    156   MCSection *MergeableConst32Section;
    157 
    158   // MachO specific sections.
    159 
    160   /// Section for thread local structure information.
    161   ///
    162   /// Contains the source code name of the variable, visibility and a pointer to
    163   /// the initial value (.tdata or .tbss).
    164   MCSection *TLSTLVSection; // Defaults to ".tlv".
    165 
    166   /// Section for thread local data initialization functions.
    167   const MCSection *TLSThreadInitSection; // Defaults to ".thread_init_func".
    168 
    169   MCSection *CStringSection;
    170   MCSection *UStringSection;
    171   MCSection *TextCoalSection;
    172   MCSection *ConstTextCoalSection;
    173   MCSection *ConstDataSection;
    174   MCSection *DataCoalSection;
    175   MCSection *DataCommonSection;
    176   MCSection *DataBSSSection;
    177   MCSection *FourByteConstantSection;
    178   MCSection *EightByteConstantSection;
    179   MCSection *SixteenByteConstantSection;
    180   MCSection *LazySymbolPointerSection;
    181   MCSection *NonLazySymbolPointerSection;
    182   MCSection *ThreadLocalPointerSection;
    183 
    184   /// COFF specific sections.
    185   MCSection *DrectveSection;
    186   MCSection *PDataSection;
    187   MCSection *XDataSection;
    188   MCSection *SXDataSection;
    189 
    190 public:
    191   void InitMCObjectFileInfo(const Triple &TT, bool PIC, CodeModel::Model CM,
    192                             MCContext &ctx);
    193 
    194   bool getSupportsWeakOmittedEHFrame() const {
    195     return SupportsWeakOmittedEHFrame;
    196   }
    197   bool getSupportsCompactUnwindWithoutEHFrame() const {
    198     return SupportsCompactUnwindWithoutEHFrame;
    199   }
    200   bool getOmitDwarfIfHaveCompactUnwind() const {
    201     return OmitDwarfIfHaveCompactUnwind;
    202   }
    203 
    204   bool getCommDirectiveSupportsAlignment() const {
    205     return CommDirectiveSupportsAlignment;
    206   }
    207 
    208   unsigned getPersonalityEncoding() const { return PersonalityEncoding; }
    209   unsigned getLSDAEncoding() const { return LSDAEncoding; }
    210   unsigned getFDEEncoding() const { return FDECFIEncoding; }
    211   unsigned getTTypeEncoding() const { return TTypeEncoding; }
    212 
    213   unsigned getCompactUnwindDwarfEHFrameOnly() const {
    214     return CompactUnwindDwarfEHFrameOnly;
    215   }
    216 
    217   MCSection *getTextSection() const { return TextSection; }
    218   MCSection *getDataSection() const { return DataSection; }
    219   MCSection *getBSSSection() const { return BSSSection; }
    220   MCSection *getReadOnlySection() const { return ReadOnlySection; }
    221   MCSection *getLSDASection() const { return LSDASection; }
    222   MCSection *getCompactUnwindSection() const { return CompactUnwindSection; }
    223   MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
    224   MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
    225   MCSection *getDwarfLineSection() const { return DwarfLineSection; }
    226   MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
    227   MCSection *getDwarfPubNamesSection() const { return DwarfPubNamesSection; }
    228   MCSection *getDwarfPubTypesSection() const { return DwarfPubTypesSection; }
    229   MCSection *getDwarfGnuPubNamesSection() const {
    230     return DwarfGnuPubNamesSection;
    231   }
    232   MCSection *getDwarfGnuPubTypesSection() const {
    233     return DwarfGnuPubTypesSection;
    234   }
    235   const MCSection *getDwarfDebugInlineSection() const {
    236     return DwarfDebugInlineSection;
    237   }
    238   MCSection *getDwarfStrSection() const { return DwarfStrSection; }
    239   MCSection *getDwarfLocSection() const { return DwarfLocSection; }
    240   MCSection *getDwarfARangesSection() const { return DwarfARangesSection; }
    241   MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
    242   MCSection *getDwarfMacinfoSection() const { return DwarfMacinfoSection; }
    243 
    244   // DWARF5 Experimental Debug Info Sections
    245   MCSection *getDwarfAccelNamesSection() const {
    246     return DwarfAccelNamesSection;
    247   }
    248   MCSection *getDwarfAccelObjCSection() const { return DwarfAccelObjCSection; }
    249   MCSection *getDwarfAccelNamespaceSection() const {
    250     return DwarfAccelNamespaceSection;
    251   }
    252   MCSection *getDwarfAccelTypesSection() const {
    253     return DwarfAccelTypesSection;
    254   }
    255   MCSection *getDwarfInfoDWOSection() const { return DwarfInfoDWOSection; }
    256   MCSection *getDwarfTypesSection(uint64_t Hash) const;
    257   MCSection *getDwarfTypesDWOSection() const { return DwarfTypesDWOSection; }
    258   MCSection *getDwarfAbbrevDWOSection() const { return DwarfAbbrevDWOSection; }
    259   MCSection *getDwarfStrDWOSection() const { return DwarfStrDWOSection; }
    260   MCSection *getDwarfLineDWOSection() const { return DwarfLineDWOSection; }
    261   MCSection *getDwarfLocDWOSection() const { return DwarfLocDWOSection; }
    262   MCSection *getDwarfStrOffDWOSection() const { return DwarfStrOffDWOSection; }
    263   MCSection *getDwarfAddrSection() const { return DwarfAddrSection; }
    264   MCSection *getDwarfCUIndexSection() const { return DwarfCUIndexSection; }
    265   MCSection *getDwarfTUIndexSection() const { return DwarfTUIndexSection; }
    266 
    267   MCSection *getCOFFDebugSymbolsSection() const {
    268     return COFFDebugSymbolsSection;
    269   }
    270   MCSection *getCOFFDebugTypesSection() const {
    271     return COFFDebugTypesSection;
    272   }
    273 
    274 
    275   MCSection *getTLSExtraDataSection() const { return TLSExtraDataSection; }
    276   const MCSection *getTLSDataSection() const { return TLSDataSection; }
    277   MCSection *getTLSBSSSection() const { return TLSBSSSection; }
    278 
    279   MCSection *getStackMapSection() const { return StackMapSection; }
    280   MCSection *getFaultMapSection() const { return FaultMapSection; }
    281 
    282   // ELF specific sections.
    283   MCSection *getDataRelROSection() const { return DataRelROSection; }
    284   const MCSection *getMergeableConst4Section() const {
    285     return MergeableConst4Section;
    286   }
    287   const MCSection *getMergeableConst8Section() const {
    288     return MergeableConst8Section;
    289   }
    290   const MCSection *getMergeableConst16Section() const {
    291     return MergeableConst16Section;
    292   }
    293   const MCSection *getMergeableConst32Section() const {
    294     return MergeableConst32Section;
    295   }
    296 
    297   // MachO specific sections.
    298   const MCSection *getTLSTLVSection() const { return TLSTLVSection; }
    299   const MCSection *getTLSThreadInitSection() const {
    300     return TLSThreadInitSection;
    301   }
    302   const MCSection *getCStringSection() const { return CStringSection; }
    303   const MCSection *getUStringSection() const { return UStringSection; }
    304   MCSection *getTextCoalSection() const { return TextCoalSection; }
    305   const MCSection *getConstTextCoalSection() const {
    306     return ConstTextCoalSection;
    307   }
    308   const MCSection *getConstDataSection() const { return ConstDataSection; }
    309   const MCSection *getDataCoalSection() const { return DataCoalSection; }
    310   const MCSection *getDataCommonSection() const { return DataCommonSection; }
    311   MCSection *getDataBSSSection() const { return DataBSSSection; }
    312   const MCSection *getFourByteConstantSection() const {
    313     return FourByteConstantSection;
    314   }
    315   const MCSection *getEightByteConstantSection() const {
    316     return EightByteConstantSection;
    317   }
    318   const MCSection *getSixteenByteConstantSection() const {
    319     return SixteenByteConstantSection;
    320   }
    321   MCSection *getLazySymbolPointerSection() const {
    322     return LazySymbolPointerSection;
    323   }
    324   MCSection *getNonLazySymbolPointerSection() const {
    325     return NonLazySymbolPointerSection;
    326   }
    327   MCSection *getThreadLocalPointerSection() const {
    328     return ThreadLocalPointerSection;
    329   }
    330 
    331   // COFF specific sections.
    332   MCSection *getDrectveSection() const { return DrectveSection; }
    333   MCSection *getPDataSection() const { return PDataSection; }
    334   MCSection *getXDataSection() const { return XDataSection; }
    335   MCSection *getSXDataSection() const { return SXDataSection; }
    336 
    337   MCSection *getEHFrameSection() {
    338     return EHFrameSection;
    339   }
    340 
    341   enum Environment { IsMachO, IsELF, IsCOFF, IsWasm };
    342   Environment getObjectFileType() const { return Env; }
    343 
    344   bool isPositionIndependent() const { return PositionIndependent; }
    345 
    346 private:
    347   Environment Env;
    348   bool PositionIndependent;
    349   CodeModel::Model CMModel;
    350   MCContext *Ctx;
    351   Triple TT;
    352 
    353   void initMachOMCObjectFileInfo(const Triple &T);
    354   void initELFMCObjectFileInfo(const Triple &T);
    355   void initCOFFMCObjectFileInfo(const Triple &T);
    356   void initWasmMCObjectFileInfo(const Triple &T);
    357 
    358 public:
    359   const Triple &getTargetTriple() const { return TT; }
    360 };
    361 
    362 } // end namespace llvm
    363 
    364 #endif
    365