manual for loop conversions

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev
2021-02-14 18:10:50 -08:00
parent b399885dd0
commit dd4d2af8db

View File

@@ -699,23 +699,25 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff,
/* If this is the .interp section, then the PT_INTERP segment /* If this is the .interp section, then the PT_INTERP segment
must be sync'ed with it. */ must be sync'ed with it. */
if (sectionName == ".interp") { if (sectionName == ".interp") {
for (unsigned int j = 0; j < phdrs.size(); ++j) for (auto & phdr : phdrs) {
if (rdi(phdrs[j].p_type) == PT_INTERP) { if (rdi(phdr.p_type) == PT_INTERP) {
phdrs[j].p_offset = shdr.sh_offset; phdr.p_offset = shdr.sh_offset;
phdrs[j].p_vaddr = phdrs[j].p_paddr = shdr.sh_addr; phdr.p_vaddr = phdr.p_paddr = shdr.sh_addr;
phdrs[j].p_filesz = phdrs[j].p_memsz = shdr.sh_size; phdr.p_filesz = phdr.p_memsz = shdr.sh_size;
} }
}
} }
/* If this is the .dynamic section, then the PT_DYNAMIC segment /* If this is the .dynamic section, then the PT_DYNAMIC segment
must be sync'ed with it. */ must be sync'ed with it. */
if (sectionName == ".dynamic") { if (sectionName == ".dynamic") {
for (unsigned int j = 0; j < phdrs.size(); ++j) for (auto & phdr : phdrs) {
if (rdi(phdrs[j].p_type) == PT_DYNAMIC) { if (rdi(phdr.p_type) == PT_DYNAMIC) {
phdrs[j].p_offset = shdr.sh_offset; phdr.p_offset = shdr.sh_offset;
phdrs[j].p_vaddr = phdrs[j].p_paddr = shdr.sh_addr; phdr.p_vaddr = phdr.p_paddr = shdr.sh_addr;
phdrs[j].p_filesz = phdrs[j].p_memsz = shdr.sh_size; phdr.p_filesz = phdr.p_memsz = shdr.sh_size;
} }
}
} }
/* If this is a note section, there might be a PT_NOTE segment that /* If this is a note section, there might be a PT_NOTE segment that
@@ -770,8 +772,8 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary()
PT_LOAD segment located directly after the last virtual address PT_LOAD segment located directly after the last virtual address
page of other segments. */ page of other segments. */
Elf_Addr startPage = 0; Elf_Addr startPage = 0;
for (unsigned int i = 0; i < phdrs.size(); ++i) { for (auto & phdr : phdrs) {
Elf_Addr thisPage = roundUp(rdi(phdrs[i].p_vaddr) + rdi(phdrs[i].p_memsz), getPageSize()); Elf_Addr thisPage = roundUp(rdi(phdr.p_vaddr) + rdi(phdr.p_memsz), getPageSize());
if (thisPage > startPage) startPage = thisPage; if (thisPage > startPage) startPage = thisPage;
} }
@@ -984,9 +986,7 @@ void ElfFile<ElfFileParamNames>::normalizeNoteSegments()
bool replaced_note = std::any_of(replacedSections.begin(), replacedSections.end(), [this](std::pair<const std::string, std::string> & i) { return rdi(findSection(i.first).sh_type) == SHT_NOTE; }); bool replaced_note = std::any_of(replacedSections.begin(), replacedSections.end(), [this](std::pair<const std::string, std::string> & i) { return rdi(findSection(i.first).sh_type) == SHT_NOTE; });
if (!replaced_note) return; if (!replaced_note) return;
size_t orig_count = phdrs.size(); for (auto & phdr : phdrs) {
for (size_t i = 0; i < orig_count; ++i) {
auto & phdr = phdrs[i];
if (rdi(phdr.p_type) != PT_NOTE) continue; if (rdi(phdr.p_type) != PT_NOTE) continue;
size_t start_off = rdi(phdr.p_offset); size_t start_off = rdi(phdr.p_offset);
@@ -1056,11 +1056,11 @@ void ElfFile<ElfFileParamNames>::rewriteHeaders(Elf_Addr phdrAddress)
/* If there is a segment for the program header table, update it. /* If there is a segment for the program header table, update it.
(According to the ELF spec, there can only be one.) */ (According to the ELF spec, there can only be one.) */
for (unsigned int i = 0; i < phdrs.size(); ++i) { for (auto phdr : phdrs) {
if (rdi(phdrs[i].p_type) == PT_PHDR) { if (rdi(phdr.p_type) == PT_PHDR) {
phdrs[i].p_offset = hdr->e_phoff; phdr.p_offset = hdr->e_phoff;
wri(phdrs[i].p_vaddr, wri(phdrs[i].p_paddr, phdrAddress)); wri(phdr.p_vaddr, wri(phdr.p_paddr, phdrAddress));
wri(phdrs[i].p_filesz, wri(phdrs[i].p_memsz, phdrs.size() * sizeof(Elf_Phdr))); wri(phdr.p_filesz, wri(phdr.p_memsz, phdrs.size() * sizeof(Elf_Phdr)));
break; break;
} }
} }