diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2008-05-27 14:05:53 (GMT) |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2008-05-27 14:05:53 (GMT) |
commit | 53f7311089de2dc767e20f1420c8118561b7a458 (patch) | |
tree | 0f3a3dd25205ea04f0fc729acb0a37206b824de7 /src | |
parent | 8f036ab190e1a2bcf45832f038bda3ff8b4e8275 (diff) | |
download | patchelf-53f7311089de2dc767e20f1420c8118561b7a458.zip patchelf-53f7311089de2dc767e20f1420c8118561b7a458.tar.gz patchelf-53f7311089de2dc767e20f1420c8118561b7a458.tar.bz2 |
* Sort the program headers. This makes "strip" contain less about
the resulting executables (but unfortunately doesn't fix
NIXPKGS-85).
Diffstat (limited to 'src')
-rw-r--r-- | src/patchelf.cc | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc index 104cb32..7088ca1 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -71,6 +71,21 @@ public: private: + struct CompPhdr + { + ElfFile * elfFile; + bool operator ()(const Elf_Phdr & x, const Elf_Phdr & y) + { + if (x.p_type == PT_PHDR) return true; + if (y.p_type == PT_PHDR) return false; + return elfFile->rdi(x.p_paddr) < elfFile->rdi(y.p_paddr); + } + }; + + friend struct CompPhdr; + + void sortPhdrs(); + struct CompShdr { ElfFile * elfFile; @@ -264,6 +279,16 @@ void ElfFile<ElfFileParamNames>::parse() template<ElfFileParams> +void ElfFile<ElfFileParamNames>::sortPhdrs() +{ + /* Sort the segments by offset. */ + CompPhdr comp; + comp.elfFile = this; + sort(phdrs.begin(), phdrs.end(), comp); +} + + +template<ElfFileParams> void ElfFile<ElfFileParamNames>::sortShdrs() { /* Translate sh_link mappings to section names, since sorting the @@ -297,7 +322,6 @@ void ElfFile<ElfFileParamNames>::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])])); - } @@ -591,6 +615,8 @@ void ElfFile<ElfFileParamNames>::rewriteSections() wri(phdrs[0].p_filesz, wri(phdrs[0].p_memsz, phdrs.size() * sizeof(Elf_Phdr))); } + sortPhdrs(); + for (unsigned int i = 0; i < phdrs.size(); ++i) * ((Elf_Phdr *) (contents + rdi(hdr->e_phoff)) + i) = phdrs[i]; |