From 49bfdf22ed551630653beedb022dfbd39c421f89 Mon Sep 17 00:00:00 2001 From: Adonis Ling Date: Tue, 29 Oct 2024 11:12:38 +0800 Subject: [PATCH] fix(toolchain): use bundled readelf in setup_toolchain.sh Issues: #2 --- toolchain/setup_toolchain.sh | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/toolchain/setup_toolchain.sh b/toolchain/setup_toolchain.sh index 91e5945..7360006 100755 --- a/toolchain/setup_toolchain.sh +++ b/toolchain/setup_toolchain.sh @@ -10,9 +10,6 @@ declare -r PATCHELF='patchelf' declare -r LIBC_SO='libc.so.6' declare -r INTERPRETER='ld-linux-*' -READELF="$(command -v readelf)" -declare -r READELF - LD="$(command -v ld)" declare -r LD @@ -71,6 +68,19 @@ function extract_toolchain() { log_info 'Success!' } +function relocate() { + local patchelf="${1}" + local rpath="${2}" + local interpreter="${3}" + shift 3 + + local file + for file in "${@}"; do + "${patchelf}" --set-rpath "${rpath}" "${file}" + "${patchelf}" --set-interpreter "${interpreter}" "${file}" + done +} + function configure_toolchain() { local prefix="${1}" log_info 'Configuring the toolchain...' @@ -133,12 +143,17 @@ function configure_toolchain() { echo "${rpaths[*]}" )" + # Use bundled readelf + local readelf + readelf="$(pwd)/bin/readelf" + relocate "${patchelf}" "${rpaths_in_line}" "${interpreter}" "${readelf}" + while read -r file; do - if ! file "${file}" | grep ELF >/dev/null; then + if ! "${readelf}" -h "${file}" &>/dev/null; then continue fi "${patchelf}" --set-rpath "${rpaths_in_line}" "${file}" - if "${READELF}" -S "${file}" | grep '.interp' >/dev/null; then + if "${readelf}" -S "${file}" | grep '.interp' >/dev/null; then "${patchelf}" --set-interpreter "${interpreter}" "${file}" fi done < <(