LDFileFormat.h revision 0dea6bc96bb52346737966839ac68644f7939f58
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 15namespace mcld { 16 17class LDSection; 18class ObjectBuilder; 19 20/** \class LDFileFormat 21 * \brief LDFileFormat describes the common file formats. 22 */ 23class LDFileFormat 24{ 25public: 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 49protected: 50 LDFileFormat(); 51 52public: 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(NULL != f_pTextSection); 64 return *f_pTextSection; 65 } 66 67 const LDSection& getText() const { 68 assert(NULL != f_pTextSection); 69 return *f_pTextSection; 70 } 71 72 LDSection& getData() { 73 assert(NULL != f_pDataSection); 74 return *f_pDataSection; 75 } 76 77 const LDSection& getData() const { 78 assert(NULL != f_pDataSection); 79 return *f_pDataSection; 80 } 81 82 LDSection& getBSS() { 83 assert(NULL != f_pBSSSection); 84 return *f_pBSSSection; 85 } 86 87 const LDSection& getBSS() const { 88 assert(NULL != f_pBSSSection); 89 return *f_pBSSSection; 90 } 91 92 LDSection& getReadOnly() { 93 assert(NULL != f_pReadOnlySection); 94 return *f_pReadOnlySection; 95 } 96 97 const LDSection& getReadOnly() const { 98 assert(NULL != f_pReadOnlySection); 99 return *f_pReadOnlySection; 100 } 101protected: 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