• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- GNUArchiveReader.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_GNU_ARCHIVE_READER_H
10 #define MCLD_GNU_ARCHIVE_READER_H
11 #ifdef ENABLE_UNITTEST
12 #include <gtest.h>
13 #endif
14 
15 #include <mcld/LD/ArchiveReader.h>
16 #include <mcld/LD/Archive.h>
17 
18 namespace mcld
19 {
20 class MemoryAreaFactory;
21 class MCLDInfo;
22 class Input;
23 class ELFObjectReader;
24 class Archive;
25 
26 /** \class GNUArchiveReader
27  *  \brief GNUArchiveReader reads GNU archive files.
28  */
29 class GNUArchiveReader : public ArchiveReader
30 {
31 public:
32   explicit GNUArchiveReader(MCLDInfo& pLDInfo,
33                             MemoryAreaFactory& pMemAreaFactory,
34                             ELFObjectReader& pELFObjectReader);
35 
36   ~GNUArchiveReader();
37 
38   /// readArchive - read an archive, include the needed members, and build up
39   /// the subtree
40   bool readArchive(Archive& pArchive);
41 
42   /// isMyFormat
43   bool isMyFormat(Input& input) const;
44 
45 private:
46   /// isArchive
47   bool isArchive(const char* pStr) const;
48 
49   /// isThinArchive
50   bool isThinArchive(const char* pStr) const;
51 
52   /// isThinArchive
53   bool isThinArchive(Input& input) const;
54 
55   /// readMemberHeader - read the header of a member in a archive file and then
56   /// return the corresponding archive member (it may be an input object or
57   /// another archive)
58   /// @param pArchiveRoot  - the archive root that holds the strtab (extended
59   ///                        name table)
60   /// @param pArchiveFile  - the archive that contains the needed object
61   /// @param pFileOffset   - file offset of the member header in the archive
62   /// @param pNestedOffset - used when we find a nested archive
63   Input* readMemberHeader(Archive& pArchiveRoot,
64                           Input& pArchiveFile,
65                           uint32_t pFileOffset,
66                           uint32_t& pNestedOffset);
67 
68   /// readSymbolTable - read the archive symbol map (armap)
69   bool readSymbolTable(Archive& pArchive);
70 
71   /// readStringTable - read the strtab for long file name of the archive
72   bool readStringTable(Archive& pArchive);
73 
74   /// shouldIncludeSymbol - given a sym name from armap and check if we should
75   /// include the corresponding archive member, and then return the decision
76   enum Archive::Symbol::Status
77   shouldIncludeSymbol(const llvm::StringRef& pSymName) const;
78 
79 private:
80   MCLDInfo& m_LDInfo;
81   MemoryAreaFactory& m_MemAreaFactory;
82   ELFObjectReader& m_ELFObjectReader;
83 };
84 
85 } // namespace of mcld
86 
87 #endif
88 
89