Skip to content

Commit 62246b1

Browse files
committed
Revert "write out replace sections in original order"
This reverts commit 42394e8.
1 parent 5908e16 commit 62246b1

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/patchelf.cc

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -604,26 +604,20 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff,
604604
}
605605

606606
std::set<unsigned int> noted_phdrs = {};
607-
608-
/* We iterate over the sorted section headers here, so that the relative
609-
position between replaced sections stays the same. */
610-
for (auto & shdr : shdrs) {
611-
std::string sectionName = getSectionName(shdr);
612-
auto i = replacedSections.find(sectionName);
613-
if (i == replacedSections.end())
614-
continue;
615-
607+
for (auto & i : replacedSections) {
608+
const std::string & sectionName = i.first;
609+
auto & shdr = findSectionHeader(sectionName);
616610
Elf_Shdr orig_shdr = shdr;
617611
debug("rewriting section '%s' from offset 0x%x (size %d) to offset 0x%x (size %d)\n",
618-
sectionName.c_str(), rdi(shdr.sh_offset), rdi(shdr.sh_size), curOff, i->second.size());
612+
sectionName.c_str(), rdi(shdr.sh_offset), rdi(shdr.sh_size), curOff, i.second.size());
619613

620-
memcpy(fileContents->data() + curOff, (unsigned char *) i->second.c_str(),
621-
i->second.size());
614+
memcpy(fileContents->data() + curOff, (unsigned char *) i.second.c_str(),
615+
i.second.size());
622616

623617
/* Update the section header for this section. */
624618
wri(shdr.sh_offset, curOff);
625619
wri(shdr.sh_addr, startAddr + (curOff - startOffset));
626-
wri(shdr.sh_size, i->second.size());
620+
wri(shdr.sh_size, i.second.size());
627621
wri(shdr.sh_addralign, sectionAlignment);
628622

629623
/* If this is the .interp section, then the PT_INTERP segment
@@ -713,7 +707,7 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff,
713707
}
714708
}
715709

716-
curOff += roundUp(i->second.size(), sectionAlignment);
710+
curOff += roundUp(i.second.size(), sectionAlignment);
717711
}
718712

719713
replacedSections.clear();

0 commit comments

Comments
 (0)