public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH v2 0/4] mbuto: Make it work on Arch Linux
@ 2024-09-18 10:12 Lukasz Gut
  2024-09-18 10:12 ` [PATCH v2 1/4] mbuto: Pick a src when ld reported as link by ldd Lukasz Gut
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Lukasz Gut @ 2024-09-18 10:12 UTC (permalink / raw)
  To: sbrivio; +Cc: sevinj.aghayeva, passt-dev

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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2 1/4] mbuto: Pick a src when ld reported as link by ldd
  2024-09-18 10:12 [PATCH v2 0/4] mbuto: Make it work on Arch Linux Lukasz Gut
@ 2024-09-18 10:12 ` Lukasz Gut
  2024-09-23  3:51   ` David Gibson
  2024-09-18 10:12 ` [PATCH v2 2/4] mbuto: Use realpath to copy ld Lukasz Gut
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Lukasz Gut @ 2024-09-18 10:12 UTC (permalink / raw)
  To: sbrivio; +Cc: sevinj.aghayeva, passt-dev, Lukasz Gut

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 <lgut@lgut.eu>
---
 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
 }
 
-- 
@@ -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
 }
 
-- 
2.46.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 2/4] mbuto: Use realpath to copy ld
  2024-09-18 10:12 [PATCH v2 0/4] mbuto: Make it work on Arch Linux Lukasz Gut
  2024-09-18 10:12 ` [PATCH v2 1/4] mbuto: Pick a src when ld reported as link by ldd Lukasz Gut
@ 2024-09-18 10:12 ` Lukasz Gut
  2024-09-23  3:53   ` David Gibson
  2024-09-18 10:12 ` [PATCH v2 3/4] mbuto: Don't try to add ld when adding libraries Lukasz Gut
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Lukasz Gut @ 2024-09-18 10:12 UTC (permalink / raw)
  To: sbrivio; +Cc: sevinj.aghayeva, passt-dev, Lukasz Gut

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 <lgut@lgut.eu>
---
 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
-- 
@@ -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
-- 
2.46.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 3/4] mbuto: Don't try to add ld when adding libraries
  2024-09-18 10:12 [PATCH v2 0/4] mbuto: Make it work on Arch Linux Lukasz Gut
  2024-09-18 10:12 ` [PATCH v2 1/4] mbuto: Pick a src when ld reported as link by ldd Lukasz Gut
  2024-09-18 10:12 ` [PATCH v2 2/4] mbuto: Use realpath to copy ld Lukasz Gut
@ 2024-09-18 10:12 ` Lukasz Gut
  2024-09-18 10:12 ` [PATCH v2 4/4] mbuto: Automatically add links related to linker Lukasz Gut
  2024-09-23  3:45 ` [PATCH v2 0/4] mbuto: Make it work on Arch Linux David Gibson
  4 siblings, 0 replies; 13+ messages in thread
From: Lukasz Gut @ 2024-09-18 10:12 UTC (permalink / raw)
  To: sbrivio; +Cc: sevinj.aghayeva, passt-dev, Lukasz Gut

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 <lgut@lgut.eu>
---
 mbuto | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mbuto b/mbuto
index 1f92bd9..4f860cd 100755
--- a/mbuto
+++ b/mbuto
@@ -685,6 +685,10 @@ __libs_copy() {
 		[ "$("${BASENAME}" "${__path}")" = "libfakeroot-sysv.so" ] && \
 			continue
 
+		# ld is handled below, skip one reported by libc
+		[ "$("${BASENAME}" "${__path}")" = "ld-linux-x86-64.so.2" ] && \
+			continue
+
 		__destpath="${wd}${__path}"
 		[ -f "${__destpath}" ] && continue
 
-- 
@@ -685,6 +685,10 @@ __libs_copy() {
 		[ "$("${BASENAME}" "${__path}")" = "libfakeroot-sysv.so" ] && \
 			continue
 
+		# ld is handled below, skip one reported by libc
+		[ "$("${BASENAME}" "${__path}")" = "ld-linux-x86-64.so.2" ] && \
+			continue
+
 		__destpath="${wd}${__path}"
 		[ -f "${__destpath}" ] && continue
 
-- 
2.46.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 4/4] mbuto: Automatically add links related to linker
  2024-09-18 10:12 [PATCH v2 0/4] mbuto: Make it work on Arch Linux Lukasz Gut
                   ` (2 preceding siblings ...)
  2024-09-18 10:12 ` [PATCH v2 3/4] mbuto: Don't try to add ld when adding libraries Lukasz Gut
@ 2024-09-18 10:12 ` Lukasz Gut
  2024-09-23  3:54   ` David Gibson
  2024-09-23  3:45 ` [PATCH v2 0/4] mbuto: Make it work on Arch Linux David Gibson
  4 siblings, 1 reply; 13+ messages in thread
From: Lukasz Gut @ 2024-09-18 10:12 UTC (permalink / raw)
  To: sbrivio; +Cc: sevinj.aghayeva, passt-dev, 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 <lgut@lgut.eu>
---
 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
-- 
@@ -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
-- 
2.46.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/4] mbuto: Make it work on Arch Linux
  2024-09-18 10:12 [PATCH v2 0/4] mbuto: Make it work on Arch Linux Lukasz Gut
                   ` (3 preceding siblings ...)
  2024-09-18 10:12 ` [PATCH v2 4/4] mbuto: Automatically add links related to linker Lukasz Gut
@ 2024-09-23  3:45 ` David Gibson
  2024-09-23 10:09   ` Lukasz Gut
  4 siblings, 1 reply; 13+ messages in thread
