Skip to content

Commit ad5f1f0

Browse files
committed
Fix shared library corruption when rerunning patchelf
When running patchelf on some existing patchelf'd binaries to change to longer RPATHS, ldd would report the binaries as invalid. The output of objdump -x on those libraryies should show the top of the .dynamic section is getting trashed, something like: 0x600000001 0x0000000000429000 0x335000 0x0000000000335000 0xc740 0x000000000000c740 0x1000 0x0000000000009098 SONAME libglib-2.0.so.0 (which should be RPATH and DT_NEEDED entries) This was tracked down to the code which injects the PT_LOAD section. The issue is that if the program headers were previously relocated to the end of the file which was how patchelf operated previously, the relocation code wouldn't work properly on a second run as it now assumes they're located after the elf header. This change forces them back to immediately follow the elf header which is where the code has made space for them. Should fix #170 and #192 Signed-off-by: Richard Purdie <[email protected]>
1 parent f3411a9 commit ad5f1f0

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/patchelf.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary()
754754
}
755755

756756
/* Add a segment that maps the replaced sections into memory. */
757+
wri(hdr->e_phoff, sizeof(Elf_Ehdr));
757758
phdrs.resize(rdi(hdr->e_phnum) + 1);
758759
wri(hdr->e_phnum, rdi(hdr->e_phnum) + 1);
759760
Elf_Phdr & phdr = phdrs[rdi(hdr->e_phnum) - 1];

0 commit comments

Comments
 (0)