LDFileFormat.h revision 5460a1f25d9ddecb5c70667267d66d51af177a99
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{ 20 21class MCLinker; 22class LDSection; 23 24/** \class LDFileFormat 25 * \brief LDFileFormat describes the common file formats. 26 */ 27class LDFileFormat 28{ 29public: 30 enum Kind { 31 Null, 32 Regular, 33 BSS, 34 NamePool, 35 Relocation, 36 Debug, 37 Target, 38 Exception, 39 Version, 40 Note, 41 MetaData, 42 Group, 43 }; 44 45protected: 46 LDFileFormat(); 47 48public: 49 virtual ~LDFileFormat(); 50 51 /// initStdSections - initialize all standard sections. 52 void initStdSections(MCLinker& pLinker); 53 54 /// initObjectFormat - different format, such as ELF and MachO, should 55 /// implement this 56 virtual void initObjectFormat(MCLinker& pLinker) = 0; 57 58 /// initObjectType - different types, such as shared object, executable 59 /// files, should implement this 60 virtual void initObjectType(MCLinker& pLinker) = 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