TargetLDBackend.h revision 22add6ff3426df1a85089fe6a6e1597ee3b6f300
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 MCLD_TARGET_TARGETLDBACKEND_H 10#define MCLD_TARGET_TARGETLDBACKEND_H 11 12#include <llvm/Support/DataTypes.h> 13 14namespace mcld { 15 16class Module; 17class LinkerConfig; 18class FragmentLinker; 19class Relocation; 20class RelocationFactory; 21class Layout; 22class ArchiveReader; 23class ObjectReader; 24class DynObjReader; 25class ObjectWriter; 26class DynObjWriter; 27class ExecWriter; 28class LDFileFormat; 29class LDSymbol; 30class LDSection; 31class SectionData; 32class Input; 33class GOT; 34class MemoryArea; 35class MemoryAreaFactory; 36class BranchIslandFactory; 37class StubFactory; 38class ObjectBuilder; 39 40//===----------------------------------------------------------------------===// 41/// TargetLDBackend - Generic interface to target specific assembler backends. 42//===----------------------------------------------------------------------===// 43class TargetLDBackend 44{ 45 TargetLDBackend(const TargetLDBackend &); // DO NOT IMPLEMENT 46 void operator=(const TargetLDBackend &); // DO NOT IMPLEMENT 47 48protected: 49 TargetLDBackend(const LinkerConfig& pConfig); 50 51public: 52 virtual ~TargetLDBackend(); 53 54 // ----- target dependent ----- // 55 virtual void initTargetSegments(FragmentLinker& pLinker) { } 56 virtual void initTargetSections(Module& pModule, ObjectBuilder& pBuilder) { } 57 virtual void initTargetSymbols(FragmentLinker& pLinker) { } 58 virtual void initTargetRelocation(FragmentLinker& pLinker) { } 59 virtual bool initStandardSymbols(FragmentLinker& pLinker, Module& pModule) = 0; 60 virtual bool initRelocFactory(const FragmentLinker& pLinker) = 0; 61 62 virtual RelocationFactory* getRelocFactory() = 0; 63 64 /// scanRelocation - When read in relocations, backend can do any modification 65 /// to relocation and generate empty entries, such as GOT, dynamic relocation 66 /// entries and other target dependent entries. These entries are generated 67 /// for layout to adjust the ouput offset. 68 /// @param pReloc - a read in relocation entry 69 /// @param pInputSym - the input LDSymbol of relocation target symbol 70 /// @param pSection - the section of relocation applying target 71 virtual void scanRelocation(Relocation& pReloc, 72 FragmentLinker& pLinker, 73 Module& pModule, 74 const LDSection& pSection) = 0; 75 76 /// partialScanRelocation - When doing partial linking, backend can do any 77 /// modification to relocation to fix the relocation offset after section 78 /// merge 79 /// @param pReloc - a read in relocation entry 80 /// @param pInputSym - the input LDSymbol of relocation target symbol 81 /// @param pSection - the section of relocation applying target 82 virtual void partialScanRelocation(Relocation& pReloc, 83 FragmentLinker& pLinker, 84 Module& pModule, 85 const LDSection& pSection) = 0; 86 87 // ----- format dependent ----- // 88 virtual ArchiveReader* createArchiveReader(Module&) = 0; 89 virtual ObjectReader* createObjectReader(FragmentLinker&) = 0; 90 virtual DynObjReader* createDynObjReader(FragmentLinker&) = 0; 91 virtual ObjectWriter* createObjectWriter(FragmentLinker&) = 0; 92 virtual DynObjWriter* createDynObjWriter(FragmentLinker&) = 0; 93 virtual ExecWriter* createExecWriter(FragmentLinker&) = 0; 94 95 virtual bool initStdSections(ObjectBuilder& pBuilder) = 0; 96 97 /// preLayout - Backend can do any needed modification before layout 98 virtual void preLayout(Module& pModule, FragmentLinker& pLinker) = 0; 99 100 /// postLayout -Backend can do any needed modification after layout 101 virtual void postLayout(Module& pModule, FragmentLinker& pLinker) = 0; 102 103 /// postProcessing - Backend can do any needed modification in the final stage 104 virtual void postProcessing(FragmentLinker& pLinker, 105 MemoryArea& pOutput) = 0; 106 107 /// Is the target machine little endian? **/ 108 virtual bool isLittleEndian() const = 0; 109 110 /// bit class. the bit length of the target machine, 32 or 64 **/ 111 virtual unsigned int bitclass() const = 0; 112 113 /// the common page size of the target machine 114 virtual uint64_t commonPageSize() const = 0; 115 116 /// the abi page size of the target machine 117 virtual uint64_t abiPageSize() const = 0; 118 119 /// section start offset in the output file 120 virtual size_t sectionStartOffset() const = 0; 121 122 /// computeSectionOrder - compute the layout order of the given section 123 virtual unsigned int getSectionOrder(const LDSection& pSectHdr) const = 0; 124 125 /// sizeNamePools - compute the size of regular name pools 126 /// In ELF executable files, regular name pools are .symtab, .strtab., 127 /// .dynsym, .dynstr, and .hash 128 virtual void 129 sizeNamePools(const Module& pModule, bool pIsStaticLink) = 0; 130 131 /// finalizeSymbol - Linker checks pSymbol.reserved() if it's not zero, 132 /// then it will ask backend to finalize the symbol value. 133 /// @return ture - if backend set the symbol value sucessfully 134 /// @return false - if backend do not recognize the symbol 135 virtual bool finalizeSymbols(FragmentLinker& pLinker) = 0; 136 137 /// finalizeTLSSymbol - Linker asks backend to set the symbol value when it 138 /// meets a TLS symbol 139 virtual bool finalizeTLSSymbol(LDSymbol& pSymbol) = 0; 140 141 /// allocateCommonSymbols - allocate common symbols in the corresponding 142 /// sections. 143 virtual bool allocateCommonSymbols(Module& pModule) = 0; 144 145 /// mergeSection - merge target dependent sections. 146 virtual bool mergeSection(Module& pModule, LDSection& pInputSection) 147 { return true; } 148 149 /// readSection - read a target dependent section 150 virtual bool readSection(Input& pInput, SectionData& pSD) 151 { return true; } 152 153 /// dyld - the name of the default dynamic linker 154 virtual const char* dyld() const = 0; 155 156 /// sizeInterp - compute the size of program interpreter's name 157 /// In ELF executables, this is the length of dynamic linker's path name 158 virtual void sizeInterp() = 0; 159 160 // ----- relaxation ----- // 161 virtual bool initBRIslandFactory() = 0; 162 virtual bool initStubFactory() = 0; 163 virtual bool initTargetStubs(FragmentLinker& pLinker) { return true; } 164 165 virtual BranchIslandFactory* getBRIslandFactory() = 0; 166 virtual StubFactory* getStubFactory() = 0; 167 168 /// relax - the relaxation pass 169 virtual bool relax(Module& pModule, FragmentLinker& pLinker) = 0; 170 171 /// mayRelax - return true if the backend needs to do relaxation 172 virtual bool mayRelax() = 0; 173 174protected: 175 const LinkerConfig& config() const { return m_Config; } 176 177private: 178 const LinkerConfig& m_Config; 179}; 180 181} // End mcld namespace 182 183#endif 184