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