1 //===- FragmentLinker.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 // 10 // This file provides a number of APIs used by SectLinker. 11 // These APIs do the things which a linker should do. 12 // 13 //===----------------------------------------------------------------------===// 14 #ifndef MCLD_FRAGMENT_FRAGMENT_LINKER_H 15 #define MCLD_FRAGMENT_FRAGMENT_LINKER_H 16 #ifdef ENABLE_UNITTEST 17 #include <gtest.h> 18 #endif 19 20 #include <string> 21 22 #include <mcld/LinkerConfig.h> 23 #include <mcld/LD/LDFileFormat.h> 24 #include <mcld/LD/LDSymbol.h> 25 #include <mcld/Fragment/Relocation.h> 26 #include <mcld/MC/MCLDInput.h> 27 28 namespace mcld { 29 30 class Module; 31 class TargetLDBackend; 32 class LinkerConfig; 33 class MemoryArea; 34 35 /** \class FragmentLinker 36 * \brief FragmentLinker provides a pass to link object files. 37 */ 38 class FragmentLinker 39 { 40 public: 41 FragmentLinker(const LinkerConfig& pConfig, 42 Module& pModule, 43 TargetLDBackend& pBackend); 44 45 ~FragmentLinker(); 46 47 bool finalizeSymbols(); 48 49 /// applyRelocations - apply all relocation enties. 50 bool applyRelocations(); 51 52 /// syncRelocationResult - After applying relocation, write back relocation target 53 /// data to output file. 54 void syncRelocationResult(MemoryArea& pOutput); 55 56 private: 57 /// normalSyncRelocationResult - sync relocation result when producing shared 58 /// objects or executables 59 void normalSyncRelocationResult(MemoryArea& pOutput); 60 61 /// partialSyncRelocationResult - sync relocation result when doing partial 62 /// link 63 void partialSyncRelocationResult(MemoryArea& pOutput); 64 65 /// writeRelocationResult - helper function of syncRelocationResult, write 66 /// relocation target data to output 67 void writeRelocationResult(Relocation& pReloc, uint8_t* pOutput); 68 69 private: 70 const LinkerConfig& m_Config; 71 Module& m_Module; 72 TargetLDBackend& m_Backend; 73 }; 74 75 } // namespace of mcld 76 77 #endif 78 79