0007-fix-adjusting-startPage.patch 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. From 4a82c97e8a0677706d1d532812daaa73249768a8 Mon Sep 17 00:00:00 2001
  2. From: Ed Bartosh <ed.bartosh@linux.intel.com>
  3. Date: Fri, 21 Jul 2017 12:33:53 +0300
  4. Subject: [PATCH] fix adjusting startPage
  5. startPage is adjusted unconditionally for all executables.
  6. This results in incorrect addresses assigned to INTERP and LOAD
  7. program headers, which breaks patched executable.
  8. Adjusting startPage variable only when startOffset > startPage
  9. should fix this.
  10. This change is related to the issue NixOS#10
  11. Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
  12. Fetch from: https://github.com/NixOS/patchelf/commit/1cc234fea5600190d872329aca60e2365cefc39e
  13. Backported to v0.9
  14. Signed-off-by: Conrad Ratschan <conrad.ratschan@rockwellcollins.com>
  15. ---
  16. src/patchelf.cc | 6 ++----
  17. 1 file changed, 2 insertions(+), 4 deletions(-)
  18. diff --git a/src/patchelf.cc b/src/patchelf.cc
  19. index 1224a89..4676157 100644
  20. --- a/src/patchelf.cc
  21. +++ b/src/patchelf.cc
  22. @@ -697,10 +697,8 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary()
  23. since DYN executables tend to start at virtual address 0, so
  24. rewriteSectionsExecutable() won't work because it doesn't have
  25. any virtual address space to grow downwards into. */
  26. - if (isExecutable) {
  27. - if (startOffset >= startPage) {
  28. - debug("shifting new PT_LOAD segment by %d bytes to work around a Linux kernel bug\n", startOffset - startPage);
  29. - }
  30. + if (isExecutable && startOffset > startPage) {
  31. + debug("shifting new PT_LOAD segment by %d bytes to work around a Linux kernel bug\n", startOffset - startPage);
  32. startPage = startOffset;
  33. }
  34. --
  35. 2.17.1