PatchELF is a simple utility for modifying existing ELF executables and libraries. It comes handy when dealing with existing binary tools with strange NEEDED or without RUNPATH in the ELF header.
Signed-off-by: Marc Kleine-Budde <m...@pengutronix.de> --- .../0001-fix-adjusting-startPage.patch | 35 +++++++++++++++++++ patches/patchelf-0.10/series | 4 +++ rules/host-patchelf.in | 15 ++++++++ rules/host-patchelf.make | 34 ++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 patches/patchelf-0.10/0001-fix-adjusting-startPage.patch create mode 100644 patches/patchelf-0.10/series create mode 100644 rules/host-patchelf.in create mode 100644 rules/host-patchelf.make diff --git a/patches/patchelf-0.10/0001-fix-adjusting-startPage.patch b/patches/patchelf-0.10/0001-fix-adjusting-startPage.patch new file mode 100644 index 000000000000..fa92041850ff --- /dev/null +++ b/patches/patchelf-0.10/0001-fix-adjusting-startPage.patch @@ -0,0 +1,35 @@ +From: Ed Bartosh <ed.bart...@linux.intel.com> +Date: Fri, 21 Jul 2017 12:33:53 +0300 +Subject: [PATCH] fix adjusting startPage + +startPage is adjusted unconditionally for all executables. +This results in incorrect addresses assigned to INTERP and LOAD +program headers, which breaks patched executable. + +Adjusting startPage variable only when startOffset > startPage +should fix this. + +This change is related to the issue NixOS#10 + +Signed-off-by: Ed Bartosh <ed.bart...@linux.intel.com> +--- + src/patchelf.cc | 6 ++---- + 1 file changed, 2 insertions(+), 4 deletions(-) + +diff --git a/src/patchelf.cc b/src/patchelf.cc +index 0b4965adff83..12d6bf1dde01 100644 +--- a/src/patchelf.cc ++++ b/src/patchelf.cc +@@ -742,10 +742,8 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary() + since DYN executables tend to start at virtual address 0, so + rewriteSectionsExecutable() won't work because it doesn't have + any virtual address space to grow downwards into. */ +- if (isExecutable) { +- if (startOffset >= startPage) { +- debug("shifting new PT_LOAD segment by %d bytes to work around a Linux kernel bug\n", startOffset - startPage); +- } ++ if (isExecutable && startOffset > startPage) { ++ debug("shifting new PT_LOAD segment by %d bytes to work around a Linux kernel bug\n", startOffset - startPage); + startPage = startOffset; + } + diff --git a/patches/patchelf-0.10/series b/patches/patchelf-0.10/series new file mode 100644 index 000000000000..c2e125d669bd --- /dev/null +++ b/patches/patchelf-0.10/series @@ -0,0 +1,4 @@ +# generated by git-ptx-patches +#tag:base --start-number 1 +0001-fix-adjusting-startPage.patch +# 2ce579fac5ddd3aade5fe8d7c080a8a9 - git-ptx-patches magic diff --git a/rules/host-patchelf.in b/rules/host-patchelf.in new file mode 100644 index 000000000000..31c42953cdee --- /dev/null +++ b/rules/host-patchelf.in @@ -0,0 +1,15 @@ +## SECTION=hosttools_noprompt +## SECTION=hosttools_platform + +config HOST_PATCHELF + tristate + default y if ALLYES + help + PatchELF is a simple utility for modifying existing ELF + executables and libraries. In particular, it can do the + following: + * Change the dynamic loader ("ELF interpreter") of + executables + * Change the RPATH of executables and libraries + * Remove declared dependencies on dynamic libraries + (DT_NEEDED entries) diff --git a/rules/host-patchelf.make b/rules/host-patchelf.make new file mode 100644 index 000000000000..a56436a8c314 --- /dev/null +++ b/rules/host-patchelf.make @@ -0,0 +1,34 @@ +# -*-makefile-*- +# +# Copyright (C) 2018, 2019 by Marc Kleine-Budde <m...@pengutronix.de> +# +# See CREDITS for details about who has contributed to this project. +# +# For further information about the PTXdist project and license conditions +# see the README file. +# + +# +# We provide this package +# +HOST_PACKAGES-$(PTXCONF_HOST_PATCHELF) += host-patchelf + +# +# Paths and names +# +HOST_PATCHELF_VERSION := 0.10 +HOST_PATCHELF_MD5 := 228ade8c1b4033670bcf7f77c0ea1fb7 +HOST_PATCHELF := patchelf-$(HOST_PATCHELF_VERSION) +HOST_PATCHELF_SUFFIX := tar.gz +HOST_PATCHELF_URL := https://nixos.org/releases/patchelf/$(HOST_PATCHELF)/$(HOST_PATCHELF).$(HOST_PATCHELF_SUFFIX) +HOST_PATCHELF_SOURCE := $(SRCDIR)/$(HOST_PATCHELF).$(HOST_PATCHELF_SUFFIX) +HOST_PATCHELF_DIR := $(HOST_BUILDDIR)/$(HOST_PATCHELF) +HOST_PATCHELF_LICENSE := GPL-3.0-or-later + +# ---------------------------------------------------------------------------- +# Prepare +# ---------------------------------------------------------------------------- + +HOST_PATCHELF_CONF_TOOL := autoconf + +# vim: syntax=make -- 2.20.1 _______________________________________________ ptxdist mailing list ptxdist@pengutronix.de