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