0009-Fix-issue-66-by-ignoring-the-first-section-header-wh.patch 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. From e22ca2f593aa8fd392f1ac4f8dd104bc56d0d100 Mon Sep 17 00:00:00 2001
  2. From: Ezra Cooper <ezra@qumulo.com>
  3. Date: Thu, 21 Jun 2018 11:07:35 -0700
  4. Subject: [PATCH] Fix issue #66 by ignoring the first section header when
  5. sorting, and not overwriting NOBITS entries.
  6. Fetch from: https://github.com/NixOS/patchelf/commit/52ab908394958a2a5d0476e306e2cad4da4fdeae
  7. Backported to v0.9
  8. Signed-off-by: Conrad Ratschan <conrad.ratschan@rockwellcollins.com>
  9. ---
  10. src/patchelf.cc | 5 +++--
  11. 1 file changed, 3 insertions(+), 2 deletions(-)
  12. diff --git a/src/patchelf.cc b/src/patchelf.cc
  13. index c025ae2..fa2945e 100644
  14. --- a/src/patchelf.cc
  15. +++ b/src/patchelf.cc
  16. @@ -435,7 +435,7 @@ void ElfFile<ElfFileParamNames>::sortShdrs()
  17. /* Sort the sections by offset. */
  18. CompShdr comp;
  19. comp.elfFile = this;
  20. - sort(shdrs.begin(), shdrs.end(), comp);
  21. + sort(shdrs.begin() + 1, shdrs.end(), comp);
  22. /* Restore the sh_link mappings. */
  23. for (unsigned int i = 1; i < rdi(hdr->e_shnum); ++i)
  24. @@ -586,7 +586,8 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff,
  25. {
  26. string sectionName = i->first;
  27. Elf_Shdr & shdr = findSection(sectionName);
  28. - memset(contents + rdi(shdr.sh_offset), 'X', rdi(shdr.sh_size));
  29. + if (shdr.sh_type != SHT_NOBITS)
  30. + memset(contents + rdi(shdr.sh_offset), 'X', rdi(shdr.sh_size));
  31. }
  32. for (ReplacedSections::iterator i = replacedSections.begin();
  33. --
  34. 2.17.1