Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(toolchain): use bundled readelf in setup_toolchain.sh #6

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading