GNUArchiveReader.h revision 22add6ff3426df1a85089fe6a6e1597ee3b6f300
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
18namespace mcld {
19
20class Module;
21class Input;
22class ELFObjectReader;
23class MemoryAreaFactory;
24class Archive;
25
26/** \class GNUArchiveReader
27 *  \brief GNUArchiveReader reads GNU archive files.
28 */
29class GNUArchiveReader : public ArchiveReader
30{
31public:
32  GNUArchiveReader(Module& pModule, ELFObjectReader& pELFObjectReader);
33
34  ~GNUArchiveReader();
35
36  /// readArchive - read an archive, include the needed members, and build up
37  /// the subtree
38  bool readArchive(Archive& pArchive);
39
40  /// isMyFormat
41  bool isMyFormat(Input& input) const;
42
43private:
44  /// isArchive
45  bool isArchive(const char* pStr) const;
46
47  /// isThinArchive
48  bool isThinArchive(const char* pStr) const;
49
50  /// isThinArchive
51  bool isThinArchive(Input& input) const;
52
53  /// readMemberHeader - read the header of a member in a archive file and then
54  /// return the corresponding archive member (it may be an input object or
55  /// another archive)
56  /// @param pArchiveRoot  - the archive root that holds the strtab (extended
57  ///                        name table)
58  /// @param pArchiveFile  - the archive that contains the needed object
59  /// @param pFileOffset   - file offset of the member header in the archive
60  /// @param pNestedOffset - used when we find a nested archive
61  /// @param pMemberSize   - the file size of this member
62  Input* readMemberHeader(Archive& pArchiveRoot,
63                          Input& pArchiveFile,
64                          uint32_t pFileOffset,
65                          uint32_t& pNestedOffset,
66                          size_t& pMemberSize);
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  /// includeMember - include the object member in the given file offset, and
80  /// return the size of the object
81  /// @param pArchiveRoot - the archive root
82  /// @param pFileOffset  - file offset of the member header in the archive
83  size_t includeMember(Archive& pArchiveRoot, uint32_t pFileOffset);
84
85  /// includeAllMembers - include all object members. This is called if
86  /// --whole-archive is the attribute for this archive file.
87  bool includeAllMembers(Archive& pArchive);
88
89private:
90  Module& m_Module;
91  ELFObjectReader& m_ELFObjectReader;
92};
93
94} // namespace of mcld
95
96#endif
97
98