0006-Fix-shared-library-corruption-when-rerunning-patchel.patch 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. From 5df4791bf077127684faceeeea8bfab063e43774 Mon Sep 17 00:00:00 2001
  2. From: Richard Purdie <richard.purdie@linuxfoundation.org>
  3. Date: Wed, 3 Jun 2020 12:14:58 +0100
  4. Subject: [PATCH] Fix shared library corruption when rerunning patchelf
  5. When running patchelf on some existing patchelf'd binaries to change to longer
  6. RPATHS, ldd would report the binaries as invalid. The output of objdump -x on
  7. those libraryies should show the top of the .dynamic section is getting trashed,
  8. something like:
  9. 0x600000001 0x0000000000429000
  10. 0x335000 0x0000000000335000
  11. 0xc740 0x000000000000c740
  12. 0x1000 0x0000000000009098
  13. SONAME libglib-2.0.so.0
  14. (which should be RPATH and DT_NEEDED entries)
  15. This was tracked down to the code which injects the PT_LOAD section.
  16. The issue is that if the program headers were previously relocated to the end
  17. of the file which was how patchelf operated previously, the relocation code
  18. wouldn't work properly on a second run as it now assumes they're located after
  19. the elf header. This change forces them back to immediately follow the elf
  20. header which is where the code has made space for them.
  21. Should fix https://github.com/NixOS/patchelf/issues/170
  22. and https://github.com/NixOS/patchelf/issues/192
  23. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
  24. Fetch from: https://github.com/NixOS/patchelf/commit/ad5f1f078b716802dfb8f7226cb1d5c720348a78
  25. Backported to v0.9
  26. Signed-off-by: Conrad Ratschan <conrad.ratschan@rockwellcollins.com>
  27. ---
  28. src/patchelf.cc | 1 +
  29. 1 file changed, 1 insertion(+)
  30. diff --git a/src/patchelf.cc b/src/patchelf.cc
  31. index c2147af..1224a89 100644
  32. --- a/src/patchelf.cc
  33. +++ b/src/patchelf.cc
  34. @@ -706,6 +706,7 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary()
  35. /* Add a segment that maps the replaced sections into memory. */
  36. + wri(hdr->e_phoff, sizeof(Elf_Ehdr));
  37. phdrs.resize(rdi(hdr->e_phnum) + 1);
  38. wri(hdr->e_phnum, rdi(hdr->e_phnum) + 1);
  39. Elf_Phdr & phdr = phdrs[rdi(hdr->e_phnum) - 1];
  40. --
  41. 2.17.1