Skip to content

Commit

Permalink
mark phdrs synced with sections, avoid rechecking it when syncing not…
Browse files Browse the repository at this point in the history
…e sections to segments.

This also serves as a bug fix when a previously synced note segment
overlaps with another section and creates a false alarm.
  • Loading branch information
rmNULL committed Aug 25, 2020
1 parent 9d3fc11 commit 6edec83
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/patchelf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff,
memset(contents + rdi(shdr.sh_offset), 'X', rdi(shdr.sh_size));
}

std::set<unsigned int> noted_phdrs = {};
for (auto & i : replacedSections) {
std::string sectionName = i.first;
auto & shdr = findSection(sectionName);
Expand Down Expand Up @@ -721,7 +722,7 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff,
shdr.sh_addralign = orig_shdr.sh_addralign;

for (unsigned int j = 0; j < phdrs.size(); ++j)
if (rdi(phdrs[j].p_type) == PT_NOTE) {
if (rdi(phdrs[j].p_type) == PT_NOTE && noted_phdrs.find(j) == noted_phdrs.end()) {
Elf_Off p_start = rdi(phdrs[j].p_offset);
Elf_Off p_end = p_start + rdi(phdrs[j].p_filesz);
Elf_Off s_start = rdi(orig_shdr.sh_offset);
Expand All @@ -739,6 +740,8 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff,
phdrs[j].p_offset = shdr.sh_offset;
phdrs[j].p_vaddr = phdrs[j].p_paddr = shdr.sh_addr;
phdrs[j].p_filesz = phdrs[j].p_memsz = shdr.sh_size;

noted_phdrs.insert(j);
}
}

Expand Down

0 comments on commit 6edec83

Please sign in to comment.