1 //===- SectionSymbolSet.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_SECTIONSYMBOLSET_H 10 #define MCLD_SECTIONSYMBOLSET_H 11 #ifdef ENABLE_UNITTEST 12 #include <gtest.h> 13 #endif 14 15 #include <mcld/ADT/HashTable.h> 16 #include <mcld/ADT/HashEntry.h> 17 #include <mcld/MC/SymbolCategory.h> 18 19 namespace mcld 20 { 21 22 class LDSection; 23 class NamePool; 24 class LDSymbol; 25 26 /** \class SectionSymbolSet 27 * \brief SectionSymbolSet contains the section symbols defined by linker for 28 * the output sections 29 */ 30 class SectionSymbolSet 31 { 32 public: 33 typedef SymbolCategory SymbolTable; 34 35 public: 36 SectionSymbolSet(); 37 ~SectionSymbolSet(); 38 39 /// add - create and add an section symbol for the output 40 /// LDSection 41 bool add(LDSection& pOutSect, NamePool& pNamePool); 42 43 /// finalize - set section symbols' fragmentRef and push it into the output 44 /// symbol table 45 bool finalize(LDSection& pOutSect, SymbolTable& pSymTab, bool relocatable); 46 47 /// get - get the section symbol for section pOutpSect 48 LDSymbol* get(const LDSection& pOutSect); 49 const LDSymbol* get(const LDSection& pOutSect) const; 50 51 private: 52 /// sectCompare - hash compare function for LDSection* 53 struct SectCompare 54 { operatorSectCompare55 bool operator()(const LDSection* X, const LDSection* Y) const 56 { return (X==Y); } 57 }; 58 59 /// SectPtrHash - hash function for LDSection* 60 struct SectPtrHash 61 { operatorSectPtrHash62 size_t operator()(const LDSection* pKey) const 63 { 64 return (unsigned((uintptr_t)pKey) >> 4) ^ 65 (unsigned((uintptr_t)pKey) >> 9); 66 } 67 }; 68 69 typedef HashEntry<const LDSection*, LDSymbol*, SectCompare> SectHashEntryType; 70 typedef HashTable<SectHashEntryType, 71 SectPtrHash, 72 EntryFactory<SectHashEntryType> > SectHashTableType; 73 74 private: 75 SectHashTableType* m_pSectionSymbolMap; 76 }; 77 78 } // namespace of mcld 79 80 #endif 81 82