Skip to content

Commit

Permalink
Simplify code and add missing wri/rdi
Browse files Browse the repository at this point in the history
  • Loading branch information
brenoguim committed Feb 19, 2023
1 parent 622712c commit b890456
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/patchelf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1912,7 +1912,7 @@ void ElfFile<ElfFileParamNames>::rebuildGnuHashTable(const char* strTab, span<El

// The hash table includes only a subset of dynsyms
auto firstSymIdx = rdi(ght.m_hdr.symndx);
auto symsToInsert = span(dynsyms.begin() + firstSymIdx, dynsyms.end());
dynsyms = span(dynsyms.begin() + firstSymIdx, dynsyms.end());

// Only use the range of symbol versions that will be changed
auto versyms = tryGetSectionSpan<Elf_Versym>(".gnu.version");
Expand All @@ -1925,10 +1925,10 @@ void ElfFile<ElfFileParamNames>::rebuildGnuHashTable(const char* strTab, span<El
};

std::vector<Entry> entries;
entries.reserve(symsToInsert.size());
entries.reserve(dynsyms.size());

uint32_t pos = 0; // Track the original position of the symbol in the table
for (auto& sym : symsToInsert)
for (auto& sym : dynsyms)
{
Entry e;
e.hash = gnuHash(strTab + rdi(sym.st_name));
Expand Down Expand Up @@ -1956,7 +1956,7 @@ void ElfFile<ElfFileParamNames>::rebuildGnuHashTable(const char* strTab, span<El
dst[old2new[i]] = tmp[i];
};

reorderSpan(symsToInsert, old2new);
reorderSpan(dynsyms, old2new);
if (versyms)
reorderSpan(versyms, old2new);

Expand All @@ -1970,9 +1970,8 @@ void ElfFile<ElfFileParamNames>::rebuildGnuHashTable(const char* strTab, span<El
if (oldSymIdx >= firstSymIdx)
{
auto newSymIdx = old2new[oldSymIdx - firstSymIdx] + firstSymIdx;
if (newSymIdx != oldSymIdx) {
if (newSymIdx != oldSymIdx)
wri(r.r_info, rel_setSymId(info, newSymIdx));
}
}
}
};
Expand All @@ -1995,7 +1994,7 @@ void ElfFile<ElfFileParamNames>::rebuildGnuHashTable(const char* strTab, span<El
size_t idx = (h / ElfClass) % ght.m_bloomFilters.size();
auto val = rdi(ght.m_bloomFilters[idx]);
val |= uint64_t(1) << (h % ElfClass);
val |= uint64_t(1) << ((h >> ght.m_hdr.shift2) % ElfClass);
val |= uint64_t(1) << ((h >> rdi(ght.m_hdr.shift2)) % ElfClass);
wri(ght.m_bloomFilters[idx], val);
}

Expand Down Expand Up @@ -2059,8 +2058,8 @@ void ElfFile<ElfFileParamNames>::rebuildHashTable(const char* strTab, span<Elf_S
auto name = strTab + rdi(sym.st_name);
uint32_t i = &sym - dynsyms.begin();
uint32_t hash = sysvHash(name) % ht.m_buckets.size();
ht.m_chain[i] = ht.m_buckets[hash];
ht.m_buckets[hash] = i;
wri(ht.m_chain[i], rdi(ht.m_buckets[hash]));
wri(ht.m_buckets[hash], i);
}
}

Expand Down

0 comments on commit b890456

Please sign in to comment.