• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- NamePool.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_NAME_POOL_H
10 #define MCLD_NAME_POOL_H
11 #ifdef ENABLE_UNITTEST
12 #include <gtest.h>
13 #endif
14 
15 #include <mcld/Config/Config.h>
16 #include <mcld/ADT/HashTable.h>
17 #include <mcld/ADT/StringHash.h>
18 #include <mcld/ADT/Uncopyable.h>
19 #include <mcld/LD/Resolver.h>
20 #include <mcld/LD/ResolveInfo.h>
21 #include <mcld/Support/GCFactory.h>
22 
23 #include <utility>
24 
25 #include <llvm/ADT/StringRef.h>
26 
27 namespace mcld {
28 
29 class StringTable;
30 class SymbolTableIF;
31 class SectionData;
32 
33 /** \class NamePool
34  *  \brief Store symbol and search symbol by name. Can help symbol resolution.
35  *
36  *  - MCLinker is responsed for creating NamePool.
37  */
38 class NamePool : private Uncopyable
39 {
40 public:
41   typedef HashTable<ResolveInfo, hash::StringHash<hash::ELF> > Table;
42   typedef size_t size_type;
43 
44 public:
45   explicit NamePool(size_type pSize = 3);
46 
47   ~NamePool();
48 
49   // -----  modifiers  ----- //
50   /// createSymbol - create a symbol but do not insert into the pool.
51   /// The created symbol did not go through the path of symbol resolution.
52   ResolveInfo* createSymbol(const llvm::StringRef& pName,
53                             bool pIsDyn,
54                             ResolveInfo::Type pType,
55                             ResolveInfo::Desc pDesc,
56                             ResolveInfo::Binding pBinding,
57                             ResolveInfo::SizeType pSize,
58                             ResolveInfo::Visibility pVisibility = ResolveInfo::Default);
59 
60   /// insertSymbol - insert a symbol and resolve the symbol immediately
61   /// @param pOldInfo - if pOldInfo is not NULL, the old ResolveInfo being
62   ///                   overriden is kept in pOldInfo.
63   /// @param pResult the result of symbol resultion.
64   /// @note pResult.override is true if the output LDSymbol also need to be
65   ///       overriden
66   void insertSymbol(const llvm::StringRef& pName,
67                     bool pIsDyn,
68                     ResolveInfo::Type pType,
69                     ResolveInfo::Desc pDesc,
70                     ResolveInfo::Binding pBinding,
71                     ResolveInfo::SizeType pSize,
72                     ResolveInfo::Visibility pVisibility,
73                     ResolveInfo* pOldInfo,
74                     Resolver::Result& pResult);
75 
76   /// findSymbol - find the resolved output LDSymbol
77   const LDSymbol* findSymbol(const llvm::StringRef& pName) const;
78   LDSymbol*       findSymbol(const llvm::StringRef& pName);
79 
80   /// findInfo - find the resolved ResolveInfo
81   const ResolveInfo* findInfo(const llvm::StringRef& pName) const;
82   ResolveInfo*       findInfo(const llvm::StringRef& pName);
83 
84   /// insertString - insert a string
85   /// if the string has existed, modify pString to the existing string
86   /// @return the StringRef points to the hash table
87   llvm::StringRef insertString(const llvm::StringRef& pString);
88 
89   // -----  observers  ----- //
size()90   size_type size() const
91   { return m_Table.numOfEntries(); }
92 
empty()93   bool empty() const
94   { return m_Table.empty(); }
95 
96   // -----  capacity  ----- //
97   void reserve(size_type pN);
98 
99   size_type capacity() const;
100 
101 private:
102   typedef GCFactory<ResolveInfo*, 128> FreeInfoSet;
103 
104 private:
105   Resolver* m_pResolver;
106   Table m_Table;
107   FreeInfoSet m_FreeInfoSet;
108 };
109 
110 } // namespace of mcld
111 
112 #endif
113 
114