From 09d182d9dfde5d68c4481edfa1bb77453b111380 Mon Sep 17 00:00:00 2001 From: Joshua Watt Date: Mon, 31 Jul 2023 13:15:27 -0600 Subject: [PATCH] Do nothing if interpreter has not changed If there is not change to the interpreter, don't make any modifications to the file. This is more efficient than requiring programs to check before changing, and also prevents thrashing of the ELF file, since changing the interpreter repeatedly will keep growing the ELF file each time, even if it's the same value. This is particularly helpful where the same binary is symlinked or hardlinked with multiple names and has patchelf run on it. --- src/patchelf.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/patchelf.cc b/src/patchelf.cc index 82b4b46c..bc400268 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -1454,6 +1454,10 @@ void ElfFile::modifySoname(sonameMode op, const std::string & template void ElfFile::setInterpreter(const std::string & newInterpreter) { + if (getInterpreter() == newInterpreter) { + return; + } + std::string & section = replaceSection(".interp", newInterpreter.size() + 1); setSubstr(section, 0, newInterpreter + '\0'); changed = true;