Skip to content

Commit aeb34c2

Browse files
committed
Avoid <class ER> syntax in lambdas. Thats C++20
1 parent 991bf3a commit aeb34c2

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

src/patchelf.cc

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,30 +2013,20 @@ void ElfFile<ElfFileParamNames>::rebuildGnuHashTable(span<char> strTab, span<Elf
20132013
if (versyms)
20142014
reorderSpan(versyms, old2new);
20152015

2016-
auto fixRelocationTable = [&old2new, firstSymIdx, this] <class ER> (auto& hdr)
2016+
auto remapSymbolId = [&old2new, firstSymIdx] (auto& oldSymIdx)
20172017
{
2018-
auto rela = getSectionSpan<ER>(hdr);
2019-
for (auto& r : rela)
2020-
{
2021-
auto info = rdi(r.r_info);
2022-
auto oldSymIdx = rel_getSymId(info);
2023-
if (oldSymIdx >= firstSymIdx)
2024-
{
2025-
auto newSymIdx = old2new[oldSymIdx - firstSymIdx] + firstSymIdx;
2026-
if (newSymIdx != oldSymIdx)
2027-
wri(r.r_info, rel_setSymId(info, newSymIdx));
2028-
}
2029-
}
2018+
return oldSymIdx >= firstSymIdx ? old2new[oldSymIdx - firstSymIdx] + firstSymIdx
2019+
: oldSymIdx;
20302020
};
20312021

20322022
for (unsigned int i = 1; i < rdi(hdr()->e_shnum); ++i)
20332023
{
20342024
auto& shdr = shdrs.at(i);
20352025
auto shtype = rdi(shdr.sh_type);
20362026
if (shtype == SHT_REL)
2037-
fixRelocationTable.template operator()<Elf_Rel>(shdr);
2027+
changeRelocTableSymIds<Elf_Rel>(shdr, remapSymbolId);
20382028
else if (shtype == SHT_RELA)
2039-
fixRelocationTable.template operator()<Elf_Rela>(shdr);
2029+
changeRelocTableSymIds<Elf_Rela>(shdr, remapSymbolId);
20402030
}
20412031

20422032
// Update bloom filters

src/patchelf.h

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ class ElfFile
169169

170170
void renameDynamicSymbols(const std::unordered_map<std::string_view, std::string>&);
171171

172+
void clearSymbolVersions(const std::set<std::string> & syms);
173+
174+
enum class ExecstackMode { print, set, clear };
175+
176+
void modifyExecstack(ExecstackMode op);
177+
178+
private:
172179
struct GnuHashTable {
173180
using BloomWord = Elf_Addr;
174181
struct Header {
@@ -215,14 +222,20 @@ class ElfFile
215222
return info;
216223
}
217224

225+
template<class ElfRelType, class RemapFn>
226+
void changeRelocTableSymIds(const Elf_Shdr& shdr, RemapFn&& old2newSymId)
227+
{
228+
static_assert(std::is_same_v<ElfRelType, Elf_Rel> || std::is_same_v<ElfRelType, Elf_Rela>);
218229

219-
void clearSymbolVersions(const std::set<std::string> & syms);
220-
221-
enum class ExecstackMode { print, set, clear };
222-
223-
void modifyExecstack(ExecstackMode op);
224-
225-
private:
230+
for (auto& r : getSectionSpan<ElfRelType>(shdr))
231+
{
232+
auto info = rdi(r.r_info);
233+
auto oldSymIdx = rel_getSymId(info);
234+
auto newSymIdx = old2newSymId(oldSymIdx);
235+
if (newSymIdx != oldSymIdx)
236+
wri(r.r_info, rel_setSymId(info, newSymIdx));
237+
}
238+
}
226239

227240
/* Convert an integer in big or little endian representation (as
228241
specified by the ELF header) to this platform's integer

0 commit comments

Comments
 (0)