Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 928509 - sys-libs/musl merged-usr cannot override libraries in /usr/lib via /etc/ld.so.conf.d/*.conf
Summary: sys-libs/musl merged-usr cannot override libraries in /usr/lib via /etc/ld.so...
Status: UNCONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Profiles (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Anthony Basile
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: usrmerge, usrmerge-fixes
  Show dependency tree
 
Reported: 2024-04-03 11:26 UTC by ktoupt
Modified: 2024-04-04 02:29 UTC (History)
6 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ktoupt 2024-04-03 11:26:52 UTC
This is on a musl merged-usr system. Maybe glibc has a different linker
where this is not a problem.

The expectation is that the paths specified in /etc/ld.so.conf.d/*.conf
override the normal paths since it appears first in /etc/ld.so.conf.
However, there seems to be an implicit /lib at the very top, which, on a
merged-usr system, is a link to /usr/lib, so libraries in /usr/lib will
always be preferred over the ones specified in /etc/ld.so.con.d/*.conf.

This is unexpected and partially the cause of bug 928506, where eselect
{blas,lapack} is not working.

A possible fix is to append /lib at the very end of /etc/ld.so.conf.
Don't forget to run ldconfig if you are going to be manually adding that
when testing.
Comment 1 Ionen Wolkens gentoo-dev 2024-04-03 12:48:28 UTC
I assume this is related to what happened in bug #927691 that made a mention of this file:

    $ cat /etc/ld-musl-x86_64.path 
    /lib
    /usr/lib/gcc/x86_64-pc-linux-musl/13
    /usr/lib
    /usr/local/lib
    /usr/lib/llvm/18/lib
    /usr/lib/llvm/17/lib

And /lib being the problem. Not that I'm familiar with how musl handle things, haven't checked what makes/update that file but it's not updated on my recently merged musl (and merge was done after I had done the -e @world for 23.0, so didn't rebuild much post-merge).
Comment 2 ktoupt 2024-04-03 14:02:54 UTC
(In reply to Ionen Wolkens from comment #1)
> I assume this is related to what happened in bug #927691 that made a mention
> of this file:
> 
>     $ cat /etc/ld-musl-x86_64.path 
>     /lib
>     /usr/lib/gcc/x86_64-pc-linux-musl/13
>     /usr/lib
>     /usr/local/lib
>     /usr/lib/llvm/18/lib
>     /usr/lib/llvm/17/lib
> 
> And /lib being the problem. Not that I'm familiar with how musl handle
> things, haven't checked what makes/update that file but it's not updated on
> my recently merged musl (and merge was done after I had done the -e @world
> for 23.0, so didn't rebuild much post-merge).

I did not know about this file. Thanks.

It looks like this file is updated after running ldconfig. ldconfig on
musl system seems to be a bash script written by Gentoo Authors.

The script reads /etc/ld.so.conf.d (and follows include
/etc/ld.so.conf.d/*.conf) to add directories for the linker.

In the function sanitize, it searches for /lib and /usr/lib and prepends
them at the very top of the directories "list" if they were not
"repeated", i.e., if they were not specified in ld.so.conf.

In merge-usr, at least, /lib is not "repeated" by default in ld.so.conf,
so it is, indeed, put at the very top, and /lib is a symlink to
/usr/lib, so it bypasses overrides.

Note how /lib (which is essentially /usr/lib) is above
/usr/lib/{blas,lapack}/openblas, which was intended to override
/usr/lib:

	$ cat /etc/ld.so.conf
	# ld.so.conf autogenerated by env-update; make all changes to
	# contents of /etc/env.d directory.
	include ld.so.conf.d/*.conf
	/usr/lib
	/usr/local/lib
	/usr/lib/rust/lib
	/usr/lib/llvm/18/lib
	/usr/lib/llvm/17/lib
	/usr/lib/octave/8.3.0

	$ ldconfig
	Updating links is not implemented.

	$ cat /etc/ld-musl-x86_64.path
	/lib
	/usr/lib/gcc/x86_64-pc-linux-musl/13
	/usr/lib/blas/openblas
	/usr/lib/lapack/openblas
	/usr/lib
	/usr/local/lib
	/usr/lib/rust/lib
	/usr/lib/llvm/18/lib
	/usr/lib/llvm/17/lib
	/usr/lib/octave/8.3.0

Now, if I specify /lib anywhere in ld.so.conf (or in the include), it
is not prepended at the very top and the /usr/lib/{blas,lapack}/openblas
overrides work:

	$ cat /etc/ld.so.conf
	# ld.so.conf autogenerated by env-update; make all changes to
	# contents of /etc/env.d directory.
	include ld.so.conf.d/*.conf
	/usr/lib
	/lib
	/usr/local/lib
	/usr/lib/rust/lib
	/usr/lib/llvm/18/lib
	/usr/lib/llvm/17/lib
	/usr/lib/octave/8.3.0

	$ ldconfig
	Updating links is not implemented.

	$ cat /etc/ld-musl-x86_64.path 
	/usr/lib/gcc/x86_64-pc-linux-musl/13
	/usr/lib/blas/openblas
	/usr/lib/lapack/openblas
	/usr/lib
	/lib
	/usr/local/lib
	/usr/lib/rust/lib
	/usr/lib/llvm/18/lib
	/usr/lib/llvm/17/lib
	/usr/lib/octave/8.3.0

I don't know what the proper solution would be. Possible solutions I
see:

	- Update ldconfig to be fine with missing /lib in merge-usr
	- Update ldconfig to append instead of prepend
	- Just add /lib in /etc/ld.so.conf somewhere

Interestingly, I cannot figure out which package ldconfig is coming
from; `qfile $(which ldconfig)` does not show anything.
Comment 3 Ionen Wolkens gentoo-dev 2024-04-03 14:20:35 UTC
(In reply to ktoupt from comment #2)
> Interestingly, I cannot figure out which package ldconfig is coming
> from; `qfile $(which ldconfig)` does not show anything.
That's an unfortunate quirk of merge-usr and ebuilds that still install through the symlink, aka if it installed to /sbin/ldconfig then this is the path that's recorded in /var/db/pkg

# qfile -v /sbin/ldconfig
sys-libs/musl-1.2.4-r1: /sbin/ldconfig

(on a related-note, ldconfig is regularly ran by env-update with each emerge invocation)
Comment 4 Ionen Wolkens gentoo-dev 2024-04-03 14:26:02 UTC
Also, musl's ldconfig seems to be some ..thing that we have in files/ldconfig.in-r3 -- so it's probably due to be fixed. Haven't really looked at it.
Comment 5 Mike Gilbert gentoo-dev 2024-04-03 20:18:20 UTC
This is not an issue on glibc systems as far as I can tell.
Comment 6 Ionen Wolkens gentoo-dev 2024-04-03 20:44:50 UTC
(In reply to Ionen Wolkens from comment #4)
> Also, musl's ldconfig seems to be some ..thing that we have in
> files/ldconfig.in-r3 -- so it's probably due to be fixed. Haven't really
> looked at it.
Unsurprisingly, it's due to[1]:

    sanitize() {
        local drs=$@

        repeated "${EPREFIX}/lib" ${drs} || drs="${EPREFIX}/lib ${drs}"
        repeated "${EPREFIX}/usr/lib" ${drs} || drs="${EPREFIX}/usr/lib ${drs}"

        echo ${drs}
    }

Dropping the first line no longer adds /lib. Seems to be a fallback for when ld.so.conf did not exist which (always) adds /lib and /usr/lib while avoiding repeating them. Suppose one could either modify with USE=-split-usr or check if /lib == /usr/lib, not that I plan to look at this myself.

[1] https://gitweb.gentoo.org/repo/gentoo.git/tree/sys-libs/musl/files/ldconfig.in-r3?id=b02003640#n113