mirror of
https://github.com/NixOS/patchelf.git
synced 2025-10-19 19:53:19 +08:00
Merge pull request #378 from a-m-joseph/pr/no-sort
add --no-sort option
This commit is contained in:
@@ -92,6 +92,11 @@ Prints all DT_NEEDED entries of the executable.
|
|||||||
Marks the object so that the search for dependencies of this object will ignore any
|
Marks the object so that the search for dependencies of this object will ignore any
|
||||||
default library search paths.
|
default library search paths.
|
||||||
|
|
||||||
|
.IP "--no-sort"
|
||||||
|
Do not sort program headers or section headers. This is useful when
|
||||||
|
debugging patchelf, because it makes it easier to read diffs of the
|
||||||
|
output of "readelf -a".
|
||||||
|
|
||||||
.IP "--add-debug-tag"
|
.IP "--add-debug-tag"
|
||||||
Adds DT_DEBUG tag to the .dynamic section if not yet present in an ELF
|
Adds DT_DEBUG tag to the .dynamic section if not yet present in an ELF
|
||||||
object. A shared library (-shared) by default does not receive DT_DEBUG tag.
|
object. A shared library (-shared) by default does not receive DT_DEBUG tag.
|
||||||
|
@@ -735,14 +735,16 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary()
|
|||||||
rewriteHeaders(firstPage + rdi(hdr()->e_phoff));
|
rewriteHeaders(firstPage + rdi(hdr()->e_phoff));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool noSort = false;
|
||||||
|
|
||||||
template<ElfFileParams>
|
template<ElfFileParams>
|
||||||
void ElfFile<ElfFileParamNames>::rewriteSectionsExecutable()
|
void ElfFile<ElfFileParamNames>::rewriteSectionsExecutable()
|
||||||
{
|
{
|
||||||
/* Sort the sections by offset, otherwise we won't correctly find
|
if (!noSort) {
|
||||||
all the sections before the last replaced section. */
|
/* Sort the sections by offset, otherwise we won't correctly find
|
||||||
sortShdrs();
|
all the sections before the last replaced section. */
|
||||||
|
sortShdrs();
|
||||||
|
}
|
||||||
|
|
||||||
/* What is the index of the last replaced section? */
|
/* What is the index of the last replaced section? */
|
||||||
unsigned int lastReplaced = 0;
|
unsigned int lastReplaced = 0;
|
||||||
@@ -955,7 +957,9 @@ void ElfFile<ElfFileParamNames>::rewriteHeaders(Elf_Addr phdrAddress)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sortPhdrs();
|
if (!noSort) {
|
||||||
|
sortPhdrs();
|
||||||
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i < phdrs.size(); ++i)
|
for (unsigned int i = 0; i < phdrs.size(); ++i)
|
||||||
* ((Elf_Phdr *) (fileContents->data() + rdi(hdr()->e_phoff)) + i) = phdrs.at(i);
|
* ((Elf_Phdr *) (fileContents->data() + rdi(hdr()->e_phoff)) + i) = phdrs.at(i);
|
||||||
@@ -964,7 +968,9 @@ void ElfFile<ElfFileParamNames>::rewriteHeaders(Elf_Addr phdrAddress)
|
|||||||
/* Rewrite the section header table. For neatness, keep the
|
/* Rewrite the section header table. For neatness, keep the
|
||||||
sections sorted. */
|
sections sorted. */
|
||||||
assert(rdi(hdr()->e_shnum) == shdrs.size());
|
assert(rdi(hdr()->e_shnum) == shdrs.size());
|
||||||
sortShdrs();
|
if (!noSort) {
|
||||||
|
sortShdrs();
|
||||||
|
}
|
||||||
for (unsigned int i = 1; i < rdi(hdr()->e_shnum); ++i)
|
for (unsigned int i = 1; i < rdi(hdr()->e_shnum); ++i)
|
||||||
* ((Elf_Shdr *) (fileContents->data() + rdi(hdr()->e_shoff)) + i) = shdrs.at(i);
|
* ((Elf_Shdr *) (fileContents->data() + rdi(hdr()->e_shoff)) + i) = shdrs.at(i);
|
||||||
|
|
||||||
@@ -1843,6 +1849,7 @@ void showHelp(const std::string & progName)
|
|||||||
[--replace-needed LIBRARY NEW_LIBRARY]\n\
|
[--replace-needed LIBRARY NEW_LIBRARY]\n\
|
||||||
[--print-needed]\n\
|
[--print-needed]\n\
|
||||||
[--no-default-lib]\n\
|
[--no-default-lib]\n\
|
||||||
|
[--no-sort]\t\tDo not sort program+section headers; useful for debugging patchelf.\n\
|
||||||
[--clear-symbol-version SYMBOL]\n\
|
[--clear-symbol-version SYMBOL]\n\
|
||||||
[--add-debug-tag]\n\
|
[--add-debug-tag]\n\
|
||||||
[--output FILE]\n\
|
[--output FILE]\n\
|
||||||
@@ -1925,6 +1932,9 @@ int mainWrapped(int argc, char * * argv)
|
|||||||
else if (arg == "--print-needed") {
|
else if (arg == "--print-needed") {
|
||||||
printNeeded = true;
|
printNeeded = true;
|
||||||
}
|
}
|
||||||
|
else if (arg == "--no-sort") {
|
||||||
|
noSort = true;
|
||||||
|
}
|
||||||
else if (arg == "--add-needed") {
|
else if (arg == "--add-needed") {
|
||||||
if (++i == argc) error("missing argument");
|
if (++i == argc) error("missing argument");
|
||||||
neededLibsToAdd.insert(resolveArgument(argv[i]));
|
neededLibsToAdd.insert(resolveArgument(argv[i]));
|
||||||
|
Reference in New Issue
Block a user