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