diff options
Diffstat (limited to 'meta/recipes-devtools/patchelf')
8 files changed, 128 insertions, 160 deletions
diff --git a/meta/recipes-devtools/patchelf/patchelf/0001-Set-interpreter-only-when-necessary.patch b/meta/recipes-devtools/patchelf/patchelf/0001-Set-interpreter-only-when-necessary.patch new file mode 100644 index 0000000000..9a8216b3fe --- /dev/null +++ b/meta/recipes-devtools/patchelf/patchelf/0001-Set-interpreter-only-when-necessary.patch @@ -0,0 +1,31 @@ +From f5df94952e87eaa390e5c845bc48fdb3dbc31cc2 Mon Sep 17 00:00:00 2001 +From: Yuta Hayama <hayama@lineo.co.jp> +Date: Fri, 21 Jul 2023 10:47:02 +0900 +Subject: [PATCH] Set interpreter only when necessary + +If the given interpreter is already set, nothing needs to be done. +As with modifySoname(), it skips unnecessary processing. + +Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com> +--- +Upstream-Status: Submitted [https://github.com/NixOS/patchelf/pull/508] + + src/patchelf.cc | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/src/patchelf.cc b/src/patchelf.cc +index 86429c4..e562c49 100644 +--- a/src/patchelf.cc ++++ b/src/patchelf.cc +@@ -1460,6 +1460,11 @@ void ElfFile<ElfFileParamNames>::modifySoname(sonameMode op, const std::string & + template<ElfFileParams> + void ElfFile<ElfFileParamNames>::setInterpreter(const std::string & newInterpreter) + { ++ if (getInterpreter() == newInterpreter) { ++ debug("given interpreter is already set\n"); ++ return; ++ } ++ + std::string & section = replaceSection(".interp", newInterpreter.size() + 1); + setSubstr(section, 0, newInterpreter + '\0'); + changed = true; diff --git a/meta/recipes-devtools/patchelf/patchelf/0002-align-startOffset-with-p_align-instead-of-pagesize-f.patch b/meta/recipes-devtools/patchelf/patchelf/0002-align-startOffset-with-p_align-instead-of-pagesize-f.patch new file mode 100644 index 0000000000..7906f0f73b --- /dev/null +++ b/meta/recipes-devtools/patchelf/patchelf/0002-align-startOffset-with-p_align-instead-of-pagesize-f.patch @@ -0,0 +1,42 @@ +From 1198329b922f3cdddc3e87a7c81d7730b646c088 Mon Sep 17 00:00:00 2001 +From: Yuta Hayama <hayama@lineo.co.jp> +Date: Fri, 28 Jul 2023 16:22:31 +0900 +Subject: [PATCH] align startOffset with p_align instead of pagesize for + compatibility + +According to the ELF specification, the alignment of loadable process segments +should satisfy (p_vaddr mod pagesize) == (p_offset mod pagesize). However, +glibc earlier than 2.35 incorrectly requires that the LOAD segment be (p_vaddr +mod p_align) == (p_offset mod p_align), and will output the error message +"ELF load command address/offset not properly aligned" if this is not met. + +Since there are many systems that use glibc earlier than 2.35, it is preferable +that newly added LOAD segments satisfy (p_vaddr mod p_align) == (p_offset mod +p_align) for compatibility. + +Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com> +--- +Upstream-Status: Submitted [https://github.com/NixOS/patchelf/pull/510] + + src/patchelf.cc | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/src/patchelf.cc b/src/patchelf.cc +index 82b4b46..6edb81a 100644 +--- a/src/patchelf.cc ++++ b/src/patchelf.cc +@@ -843,7 +843,13 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary() + neededSpace += headerTableSpace; + debug("needed space is %d\n", neededSpace); + +- Elf_Off startOffset = roundUp(fileContents->size(), getPageSize()); ++ /* glibc earlier than 2.35 requires that the LOAD segment satisfies ++ (p_vaddr mod p_align) == (p_offset mod p_align). ++ The ELF specification requires that loadable process segments satisfy ++ (p_vaddr mod pagesize) == (p_offset mod pagesize), so glibc is probably ++ wrong, but here startOffset is calculated according to p_align for ++ compatibility. */ ++ Elf_Off startOffset = roundUp(fileContents->size(), alignStartPage); + + // In older version of binutils (2.30), readelf would check if the dynamic + // section segment is strictly smaller than the file (and not same size). diff --git a/meta/recipes-devtools/patchelf/patchelf/0003-make-LOAD-segment-extensions-based-on-p_align-instea.patch b/meta/recipes-devtools/patchelf/patchelf/0003-make-LOAD-segment-extensions-based-on-p_align-instea.patch new file mode 100644 index 0000000000..37eaf992d8 --- /dev/null +++ b/meta/recipes-devtools/patchelf/patchelf/0003-make-LOAD-segment-extensions-based-on-p_align-instea.patch @@ -0,0 +1,32 @@ +From 299ad5766921d593e11a42a8e4dec55b4b350876 Mon Sep 17 00:00:00 2001 +From: Yuta Hayama <hayama@lineo.co.jp> +Date: Mon, 31 Jul 2023 11:58:49 +0900 +Subject: [PATCH] make LOAD segment extensions based on p_align instead of + pagesize + +Since the p_align of the LOAD segment is no longer pagesize, the actual p_align +value is used to calculate for the LOAD segment extension. + +If calculated with pagesize, new LOAD segment may be added even though the +existing LOAD segment can be extended. + +Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com> +--- +Upstream-Status: Submitted [https://github.com/NixOS/patchelf/pull/510] + + src/patchelf.cc | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/patchelf.cc b/src/patchelf.cc +index 6edb81a..86429c4 100644 +--- a/src/patchelf.cc ++++ b/src/patchelf.cc +@@ -885,7 +885,7 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary() + rdi(lastSeg.p_type) == PT_LOAD && + rdi(lastSeg.p_flags) == (PF_R | PF_W) && + rdi(lastSeg.p_align) == alignStartPage) { +- auto segEnd = roundUp(rdi(lastSeg.p_offset) + rdi(lastSeg.p_memsz), getPageSize()); ++ auto segEnd = roundUp(rdi(lastSeg.p_offset) + rdi(lastSeg.p_memsz), alignStartPage); + if (segEnd == startOffset) { + auto newSz = startOffset + neededSpace - rdi(lastSeg.p_offset); + wri(lastSeg.p_filesz, wri(lastSeg.p_memsz, newSz)); diff --git a/meta/recipes-devtools/patchelf/patchelf/6edec83653ce1b5fc201ff6db93b966394766814.patch b/meta/recipes-devtools/patchelf/patchelf/6edec83653ce1b5fc201ff6db93b966394766814.patch deleted file mode 100644 index ba35ec6ffc..0000000000 --- a/meta/recipes-devtools/patchelf/patchelf/6edec83653ce1b5fc201ff6db93b966394766814.patch +++ /dev/null @@ -1,44 +0,0 @@ -From 6edec83653ce1b5fc201ff6db93b966394766814 Mon Sep 17 00:00:00 2001 -From: rmnull <rmnull@users.noreply.github.com> -Date: Tue, 18 Aug 2020 20:22:52 +0530 -Subject: [PATCH] mark phdrs synced with sections, avoid rechecking it when - syncing note 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. - -Upstream-Status: Backport ---- - src/patchelf.cc | 5 ++++- - 1 file changed, 4 insertions(+), 1 deletion(-) - -diff --git a/src/patchelf.cc b/src/patchelf.cc -index 05ec793..622f0b6 100644 ---- a/src/patchelf.cc -+++ b/src/patchelf.cc -@@ -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); -@@ -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); -@@ -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); - } - } - diff --git a/meta/recipes-devtools/patchelf/patchelf/alignmentfix.patch b/meta/recipes-devtools/patchelf/patchelf/alignmentfix.patch deleted file mode 100644 index a06876e50a..0000000000 --- a/meta/recipes-devtools/patchelf/patchelf/alignmentfix.patch +++ /dev/null @@ -1,44 +0,0 @@ -If a binary has multiple SHT_NOTE sections and corresponding PT_NOTE -headers, we can see the error: - -patchelf: cannot normalize PT_NOTE segment: non-contiguous SHT_NOTE sections - -if the SHT_NOTE sections aren't sized to end on aligned boundaries. An example -would be a binary with: - - [ 2] .note.ABI-tag NOTE 00000000000002f4 000002f4 - 0000000000000020 0000000000000000 A 0 0 4 - [ 3] .note.gnu.propert NOTE 0000000000000318 00000318 - 0000000000000030 0000000000000000 A 0 0 8 - [ 4] .note.gnu.build-i NOTE 0000000000000348 00000348 - 0000000000000024 0000000000000000 A 0 0 4 - - NOTE 0x0000000000000318 0x0000000000000318 0x0000000000000318 - 0x0000000000000030 0x0000000000000030 R 0x8 - NOTE 0x00000000000002f4 0x00000000000002f4 0x00000000000002f4 - 0x0000000000000078 0x0000000000000074 R 0x4 - -since the PT_NOTE section at 2f4 covers [2] and [3] but the code -calclates curr_off should be 314, not the 318 in the binary. This -is an alignment issue. - -To fix this, we need to round curr_off to the next section alignment. - -Upstream-Status: Submitted [https://github.com/NixOS/patchelf/pull/274] -Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> - -Index: git/src/patchelf.cc -=================================================================== ---- git.orig/src/patchelf.cc -+++ git/src/patchelf.cc -@@ -1010,8 +1010,9 @@ void ElfFile<ElfFileParamNames>::normali - size_t size = 0; - for (const auto & shdr : shdrs) { - if (rdi(shdr.sh_type) != SHT_NOTE) continue; -- if (rdi(shdr.sh_offset) != curr_off) continue; -+ if (rdi(shdr.sh_offset) != roundUp(curr_off, rdi(shdr.sh_addralign))) continue; - size = rdi(shdr.sh_size); -+ curr_off = roundUp(curr_off, rdi(shdr.sh_addralign)); - break; - } - if (size == 0) diff --git a/meta/recipes-devtools/patchelf/patchelf/handle-read-only-files.patch b/meta/recipes-devtools/patchelf/patchelf/handle-read-only-files.patch deleted file mode 100644 index bf721c1af8..0000000000 --- a/meta/recipes-devtools/patchelf/patchelf/handle-read-only-files.patch +++ /dev/null @@ -1,52 +0,0 @@ -From 7f1fd10cfebd5ea2f3e1938abe1bd1c4828164a7 Mon Sep 17 00:00:00 2001 -From: Fabio Berton <fabio.berton@ossystems.com.br> -Date: Fri, 9 Sep 2016 16:00:42 -0300 -Subject: [PATCH] handle read-only files - -Patch from: -https://github.com/darealshinji/patchelf/commit/40e66392bc4b96e9b4eda496827d26348a503509 - -Upstream-Status: Denied [https://github.com/NixOS/patchelf/pull/89] - -Signed-off-by: Fabio Berton <fabio.berton@ossystems.com.br> - ---- - src/patchelf.cc | 16 +++++++++++++++- - 1 file changed, 15 insertions(+), 1 deletion(-) - -Index: git/src/patchelf.cc -=================================================================== ---- git.orig/src/patchelf.cc -+++ git/src/patchelf.cc -@@ -499,9 +499,19 @@ void ElfFile<ElfFileParamNames>::sortShd - - static void writeFile(std::string fileName, FileContents contents) - { -+ struct stat st; -+ int fd; -+ - debug("writing %s\n", fileName.c_str()); - -- int fd = open(fileName.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0777); -+ if (stat(fileName.c_str(), &st) != 0) -+ error("stat"); -+ -+ if (chmod(fileName.c_str(), 0600) != 0) -+ error("chmod"); -+ -+ fd = open(fileName.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0777); -+ - if (fd == -1) - error("open"); - -@@ -515,6 +525,10 @@ static void writeFile(std::string fileNa - - if (close(fd) != 0) - error("close"); -+ -+ if (chmod(fileName.c_str(), st.st_mode) != 0) -+ error("chmod"); -+ - } - - diff --git a/meta/recipes-devtools/patchelf/patchelf_0.12.bb b/meta/recipes-devtools/patchelf/patchelf_0.12.bb deleted file mode 100644 index 7c97ea0789..0000000000 --- a/meta/recipes-devtools/patchelf/patchelf_0.12.bb +++ /dev/null @@ -1,20 +0,0 @@ -SUMMARY = "Tool to allow editing of RPATH and interpreter fields in ELF binaries" -DESCRIPTION = "PatchELF is a simple utility for modifying existing ELF executables and libraries." -HOMEPAGE = "https://github.com/NixOS/patchelf" - -LICENSE = "GPLv3" - -SRC_URI = "git://github.com/NixOS/patchelf;protocol=https \ - file://handle-read-only-files.patch \ - file://6edec83653ce1b5fc201ff6db93b966394766814.patch \ - file://alignmentfix.patch \ - " -SRCREV = "8d3a16e97294e3c5521c61b4c8835499c9918264" - -S = "${WORKDIR}/git" - -LIC_FILES_CHKSUM = "file://COPYING;md5=d32239bcb673463ab874e80d47fae504" - -inherit autotools - -BBCLASSEXTEND = "native nativesdk" diff --git a/meta/recipes-devtools/patchelf/patchelf_0.18.0.bb b/meta/recipes-devtools/patchelf/patchelf_0.18.0.bb new file mode 100644 index 0000000000..dece34240c --- /dev/null +++ b/meta/recipes-devtools/patchelf/patchelf_0.18.0.bb @@ -0,0 +1,23 @@ +SUMMARY = "Tool to allow editing of RPATH and interpreter fields in ELF binaries" +DESCRIPTION = "PatchELF is a simple utility for modifying existing ELF executables and libraries." +HOMEPAGE = "https://github.com/NixOS/patchelf" + +LICENSE = "GPL-3.0-only" + +SRC_URI = "git://github.com/NixOS/patchelf;protocol=https;branch=master \ + file://0001-Set-interpreter-only-when-necessary.patch \ + file://0002-align-startOffset-with-p_align-instead-of-pagesize-f.patch \ + file://0003-make-LOAD-segment-extensions-based-on-p_align-instea.patch \ +" +SRCREV = "99c24238981b7b1084313aca8f5c493bb46f302c" + +S = "${WORKDIR}/git" + +LIC_FILES_CHKSUM = "file://COPYING;md5=d32239bcb673463ab874e80d47fae504" + +inherit autotools + +PACKAGES += "${PN}-zsh-completion" +FILES:${PN}-zsh-completion = "${datadir}/zsh" + +BBCLASSEXTEND = "native nativesdk" |