summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2023-02-21 19:41:08 +0100
committerChristian Göttsche <cgzones@googlemail.com>2023-02-21 19:41:08 +0100
commit81c64ddc99ad448408689bea0de2f1d22dd10762 (patch)
tree0d0c1e9784152185ded957e71f4e1ce80fad1454
parent00d1e82f2b1e415ec66d9aacb7e760d3ff617f02 (diff)
downloadpatchelf-81c64ddc99ad448408689bea0de2f1d22dd10762.tar.gz
Declare more read-only functions const
-rw-r--r--src/patchelf.cc16
-rw-r--r--src/patchelf.h8
2 files changed, 12 insertions, 12 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc
index c10e369..7bfabb4 100644
--- a/src/patchelf.cc
+++ b/src/patchelf.cc
@@ -535,7 +535,7 @@ std::string ElfFile<ElfFileParamNames>::getSectionName(const Elf_Shdr & shdr) co
template<ElfFileParams>
-Elf_Shdr & ElfFile<ElfFileParamNames>::findSectionHeader(const SectionName & sectionName)
+const Elf_Shdr & ElfFile<ElfFileParamNames>::findSectionHeader(const SectionName & sectionName) const
{
auto shdr = tryFindSectionHeader(sectionName);
if (!shdr) {
@@ -549,7 +549,7 @@ Elf_Shdr & ElfFile<ElfFileParamNames>::findSectionHeader(const SectionName & sec
template<ElfFileParams>
-std::optional<std::reference_wrapper<Elf_Shdr>> ElfFile<ElfFileParamNames>::tryFindSectionHeader(const SectionName & sectionName)
+std::optional<std::reference_wrapper<const Elf_Shdr>> ElfFile<ElfFileParamNames>::tryFindSectionHeader(const SectionName & sectionName) const
{
auto i = getSectionIndex(sectionName);
if (i)
@@ -602,7 +602,7 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff,
clobbering previously written new section contents. */
for (auto & i : replacedSections) {
const std::string & sectionName = i.first;
- Elf_Shdr & shdr = findSectionHeader(sectionName);
+ const Elf_Shdr & shdr = findSectionHeader(sectionName);
if (rdi(shdr.sh_type) != SHT_NOBITS)
memset(fileContents->data() + rdi(shdr.sh_offset), 'X', rdi(shdr.sh_size));
}
@@ -1190,10 +1190,10 @@ static void setSubstr(std::string & s, unsigned int pos, const std::string & t)
template<ElfFileParams>
-std::string ElfFile<ElfFileParamNames>::getInterpreter()
+std::string ElfFile<ElfFileParamNames>::getInterpreter() const
{
auto shdr = findSectionHeader(".interp");
- return std::string((char *) fileContents->data() + rdi(shdr.sh_offset), rdi(shdr.sh_size) - 1);
+ return std::string((const char *) fileContents->data() + rdi(shdr.sh_offset), rdi(shdr.sh_size) - 1);
}
template<ElfFileParams>
@@ -1776,13 +1776,13 @@ void ElfFile<ElfFileParamNames>::addNeeded(const std::set<std::string> & libs)
}
template<ElfFileParams>
-void ElfFile<ElfFileParamNames>::printNeededLibs() // const
+void ElfFile<ElfFileParamNames>::printNeededLibs() const
{
const auto shdrDynamic = findSectionHeader(".dynamic");
const auto shdrDynStr = findSectionHeader(".dynstr");
- const char *strTab = (char *)fileContents->data() + rdi(shdrDynStr.sh_offset);
+ const char *strTab = (const char *)fileContents->data() + rdi(shdrDynStr.sh_offset);
- const Elf_Dyn *dyn = (Elf_Dyn *) (fileContents->data() + rdi(shdrDynamic.sh_offset));
+ const Elf_Dyn *dyn = (const Elf_Dyn *) (fileContents->data() + rdi(shdrDynamic.sh_offset));
for (; rdi(dyn->d_tag) != DT_NULL; dyn++) {
if (rdi(dyn->d_tag) == DT_NEEDED) {
diff --git a/src/patchelf.h b/src/patchelf.h
index 101b1c9..677462d 100644
--- a/src/patchelf.h
+++ b/src/patchelf.h
@@ -87,9 +87,9 @@ private:
[[nodiscard]] std::string getSectionName(const Elf_Shdr & shdr) const;
- Elf_Shdr & findSectionHeader(const SectionName & sectionName);
+ const Elf_Shdr & findSectionHeader(const SectionName & sectionName) const;
- [[nodiscard]] std::optional<std::reference_wrapper<Elf_Shdr>> tryFindSectionHeader(const SectionName & sectionName);
+ [[nodiscard]] std::optional<std::reference_wrapper<const Elf_Shdr>> tryFindSectionHeader(const SectionName & sectionName) const;
[[nodiscard]] unsigned int getSectionIndex(const SectionName & sectionName) const;
@@ -113,7 +113,7 @@ public:
void rewriteSections(bool force = false);
- [[nodiscard]] std::string getInterpreter();
+ [[nodiscard]] std::string getInterpreter() const;
typedef enum { printOsAbi, replaceOsAbi } osAbiMode;
@@ -137,7 +137,7 @@ public:
void replaceNeeded(const std::map<std::string, std::string> & libs);
- void printNeededLibs() /* should be const */;
+ void printNeededLibs() const;
void noDefaultLib();