@@ -1892,11 +1892,11 @@ static uint32_t gnuHash(std::string_view name) {
1892
1892
}
1893
1893
1894
1894
template <ElfFileParams>
1895
- auto ElfFile<ElfFileParamNames>::GnuHashTable::parse (span<char > sectionData) -> GnuHashTable
1895
+ auto ElfFile<ElfFileParamNames>::parseGnuHashTable (span<char > sectionData) -> GnuHashTable
1896
1896
{
1897
- auto hdr = (Header*)sectionData.begin ();
1898
- auto bloomFilters = span ((BloomWord*)(hdr+1 ), hdr->maskwords );
1899
- auto buckets = span ((uint32_t *)bloomFilters.end (), hdr->numBuckets );
1897
+ auto hdr = (typename GnuHashTable:: Header*)sectionData.begin ();
1898
+ auto bloomFilters = span ((typename GnuHashTable:: BloomWord*)(hdr+1 ), rdi ( hdr->maskwords ) );
1899
+ auto buckets = span ((uint32_t *)bloomFilters.end (), rdi ( hdr->numBuckets ) );
1900
1900
auto table = span (buckets.end (), ((uint32_t *)sectionData.end ()) - buckets.end ());
1901
1901
return GnuHashTable{*hdr, bloomFilters, buckets, table};
1902
1902
}
@@ -1908,11 +1908,10 @@ void ElfFile<ElfFileParamNames>::rebuildGnuHashTable(const char* strTab, span<El
1908
1908
if (!sectionData)
1909
1909
return ;
1910
1910
1911
- auto ght = GnuHashTable::parse (sectionData);
1911
+ auto ght = parseGnuHashTable (sectionData);
1912
1912
1913
- // Only work with the last "m_table.size()" symbols from dynsyms which are the
1914
- // symbols that belong to the hash table
1915
- auto firstSymIdx = dynsyms.size () - ght.m_table .size ();
1913
+ // The hash table includes only a subset of dynsyms
1914
+ auto firstSymIdx = rdi (ght.m_hdr .symndx );
1916
1915
auto symsToInsert = span (dynsyms.begin () + firstSymIdx, dynsyms.end ());
1917
1916
1918
1917
// Only use the range of symbol versions that will be changed
@@ -1933,7 +1932,7 @@ void ElfFile<ElfFileParamNames>::rebuildGnuHashTable(const char* strTab, span<El
1933
1932
{
1934
1933
Entry e;
1935
1934
e.hash = gnuHash (strTab + rdi (sym.st_name ));
1936
- e.bucketIdx = e.hash % ght.m_hdr .numBuckets ;
1935
+ e.bucketIdx = e.hash % rdi ( ght.m_hdr .numBuckets ) ;
1937
1936
e.originalPos = pos++;
1938
1937
entries.push_back (e);
1939
1938
}
@@ -1993,10 +1992,10 @@ void ElfFile<ElfFileParamNames>::rebuildGnuHashTable(const char* strTab, span<El
1993
1992
for (size_t i = 0 ; i < entries.size (); ++i)
1994
1993
{
1995
1994
auto h = entries[i].hash ;
1996
- size_t idx = (h / ElfWordSize ) % ght.m_bloomFilters .size ();
1995
+ size_t idx = (h / ElfClass ) % ght.m_bloomFilters .size ();
1997
1996
auto val = rdi (ght.m_bloomFilters [idx]);
1998
- val |= uint64_t (1 ) << (h % ElfWordSize );
1999
- val |= uint64_t (1 ) << ((h >> ght.m_hdr .shift2 ) % ElfWordSize );
1997
+ val |= uint64_t (1 ) << (h % ElfClass );
1998
+ val |= uint64_t (1 ) << ((h >> ght.m_hdr .shift2 ) % ElfClass );
2000
1999
wri (ght.m_bloomFilters [idx], val);
2001
2000
}
2002
2001
@@ -2006,7 +2005,7 @@ void ElfFile<ElfFileParamNames>::rebuildGnuHashTable(const char* strTab, span<El
2006
2005
{
2007
2006
auto symBucketIdx = entries[i].bucketIdx ;
2008
2007
if (!ght.m_buckets [symBucketIdx])
2009
- ght.m_buckets [symBucketIdx] = i + ght. m_hdr . symndx ;
2008
+ wri ( ght.m_buckets [symBucketIdx], i + firstSymIdx) ;
2010
2009
}
2011
2010
2012
2011
// Fill hash table
@@ -2015,7 +2014,7 @@ void ElfFile<ElfFileParamNames>::rebuildGnuHashTable(const char* strTab, span<El
2015
2014
auto & n = entries[i];
2016
2015
bool isLast = (i == entries.size () - 1 ) || (n.bucketIdx != entries[i+1 ].bucketIdx );
2017
2016
// Add hash with first bit indicating end of chain
2018
- ght.m_table [i] = isLast ? (n.hash | 1 ) : (n.hash & ~1 );
2017
+ wri ( ght.m_table [i], isLast ? (n.hash | 1 ) : (n.hash & ~1 ) );
2019
2018
}
2020
2019
}
2021
2020
@@ -2033,10 +2032,10 @@ static uint32_t sysvHash(std::string_view name) {
2033
2032
}
2034
2033
2035
2034
template <ElfFileParams>
2036
- auto ElfFile<ElfFileParamNames>::HashTable::parse (span<char > sectionData) -> HashTable
2035
+ auto ElfFile<ElfFileParamNames>::parseHashTable (span<char > sectionData) -> HashTable
2037
2036
{
2038
- auto hdr = (Header*)sectionData.begin ();
2039
- auto buckets = span ((uint32_t *)(hdr+1 ), hdr->numBuckets );
2037
+ auto hdr = (typename HashTable:: Header*)sectionData.begin ();
2038
+ auto buckets = span ((uint32_t *)(hdr+1 ), rdi ( hdr->numBuckets ) );
2040
2039
auto table = span (buckets.end (), ((uint32_t *)sectionData.end ()) - buckets.end ());
2041
2040
return HashTable{*hdr, buckets, table};
2042
2041
}
@@ -2048,7 +2047,7 @@ void ElfFile<ElfFileParamNames>::rebuildHashTable(const char* strTab, span<Elf_S
2048
2047
if (!sectionData)
2049
2048
return ;
2050
2049
2051
- auto ht = HashTable::parse (sectionData);
2050
+ auto ht = parseHashTable (sectionData);
2052
2051
2053
2052
std::fill (ht.m_buckets .begin (), ht.m_buckets .end (), 0 );
2054
2053
std::fill (ht.m_chain .begin (), ht.m_chain .end (), 0 );
@@ -2222,9 +2221,9 @@ static void patchElf()
2222
2221
const std::string & outputFileName2 = outputFileName.empty () ? fileName : outputFileName;
2223
2222
2224
2223
if (getElfType (fileContents).is32Bit )
2225
- patchElf2 (ElfFile<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, Elf32_Addr, Elf32_Off, Elf32_Dyn, Elf32_Sym, Elf32_Verneed, Elf32_Versym, Elf32_Rel, Elf32_Rela>(fileContents), fileContents, outputFileName2);
2224
+ patchElf2 (ElfFile<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, Elf32_Addr, Elf32_Off, Elf32_Dyn, Elf32_Sym, Elf32_Verneed, Elf32_Versym, Elf32_Rel, Elf32_Rela, 32 >(fileContents), fileContents, outputFileName2);
2226
2225
else
2227
- patchElf2 (ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, Elf64_Addr, Elf64_Off, Elf64_Dyn, Elf64_Sym, Elf64_Verneed, Elf64_Versym, Elf64_Rel, Elf64_Rela>(fileContents), fileContents, outputFileName2);
2226
+ patchElf2 (ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, Elf64_Addr, Elf64_Off, Elf64_Dyn, Elf64_Sym, Elf64_Verneed, Elf64_Versym, Elf64_Rel, Elf64_Rela, 64 >(fileContents), fileContents, outputFileName2);
2228
2227
}
2229
2228
}
2230
2229
0 commit comments