From: Victor Dumas <dumasv.dev@gmail.com>
To: buildroot@buildroot.org
Cc: Victor Dumas <dumasv.dev@gmail.com>
Subject: [Buildroot] [PATCH v2] support/scripts/fix-rpath: parallelize patching files
Date: Fri, 7 Oct 2022 17:54:34 +0200 [thread overview]
Message-ID: <20221007155434.178261-1-dumasv.dev@gmail.com> (raw)
In-Reply-To: <20221006155217.626248-1-dumasv.dev@gmail.com>
Using "xargs" instead of "while read" loop allows for the patching of files to be parallelized, significantly reducing the amount of time it takes to fix all the paths.On a larger RFS(~300MB) this script was taking 5 minutes, it now only takes about 30s on a 12 core machine
Signed-off-by: Victor Dumas <dumasv.dev@gmail.com>
---
support/scripts/fix-rpath | 66 ++++++++++++++++++++++-----------------
1 file changed, 38 insertions(+), 28 deletions(-)
diff --git a/support/scripts/fix-rpath b/support/scripts/fix-rpath
index 3e67e770e5..7ed1851aac 100755
--- a/support/scripts/fix-rpath
+++ b/support/scripts/fix-rpath
@@ -58,6 +58,40 @@ HOST_EXCLUDEPATHS="/share/terminfo"
STAGING_EXCLUDEPATHS="/usr/include /usr/share/terminfo"
TARGET_EXCLUDEPATHS="/lib/firmware"
+patch_file() {
+ PATCHELF="${1}"
+ rootdir="${2}"
+ sanitize_extra_args="${3}"
+ file="${4}"
+
+ echo "patch file $file"
+
+ # 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.
+ 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}"
@@ -123,34 +157,10 @@ main() {
;;
esac
- find_args+=( "-type" "f" "-print" )
-
- 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[@]})
+ find_args+=( "-type" "f" "-print0" )
+
+ export -f patch_file
+ find "${rootdir}" ${find_args[@]} | xargs -0 -r -P $(nproc) -I {} bash -c "patch_file '${PATCHELF}' '${rootdir}' '${sanitize_extra_args}' $@" _ {}
# Restore patched patchelf utility
test "${tree}" = "host" && mv "${PATCHELF}.__to_be_patched" "${PATCHELF}"
--
2.30.2
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
next prev parent reply other threads:[~2022-10-07 15:54 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-03 12:24 [Buildroot] [PATCH] support/scripts/fix-rpath: parallelize patch files Victor Dumas
2022-10-06 13:18 ` Quentin Schulz via buildroot
2022-10-06 15:52 ` [Buildroot] [PATCH] support/scripts/fix-rpath: parallelize patching files Victor Dumas
2022-10-07 8:10 ` Quentin Schulz via buildroot
2022-10-07 15:50 ` [Buildroot] [PATCH v2] " Victor Dumas
2022-10-07 15:54 ` Victor Dumas [this message]
2022-10-19 12:40 ` [Buildroot] [PATCH v3] " Victor Dumas
2022-10-19 13:42 ` Angelo Compagnucci
2022-10-20 11:52 ` [Buildroot] [PATCH v4] " Victor Dumas
2022-10-20 11:55 ` Victor Dumas
2022-11-14 16:33 ` Quentin Schulz via buildroot
2022-11-15 8:47 ` David Laight
2022-11-15 9:24 ` Quentin Schulz via buildroot
2022-11-17 13:21 ` Gleb Mazovetskiy
2022-10-20 11:46 ` Victor Dumas
2022-10-20 11:50 ` Victor Dumas
2023-08-06 21:33 ` Thomas Petazzoni via buildroot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221007155434.178261-1-dumasv.dev@gmail.com \
--to=dumasv.dev@gmail.com \
--cc=buildroot@buildroot.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox