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 15 namespace mcld { 16 17 class MCLinker; 18 class Relocation; 19 class RelocationFactory; 20 class Layout; 21 class ArchiveReader; 22 class ObjectReader; 23 class DynObjReader; 24 class ObjectWriter; 25 class DynObjWriter; 26 class LDContext; 27 class SectionMap; 28 class Output; 29 class MCLDInfo; 30 class SymbolCategory; 31 class Input; 32 class LDFileFormat; 33 class GOT; 34 35 //===----------------------------------------------------------------------===// 36 /// TargetLDBackend - Generic interface to target specific assembler backends. 37 /// 38 class TargetLDBackend 39 { 40 TargetLDBackend(const TargetLDBackend &); // DO NOT IMPLEMENT 41 void operator=(const TargetLDBackend &); // DO NOT IMPLEMENT 42 43 protected: 44 TargetLDBackend(); 45 46 public: 47 virtual ~TargetLDBackend(); 48 49 // ----- target dependent ----- // 50 virtual bool initTargetSectionMap(SectionMap& pSectionMap) { return true;} 51 virtual void initTargetSegments(MCLinker& pLinker) { } 52 virtual void initTargetSections(MCLinker& pLinker) { } 53 virtual void initTargetSymbols(MCLinker& pLinker) { } 54 virtual void initTargetRelocation(MCLinker& pLinker) { } 55 virtual bool initStandardSymbols(MCLinker& pLinker) = 0; 56 virtual bool initRelocFactory(const MCLinker& pLinker) = 0; 57 58 virtual RelocationFactory* getRelocFactory() = 0; 59 60 /// scanRelocation - When read in relocations, backend can do any modification 61 /// to relocation and generate empty entries, such as GOT, dynamic relocation 62 /// entries and other target dependent entries. These entries are generated 63 /// for layout to adjust the ouput offset. 64 /// @param pReloc - a read in relocation entry 65 /// @param pInputSym - the input LDSymbol of relocation target symbol 66 /// @param pOutput - the ouput file 67 virtual void scanRelocation(Relocation& pReloc, 68 const LDSymbol& pInputSym, 69 MCLinker& pLinker, 70 const MCLDInfo& pLDInfo, 71 const Output& pOutput) = 0; 72 73 // ----- format dependent ----- // 74 virtual bool initArchiveReader(MCLinker&, MCLDInfo&) = 0; 75 virtual bool initObjectReader(MCLinker&) = 0; 76 virtual bool initDynObjReader(MCLinker&) = 0; 77 virtual bool initObjectWriter(MCLinker&) = 0; 78 virtual bool initDynObjWriter(MCLinker&) = 0; 79 80 virtual bool initExecSections(MCLinker&) = 0; 81 virtual bool initDynObjSections(MCLinker&) = 0; 82 83 virtual ArchiveReader *getArchiveReader() = 0; 84 virtual ObjectReader *getObjectReader() = 0; 85 virtual DynObjReader *getDynObjReader() = 0; 86 virtual ObjectWriter *getObjectWriter() = 0; 87 virtual DynObjWriter *getDynObjWriter() = 0; 88 89 virtual LDFileFormat* getDynObjFileFormat() = 0; 90 virtual LDFileFormat* getExecFileFormat() = 0; 91 92 /// preLayout - Backend can do any needed modification before layout 93 virtual void preLayout(const Output& pOutput, 94 const MCLDInfo& pInfo, 95 MCLinker& pLinker) = 0; 96 97 /// postLayout -Backend can do any needed modification after layout 98 virtual void postLayout(const Output& pOutput, 99 const MCLDInfo& pInfo, 100 MCLinker& pLinker) = 0; 101 102 /// Is the target machine little endian? **/ 103 virtual bool isLittleEndian() const = 0; 104 105 /// bit class. the bit length of the target machine, 32 or 64 **/ 106 virtual unsigned int bitclass() const = 0; 107 108 /// the page size of the target machine 109 virtual unsigned int pagesize() const = 0; 110 111 /// section start offset in the output file 112 virtual size_t sectionStartOffset() const = 0; 113 114 /// computeSectionOrder - compute the layout order of the given section 115 virtual unsigned int getSectionOrder(const Output& pOutput, 116 const LDSection& pSectHdr) const = 0; 117 118 /// sizeNamePools - compute the size of regular name pools 119 /// In ELF executable files, regular name pools are .symtab, .strtab., 120 /// .dynsym, .dynstr, and .hash 121 virtual void 122 sizeNamePools(const Output& pOutput, 123 const SymbolCategory& pSymbols, 124 const MCLDInfo& pLDInfo) = 0; 125 126 /// finalizeSymbol - Linker checks pSymbol.reserved() if it's not zero, 127 /// then it will ask backend to finalize the symbol value. 128 /// @return ture - if backend set the symbol value sucessfully 129 /// @return false - if backend do not recognize the symbol 130 virtual bool finalizeSymbol(LDSymbol& pSymbol) const = 0; 131 132 /// allocateCommonSymbols - allocate common symbols in the corresponding 133 /// sections. 134 virtual bool allocateCommonSymbols(const MCLDInfo& pLDInfo, MCLinker& pLinker) const = 0; 135 136 /// readSection - read a target dependent section 137 virtual bool readSection(Input& pInput, 138 MCLinker& pLinker, 139 LDSection& pInputSectHdr) 140 { return true; } 141 142 }; 143 144 } // End mcld namespace 145 146 #endif 147