Skip to content

Commit

Permalink
Revert "write out replace sections in original order"
Browse files Browse the repository at this point in the history
This reverts commit 42394e8.
  • Loading branch information
brenoguim committed Feb 20, 2023
1 parent 5908e16 commit 62246b1
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/patchelf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -604,26 +604,20 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff,
}

std::set<unsigned int> noted_phdrs = {};

/* We iterate over the sorted section headers here, so that the relative
position between replaced sections stays the same. */
for (auto & shdr : shdrs) {
std::string sectionName = getSectionName(shdr);
auto i = replacedSections.find(sectionName);
if (i == replacedSections.end())
continue;

for (auto & i : replacedSections) {
const std::string & sectionName = i.first;
auto & shdr = findSectionHeader(sectionName);
Elf_Shdr orig_shdr = shdr;
debug("rewriting section '%s' from offset 0x%x (size %d) to offset 0x%x (size %d)\n",
sectionName.c_str(), rdi(shdr.sh_offset), rdi(shdr.sh_size), curOff, i->second.size());
sectionName.c_str(), rdi(shdr.sh_offset), rdi(shdr.sh_size), curOff, i.second.size());

memcpy(fileContents->data() + curOff, (unsigned char *) i->second.c_str(),
i->second.size());
memcpy(fileContents->data() + curOff, (unsigned char *) i.second.c_str(),
i.second.size());

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

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

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

replacedSections.clear();
Expand Down

0 comments on commit 62246b1

Please sign in to comment.