Skip to content

Commit

Permalink
Allow multiple modifications in same call
Browse files Browse the repository at this point in the history
`patchelf` previously would incorrectly patch the ELF header if it was
called with multiple changes at once such as _add_ & _replace_.

In order to support that, rewrite the sections in between each section
modification.

Fix #359
  • Loading branch information
fzakaria committed Dec 21, 2021
1 parent b73dbc1 commit d306abe
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/patchelf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1878,10 +1878,22 @@ static void patchElf2(ElfFile && elfFile, const FileContents & fileContents, con

if (printNeeded) elfFile.printNeededLibs();

elfFile.removeNeeded(neededLibsToRemove);
elfFile.replaceNeeded(neededLibsToReplace);
elfFile.addNeeded(neededLibsToAdd);
elfFile.clearSymbolVersions(symbolsToClearVersion);
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();
Expand Down

0 comments on commit d306abe

Please sign in to comment.