mirror of
https://github.com/NixOS/patchelf.git
synced 2025-10-20 21:50:16 +08:00
Code clarity and test working with musl
Made changes according to feedback from @Mic92 such as moving the `rewriteSections` inline into every method. Improved `replace-add-needed.sh` to work with musl libc
This commit is contained in:
@@ -1311,6 +1311,7 @@ void ElfFile<ElfFileParamNames>::modifySoname(sonameMode op, const std::string &
|
||||
}
|
||||
|
||||
changed = true;
|
||||
this->rewriteSections();
|
||||
}
|
||||
|
||||
template<ElfFileParams>
|
||||
@@ -1319,6 +1320,7 @@ void ElfFile<ElfFileParamNames>::setInterpreter(const std::string & newInterpret
|
||||
std::string & section = replaceSection(".interp", newInterpreter.size() + 1);
|
||||
setSubstr(section, 0, newInterpreter + '\0');
|
||||
changed = true;
|
||||
this->rewriteSections();
|
||||
}
|
||||
|
||||
|
||||
@@ -1395,6 +1397,7 @@ void ElfFile<ElfFileParamNames>::removeRPath(Elf_Shdr & shdrDynamic) {
|
||||
}
|
||||
}
|
||||
memset(last, 0, sizeof(Elf_Dyn) * (dyn - last));
|
||||
this->rewriteSections();
|
||||
}
|
||||
|
||||
template<ElfFileParams>
|
||||
@@ -1541,6 +1544,7 @@ void ElfFile<ElfFileParamNames>::modifyRPath(RPathOp op,
|
||||
newDyn.d_un.d_val = shdrDynStr.sh_size;
|
||||
setSubstr(newDynamic, 0, std::string((char *) &newDyn, sizeof(Elf_Dyn)));
|
||||
}
|
||||
this->rewriteSections();
|
||||
}
|
||||
|
||||
|
||||
@@ -1570,6 +1574,8 @@ void ElfFile<ElfFileParamNames>::removeNeeded(const std::set<std::string> & libs
|
||||
}
|
||||
|
||||
memset(last, 0, sizeof(Elf_Dyn) * (dyn - last));
|
||||
|
||||
this->rewriteSections();
|
||||
}
|
||||
|
||||
template<ElfFileParams>
|
||||
@@ -1693,6 +1699,8 @@ void ElfFile<ElfFileParamNames>::replaceNeeded(const std::map<std::string, std::
|
||||
--verNeedNum;
|
||||
}
|
||||
}
|
||||
|
||||
this->rewriteSections();
|
||||
}
|
||||
|
||||
template<ElfFileParams>
|
||||
@@ -1743,6 +1751,8 @@ void ElfFile<ElfFileParamNames>::addNeeded(const std::set<std::string> & libs)
|
||||
}
|
||||
|
||||
changed = true;
|
||||
|
||||
this->rewriteSections();
|
||||
}
|
||||
|
||||
template<ElfFileParams>
|
||||
@@ -1799,6 +1809,7 @@ void ElfFile<ElfFileParamNames>::noDefaultLib()
|
||||
setSubstr(newDynamic, 0, std::string((char *) &newDyn, sizeof(Elf_Dyn)));
|
||||
}
|
||||
|
||||
this->rewriteSections();
|
||||
changed = true;
|
||||
}
|
||||
|
||||
@@ -1828,6 +1839,7 @@ void ElfFile<ElfFileParamNames>::clearSymbolVersions(const std::set<std::string>
|
||||
}
|
||||
}
|
||||
changed = true;
|
||||
this->rewriteSections();
|
||||
}
|
||||
|
||||
static bool printInterpreter = false;
|
||||
@@ -1878,28 +1890,15 @@ static void patchElf2(ElfFile && elfFile, const FileContents & fileContents, con
|
||||
|
||||
if (printNeeded) elfFile.printNeededLibs();
|
||||
|
||||
if (!neededLibsToRemove.empty()) {
|
||||
elfFile.removeNeeded(neededLibsToRemove);
|
||||
elfFile.rewriteSections();
|
||||
}
|
||||
if (!neededLibsToReplace.empty()) {
|
||||
elfFile.replaceNeeded(neededLibsToReplace);
|
||||
elfFile.rewriteSections();
|
||||
}
|
||||
if (!neededLibsToAdd.empty()) {
|
||||
elfFile.addNeeded(neededLibsToAdd);
|
||||
elfFile.rewriteSections();
|
||||
}
|
||||
if (!symbolsToClearVersion.empty()) {
|
||||
elfFile.clearSymbolVersions(symbolsToClearVersion);
|
||||
elfFile.rewriteSections();
|
||||
}
|
||||
|
||||
if (noDefaultLib)
|
||||
elfFile.noDefaultLib();
|
||||
|
||||
if (elfFile.isChanged()){
|
||||
elfFile.rewriteSections();
|
||||
writeFile(fileName, elfFile.fileContents);
|
||||
} else if (alwaysWrite) {
|
||||
debug("not modified, but alwaysWrite=true\n");
|
||||
|
@@ -12,7 +12,7 @@ cp libbar.so ${SCRATCH}/
|
||||
|
||||
cd ${SCRATCH}
|
||||
|
||||
libcldd=$(ldd ./simple | grep -oP "(?<=libc.so.6 => )[^ ]+")
|
||||
libcldd=$(ldd ./simple | awk '/ => / { print $3 }' | grep .so | head -n 1)
|
||||
|
||||
# We have to set the soname on these libraries
|
||||
${PATCHELF} --set-soname libbar.so ./libbar.so
|
||||
|
Reference in New Issue
Block a user