From 36f96d03dba4a3bf19a3a228786aac5e69ea85d2 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 28 May 2008 11:53:16 +0000 Subject: [PATCH] * When reordering the section headers, the e_shstrndx field in the ELF header should be updated as well. --- src/patchelf.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/patchelf.cc b/src/patchelf.cc index f47c814..29d51ac 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -307,6 +307,9 @@ void ElfFile::sortShdrs() (rdi(shdrs[i].sh_type) == SHT_REL || rdi(shdrs[i].sh_type) == SHT_RELA)) info[getSectionName(shdrs[i])] = getSectionName(shdrs[rdi(shdrs[i].sh_info)]); + /* Idem for the index of the .shstrtab section in the ELF header. */ + SectionName shstrtabName = getSectionName(shdrs[rdi(hdr->e_shstrndx)]); + /* Sort the sections by offset. */ CompShdr comp; comp.elfFile = this; @@ -324,6 +327,9 @@ void ElfFile::sortShdrs() (rdi(shdrs[i].sh_type) == SHT_REL || rdi(shdrs[i].sh_type) == SHT_RELA)) wri(shdrs[i].sh_info, findSection3(info[getSectionName(shdrs[i])])); + + /* And the .shstrtab index. */ + wri(hdr->e_shstrndx, findSection3(shstrtabName)); } @@ -579,7 +585,7 @@ void ElfFile::rewriteSections() /* Rewrite the section header table. For neatness, keep the sections sorted. */ assert(rdi(hdr->e_shnum) == shdrs.size()); - //sortShdrs(); !!! breaks the library + sortShdrs(); for (unsigned int i = 1; i < rdi(hdr->e_shnum); ++i) * ((Elf_Shdr *) (contents + rdi(hdr->e_shoff)) + i) = shdrs[i];