1 //===- ELFObjectReader.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 MCLD_ELF_OBJECT_READER_H 10 #define MCLD_ELF_OBJECT_READER_H 11 #ifdef ENABLE_UNITTEST 12 #include <gtest.h> 13 #endif 14 15 #include <mcld/LD/ObjectReader.h> 16 #include <mcld/ADT/Flags.h> 17 18 namespace mcld { 19 20 class Module; 21 class Input; 22 class IRBuilder; 23 class GNULDBackend; 24 class ELFReaderIF; 25 class EhFrameReader; 26 class LinkerConfig; 27 28 /** \lclass ELFObjectReader 29 * \brief ELFObjectReader reads target-independent parts of ELF object file 30 */ 31 class ELFObjectReader : public ObjectReader 32 { 33 public: 34 enum ReadFlagType { 35 ParseEhFrame = 0x1, ///< parse .eh_frame section if the bit is set. 36 NumOfReadFlags = 1 37 }; 38 39 typedef Flags<ReadFlagType> ReadFlag; 40 41 public: 42 ELFObjectReader(GNULDBackend& pBackend, 43 IRBuilder& pBuilder, 44 const LinkerConfig& pConfig); 45 46 ~ELFObjectReader(); 47 48 // ----- observers ----- // 49 bool isMyFormat(Input &pFile) const; 50 51 // ----- readers ----- // 52 bool readHeader(Input& pFile); 53 54 virtual bool readSections(Input& pFile); 55 56 virtual bool readSymbols(Input& pFile); 57 58 /// readRelocations - read relocation sections 59 /// 60 /// This function should be called after symbol resolution. 61 virtual bool readRelocations(Input& pFile); 62 63 private: 64 ELFReaderIF* m_pELFReader; 65 EhFrameReader* m_pEhFrameReader; 66 IRBuilder& m_Builder; 67 ReadFlag m_ReadFlag; 68 GNULDBackend& m_Backend; 69 const LinkerConfig& m_Config; 70 }; 71 72 } // namespace of mcld 73 74 #endif 75 76