Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame^] | 1 | From 6edec83653ce1b5fc201ff6db93b966394766814 Mon Sep 17 00:00:00 2001 |
| 2 | From: rmnull <rmnull@users.noreply.github.com> |
| 3 | Date: Tue, 18 Aug 2020 20:22:52 +0530 |
| 4 | Subject: [PATCH] mark phdrs synced with sections, avoid rechecking it when |
| 5 | syncing note sections to segments. |
| 6 | |
| 7 | This also serves as a bug fix when a previously synced note segment |
| 8 | overlaps with another section and creates a false alarm. |
| 9 | |
| 10 | Upstream-Status: Backport |
| 11 | --- |
| 12 | src/patchelf.cc | 5 ++++- |
| 13 | 1 file changed, 4 insertions(+), 1 deletion(-) |
| 14 | |
| 15 | diff --git a/src/patchelf.cc b/src/patchelf.cc |
| 16 | index 05ec793..622f0b6 100644 |
| 17 | --- a/src/patchelf.cc |
| 18 | +++ b/src/patchelf.cc |
| 19 | @@ -669,6 +669,7 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff, |
| 20 | memset(contents + rdi(shdr.sh_offset), 'X', rdi(shdr.sh_size)); |
| 21 | } |
| 22 | |
| 23 | + std::set<unsigned int> noted_phdrs = {}; |
| 24 | for (auto & i : replacedSections) { |
| 25 | std::string sectionName = i.first; |
| 26 | auto & shdr = findSection(sectionName); |
| 27 | @@ -721,7 +722,7 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff, |
| 28 | shdr.sh_addralign = orig_shdr.sh_addralign; |
| 29 | |
| 30 | for (unsigned int j = 0; j < phdrs.size(); ++j) |
| 31 | - if (rdi(phdrs[j].p_type) == PT_NOTE) { |
| 32 | + if (rdi(phdrs[j].p_type) == PT_NOTE && noted_phdrs.find(j) == noted_phdrs.end()) { |
| 33 | Elf_Off p_start = rdi(phdrs[j].p_offset); |
| 34 | Elf_Off p_end = p_start + rdi(phdrs[j].p_filesz); |
| 35 | Elf_Off s_start = rdi(orig_shdr.sh_offset); |
| 36 | @@ -739,6 +740,8 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff, |
| 37 | phdrs[j].p_offset = shdr.sh_offset; |
| 38 | phdrs[j].p_vaddr = phdrs[j].p_paddr = shdr.sh_addr; |
| 39 | phdrs[j].p_filesz = phdrs[j].p_memsz = shdr.sh_size; |
| 40 | + |
| 41 | + noted_phdrs.insert(j); |
| 42 | } |
| 43 | } |
| 44 | |