[PATCH v2 0/4] mbuto: Make it work on Arch Linux
Hi Stefano, This set of patches makes mbuto work also on Arch Linux. I have changed PATCH 4/4 based on your comments. Thank you for pointing out the correct recepient list. Cheers, Lukasz
On Arch Linux ldd /bin/sh reports:
/lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2
Use a regex to pick only right side and use it for path processing.
Signed-off-by: Lukasz Gut
On Wed, Sep 18, 2024 at 12:12:56PM +0200, Lukasz Gut wrote:
On Arch Linux ldd /bin/sh reports: /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 Use a regex to pick only right side and use it for path processing.
I think this approach is overly specific. The broader point here is that ldd can list libraries (including the dynamic linker) as either a link, or directly as a file. In the cases Stefano wrote for, it was always a single file for the dynamic linker and a link for everything else. For Arch it seems to be a link for everything, but both of those might not be true everywhere. It would make more sense to alter the loop above which processes all libraries to handle both the link and no-link cases, and remove the special case handling of ld.so.
Signed-off-by: Lukasz Gut
--- mbuto | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mbuto b/mbuto index b80ea78..1c3b347 100755 --- a/mbuto +++ b/mbuto @@ -704,9 +704,14 @@ __libs_copy() { for __l in $("${LDD}" "${1}" 2>/dev/null); do case ${__l} in "/"*" "*) __ld_so="${__l% *}" ;; *) ;; esac done - if [ -n "${__ld_so}" ]; then - libs_copy_ld_so "${__ld_so}" - libs_path_add "${__ld_so##${wd}}" + # On Arch Linux ld is reported by ldd in form: + # /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 + # Make sure to take only right part in this case. + __ld_path="${__ld_so##*=> }" + + if [ -n "${__ld_path}" ]; then + libs_copy_ld_so "${__ld_path}" + libs_path_add "${__ld_path##${wd}}" fi }
-- David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson
On Mon, 2024-09-23 at 13:51 +1000, David Gibson wrote:
On Wed, Sep 18, 2024 at 12:12:56PM +0200, Lukasz Gut wrote:
On Arch Linux ldd /bin/sh reports: /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 Use a regex to pick only right side and use it for path processing.
I think this approach is overly specific. The broader point here is that ldd can list libraries (including the dynamic linker) as either a link, or directly as a file. In the cases Stefano wrote for, it was always a single file for the dynamic linker and a link for everything else. For Arch it seems to be a link for everything, but both of those might not be true everywhere.
It would make more sense to alter the loop above which processes all libraries to handle both the link and no-link cases, and remove the special case handling of ld.so.
That's a very good point. I have even briefly tried that before, since that should produce less code instead of more, but I've had some difficulties. I will attempt it again.
Signed-off-by: Lukasz Gut
--- mbuto | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mbuto b/mbuto index b80ea78..1c3b347 100755 --- a/mbuto +++ b/mbuto @@ -704,9 +704,14 @@ __libs_copy() { for __l in $("${LDD}" "${1}" 2>/dev/null); do case ${__l} in "/"*" "*) __ld_so="${__l% *}" ;; *) ;; esac done - if [ -n "${__ld_so}" ]; then - libs_copy_ld_so "${__ld_so}" - libs_path_add "${__ld_so##${wd}}" + # On Arch Linux ld is reported by ldd in form: + # /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 + # Make sure to take only right part in this case. + __ld_path="${__ld_so##*=> }" + + if [ -n "${__ld_path}" ]; then + libs_copy_ld_so "${__ld_path}" + libs_path_add "${__ld_path##${wd}}" fi }
-- Lukasz
Place ld in exact physical location as on host, not being confused by
links. Use realpath, that was already on the list of default PROGS.
Signed-off-by: Lukasz Gut
On Wed, Sep 18, 2024 at 12:12:57PM +0200, Lukasz Gut wrote:
Place ld in exact physical location as on host, not being confused by links. Use realpath, that was already on the list of default PROGS.
It's not clear to me why this change is necessary.
Signed-off-by: Lukasz Gut
--- mbuto | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mbuto b/mbuto index 1c3b347..1f92bd9 100755 --- a/mbuto +++ b/mbuto @@ -644,12 +644,13 @@ libs_path_add() { # libs_copy_ld_so() - Copy run-time linker program, mimic location from host # $1: Path to run-time linker libs_copy_ld_so() { - [ -f "${wd}/${1}" ] && return + __srcfile="$("${REALPATH}" "${1}")" + __destfile="${wd}""${__srcfile}" + [ -f "${__destfile}" ] && return
- __destdir="$("${DIRNAME}" "${wd}/${1}")" + __destdir="$("${DIRNAME}" "${__destfile}")" "${MKDIR}" -p "${__destdir}" - - "${CP}" --parents --preserve=all "${1}" "${wd}" + "${CP}" --parents --preserve=all "${__srcfile}" "${wd}" }
# libs_dlopen_copy() - Recursively copy matching libraries from LIBS_DLOPEN
-- David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson
On Wed, Sep 18, 2024 at 12:12:57PM +0200, Lukasz Gut wrote:
Place ld in exact physical location as on host, not being confused by links. Use realpath, that was already on the list of default PROGS.
It's not clear to me why this change is necessary. I would like `ld-linux.so` to be copied to the exact same location as in host. Without this change, it was copied to `/usr/lib64` directory. There is no such a directory on the host, but there is a link `lib64 ->
On Mon, 2024-09-23 at 13:53 +1000, David Gibson wrote: lib` inside of `/usr` directory. I thought to: 1. Copy things to exactly the same locations as they are on the host. 2. Recreate necessary links.
Signed-off-by: Lukasz Gut
--- mbuto | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mbuto b/mbuto index 1c3b347..1f92bd9 100755 --- a/mbuto +++ b/mbuto @@ -644,12 +644,13 @@ libs_path_add() { # libs_copy_ld_so() - Copy run-time linker program, mimic location from host # $1: Path to run-time linker libs_copy_ld_so() { - [ -f "${wd}/${1}" ] && return + __srcfile="$("${REALPATH}" "${1}")" + __destfile="${wd}""${__srcfile}" + [ -f "${__destfile}" ] && return
- __destdir="$("${DIRNAME}" "${wd}/${1}")" + __destdir="$("${DIRNAME}" "${__destfile}")" "${MKDIR}" -p "${__destdir}" - - "${CP}" --parents --preserve=all "${1}" "${wd}" + "${CP}" --parents --preserve=all "${__srcfile}" "${wd}" }
# libs_dlopen_copy() - Recursively copy matching libraries from LIBS_DLOPEN
-- Lukasz
There is a function to add linker, but it was also added while copying
other librares (as dep of libc).
Now it is explicitely skipped.
Signed-off-by: Lukasz Gut
Fix dynamic linking on Arch Linux by adding (some of) missing links.
The ldd reports linker in many ways:
ldd /usr/lib/libreadline.so.8
/usr/lib64/ld-linux-x86-64.so.2 (0x000071244211c000)
ldd /bin/sh
/lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2
(0x000077457d5ec000)
ldd /usr/lib/libc.so.6
/usr/lib/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2
(0x000075d218b8b000)
This patch looks at the left side and determines if there is a link
there, then adds it.
Signed-off-by: Lukasz Gut
On Wed, Sep 18, 2024 at 12:12:59PM +0200, Lukasz Gut wrote:
Fix dynamic linking on Arch Linux by adding (some of) missing links.
The ldd reports linker in many ways: ldd /usr/lib/libreadline.so.8 /usr/lib64/ld-linux-x86-64.so.2 (0x000071244211c000) ldd /bin/sh /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x000077457d5ec000) ldd /usr/lib/libc.so.6 /usr/lib/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x000075d218b8b000)
This patch looks at the left side and determines if there is a link there, then adds it.
Again, having this be specific to ld.so looks bogus to me. AFAICT the same considerations could apply in theory to any shared library.
Signed-off-by: Lukasz Gut
--- mbuto | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/mbuto b/mbuto index 4f860cd..7d67160 100755 --- a/mbuto +++ b/mbuto @@ -668,6 +668,27 @@ libs_dlopen_copy() { done }
+# libs_add_links() - Rebuild alternate links to ld as they appear on the host +# $1: String returned by ldd in form 's => d' describing location of ld +libs_add_links() { + __ld_path="${1##*=> }" + __ld_link="${1%%=>*}" + [ -z "${__ld_link}" ] && return + [ "${__ld_path}" = "${__ld_link}" ] && return + while [ "${__ld_link}" != "/" ]; do + if [ -L "${__ld_link}" ]; then + __target="$("${READLINK}" -f "${__ld_link}")" + __link="$("${REALPATH}" -s "${__ld_link}" --relative-to "/")" + __link="${wd}"/"${__link}" + [ -L "${__link}" ] && break + __destdir="$("${DIRNAME}" "${__link}")" + "${MKDIR}" -p "${__destdir}" + "${LN}" -s "${__target}" "${__link}" + fi + __ld_link="$("${DIRNAME}" "${__ld_link}")" + done +} + # __libs_copy() - Recursively copy shared dependencies for programs, libraries # $1: Host path to program or library __libs_copy() { @@ -716,8 +737,13 @@ __libs_copy() {
if [ -n "${__ld_path}" ]; then libs_copy_ld_so "${__ld_path}" - libs_path_add "${__ld_path##${wd}}" + libs_path_add "${__ld_path##"${wd}"}" fi + + # On Arch Linux, to execute /bin/sh, the system expects the linker + # to be under /lib64. Linker is located in /usr/lib, and there is + # a link /lib64 => /usr/lib. + libs_add_links "${__ld_so}" }
# libs_copy() - Call __libs_copy with tabs and newlines as IFS
-- David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson
On Wed, Sep 18, 2024 at 12:12:59PM +0200, Lukasz Gut wrote:
Fix dynamic linking on Arch Linux by adding (some of) missing links.
The ldd reports linker in many ways: ldd /usr/lib/libreadline.so.8 /usr/lib64/ld-linux-x86-64.so.2 (0x000071244211c000) ldd /bin/sh /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x000077457d5ec000) ldd /usr/lib/libc.so.6 /usr/lib/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x000075d218b8b000)
This patch looks at the left side and determines if there is a link there, then adds it.
Again, having this be specific to ld.so looks bogus to me. AFAICT the same considerations could apply in theory to any shared library. Yes, I will rework it to use a single function for every shared
On Mon, 2024-09-23 at 13:54 +1000, David Gibson wrote: library.
Signed-off-by: Lukasz Gut
--- mbuto | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/mbuto b/mbuto index 4f860cd..7d67160 100755 --- a/mbuto +++ b/mbuto @@ -668,6 +668,27 @@ libs_dlopen_copy() { done }
+# libs_add_links() - Rebuild alternate links to ld as they appear on the host +# $1: String returned by ldd in form 's => d' describing location of ld +libs_add_links() { + __ld_path="${1##*=> }" + __ld_link="${1%%=>*}" + [ -z "${__ld_link}" ] && return + [ "${__ld_path}" = "${__ld_link}" ] && return + while [ "${__ld_link}" != "/" ]; do + if [ -L "${__ld_link}" ]; then + __target="$("${READLINK}" -f "${__ld_link}")" + __link="$("${REALPATH}" -s "${__ld_link}" --relative-to "/")" + __link="${wd}"/"${__link}" + [ -L "${__link}" ] && break + __destdir="$("${DIRNAME}" "${__link}")" + "${MKDIR}" -p "${__destdir}" + "${LN}" -s "${__target}" "${__link}" + fi + __ld_link="$("${DIRNAME}" "${__ld_link}")" + done +} + # __libs_copy() - Recursively copy shared dependencies for programs, libraries # $1: Host path to program or library __libs_copy() { @@ -716,8 +737,13 @@ __libs_copy() {
if [ -n "${__ld_path}" ]; then libs_copy_ld_so "${__ld_path}" - libs_path_add "${__ld_path##${wd}}" + libs_path_add "${__ld_path##"${wd}"}" fi + + # On Arch Linux, to execute /bin/sh, the system expects the linker + # to be under /lib64. Linker is located in /usr/lib, and there is + # a link /lib64 => /usr/lib. + libs_add_links "${__ld_so}" }
# libs_copy() - Call __libs_copy with tabs and newlines as IFS
-- Lukasz
On Wed, Sep 18, 2024 at 12:12:54PM +0200, Lukasz Gut wrote:
Hi Stefano,
This set of patches makes mbuto work also on Arch Linux. I have changed PATCH 4/4 based on your comments.
Thank you for pointing out the correct recepient list.
One overall nit in the commit messages, rather than the patches themslves: To me "ld" without clarification means the static linker not the dynamic linker (that's "ld.so"). But many of your messages are referring to the dynamic linker as "ld". -- David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson
On Mon, 2024-09-23 at 13:45 +1000, David Gibson wrote:
On Wed, Sep 18, 2024 at 12:12:54PM +0200, Lukasz Gut wrote:
Hi Stefano,
This set of patches makes mbuto work also on Arch Linux. I have changed PATCH 4/4 based on your comments.
Thank you for pointing out the correct recepient list.
One overall nit in the commit messages, rather than the patches themslves:
To me "ld" without clarification means the static linker not the dynamic linker (that's "ld.so"). But many of your messages are referring to the dynamic linker as "ld".
Thanks David for pointing that out, I will be more specific next time. -- Lukasz
participants (2)
-
David Gibson
-
Lukasz Gut