LDFileFormat.h revision 533eae20118036f425f27bf0536ef0ccbb090b65
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 Regular, 29 BSS, 30 NamePool, 31 Relocation, 32 Debug, 33 Target, 34 EhFrame, 35 EhFrameHdr, 36 GCCExceptTable, 37 Version, 38 Note, 39 MetaData, 40 Group, 41 LinkOnce, 42 StackNote, 43 Ignore, 44 Exclude 45 }; 46 47protected: 48 LDFileFormat(); 49 50public: 51 virtual ~LDFileFormat(); 52 53 /// initStdSections - initialize all standard section headers. 54 /// @param [in] pBuilder The ObjectBuilder to create section headers 55 /// @param [in] pBitClass The bitclass of target backend. 56 virtual void initStdSections(ObjectBuilder& pBuilder, 57 unsigned int pBitClass) = 0; 58 59 // ----- access functions ----- // 60 LDSection& getText() { 61 assert(NULL != f_pTextSection); 62 return *f_pTextSection; 63 } 64 65 const LDSection& getText() const { 66 assert(NULL != f_pTextSection); 67 return *f_pTextSection; 68 } 69 70 LDSection& getData() { 71 assert(NULL != f_pDataSection); 72 return *f_pDataSection; 73 } 74 75 const LDSection& getData() const { 76 assert(NULL != f_pDataSection); 77 return *f_pDataSection; 78 } 79 80 LDSection& getBSS() { 81 assert(NULL != f_pBSSSection); 82 return *f_pBSSSection; 83 } 84 85 const LDSection& getBSS() const { 86 assert(NULL != f_pBSSSection); 87 return *f_pBSSSection; 88 } 89 90 LDSection& getReadOnly() { 91 assert(NULL != f_pReadOnlySection); 92 return *f_pReadOnlySection; 93 } 94 95 const LDSection& getReadOnly() const { 96 assert(NULL != f_pReadOnlySection); 97 return *f_pReadOnlySection; 98 } 99protected: 100 // variable name : ELF MachO 101 LDSection* f_pTextSection; // .text __text 102 LDSection* f_pDataSection; // .data __data 103 LDSection* f_pBSSSection; // .bss __bss 104 LDSection* f_pReadOnlySection; // .rodata __const 105}; 106 107} // namespace of mcld 108 109#endif 110 111