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_LDFILE_FORMAT_H 10 #define MCLD_LDFILE_FORMAT_H 11 #ifdef ENABLE_UNITTEST 12 #include <gtest.h> 13 #endif 14 15 #include <cstdio> 16 #include <cassert> 17 18 namespace mcld 19 { 20 21 class MCLinker; 22 class LDSection; 23 24 /** \class LDFileFormat 25 * \brief LDFileFormat describes the common file formats. 26 */ 27 class LDFileFormat 28 { 29 public: 30 enum Kind { 31 Null, 32 Regular, 33 BSS, 34 NamePool, 35 Relocation, 36 Debug, 37 Target, 38 EhFrame, 39 EhFrameHdr, 40 GCCExceptTable, 41 Version, 42 Note, 43 MetaData, 44 Group, 45 }; 46 47 protected: 48 LDFileFormat(); 49 50 public: 51 virtual ~LDFileFormat(); 52 53 /// initStdSections - initialize all standard sections. 54 void initStdSections(MCLinker& pLinker); 55 56 /// initObjectFormat - different format, such as ELF and MachO, should 57 /// implement this 58 virtual void initObjectFormat(MCLinker& pLinker) = 0; 59 60 /// initObjectType - different types, such as shared object, executable 61 /// files, should implement this 62 virtual void initObjectType(MCLinker& pLinker) = 0; 63 64 // ----- access functions ----- // getText()65 LDSection& getText() { 66 assert(NULL != f_pTextSection); 67 return *f_pTextSection; 68 } 69 getText()70 const LDSection& getText() const { 71 assert(NULL != f_pTextSection); 72 return *f_pTextSection; 73 } 74 getData()75 LDSection& getData() { 76 assert(NULL != f_pDataSection); 77 return *f_pDataSection; 78 } 79 getData()80 const LDSection& getData() const { 81 assert(NULL != f_pDataSection); 82 return *f_pDataSection; 83 } 84 getBSS()85 LDSection& getBSS() { 86 assert(NULL != f_pBSSSection); 87 return *f_pBSSSection; 88 } 89 getBSS()90 const LDSection& getBSS() const { 91 assert(NULL != f_pBSSSection); 92 return *f_pBSSSection; 93 } 94 getReadOnly()95 LDSection& getReadOnly() { 96 assert(NULL != f_pReadOnlySection); 97 return *f_pReadOnlySection; 98 } 99 getReadOnly()100 const LDSection& getReadOnly() const { 101 assert(NULL != f_pReadOnlySection); 102 return *f_pReadOnlySection; 103 } 104 protected: 105 // variable name : ELF MachO 106 LDSection* f_pTextSection; // .text __text 107 LDSection* f_pDataSection; // .data __data 108 LDSection* f_pBSSSection; // .bss __bss 109 LDSection* f_pReadOnlySection; // .rodata __const 110 }; 111 112 } // namespace of mcld 113 114 #endif 115 116