diff mbox series

rust: Use patchelf in place of chrpath to edit rpaths

Message ID 20250517212855.349153-1-raj.khem@gmail.com
State Accepted, archived
Commit 22b903f6620455e142e836412d3f7f6a4f03bea7
Headers show
Series rust: Use patchelf in place of chrpath to edit rpaths | expand

Commit Message

Khem Raj May 17, 2025, 9:28 p.m. UTC
chrpath has limitations e.g. the original rpath in ELF have to bigger in size
than the one being edited into it by chrpath, some toolchains do not use RPATH
but emit the RUNPATHs into ELF files and chrpath is not able to handle the
runpaths, this is the case with mips and pp32 build of rust, especially
when using clang compiler to build them.

patchelf can do more:

Modify RUNPATH entries
Add RPATH/RUNPATH where none existed
Set longer paths than the original
Convert between RPATH and RUNPATH

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 meta/recipes-devtools/rust/rust_1.85.1.bb | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Joshua Watt May 19, 2025, 4:49 p.m. UTC | #1
I don't think patchelf-uninative is available if uninative is not in
use. Probably better to DEPENDS += "patchelf-native" instead

On Sat, May 17, 2025 at 3:29 PM Khem Raj via lists.openembedded.org
<raj.khem=gmail.com@lists.openembedded.org> wrote:
>
> chrpath has limitations e.g. the original rpath in ELF have to bigger in size
> than the one being edited into it by chrpath, some toolchains do not use RPATH
> but emit the RUNPATHs into ELF files and chrpath is not able to handle the
> runpaths, this is the case with mips and pp32 build of rust, especially
> when using clang compiler to build them.
>
> patchelf can do more:
>
> Modify RUNPATH entries
> Add RPATH/RUNPATH where none existed
> Set longer paths than the original
> Convert between RPATH and RUNPATH
>
> Signed-off-by: Khem Raj <raj.khem@gmail.com>
> ---
>  meta/recipes-devtools/rust/rust_1.85.1.bb | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/meta/recipes-devtools/rust/rust_1.85.1.bb b/meta/recipes-devtools/rust/rust_1.85.1.bb
> index dc4f5648552..3b7226ae408 100644
> --- a/meta/recipes-devtools/rust/rust_1.85.1.bb
> +++ b/meta/recipes-devtools/rust/rust_1.85.1.bb
> @@ -207,9 +207,9 @@ rust_runx () {
>          mkdir -p `dirname ${RUST_ALTERNATE_EXE_PATH}`
>          cp ${RUST_ALTERNATE_EXE_PATH_NATIVE} ${RUST_ALTERNATE_EXE_PATH}
>          if [ -e ${STAGING_LIBDIR_NATIVE}/libc++.so.1 ]; then
> -            chrpath -r \$ORIGIN/../../../../../`basename ${STAGING_DIR_NATIVE}`${libdir_native} ${RUST_ALTERNATE_EXE_PATH}
> +            patchelf-uninative --set-rpath \$ORIGIN/../../../../../`basename ${STAGING_DIR_NATIVE}`${libdir_native} ${RUST_ALTERNATE_EXE_PATH}
>          else
> -            chrpath -d ${RUST_ALTERNATE_EXE_PATH}
> +            patchelf-uninative --remove-rpath ${RUST_ALTERNATE_EXE_PATH}
>          fi
>      fi
>
> @@ -266,7 +266,7 @@ rust_do_install:class-nativesdk() {
>      install -d ${D}${bindir}
>      for i in cargo-clippy clippy-driver rustfmt; do
>          cp build/${RUST_BUILD_SYS}/stage2-tools/${RUST_HOST_SYS}/release/$i ${D}${bindir}
> -        chrpath -r "\$ORIGIN/../lib" ${D}${bindir}/$i
> +        patchelf-uninative --set-rpath "\$ORIGIN/../lib" ${D}${bindir}/$i
>      done
>
>      chown root:root ${D}/ -R
> @@ -301,7 +301,7 @@ rust_do_install:class-target() {
>      install -d ${D}${bindir}
>      for i in ${EXTRA_TOOLS}; do
>          cp build/${RUST_BUILD_SYS}/stage2-tools/${RUST_HOST_SYS}/release/$i ${D}${bindir}
> -        chrpath -r "\$ORIGIN/../lib" ${D}${bindir}/$i
> +        patchelf-uninative --set-rpath "\$ORIGIN/../lib" ${D}${bindir}/$i
>      done
>
>      install -d ${D}${libdir}/rustlib/${RUST_HOST_SYS}
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#216772): https://lists.openembedded.org/g/openembedded-core/message/216772
> Mute This Topic: https://lists.openembedded.org/mt/113168136/3616693
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [JPEWhacker@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Khem Raj May 19, 2025, 4:54 p.m. UTC | #2
On Mon, May 19, 2025 at 9:50 AM Joshua Watt <jpewhacker@gmail.com> wrote:
>
> I don't think patchelf-uninative is available if uninative is not in
> use. Probably better to DEPENDS += "patchelf-native" instead
>

there was another place in rust recipe using patchelf from uninative
but this perhaps makes sense.

> On Sat, May 17, 2025 at 3:29 PM Khem Raj via lists.openembedded.org
> <raj.khem=gmail.com@lists.openembedded.org> wrote:
> >
> > chrpath has limitations e.g. the original rpath in ELF have to bigger in size
> > than the one being edited into it by chrpath, some toolchains do not use RPATH
> > but emit the RUNPATHs into ELF files and chrpath is not able to handle the
> > runpaths, this is the case with mips and pp32 build of rust, especially
> > when using clang compiler to build them.
> >
> > patchelf can do more:
> >
> > Modify RUNPATH entries
> > Add RPATH/RUNPATH where none existed
> > Set longer paths than the original
> > Convert between RPATH and RUNPATH
> >
> > Signed-off-by: Khem Raj <raj.khem@gmail.com>
> > ---
> >  meta/recipes-devtools/rust/rust_1.85.1.bb | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/meta/recipes-devtools/rust/rust_1.85.1.bb b/meta/recipes-devtools/rust/rust_1.85.1.bb
> > index dc4f5648552..3b7226ae408 100644
> > --- a/meta/recipes-devtools/rust/rust_1.85.1.bb
> > +++ b/meta/recipes-devtools/rust/rust_1.85.1.bb
> > @@ -207,9 +207,9 @@ rust_runx () {
> >          mkdir -p `dirname ${RUST_ALTERNATE_EXE_PATH}`
> >          cp ${RUST_ALTERNATE_EXE_PATH_NATIVE} ${RUST_ALTERNATE_EXE_PATH}
> >          if [ -e ${STAGING_LIBDIR_NATIVE}/libc++.so.1 ]; then
> > -            chrpath -r \$ORIGIN/../../../../../`basename ${STAGING_DIR_NATIVE}`${libdir_native} ${RUST_ALTERNATE_EXE_PATH}
> > +            patchelf-uninative --set-rpath \$ORIGIN/../../../../../`basename ${STAGING_DIR_NATIVE}`${libdir_native} ${RUST_ALTERNATE_EXE_PATH}
> >          else
> > -            chrpath -d ${RUST_ALTERNATE_EXE_PATH}
> > +            patchelf-uninative --remove-rpath ${RUST_ALTERNATE_EXE_PATH}
> >          fi
> >      fi
> >
> > @@ -266,7 +266,7 @@ rust_do_install:class-nativesdk() {
> >      install -d ${D}${bindir}
> >      for i in cargo-clippy clippy-driver rustfmt; do
> >          cp build/${RUST_BUILD_SYS}/stage2-tools/${RUST_HOST_SYS}/release/$i ${D}${bindir}
> > -        chrpath -r "\$ORIGIN/../lib" ${D}${bindir}/$i
> > +        patchelf-uninative --set-rpath "\$ORIGIN/../lib" ${D}${bindir}/$i
> >      done
> >
> >      chown root:root ${D}/ -R
> > @@ -301,7 +301,7 @@ rust_do_install:class-target() {
> >      install -d ${D}${bindir}
> >      for i in ${EXTRA_TOOLS}; do
> >          cp build/${RUST_BUILD_SYS}/stage2-tools/${RUST_HOST_SYS}/release/$i ${D}${bindir}
> > -        chrpath -r "\$ORIGIN/../lib" ${D}${bindir}/$i
> > +        patchelf-uninative --set-rpath "\$ORIGIN/../lib" ${D}${bindir}/$i
> >      done
> >
> >      install -d ${D}${libdir}/rustlib/${RUST_HOST_SYS}
> >
> > -=-=-=-=-=-=-=-=-=-=-=-
> > Links: You receive all messages sent to this group.
> > View/Reply Online (#216772): https://lists.openembedded.org/g/openembedded-core/message/216772
> > Mute This Topic: https://lists.openembedded.org/mt/113168136/3616693
> > Group Owner: openembedded-core+owner@lists.openembedded.org
> > Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [JPEWhacker@gmail.com]
> > -=-=-=-=-=-=-=-=-=-=-=-
> >
diff mbox series

Patch

diff --git a/meta/recipes-devtools/rust/rust_1.85.1.bb b/meta/recipes-devtools/rust/rust_1.85.1.bb
index dc4f5648552..3b7226ae408 100644
--- a/meta/recipes-devtools/rust/rust_1.85.1.bb
+++ b/meta/recipes-devtools/rust/rust_1.85.1.bb
@@ -207,9 +207,9 @@  rust_runx () {
         mkdir -p `dirname ${RUST_ALTERNATE_EXE_PATH}`
         cp ${RUST_ALTERNATE_EXE_PATH_NATIVE} ${RUST_ALTERNATE_EXE_PATH}
         if [ -e ${STAGING_LIBDIR_NATIVE}/libc++.so.1 ]; then
-            chrpath -r \$ORIGIN/../../../../../`basename ${STAGING_DIR_NATIVE}`${libdir_native} ${RUST_ALTERNATE_EXE_PATH}
+            patchelf-uninative --set-rpath \$ORIGIN/../../../../../`basename ${STAGING_DIR_NATIVE}`${libdir_native} ${RUST_ALTERNATE_EXE_PATH}
         else
-            chrpath -d ${RUST_ALTERNATE_EXE_PATH}
+            patchelf-uninative --remove-rpath ${RUST_ALTERNATE_EXE_PATH}
         fi
     fi
 
@@ -266,7 +266,7 @@  rust_do_install:class-nativesdk() {
     install -d ${D}${bindir}
     for i in cargo-clippy clippy-driver rustfmt; do
         cp build/${RUST_BUILD_SYS}/stage2-tools/${RUST_HOST_SYS}/release/$i ${D}${bindir}
-        chrpath -r "\$ORIGIN/../lib" ${D}${bindir}/$i
+        patchelf-uninative --set-rpath "\$ORIGIN/../lib" ${D}${bindir}/$i
     done
 
     chown root:root ${D}/ -R
@@ -301,7 +301,7 @@  rust_do_install:class-target() {
     install -d ${D}${bindir}
     for i in ${EXTRA_TOOLS}; do
         cp build/${RUST_BUILD_SYS}/stage2-tools/${RUST_HOST_SYS}/release/$i ${D}${bindir}
-        chrpath -r "\$ORIGIN/../lib" ${D}${bindir}/$i
+        patchelf-uninative --set-rpath "\$ORIGIN/../lib" ${D}${bindir}/$i
     done
 
     install -d ${D}${libdir}/rustlib/${RUST_HOST_SYS}