From de79f1a14494d237ef0a75da6fa8db4f095bc65c Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Mon, 10 Oct 2022 15:32:03 +0100 Subject: [PATCH] Sync .note.gnu.property to PT_GNU_PROPERTY --- src/elf.h | 1 + src/patchelf.cc | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/elf.h b/src/elf.h index 702f2e60..b87c2c7f 100644 --- a/src/elf.h +++ b/src/elf.h @@ -585,6 +585,7 @@ typedef struct #define PT_GNU_EH_FRAME 0x6474e550 /* GCC .eh_frame_hdr segment */ #define PT_GNU_STACK 0x6474e551 /* Indicates stack executability */ #define PT_GNU_RELRO 0x6474e552 /* Read-only after relocation */ +#define PT_GNU_PROPERTY 0x6474e553 /* GNU property */ #define PT_LOSUNW 0x6ffffffa #define PT_SUNWBSS 0x6ffffffa /* Sun Specific segment */ #define PT_SUNWSTACK 0x6ffffffb /* Stack segment */ diff --git a/src/patchelf.cc b/src/patchelf.cc index 505c9802..54a208a6 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -652,6 +652,18 @@ void ElfFile::writeReplacedSections(Elf_Off & curOff, } } + /* If there is .note.gnu.property section, then the PT_GNU_PROPERTY + segment must be sync'ed with it. */ + if (sectionName == ".note.gnu.property") { + for (auto & phdr : phdrs) { + if (rdi(phdr.p_type) == PT_GNU_PROPERTY) { + phdr.p_offset = shdr.sh_offset; + phdr.p_vaddr = phdr.p_paddr = shdr.sh_addr; + phdr.p_filesz = phdr.p_memsz = shdr.sh_size; + } + } + } + curOff += roundUp(i.second.size(), sectionAlignment); }