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 <cstdio> 13 #include <cassert> 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 { 25 public: 26 enum Kind { 27 Null, 28 TEXT, // Executable regular sections 29 DATA, // Non-executable regular sections 30 BSS, 31 NamePool, 32 Relocation, 33 Debug, 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 ----- // getText()62 LDSection& getText() { 63 assert(NULL != f_pTextSection); 64 return *f_pTextSection; 65 } 66 getText()67 const LDSection& getText() const { 68 assert(NULL != f_pTextSection); 69 return *f_pTextSection; 70 } 71 getData()72 LDSection& getData() { 73 assert(NULL != f_pDataSection); 74 return *f_pDataSection; 75 } 76 getData()77 const LDSection& getData() const { 78 assert(NULL != f_pDataSection); 79 return *f_pDataSection; 80 } 81 getBSS()82 LDSection& getBSS() { 83 assert(NULL != f_pBSSSection); 84 return *f_pBSSSection; 85 } 86 getBSS()87 const LDSection& getBSS() const { 88 assert(NULL != f_pBSSSection); 89 return *f_pBSSSection; 90 } 91 getReadOnly()92 LDSection& getReadOnly() { 93 assert(NULL != f_pReadOnlySection); 94 return *f_pReadOnlySection; 95 } 96 getReadOnly()97 const LDSection& getReadOnly() const { 98 assert(NULL != f_pReadOnlySection); 99 return *f_pReadOnlySection; 100 } 101 protected: 102 // variable name : ELF MachO 103 LDSection* f_pTextSection; // .text __text 104 LDSection* f_pDataSection; // .data __data 105 LDSection* f_pBSSSection; // .bss __bss 106 LDSection* f_pReadOnlySection; // .rodata __const 107 }; 108 109 } // namespace of mcld 110 111 #endif 112 113