Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/patchelf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -757,12 +757,15 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary()
PT_LOAD segment located directly after the last virtual address
page of other segments. */
Elf_Addr startPage = 0;
Elf_Addr firstPage = 0;
for (unsigned int i = 0; i < phdrs.size(); ++i) {
Elf_Addr thisPage = roundUp(rdi(phdrs[i].p_vaddr) + rdi(phdrs[i].p_memsz), getPageSize());
if (thisPage > startPage) startPage = thisPage;
if (rdi(phdrs[i].p_type) == PT_PHDR) firstPage = rdi(phdrs[i].p_vaddr) - rdi(phdrs[i].p_offset);
}

debug("last page is 0x%llx\n", (unsigned long long) startPage);
debug("first page is 0x%llx\n", (unsigned long long) firstPage);

/* When normalizing note segments we will in the worst case be adding
1 program header for each SHT_NOTE section. */
Expand Down Expand Up @@ -834,8 +837,9 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary()
writeReplacedSections(curOff, startPage, startOffset);
assert(curOff == startOffset + neededSpace);


/* Write out the updated program and section headers */
rewriteHeaders(hdr->e_phoff);
rewriteHeaders(firstPage + hdr->e_phoff);
}


Expand Down