• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- llvm/Target/TargetLDBackend.h - Target LD Backend -----*- C++ -*-===//
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 LLVM_TARGET_TARGETLDBACKEND_H
10 #define LLVM_TARGET_TARGETLDBACKEND_H
11 
12 #include <llvm/Support/DataTypes.h>
13 #include <mcld/MC/MCLDOutput.h>
14 #include <mcld/LD/EhFrame.h>
15 
16 namespace mcld {
17 
18 class MCLinker;
19 class Relocation;
20 class RelocationFactory;
21 class Layout;
22 class ArchiveReader;
23 class ObjectReader;
24 class DynObjReader;
25 class ObjectWriter;
26 class DynObjWriter;
27 class ExecWriter;
28 class LDContext;
29 class SectionMap;
30 class Output;
31 class MCLDInfo;
32 class SymbolCategory;
33 class Input;
34 class LDFileFormat;
35 class GOT;
36 class MemoryAreaFactory;
37 
38 //===----------------------------------------------------------------------===//
39 /// TargetLDBackend - Generic interface to target specific assembler backends.
40 ///
41 class TargetLDBackend
42 {
43   TargetLDBackend(const TargetLDBackend &);   // DO NOT IMPLEMENT
44   void operator=(const TargetLDBackend &);  // DO NOT IMPLEMENT
45 
46 protected:
47   TargetLDBackend();
48 
49 public:
50   virtual ~TargetLDBackend();
51 
52   // -----  target dependent  ----- //
initTargetSectionMap(SectionMap & pSectionMap)53   virtual bool initTargetSectionMap(SectionMap& pSectionMap) { return true;}
initTargetSegments(MCLinker & pLinker)54   virtual void initTargetSegments(MCLinker& pLinker) { }
initTargetSections(MCLinker & pLinker)55   virtual void initTargetSections(MCLinker& pLinker) { }
initTargetSymbols(MCLinker & pLinker,const Output & pOutput)56   virtual void initTargetSymbols(MCLinker& pLinker, const Output& pOutput) { }
initTargetRelocation(MCLinker & pLinker)57   virtual void initTargetRelocation(MCLinker& pLinker) { }
58   virtual bool initStandardSymbols(MCLinker& pLinker, const Output& pOutput) = 0;
59   virtual bool initRelocFactory(const MCLinker& pLinker) = 0;
60 
61   virtual RelocationFactory* getRelocFactory() = 0;
62 
63   /// scanRelocation - When read in relocations, backend can do any modification
64   /// to relocation and generate empty entries, such as GOT, dynamic relocation
65   /// entries and other target dependent entries. These entries are generated
66   /// for layout to adjust the ouput offset.
67   /// @param pReloc - a read in relocation entry
68   /// @param pInputSym - the input LDSymbol of relocation target symbol
69   /// @param pOutput - the ouput file
70   virtual void scanRelocation(Relocation& pReloc,
71                               const LDSymbol& pInputSym,
72                               MCLinker& pLinker,
73                               const MCLDInfo& pLDInfo,
74                               const Output& pOutput,
75                               const LDSection& pSection) = 0;
76 
77   // -----  format dependent  ----- //
78   virtual bool initArchiveReader(MCLinker&,
79                                  MCLDInfo&,
80                                  MemoryAreaFactory&) = 0;
81   virtual bool initObjectReader(MCLinker&) = 0;
82   virtual bool initDynObjReader(MCLinker&) = 0;
83   virtual bool initObjectWriter(MCLinker&) = 0;
84   virtual bool initDynObjWriter(MCLinker&) = 0;
85   virtual bool initExecWriter(MCLinker&) = 0;
86 
87   virtual bool initExecSections(MCLinker&) = 0;
88   virtual bool initDynObjSections(MCLinker&) = 0;
89 
90   virtual ArchiveReader *getArchiveReader() = 0;
91   virtual ObjectReader *getObjectReader() = 0;
92   virtual DynObjReader *getDynObjReader() = 0;
93   virtual ObjectWriter *getObjectWriter() = 0;
94   virtual DynObjWriter *getDynObjWriter() = 0;
95   virtual ExecWriter *getExecWriter() = 0;
96 
97   virtual LDFileFormat* getDynObjFileFormat() = 0;
98   virtual LDFileFormat* getExecFileFormat() = 0;
99 
100   /// preLayout - Backend can do any needed modification before layout
101   virtual void preLayout(const Output& pOutput,
102                          const MCLDInfo& pInfo,
103                          MCLinker& pLinker) = 0;
104 
105   /// postLayout -Backend can do any needed modification after layout
106   virtual void postLayout(const Output& pOutput,
107                           const MCLDInfo& pInfo,
108                           MCLinker& pLinker) = 0;
109 
110   /// postProcessing - Backend can do any needed modification in the final stage
111   virtual void postProcessing(const Output& pOutput,
112                               const MCLDInfo& pInfo,
113                               MCLinker& pLinker) = 0;
114 
115   /// Is the target machine little endian? **/
116   virtual bool isLittleEndian() const = 0;
117 
118   /// bit class. the bit length of the target machine, 32 or 64 **/
119   virtual unsigned int bitclass() const = 0;
120 
121   /// the common page size of the target machine
122   virtual uint64_t commonPageSize(const MCLDInfo& pInfo) const = 0;
123 
124   /// the abi page size of the target machine
125   virtual uint64_t abiPageSize(const MCLDInfo& pInfo) const = 0;
126 
127   /// section start offset in the output file
128   virtual size_t sectionStartOffset() const = 0;
129 
130   /// computeSectionOrder - compute the layout order of the given section
131   virtual unsigned int getSectionOrder(const Output& pOutput,
132                                        const LDSection& pSectHdr,
133                                        const MCLDInfo& pInfo) const = 0;
134 
135   /// sizeNamePools - compute the size of regular name pools
136   /// In ELF executable files, regular name pools are .symtab, .strtab.,
137   /// .dynsym, .dynstr, and .hash
138   virtual void
139   sizeNamePools(const Output& pOutput,
140                 const SymbolCategory& pSymbols,
141                 const MCLDInfo& pLDInfo) = 0;
142 
143   /// finalizeSymbol - Linker checks pSymbol.reserved() if it's not zero,
144   /// then it will ask backend to finalize the symbol value.
145   /// @return ture - if backend set the symbol value sucessfully
146   /// @return false - if backend do not recognize the symbol
147   virtual bool finalizeSymbols(MCLinker& pLinker, const Output& pOutput) = 0;
148 
149   /// allocateCommonSymbols - allocate common symbols in the corresponding
150   /// sections.
151   virtual bool allocateCommonSymbols(const MCLDInfo& pLDInfo, MCLinker& pLinker) const = 0;
152 
153   /// readSection - read a target dependent section
readSection(Input & pInput,MCLinker & pLinker,LDSection & pInputSectHdr)154   virtual bool readSection(Input& pInput,
155                            MCLinker& pLinker,
156                            LDSection& pInputSectHdr)
157   { return true; }
158 
159   /// dyld - the name of the default dynamic linker
160   virtual const char* dyld() const = 0;
161 
162   /// sizeInterp - compute the size of program interpreter's name
163   /// In ELF executables, this is the length of dynamic linker's path name
164   virtual void sizeInterp(const Output& pOutput, const MCLDInfo& pLDInfo) = 0;
165 
166 public:
167   EhFrame* getEhFrame();
168 
169   const EhFrame* getEhFrame() const;
170 
171 private:
172   /// m_pEhFrame - section .eh_frame
173   EhFrame* m_pEhFrame;
174 
175 };
176 
177 } // End mcld namespace
178 
179 #endif
180