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