GNUArchiveReader.h revision affc150dc44fab1911775a49636d0ce85333b634
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 17#include <vector> 18#include <string> 19 20namespace llvm 21{ 22class MemoryBuffer; 23 24} 25 26namespace mcld 27{ 28class MemoryArea; 29class MCLDInfo; 30class Input; 31class InputTree; 32 33/** \class GNUArchiveReader 34 * \brief GNUArchiveReader reads GNU archive files. 35 */ 36class GNUArchiveReader : public ArchiveReader 37{ 38private: 39 struct SymbolTableEntry; 40 41 enum Constant 42 { 43 /// The length of the magic strign at the end of an archive member header. 44 HeaderFinalMagicSize = 2, 45 /// The length of the magic string at the start of an archive. 46 ArchiveMagicSize = 8 47 }; 48 /// The magic string at the start of an archive. 49 static const char ArchiveMagic[ArchiveMagicSize]; 50 static const char ThinArchiveMagic[ArchiveMagicSize]; 51 /// The Magic string expected at the end of an archive member header. 52 static const char HeaderFinalMagic[HeaderFinalMagicSize]; 53 54public: 55 explicit GNUArchiveReader(MCLDInfo &pLDInfo) 56 : m_pLDInfo(pLDInfo) 57 { } 58 59 ~GNUArchiveReader() 60 { } 61 62 /// Read an archive and extract each member in. 63 /// Construct the coresponding Input for each member. 64 InputTree *readArchive(Input &input); 65 66 bool isMyFormat(Input &input) const; 67 68 LDReader::Endian endian(Input& pFile) const; 69 70private: 71 /// set up the archive, including 72 /// first, read symbol table 73 /// second, read extended file name which is used in thin archive 74 InputTree *setupNewArchive(Input &pInput, size_t off); 75 76 /// read the archive header, and return the member size 77 size_t readMemberHeader(MemoryArea &pArea, 78 off_t off, 79 std::string *p_Name, 80 off_t *nestedOff, 81 std::string &p_ExtendedName); 82 83 void readSymbolTable(MemoryArea &pArea, 84 std::vector<SymbolTableEntry> &pSymbolTable, 85 off_t start, 86 size_t size); 87 88private: 89 MCLDInfo &m_pLDInfo; 90}; 91 92} // namespace of mcld 93 94#endif 95 96