From aeb34c2cc9d473319f320db49cd20e7e9ea4bff8 Mon Sep 17 00:00:00 2001 From: Breno Rodrigues Guimaraes Date: Wed, 22 Feb 2023 07:18:28 -0300 Subject: Avoid syntax in lambdas. Thats C++20 --- src/patchelf.cc | 20 +++++--------------- src/patchelf.h | 27 ++++++++++++++++++++------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/patchelf.cc b/src/patchelf.cc index a4388f9..db18837 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -2013,20 +2013,10 @@ void ElfFile::rebuildGnuHashTable(span strTab, span (auto& hdr) + auto remapSymbolId = [&old2new, firstSymIdx] (auto& oldSymIdx) { - auto rela = getSectionSpan(hdr); - for (auto& r : rela) - { - auto info = rdi(r.r_info); - auto oldSymIdx = rel_getSymId(info); - if (oldSymIdx >= firstSymIdx) - { - auto newSymIdx = old2new[oldSymIdx - firstSymIdx] + firstSymIdx; - if (newSymIdx != oldSymIdx) - wri(r.r_info, rel_setSymId(info, newSymIdx)); - } - } + return oldSymIdx >= firstSymIdx ? old2new[oldSymIdx - firstSymIdx] + firstSymIdx + : oldSymIdx; }; for (unsigned int i = 1; i < rdi(hdr()->e_shnum); ++i) @@ -2034,9 +2024,9 @@ void ElfFile::rebuildGnuHashTable(span strTab, span(shdr); + changeRelocTableSymIds(shdr, remapSymbolId); else if (shtype == SHT_RELA) - fixRelocationTable.template operator()(shdr); + changeRelocTableSymIds(shdr, remapSymbolId); } // Update bloom filters diff --git a/src/patchelf.h b/src/patchelf.h index 8f96ec6..9fab18c 100644 --- a/src/patchelf.h +++ b/src/patchelf.h @@ -169,6 +169,13 @@ public: void renameDynamicSymbols(const std::unordered_map&); + void clearSymbolVersions(const std::set & syms); + + enum class ExecstackMode { print, set, clear }; + + void modifyExecstack(ExecstackMode op); + +private: struct GnuHashTable { using BloomWord = Elf_Addr; struct Header { @@ -215,14 +222,20 @@ public: return info; } + template + void changeRelocTableSymIds(const Elf_Shdr& shdr, RemapFn&& old2newSymId) + { + static_assert(std::is_same_v || std::is_same_v); - void clearSymbolVersions(const std::set & syms); - - enum class ExecstackMode { print, set, clear }; - - void modifyExecstack(ExecstackMode op); - -private: + for (auto& r : getSectionSpan(shdr)) + { + auto info = rdi(r.r_info); + auto oldSymIdx = rel_getSymId(info); + auto newSymIdx = old2newSymId(oldSymIdx); + if (newSymIdx != oldSymIdx) + wri(r.r_info, rel_setSymId(info, newSymIdx)); + } + } /* Convert an integer in big or little endian representation (as specified by the ELF header) to this platform's integer -- cgit v1.2.1