merge from PR243

This commit is contained in:
Satadru Pramanik
2021-05-20 16:52:21 -04:00
parent d75ad358f4
commit 4efbce410d

View File

@@ -772,12 +772,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 (auto & phdr : phdrs) {
Elf_Addr thisPage = roundUp(rdi(phdr.p_vaddr) + rdi(phdr.p_memsz), getPageSize());
if (thisPage > startPage) startPage = thisPage;
if (rdi(phdr.p_type) == PT_PHDR) firstPage = rdi(phdr.p_vaddr) - rdi(phdr.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. */
@@ -848,7 +851,7 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary()
assert(curOff == startOffset + neededSpace);
/* Write out the updated program and section headers */
rewriteHeaders(rdi(hdr->e_phoff));
rewriteHeaders(firstPage + hdr->e_phoff);
}