From: David Gibson @ 2024-09-23  3:45 UTC (permalink / raw)
  To: Lukasz Gut; +Cc: sbrivio, sevinj.aghayeva, passt-dev

[-- Attachment #1: Type: text/plain, Size: 705 bytes --]

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 1/4] mbuto: Pick a src when ld reported as link by ldd
  2024-09-18 10:12 ` [PATCH v2 1/4] mbuto: Pick a src when ld reported as link by ldd Lukasz Gut
@ 2024-09-23  3:51   ` David Gibson
  2024-09-23 10:09     ` Lukasz Gut
  0 siblings, 1 reply; 13+ messages in thread
From: David Gibson @ 2024-09-23  3:51 UTC (permalink / raw)
  To: Lukasz Gut; +Cc: sbrivio, sevinj.aghayeva, passt-dev

[-- Attachment #1: Type: text/plain, Size: 1855 bytes --]

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 <lgut@lgut.eu>
> ---
>  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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/4] mbuto: Use realpath to copy ld
  2024-09-18 10:12 ` [PATCH v2 2/4] mbuto: Use realpath to copy ld Lukasz Gut
@ 2024-09-23  3:53   ` David Gibson
  2024-09-23 10:09     ` Lukasz Gut
  0 siblings, 1 reply; 13+ messages in thread
From: David Gibson @ 2024-09-23  3:53 UTC (permalink / raw)
  To: Lukasz Gut; +Cc: sbrivio, sevinj.aghayeva, passt-dev

[-- Attachment #1: Type: text/plain, Size: 1365 bytes --]

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 <lgut@lgut.eu>
> ---
>  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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 4/4] mbuto: Automatically add links related to linker
  2024-09-18 10:12 ` [PATCH v2 4/4] mbuto: Automatically add links related to linker Lukasz Gut
@ 2024-09-23  3:54   ` David Gibson
  2024-09-23 10:09     ` Lukasz Gut
  0 siblings, 1 reply; 13+ messages in thread
From: David Gibson @ 2024-09-23  3:54 UTC (permalink / raw)
  To: Lukasz Gut; +Cc: sbrivio, sevinj.aghayeva, passt-dev

[-- Attachment #1: Type: text/plain, Size: 2711 bytes --]

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 <lgut@lgut.eu>
> ---
>  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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/4] mbuto: Make it work on Arch Linux
  2024-09-23  3:45 ` [PATCH v2 0/4] mbuto: Make it work on Arch Linux David Gibson
@ 2024-09-23 10:09   ` Lukasz Gut
  0 siblings, 0 replies; 13+ messages in thread
From: Lukasz Gut @ 2024-09-23 10:09 UTC (permalink / raw)
  To: David Gibson; +Cc: sbrivio, sevinj.aghayeva, passt-dev

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 1/4] mbuto: Pick a src when ld reported as link by ldd
  2024-09-23  3:51   ` David Gibson
@ 2024-09-23 10:09     ` Lukasz Gut
  0 siblings, 0 replies; 13+ messages in thread
From: Lukasz Gut @ 2024-09-23 10:09 UTC (permalink / raw)
  To: David Gibson; +Cc: sbrivio, sevinj.aghayeva, passt-dev

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 <lgut@lgut.eu>
> > ---
> >  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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/4] mbuto: Use realpath to copy ld
  2024-09-23  3:53   ` David Gibson
@ 2024-09-23 10:09     ` Lukasz Gut
  0 siblings, 0 replies; 13+ messages in thread
From: Lukasz Gut @ 2024-09-23 10:09 UTC (permalink / raw)
  To: David Gibson; +Cc: sbrivio, sevinj.aghayeva, passt-dev

On Mon, 2024-09-23 at 13:53 +1000, David Gibson wrote:
> 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 ->
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 <lgut@lgut.eu>
> > ---
> >  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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 4/4] mbuto: Automatically add links related to linker
  2024-09-23  3:54   ` David Gibson
@ 2024-09-23 10:09     ` Lukasz Gut
  0 siblings, 0 replies; 13+ messages in thread
From: Lukasz Gut @ 2024-09-23 10:09 UTC (permalink / raw)
  To: David Gibson; +Cc: sbrivio, sevinj.aghayeva, passt-dev

On Mon, 2024-09-23 at 13:54 +1000, David Gibson wrote:
> 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
library.
> 
> > 
> > Signed-off-by: Lukasz Gut <lgut@lgut.eu>
> > ---
> >  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

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-09-23 10:09 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-18 10:12 [PATCH v2 0/4] mbuto: Make it work on Arch Linux Lukasz Gut
2024-09-18 10:12 ` [PATCH v2 1/4] mbuto: Pick a src when ld reported as link by ldd Lukasz Gut
2024-09-23  3:51   ` David Gibson
2024-09-23 10:09     ` Lukasz Gut
2024-09-18 10:12 ` [PATCH v2 2/4] mbuto: Use realpath to copy ld Lukasz Gut
2024-09-23  3:53   ` David Gibson
2024-09-23 10:09     ` Lukasz Gut
2024-09-18 10:12 ` [PATCH v2 3/4] mbuto: Don't try to add ld when adding libraries Lukasz Gut
2024-09-18 10:12 ` [PATCH v2 4/4] mbuto: Automatically add links related to linker Lukasz Gut
2024-09-23  3:54   ` David Gibson
2024-09-23 10:09     ` Lukasz Gut
2024-09-23  3:45 ` [PATCH v2 0/4] mbuto: Make it work on Arch Linux David Gibson
2024-09-23 10:09   ` Lukasz Gut

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).