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