Skip to content

Commit

Permalink
fix(toolchain): use bundled readelf in setup_toolchain.sh
Browse files Browse the repository at this point in the history
    Issues: #2
  • Loading branch information
adonis0147 committed Oct 29, 2024
1 parent 28c7e08 commit 49bfdf2
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions toolchain/setup_toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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...'
Expand Down Expand Up @@ -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 < <(
Expand Down

0 comments on commit 49bfdf2

Please sign in to comment.