1 //===- SectLinker.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 //SectLinker is a base class inherited by target specific linker. 11 //This class primarily handles common functionality used by all linkers. 12 // 13 //===----------------------------------------------------------------------===// 14 #ifndef MCLD_SECTION_LINKER_H 15 #define MCLD_SECTION_LINKER_H 16 #ifdef ENABLE_UNITTEST 17 #include <gtest.h> 18 #endif 19 #include <llvm/CodeGen/MachineFunctionPass.h> 20 #include <mcld/Support/PositionDependentOption.h> 21 #include <vector> 22 23 namespace llvm 24 { 25 class Module; 26 class MachineFunction; 27 } // namespace of llvm 28 29 namespace mcld 30 { 31 class MCLDInfo; 32 class MCLDFile; 33 class MCLDDriver; 34 class TargetLDBackend; 35 class AttributeFactory; 36 class SectLinkerOption; 37 class MemoryAreaFactory; 38 39 /** \class SectLinker 40 * \brief SectLinker provides a linking pass for standard compilation flow 41 * 42 * SectLinker is responded for 43 * - provide an interface for target-specific SectLinekr 44 * - set up environment for MCLDDriver 45 * - control AsmPrinter, make sure AsmPrinter has already prepared 46 * all SectionDatas for linking 47 * 48 * SectLinker resolves the absolue paths of input arguments. 49 * 50 * @see MachineFunctionPass MCLDDriver 51 */ 52 class SectLinker : public llvm::MachineFunctionPass 53 { 54 protected: 55 // Constructor. Although SectLinker has only two arguments, 56 // TargetSectLinker should handle 57 // - enabled attributes 58 // - the default attribute 59 // - the default link script 60 // - the standard symbols 61 SectLinker(SectLinkerOption &pOption, 62 TargetLDBackend &pLDBackend); 63 64 public: 65 virtual ~SectLinker(); 66 67 /// doInitialization - Read all parameters and set up the AsmPrinter. 68 /// If your pass overrides this, it must make sure to explicitly call 69 /// this implementation. 70 virtual bool doInitialization(llvm::Module &pM); 71 72 /// doFinalization - Shut down the AsmPrinter, and do really linking. 73 /// If you override this in your pass, you must make sure to call it 74 /// explicitly. 75 virtual bool doFinalization(llvm::Module &pM); 76 77 /// runOnMachineFunction 78 /// redirect to AsmPrinter 79 virtual bool runOnMachineFunction(llvm::MachineFunction& pMFn); 80 81 protected: 82 void initializeInputTree(const PositionDependentOptions &pOptions) const; 83 84 void initializeInputOutput(MCLDInfo& pLDInfo); 85 memAreaFactory()86 MemoryAreaFactory* memAreaFactory() 87 { return m_pMemAreaFactory; } 88 89 private: 90 SectLinkerOption *m_pOption; 91 92 protected: 93 TargetLDBackend *m_pLDBackend; 94 MCLDDriver *m_pLDDriver; 95 MemoryAreaFactory *m_pMemAreaFactory; 96 97 private: 98 static char m_ID; 99 }; 100 101 } // namespace of MC Linker 102 103 #endif 104 105