Skip to content

Commit 0f87d7f

Browse files
ezquatClaudio Matsuoka
authored and
Claudio Matsuoka
committed
Fix issue NixOS#66 by ignoring the first section header when sorting, and not overwriting NOBITS entries.
1 parent 702cb04 commit 0f87d7f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/patchelf.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ void ElfFile<ElfFileParamNames>::sortShdrs()
366366
/* Sort the sections by offset. */
367367
CompShdr comp;
368368
comp.elfFile = this;
369-
sort(shdrs.begin(), shdrs.end(), comp);
369+
sort(shdrs.begin() + 1, shdrs.end(), comp);
370370

371371
/* Restore the sh_link mappings. */
372372
for (unsigned int i = 1; i < rdi(hdr->e_shnum); ++i)
@@ -517,7 +517,8 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff,
517517
{
518518
string sectionName = i->first;
519519
Elf_Shdr & shdr = findSection(sectionName);
520-
memset(contents + rdi(shdr.sh_offset), 'X', rdi(shdr.sh_size));
520+
if (shdr.sh_type != SHT_NOBITS)
521+
memset(contents + rdi(shdr.sh_offset), 'X', rdi(shdr.sh_size));
521522
}
522523

523524
for (ReplacedSections::iterator i = replacedSections.begin();

0 commit comments

Comments
 (0)