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