Merge branch 'next'

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
This commit is contained in:
Peter Korsgaard
2023-09-07 16:50:14 +02:00
509 changed files with 6169 additions and 3662 deletions

View File

@@ -46,27 +46,66 @@ Environment:
TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR
(default HOST_DIR/opt/ext-toolchain)
PARALLEL_JOBS number of parallel jobs to run
Returns: 0 if success or 1 in case of error
EOF
}
: ${PATCHELF:=${HOST_DIR}/bin/patchelf}
: "${PATCHELF:=${HOST_DIR}/bin/patchelf}"
# ELF files should not be in these sub-directories
HOST_EXCLUDEPATHS="/share/terminfo"
STAGING_EXCLUDEPATHS="/usr/include /usr/share/terminfo"
TARGET_EXCLUDEPATHS="/lib/firmware"
patch_file() {
local PATCHELF rootdir file
local -a sanitize_extra_args
PATCHELF="${1}"
rootdir="${2}"
file="${3}"
shift 3
sanitize_extra_args=("${@}")
# check if it's an ELF file
rpath="$("${PATCHELF}" --print-rpath "${file}" 2>&1)"
if test $? -ne 0 ; then
return 0
fi
# make files writable if necessary
changed="$(chmod -c u+w "${file}")"
# With per-package directory support, most RPATH of host
# binaries will point to per-package directories. This won't
# work with the --make-rpath-relative ${rootdir} invocation as
# the per-package host directory is not within ${rootdir}. So,
# we rewrite all RPATHs pointing to per-package directories so
# that they point to the global host directry.
# shellcheck disable=SC2001 # ${var//search/replace} hard when search or replace have / in them
changed_rpath="$(echo "${rpath}" | sed "s@${PER_PACKAGE_DIR}/[^/]\+/host@${HOST_DIR}@")"
if test "${rpath}" != "${changed_rpath}" ; then
"${PATCHELF}" --set-rpath "${changed_rpath}" "${file}"
fi
# call patchelf to sanitize the rpath
"${PATCHELF}" --make-rpath-relative "${rootdir}" "${sanitize_extra_args[@]}" "${file}"
# restore the original permission
test "${changed}" != "" && chmod u-w "${file}"
}
main() {
local rootdir
local tree="${1}"
local find_args=( )
local sanitize_extra_args=( )
local rootdir tree
local -a find_args sanitize_extra_args
tree="${1}"
if ! "${PATCHELF}" --version > /dev/null 2>&1; then
echo "Error: can't execute patchelf utility '${PATCHELF}'"
exit 1
echo "Error: can't execute patchelf utility '${PATCHELF}'"
exit 1
fi
case "${tree}" in
@@ -123,34 +162,14 @@ main() {
;;
esac
find_args+=( "-type" "f" "-print" )
find_args+=( "-type" "f" "-print0" )
while read file ; do
# check if it's an ELF file
rpath=$(${PATCHELF} --print-rpath "${file}" 2>&1)
if test $? -ne 0 ; then
continue
fi
# make files writable if necessary
changed=$(chmod -c u+w "${file}")
# With per-package directory support, most RPATH of host
# binaries will point to per-package directories. This won't
# work with the --make-rpath-relative ${rootdir} invocation as
# the per-package host directory is not within ${rootdir}. So,
# we rewrite all RPATHs pointing to per-package directories so
# that they point to the global host directry.
changed_rpath=$(echo ${rpath} | sed "s@${PER_PACKAGE_DIR}/[^/]\+/host@${HOST_DIR}@")
if test "${rpath}" != "${changed_rpath}" ; then
${PATCHELF} --set-rpath ${changed_rpath} "${file}"
fi
# call patchelf to sanitize the rpath
${PATCHELF} --make-rpath-relative "${rootdir}" ${sanitize_extra_args[@]} "${file}"
# restore the original permission
test "${changed}" != "" && chmod u-w "${file}"
done < <(find "${rootdir}" ${find_args[@]})
export -f patch_file
# Limit the number of cores used
# shellcheck disable=SC2016 # ${@} has to be expanded in the sub-shell.
find "${rootdir}" "${find_args[@]}" \
| xargs -0 -r -P "${PARALLEL_JOBS:-1}" -I {} \
bash -c 'patch_file "${@}"' _ "${PATCHELF}" "${rootdir}" {} "${sanitize_extra_args[@]}"
# Restore patched patchelf utility
test "${tree}" = "host" && mv "${PATCHELF}.__to_be_patched" "${PATCHELF}"
@@ -159,4 +178,4 @@ main() {
return 0
}
main ${@}
main "${@}"