This commit is contained in:
Eelco Dolstra
2015-07-24 01:33:34 +02:00

View File

@@ -696,11 +696,22 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsExecutable()
Elf_Addr firstPage = startAddr - startOffset; Elf_Addr firstPage = startAddr - startOffset;
debug("first page is 0x%llx\n", (unsigned long long) firstPage); debug("first page is 0x%llx\n", (unsigned long long) firstPage);
/* Right now we assume that the section headers are somewhere near if ((off_t) rdi(hdr->e_shoff) < startOffset) {
the end, which appears to be the case most of the time. /* The section headers occur too early in the file and would be
Therefore they're not accidentally overwritten by the replaced overwritten by the replaced sections. Move them to the end of the file
sections. !!! Fix this. */ before proceeding. */
assert((off_t) rdi(hdr->e_shoff) >= startOffset); off_t shoffNew = fileSize;
off_t shSize = rdi(hdr->e_shoff) + rdi(hdr->e_shnum) * rdi(hdr->e_shentsize);
growFile (fileSize + shSize);
wri(hdr->e_shoff, shoffNew);
/* Rewrite the section header table. For neatness, keep the
sections sorted. */
assert(rdi(hdr->e_shnum) == shdrs.size());
sortShdrs();
for (unsigned int i = 1; i < rdi(hdr->e_shnum); ++i)
* ((Elf_Shdr *) (contents + rdi(hdr->e_shoff)) + i) = shdrs[i];
}
/* Compute the total space needed for the replaced sections, the /* Compute the total space needed for the replaced sections, the