Home | History | Annotate | Download | only in LD
      1 //===- LDFileFormat.h -----------------------------------------------------===//
      2 //
      3 //                     The MCLinker Project
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 #ifndef MCLD_LD_LDFILEFORMAT_H_
     10 #define MCLD_LD_LDFILEFORMAT_H_
     11 
     12 #include <cassert>
     13 #include <cstddef>
     14 
     15 namespace mcld {
     16 
     17 class LDSection;
     18 class ObjectBuilder;
     19 
     20 /** \class LDFileFormat
     21  *  \brief LDFileFormat describes the common file formats.
     22  */
     23 class LDFileFormat {
     24  public:
     25   enum Kind {
     26     Null,
     27     TEXT,  // Executable regular sections
     28     DATA,  // Non-executable regular sections
     29     BSS,
     30     NamePool,
     31     Relocation,
     32     Debug,
     33     DebugString,
     34     Target,
     35     EhFrame,
     36     EhFrameHdr,
     37     GCCExceptTable,
     38     Version,
     39     Note,
     40     MetaData,
     41     Group,
     42     LinkOnce,
     43     StackNote,
     44     Ignore,
     45     Exclude,
     46     Folded
     47   };
     48 
     49  protected:
     50   LDFileFormat();
     51 
     52  public:
     53   virtual ~LDFileFormat();
     54 
     55   /// initStdSections - initialize all standard section headers.
     56   /// @param [in] pBuilder The ObjectBuilder to create section headers
     57   /// @param [in] pBitClass The bitclass of target backend.
     58   virtual void initStdSections(ObjectBuilder& pBuilder,
     59                                unsigned int pBitClass) = 0;
     60 
     61   // -----  access functions  ----- //
     62   LDSection& getText() {
     63     assert(f_pTextSection != NULL);
     64     return *f_pTextSection;
     65   }
     66 
     67   const LDSection& getText() const {
     68     assert(f_pTextSection != NULL);
     69     return *f_pTextSection;
     70   }
     71 
     72   LDSection& getData() {
     73     assert(f_pDataSection != NULL);
     74     return *f_pDataSection;
     75   }
     76 
     77   const LDSection& getData() const {
     78     assert(f_pDataSection != NULL);
     79     return *f_pDataSection;
     80   }
     81 
     82   LDSection& getBSS() {
     83     assert(f_pBSSSection != NULL);
     84     return *f_pBSSSection;
     85   }
     86 
     87   const LDSection& getBSS() const {
     88     assert(f_pBSSSection != NULL);
     89     return *f_pBSSSection;
     90   }
     91 
     92   LDSection& getReadOnly() {
     93     assert(f_pReadOnlySection != NULL);
     94     return *f_pReadOnlySection;
     95   }
     96 
     97   const LDSection& getReadOnly() const {
     98     assert(f_pReadOnlySection != NULL);
     99     return *f_pReadOnlySection;
    100   }
    101 
    102  protected:
    103   //         variable name         :  ELF               MachO
    104   LDSection* f_pTextSection;      // .text             __text
    105   LDSection* f_pDataSection;      // .data             __data
    106   LDSection* f_pBSSSection;       // .bss              __bss
    107   LDSection* f_pReadOnlySection;  // .rodata           __const
    108 };
    109 
    110 }  // namespace mcld
    111 
    112 #endif  // MCLD_LD_LDFILEFORMAT_H_
    113