15460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===- MipsLDBackend.h ----------------------------------------------------===// 25460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// 35460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// The MCLinker Project 45460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// 55460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// This file is distributed under the University of Illinois Open Source 65460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// License. See LICENSE.TXT for details. 75460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// 85460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===----------------------------------------------------------------------===// 95460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#ifndef MIPS_LDBACKEND_H 105460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#define MIPS_LDBACKEND_H 1122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao#include <mcld/Target/GNULDBackend.h> 125460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include "MipsELFDynamic.h" 135460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include "MipsGOT.h" 145460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 155460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaonamespace mcld { 165460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1722add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liaoclass LinkerConfig; 185460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoclass OutputRelocSection; 195460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoclass SectionMap; 2022add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liaoclass MemoryArea; 21d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liaoclass MipsGNUInfo; 225460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 235460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===----------------------------------------------------------------------===// 245460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao/// MipsGNULDBackend - linker backend of Mips target of GNU ELF format 255460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao/// 265460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoclass MipsGNULDBackend : public GNULDBackend 275460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao{ 285460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaopublic: 29f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hines typedef std::vector<LDSymbol*> SymbolListType; 305460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 315460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaopublic: 32d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao MipsGNULDBackend(const LinkerConfig& pConfig, MipsGNUInfo* pInfo); 335460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao ~MipsGNULDBackend(); 345460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 355460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaopublic: 365460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// initTargetSections - initialize target dependent sections in output 3722add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao void initTargetSections(Module& pModule, ObjectBuilder& pBuilder); 385460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 395460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// initTargetSymbols - initialize target dependent symbols in output. 406f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines void initTargetSymbols(IRBuilder& pBuilder, Module& pModule); 415460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 42d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao /// initRelocator - create and initialize Relocator. 436f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines bool initRelocator(); 445460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 45d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao /// getRelocator - return relocator. 46d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao Relocator* getRelocator(); 475460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 485460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// preLayout - Backend can do any needed modification before layout 496f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines void doPreLayout(IRBuilder& pBuilder); 505460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 516f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines /// postLayout - Backend can do any needed modification after layout 526f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines void doPostLayout(Module& pModule, IRBuilder& pBuilder); 535460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 545460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// dynamic - the dynamic section of the target machine. 555460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// Use co-variant return type to return its own dynamic section. 565460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao MipsELFDynamic& dynamic(); 575460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 585460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// dynamic - the dynamic section of the target machine. 595460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// Use co-variant return type to return its own dynamic section. 605460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao const MipsELFDynamic& dynamic() const; 615460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 625460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// emitSectionData - write out the section data into the memory region. 635460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// When writers get a LDSection whose kind is LDFileFormat::Target, writers 645460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// call back target backend to emit the data. 655460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// 665460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// Backends handle the target-special tables (plt, gp,...) by themselves. 67cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao /// Backend can put the data of the tables in SectionData directly 685460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// - LDSection.getSectionData can get the section data. 695460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// Or, backend can put the data into special data structure 705460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// - backend can maintain its own map<LDSection, table> to get the table 715460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// from given LDSection. 725460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// 735460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// @param pSection - the given LDSection 745460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// @param pRegion - the region to write out data 755460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// @return the size of the table in the file. 7622add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao uint64_t emitSectionData(const LDSection& pSection, 775460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao MemoryRegion& pRegion) const; 785460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 79f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hines /// hasEntryInStrTab - symbol has an entry in a .strtab 80f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hines bool hasEntryInStrTab(const LDSymbol& pSym) const; 8122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao 82f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hines /// orderSymbolTable - order symbol table before emitting 83f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hines void orderSymbolTable(Module& pModule); 845460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 855460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao MipsGOT& getGOT(); 865460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao const MipsGOT& getGOT() const; 875460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 885460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao OutputRelocSection& getRelDyn(); 895460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao const OutputRelocSection& getRelDyn() const; 905460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 91f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hines LDSymbol* getGOTSymbo() { return m_pGOTSymbol; } 92f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hines const LDSymbol* getGOTSymbo() const { return m_pGOTSymbol; } 93f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hines 94f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hines LDSymbol* getGpDispSymbol() { return m_pGpDispSymbol; } 95f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hines const LDSymbol* getGpDispSymbol() const { return m_pGpDispSymbol; } 96f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hines 97f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hines SymbolListType& getGlobalGOTSyms() { return m_GlobalGOTSyms; } 98f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hines const SymbolListType& getGlobalGOTSyms() const { return m_GlobalGOTSyms; } 99f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hines 1005460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// getTargetSectionOrder - compute the layout order of ARM target sections 10122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao unsigned int getTargetSectionOrder(const LDSection& pSectHdr) const; 1025460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1035460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// finalizeSymbol - finalize the symbol value 1046f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines bool finalizeTargetSymbols(); 1055460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1065460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// allocateCommonSymbols - allocate common symbols in the corresponding 1075460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao /// sections. 10822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao bool allocateCommonSymbols(Module& pModule); 1095460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1105460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoprivate: 1116f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines void defineGOTSymbol(IRBuilder& pBuilder); 11222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao 11322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao /// emitSymbol32 - emit an ELF32 symbol, override parent's function 11422add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao void emitSymbol32(llvm::ELF::Elf32_Sym& pSym32, 11522add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao LDSymbol& pSymbol, 11622add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao char* pStrtab, 11722add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao size_t pStrtabsize, 11822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao size_t pSymtabIdx); 11922add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao 12022add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao /// getRelEntrySize - the size in BYTE of rel type relocation 12122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao size_t getRelEntrySize() 12222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao { return 8; } 12322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao 12422add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao /// getRelEntrySize - the size in BYTE of rela type relocation 12522add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao size_t getRelaEntrySize() 12622add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao { return 12; } 12722add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao 12822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao /// doCreateProgramHdrs - backend can implement this function to create the 12922add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao /// target-dependent segments 1306f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines void doCreateProgramHdrs(Module& pModule); 1315460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1325460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoprivate: 133d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao Relocator* m_pRelocator; 1345460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1355460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao MipsGOT* m_pGOT; // .got 1365460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao OutputRelocSection* m_pRelDyn; // .rel.dyn 1375460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1385460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao MipsELFDynamic* m_pDynamic; 1395460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao LDSymbol* m_pGOTSymbol; 1405460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao LDSymbol* m_pGpDispSymbol; 1415460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 142f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hines SymbolListType m_GlobalGOTSyms; 1435460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao}; 1445460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1455460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} // namespace of mcld 1465460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1475460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#endif 148affc150dc44fab1911775a49636d0ce85333b634Zonr Chang 149