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