Subject: Re: bug#70349: Clang fails to communicate RUNPATH?

From: Liliana Marie Prikler <[email-masked]>
Date: Mon, 27 May 2024 08:49:06 +0200

Hi Ludo,

Am Samstag, dem 25.05.2024 um 11:26 +0200 schrieb Ludovic Courtès:
> Could this be an issue specific to ‘meson-build-system’?
> 
> For instance, this works fine (both mpfr and mpc use
> ‘gnu-build-system’):
> 
>   guix build mpc --with-c-toolchain=mpfr=clang-toolchain
> 
> If we add this to the example you posted:
> 
>    (arguments
>     (list #:phases #~(modify-phases %standard-phases
>                        (add-after 'unpack 'debug-ld-wrapper
>                          (lambda _
>                            (setenv "GUIX_LD_WRAPPER_DEBUG"
> "yes"))))))
> 
> … we see:
> 
> --8<---------------cut here---------------start------------->8---
> ld-wrapper: library search path:
> ("/gnu/store/l684qgqlrqkbsh8jffp9d8ag6vrpcwgs-gcc-11.3.0-
> lib/lib/gcc/x86_64-unknown-linux-gnu/11.3.0"
> "/gnu/store/gsjczqir1wbz8p770zndrpw4rnppmxi3-glibc-2.35/lib"
> "/gnu/store/l684qgqlrqkbsh8jffp9d8ag6vrpcwgs-gcc-11.3.0-
> lib/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../.."
> "/gnu/store/inpy5mz35fwvclynpag5gsp6d1hflfsz-meson-1.1.0/lib"
> "/gnu/store/qhz8n6mxzalifcrml6fwsvnxw92bk7n0-fmt-9.1.0/lib"
> "/gnu/store/j8wlfmlmfvpbza6is9wv9xsd8psrxn00-bzip2-1.0.8/lib"
> "/gnu/store/gr0sy0m1mv36qv54idm6cn10l3mngshq-file-5.44/lib"
> "/gnu/store/hc05d76f1j3iz3v2bs5jz4fpljl1r4dj-gawk-5.2.1/lib"
> "/gnu/store/6k1yys9wqrfn4y41ic1win8gpnimncwj-xz-5.2.8/lib"
> "/gnu/store/visfdda934gvivwihwhlm63fdqhhcc8a-glibc-utf8-locales-
> 2.35/lib" "/gnu/store/0irvg0gvvfwagdjckigvr4g8xap94y1j-clang-
> toolchain-18.1.5/lib")
> ld-wrapper: libraries linked:
> ("/gnu/store/qhz8n6mxzalifcrml6fwsvnxw92bk7n0-fmt-
> 9.1.0/lib/libfmt.so" "/gnu/store/l684qgqlrqkbsh8jffp9d8ag6vrpcwgs-
> gcc-11.3.0-lib/lib/gcc/x86_64-unknown-linux-
> gnu/11.3.0/../../../libstdc++.so"
> "/gnu/store/gsjczqir1wbz8p770zndrpw4rnppmxi3-glibc-2.35/lib/libm.so"
> "/gnu/store/l684qgqlrqkbsh8jffp9d8ag6vrpcwgs-gcc-11.3.0-
> lib/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../libgcc_s.so"
> "/gnu/store/gsjczqir1wbz8p770zndrpw4rnppmxi3-glibc-2.35/lib/libc.so"
> "/gnu/store/l684qgqlrqkbsh8jffp9d8ag6vrpcwgs-gcc-11.3.0-
> lib/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../libgcc_s.so")
> ld-wrapper: invoking `/gnu/store/zh4x65snfis7svs6906gj1z8i7dx2j3m-
> binutils-2.38/bin/ld' with ("--eh-frame-hdr" "-m" "elf_x86_64" "-pie"
> "-dynamic-linker" "//gnu/store/gsjczqir1wbz8p770zndrpw4rnppmxi3-
> glibc-2.35/lib/ld-linux-x86-64.so.2" "-o" "hello"
> "/gnu/store/gsjczqir1wbz8p770zndrpw4rnppmxi3-glibc-2.35/lib/Scrt1.o"
> "/gnu/store/gsjczqir1wbz8p770zndrpw4rnppmxi3-glibc-2.35/lib/crti.o"
> "/gnu/store/l684qgqlrqkbsh8jffp9d8ag6vrpcwgs-gcc-11.3.0-
> lib/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/crtbeginS.o" "-
> L/gnu/store/l684qgqlrqkbsh8jffp9d8ag6vrpcwgs-gcc-11.3.0-
> lib/lib/gcc/x86_64-unknown-linux-gnu/11.3.0" "-
> L/gnu/store/gsjczqir1wbz8p770zndrpw4rnppmxi3-glibc-2.35/lib" "-
> L/gnu/store/l684qgqlrqkbsh8jffp9d8ag6vrpcwgs-gcc-11.3.0-
> lib/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../.." "-
> L/gnu/store/inpy5mz35fwvclynpag5gsp6d1hflfsz-meson-1.1.0/lib" "-
> L/gnu/store/qhz8n6mxzalifcrml6fwsvnxw92bk7n0-fmt-9.1.0/lib" "-
> L/gnu/store/j8wlfmlmfvpbza6is9wv9xsd8psrxn00-bzip2-1.0.8/lib" "-
> L/gnu/store/gr0sy0m1mv36qv54idm6cn10l3mngshq-file-5.44/lib" "-
> L/gnu/store/hc05d76f1j3iz3v2bs5jz4fpljl1r4dj-gawk-5.2.1/lib" "-
> L/gnu/store/6k1yys9wqrfn4y41ic1win8gpnimncwj-xz-5.2.8/lib" "-
> L/gnu/store/visfdda934gvivwihwhlm63fdqhhcc8a-glibc-utf8-locales-
> 2.35/lib" "-L/gnu/store/0irvg0gvvfwagdjckigvr4g8xap94y1j-clang-
> toolchain-18.1.5/lib" "hello.p/hello.cpp.o" "--as-needed" "--no-
> undefined" "-rpath=/gnu/store/g9wxj9a27jhnxa40zafh0ff33dd8906y-why-
> hello-0/lib" "-rpath" "/gnu/store/qhz8n6mxzalifcrml6fwsvnxw92bk7n0-
> fmt-9.1.0/lib" "-rpath-link"
> "/gnu/store/qhz8n6mxzalifcrml6fwsvnxw92bk7n0-fmt-9.1.0/lib" "--start-
> group" "/gnu/store/qhz8n6mxzalifcrml6fwsvnxw92bk7n0-fmt-
> 9.1.0/lib/libfmt.so" "--end-group" "-lstdc++" "-lm" "-lgcc_s" "-lgcc"
> "-lc" "-lgcc_s" "-lgcc" "/gnu/store/l684qgqlrqkbsh8jffp9d8ag6vrpcwgs-
> gcc-11.3.0-lib/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/crtendS.o"
> "/gnu/store/gsjczqir1wbz8p770zndrpw4rnppmxi3-glibc-2.35/lib/crtn.o"
> "-rpath" "/gnu/store/qhz8n6mxzalifcrml6fwsvnxw92bk7n0-fmt-9.1.0/lib"
> "-rpath" "/gnu/store/l684qgqlrqkbsh8jffp9d8ag6vrpcwgs-gcc-11.3.0-
> lib/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../.." "-rpath"
> "/gnu/store/gsjczqir1wbz8p770zndrpw4rnppmxi3-glibc-2.35/lib" "-rpath"
> "/gnu/store/l684qgqlrqkbsh8jffp9d8ag6vrpcwgs-gcc-11.3.0-
> lib/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../.." "-rpath"
> "/gnu/store/gsjczqir1wbz8p770zndrpw4rnppmxi3-glibc-2.35/lib" "-rpath"
> "/gnu/store/l684qgqlrqkbsh8jffp9d8ag6vrpcwgs-gcc-11.3.0-
> lib/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../..")
> 
> […]
> 
> starting phase `shrink-runpath'
> /gnu/store/g9wxj9a27jhnxa40zafh0ff33dd8906y-why-hello-0/bin/hello:
> stripping RUNPATH to ("/gnu/store/gsjczqir1wbz8p770zndrpw4rnppmxi3-
> glibc-2.35/lib") (removed
> ("/gnu/store/g9wxj9a27jhnxa40zafh0ff33dd8906y-why-hello-0/lib"
> "/gnu/store/l684qgqlrqkbsh8jffp9d8ag6vrpcwgs-gcc-11.3.0-
> lib/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../.."))
> phase `shrink-runpath' succeeded after 0.0 seconds
> starting phase `validate-runpath'
> validating RUNPATH of 1 binaries in
> "/gnu/store/g9wxj9a27jhnxa40zafh0ff33dd8906y-why-hello-0/bin"...
> /gnu/store/g9wxj9a27jhnxa40zafh0ff33dd8906y-why-hello-0/bin/hello:
> error: depends on 'libfmt.so.9', which cannot be found in RUNPATH
> ("/gnu/store/gsjczqir1wbz8p770zndrpw4rnppmxi3-glibc-2.35/lib")
> --8<---------------cut here---------------end--------------->8---
> 
> So the ‘ld’ wrapper is indeed passing ‘-rpath /path/to/fmt’ but down
> the road that gets lost.  Could it be that Meson removes it when it
> install files?
So it seems.  I retried this in a `guix shell`, and:

--8<---------------cut here---------------start------------->8---
$ ldd build/hello
	linux-vdso.so.1 (0x00007fffd54f9000)
	libfmt.so.10 => /gnu/store/cn0vmkz3h0wz0wz6hbdnjv4zphzr8z06-
fmt-10.2.1/lib/libfmt.so.10 (0x00007fecae2e1000)
	libc.so.6 => /gnu/store/ln6hxqjvz6m9gdd9s97pivlqck7hzs99-
glibc-2.35/lib/libc.so.6 (0x00007fecae0e5000)
	libstdc++.so.6 => /gnu/store/6ncav55lbk5kqvwwflrzcr41hp5jbq0c-
gcc-11.3.0-lib/lib/libstdc++.so.6 (0x00007fecade00000)
	libm.so.6 => /gnu/store/ln6hxqjvz6m9gdd9s97pivlqck7hzs99-
glibc-2.35/lib/libm.so.6 (0x00007fecadd23000)
	libgcc_s.so.1 => /gnu/store/6ncav55lbk5kqvwwflrzcr41hp5jbq0c-
gcc-11.3.0-lib/lib/libgcc_s.so.1 (0x00007fecae0c9000)
	//gnu/store/ln6hxqjvz6m9gdd9s97pivlqck7hzs99-glibc-
2.35/lib/ld-linux-x86-64.so.2 =>
/gnu/store/daas786mm1zi3kxp03640n6anhrlrcng-glibc-2.35/lib/ld-linux-
x86-64.so.2 (0x00007fecae30b000)
--8<---------------cut here---------------end--------------->8--

but after installing

--8<---------------cut here---------------start------------->8---
$ ldd build/.install/bin/hello 
	linux-vdso.so.1 (0x00007fffbc269000)
	libfmt.so.10 => not found
	libc.so.6 => /gnu/store/ln6hxqjvz6m9gdd9s97pivlqck7hzs99-
glibc-2.35/lib/libc.so.6 (0x00007fae94274000)
	//gnu/store/ln6hxqjvz6m9gdd9s97pivlqck7hzs99-glibc-
2.35/lib/ld-linux-x86-64.so.2 =>
/gnu/store/daas786mm1zi3kxp03640n6anhrlrcng-glibc-2.35/lib/ld-linux-
x86-64.so.2 (0x00007fae94477000)
--8<---------------cut here---------------end--------------->8--

If I recall correctly, Meson performs separate linking on install, so
that certain stuff works from the build directory without resorting to
`./pre-inst-env` or the like.¹  However, why does it not find libfmt.so
when using Clang, but does find it when using GCC?  Does our clang-
toolchain prepare the correct wrapper?  I feel like lld might be hidden
and unpatched in there – or something else weird is happening.

Cheers

¹ I actually can't support this claim, as the GUIX_LD_WRAPPER_DEBUG
only shows up on build as expected even with the gcc-toolchain variant.