Skip to content
Open
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
16 changes: 12 additions & 4 deletions recipes-devtools/sdk-files/files/relocate-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,22 @@ if [ -z $(which patchelf 2>/dev/null) ]; then
exit 1
fi

# Use patchelf "--no-sort" option to avoid segfaults for long install directory
# if the version is newer than 0.14.3 (eg. Debian 13).
patchelf_opts=""
patchelf_ver=$(patchelf --version | awk '{print $2}')
if dpkg --compare-versions "${patchelf_ver}" "gt" "0.14.3"; then
patchelf_opts="--no-sort"
fi

echo -n "Adjusting path of SDK to '${new_sdkroot}'... "

for binary in $(find ${sdkroot}/usr/bin ${sdkroot}/usr/sbin ${sdkroot}/usr/lib/gcc* -executable -type f,l -exec file -L {} \; | grep ELF | awk -F ':' '{ print $1 }'); do
interpreter=$(patchelf --print-interpreter ${binary} 2>/dev/null)
oldpath=${interpreter%/lib*/ld-linux*}
interpreter=${interpreter#${oldpath}}
if [ -n "${interpreter}" ]; then
patchelf --set-interpreter ${new_sdkroot}${interpreter} \
patchelf ${patchelf_opts} --set-interpreter ${new_sdkroot}${interpreter} \
--set-rpath ${new_sdkroot}/usr/lib:${new_sdkroot}/usr/lib/${arch}-linux-gnu \
--force-rpath \
$binary 2>/dev/null
Expand All @@ -62,7 +70,7 @@ done
for library in $(find ${sdkroot}/usr/lib -type f,l -name "lib*.so*" -exec file -L {} \; | grep ELF | awk -F ':' '{ print $1 }'); do
rpath=$(patchelf --print-rpath ${library})
if [ -n "${library}" ]; then
patchelf --set-rpath ${new_sdkroot}/usr/lib:${new_sdkroot}/usr/lib/${arch}-linux-gnu \
patchelf ${patchelf_opts} --set-rpath ${new_sdkroot}/usr/lib:${new_sdkroot}/usr/lib/${arch}-linux-gnu \
--force-rpath \
$library 2>/dev/null
fi
Expand All @@ -79,15 +87,15 @@ for binary in $(cat $repatch_list ${new_sdkroot}/repatch.list); do
oldpath=${interpreter%/lib*/ld-linux*}
interpreter=${interpreter#${oldpath}}
if [ -n "${interpreter}" ]; then
patchelf --set-interpreter ${new_sdkroot}${interpreter} \
patchelf ${patchelf_opts} --set-interpreter ${new_sdkroot}${interpreter} \
--set-rpath ${new_sdkroot}/usr/lib:${new_sdkroot}/usr/lib/${arch}-linux-gnu \
--force-rpath \
$binary 2>/dev/null
fi
else
rpath=$(patchelf --print-rpath ${binary})
if [ -n "${rpath}" ]; then
patchelf --set-rpath ${new_sdkroot}/usr/lib:${new_sdkroot}/usr/lib/${arch}-linux-gnu \
patchelf ${patchelf_opts} --set-rpath ${new_sdkroot}/usr/lib:${new_sdkroot}/usr/lib/${arch}-linux-gnu \
--force-rpath \
$binary 2>/dev/null
fi
Expand Down