AArch64LDBackend.h revision 551ae4ebd3e9d137ea668fb83ae4a55b8cfba451
1//===- AArch64LDBackend.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 TARGET_AARCH64_AARCH64LDBACKEND_H 10#define TARGET_AARCH64_AARCH64LDBACKEND_H 11 12#include "AArch64ELFDynamic.h" 13#include "AArch64GOT.h" 14#include "AArch64PLT.h" 15#include <mcld/LD/LDSection.h> 16#include <mcld/Target/GNULDBackend.h> 17#include <mcld/Target/OutputRelocSection.h> 18 19namespace mcld { 20 21class LinkerConfig; 22class GNUInfo; 23 24//===----------------------------------------------------------------------===// 25/// AArch64GNULDBackend - linker backend of AArch64 target of GNU ELF format 26/// 27class AArch64GNULDBackend : public GNULDBackend 28{ 29public: 30 AArch64GNULDBackend(const LinkerConfig& pConfig, GNUInfo* pInfo); 31 ~AArch64GNULDBackend(); 32 33public: 34 /// initTargetSections - initialize target dependent sections in output. 35 void initTargetSections(Module& pModule, ObjectBuilder& pBuilder); 36 37 /// initTargetSymbols - initialize target dependent symbols in output. 38 void initTargetSymbols(IRBuilder& pBuilder, Module& pModule); 39 40 /// initRelocator - create and initialize Relocator. 41 bool initRelocator(); 42 43 /// getRelocator - return relocator. 44 Relocator* getRelocator(); 45 46 47 /// doPreLayout - Backend can do any needed modification before layout 48 void doPreLayout(IRBuilder& pBuilder); 49 50 /// doPostLayout -Backend can do any needed modification after layout 51 void doPostLayout(Module& pModule, IRBuilder& pBuilder); 52 53 /// dynamic - the dynamic section of the target machine. 54 /// Use co-variant return type to return its own dynamic section. 55 AArch64ELFDynamic& dynamic(); 56 57 /// dynamic - the dynamic section of the target machine. 58 /// Use co-variant return type to return its own dynamic section. 59 const AArch64ELFDynamic& dynamic() const; 60 61 62 /// emitSectionData - write out the section data into the memory region. 63 /// When writers get a LDSection whose kind is LDFileFormat::Target, writers 64 /// call back target backend to emit the data. 65 /// 66 /// Backends handle the target-special tables (plt, gp,...) by themselves. 67 /// Backend can put the data of the tables in SectionData directly 68 /// - LDSection.getSectionData can get the section data. 69 /// Or, backend can put the data into special data structure 70 /// - backend can maintain its own map<LDSection, table> to get the table 71 /// from given LDSection. 72 /// 73 /// @param pSection - the given LDSection 74 /// @param pConfig - all options in the command line. 75 /// @param pRegion - the region to write out data 76 /// @return the size of the table in the file. 77 uint64_t emitSectionData(const LDSection& pSection, 78 MemoryRegion& pRegion) const; 79 80 AArch64GOT& getGOT(); 81 const AArch64GOT& getGOT() const; 82 83 AArch64GOT& getGOTPLT(); 84 const AArch64GOT& getGOTPLT() const; 85 86 AArch64PLT& getPLT(); 87 const AArch64PLT& getPLT() const; 88 89 OutputRelocSection& getRelaDyn(); 90 const OutputRelocSection& getRelaDyn() const; 91 92 OutputRelocSection& getRelaPLT(); 93 const OutputRelocSection& getRelaPLT() const; 94 95 LDSymbol* getGOTSymbol() { return m_pGOTSymbol; } 96 const LDSymbol* getGOTSymbol() const { return m_pGOTSymbol; } 97 98 /// getTargetSectionOrder - compute the layout order of AArch64 target sections 99 unsigned int getTargetSectionOrder(const LDSection& pSectHdr) const; 100 101 /// finalizeTargetSymbols - finalize the symbol value 102 bool finalizeTargetSymbols(); 103 104 /// mergeSection - merge target dependent sections 105 bool mergeSection(Module& pModule, const Input& pInput, LDSection& pSection); 106 107 /// readSection - read target dependent sections 108 bool readSection(Input& pInput, SectionData& pSD); 109 110private: 111 void defineGOTSymbol(IRBuilder& pBuilder); 112 113 /// maxBranchOffset 114 /// FIXME: 115 uint64_t maxBranchOffset() { return 0x0; } 116 117 /// mayRelax - Backends should override this function if they need relaxation 118 bool mayRelax() { return true; } 119 120 /// doRelax - Backend can orevride this function to add its relaxation 121 /// implementation. Return true if the output (e.g., .text) is "relaxed" 122 /// (i.e. layout is changed), and set pFinished to true if everything is fit, 123 /// otherwise set it to false. 124 bool doRelax(Module& pModule, IRBuilder& pBuilder, bool& pFinished); 125 126 /// initTargetStubs 127 bool initTargetStubs(); 128 129 /// getRelEntrySize - the size in BYTE of rel type relocation 130 size_t getRelEntrySize() 131 { return 16; } 132 133 /// getRelEntrySize - the size in BYTE of rela type relocation 134 size_t getRelaEntrySize() 135 { return 24; } 136 137 /// doCreateProgramHdrs - backend can implement this function to create the 138 /// target-dependent segments 139 virtual void doCreateProgramHdrs(Module& pModule); 140 141private: 142 Relocator* m_pRelocator; 143 144 AArch64GOT* m_pGOT; 145 AArch64GOT* m_pGOTPLT; 146 AArch64PLT* m_pPLT; 147 /// m_RelDyn - dynamic relocation table of .rel.dyn 148 OutputRelocSection* m_pRelaDyn; 149 /// m_RelPLT - dynamic relocation table of .rel.plt 150 OutputRelocSection* m_pRelaPLT; 151 152 /// m_pAttrData - attribute data in public ("aeabi") attribute subsection 153 // AArch64ELFAttributeData* m_pAttrData; 154 155 AArch64ELFDynamic* m_pDynamic; 156 LDSymbol* m_pGOTSymbol; 157 158 // variable name : ELF 159 LDSection* m_pAttributes; // .ARM.attributes 160// LDSection* m_pPreemptMap; // .AArch64.preemptmap 161// LDSection* m_pDebugOverlay; // .AArch64.debug_overlay 162// LDSection* m_pOverlayTable; // .AArch64.overlay_table 163}; 164} // namespace of mcld 165 166#endif 167 168