From 6f4d5afce23eb2f747f62e82d47489e74163cf7d Mon Sep 17 00:00:00 2001 From: Alexei Colin Date: Wed, 3 Feb 2021 14:35:34 -0500 Subject: [PATCH 1/2] eclass/prefix: exprefixify: relocate executables A function for relocating executables by replacing the path to program interpreter (dynamic loader). Signed-off-by: Alexei Colin --- eclass/prefix.eclass | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/eclass/prefix.eclass b/eclass/prefix.eclass index d00c0d7..5e89cfc 100644 --- a/eclass/prefix.eclass +++ b/eclass/prefix.eclass @@ -135,4 +135,26 @@ prefixify_ro() { die "$1 does not exist" fi } + +# @FUNCTION: exprefixify +# @USAGE: +# @DESCRIPTION: +# For each ELF executable in given directory replaces the path to +# program interpreter (i.e. the dynamic loader, for example +# '/lib64/ld-linux-x86-64.so.2') with the path where the prefix is +# appended the original path. +# NOTE: ebuilds that call this must add dev-util/patchelf to DEPENDS +exprefixify() { + local dir="$1" + einfo "Prefixifying executables in ${dir}..." + type -P patchelf 1>/dev/null || die "patchelf not found (add dev-util/patchelf to DEPENDS)" + + # The first -exec is to filter out non-ELF executables + find "${dir}" \ + \( -type f -or -type l \) -executable \ + -not \( -name '*.la' -or -name '*.a' -or -name '*.so.*' -or -name '*.so' \) \ + -exec sh -c 'patchelf --print-interpreter {} 1>/dev/null 2>/dev/null' \; \ + -exec sh -c 'patchelf --set-interpreter ${EPREFIX}/$(patchelf --print-interpreter {}) {}' \; \ + || die +} # vim: tw=72: -- 1.8.3.1