Created attachment 246246 [details] stable/12: Prepend /lib/casper to rc.d/ldconfig's baseline Synopsis ======== ldconfig manages the file at _PATH_ELF_HINTS and always includes a baseline set of directories independent of its rc vars such as ldconfig_paths and ldconfig_local_dirs. After consulting the hints, rtld falls back to a hard-coded list of library directories. The ldconfig hard-coded path is a subset of the rtld hard-coded path whereas they should be identical. Context ======= % ldd /usr/local/sbin/tcpdump | grep libcap_dns libcap_dns.so.2 => /lib/casper/libcap_dns.so.2 (0x21349571a000) % /usr/local/sbin/tcpdump --version tcpdump version 4.99.4 libpcap version 1.10.4 OpenSSL 1.1.1w 11 Sep 2023 % Expected behavior ================= % sudo pkg check -B tcpdump Checking tcpdump: 100% % Observed behavior ================= % sudo pkg check -B tcpdump Checking tcpdump: 0% (tcpdump-4.99.4_1) /usr/local/sbin/tcpdump - required shared library libcap_dns.so.2 not found Checking tcpdump: 100% % Analysis ======== The "pkg check -B" command has no hard-coded default path and relies on the elf-hints maintained by ldconfig. The ldconfig baseline (_LDC) is set to "/lib /usr/lib" in libexec/rc/rc.d/ldconfig on the (still supported) stable/12 and stable/13 branches. The rtld baseline (STANDARD_LIBRARY_PATH) is set to "/lib/casper:/lib:/usr/lib" in libexec/rtld-elf/paths.h on the stable/12 branch and in libexec/rtld-elf/rtld_paths.h on the stable/13 branch. Considering rtld to be authoritative, ldconfig's baseline needs correction. The main and stable/14 branches are not affected because the casper shared libs have been moved to /lib, so the rtld and ldconfig baselines agree. See also ======== https://lists.freebsd.org/archives/freebsd-ports/2023-November/004889.html Testing ======= % echo /lib/casper | sudo tee /usr/local/libdata/ldconfig/casper > /dev/null % sudo service ldconfig restart ELF ldconfig path: /lib /usr/lib /usr/lib/compat /usr/local/lib /usr/local/lib/compat/pkg /lib/casper /usr/local/lib/compat/pkg /usr/local/lib/perl5/5.36/mach/CORE /usr/local/llvm15/lib 32-bit compatibility ldconfig path: /usr/lib32 % sudo pkg check -B tcpdump Checking tcpdump: 100%
Created attachment 246247 [details] stable/13: Prepend /lib/casper to rc.d/ldconfig's baseline The patches for stable/12 and stable/13 are nearly identical. Both are included for completeness.
I have no opinion about (dying) stable/12. For main and all living stable branches (stable/14, and stable/13) the better approach is to initialize _LDC from the 'Default lib path' line in the /libexec/ld-elf.so.1 -v output. Similarly, ldconfig32_paths should take system paths from the /libexec/ld-elf32.so.1 -v output. This way it would be fixed once and for all future tweaks.
(In reply to Konstantin Belousov from comment #2) > For main and all living stable branches (stable/14, and > stable/13) the better approach is to initialize _LDC from > the 'Default lib path' line in the /libexec/ld-elf.so.1 -v > output. Like this? _LDC=`/libexec/ld-elf.so.1 -v | sed -n -e 's/:/ /' -e 's/^Default lib path //p'` > Similarly, ldconfig32_paths should take system paths from > the /libexec/ld-elf32.so.1 -v output. Should that happen when /etc/defaults/rc.conf is first generated, or every time it is processed?
(In reply to Konstantin Belousov from comment #2) > I have no opinion about (dying) stable/12. I used 12.4-STABLE when I did my research on this :) A quick workaround is the following echo 'ldconfig_paths="/lib/casper ${ldconfig_paths:-}"' >> /etc/rc.conf If anything, I would prefer to consider this hard-coded on ports/ports-mgmt/pkg side...
(In reply to John W. O'Brien from comment #3) I do not understand what it has to do with rc.conf. Also, I would write the calculation somewhat differently: _LDC=$(/libexec/ld-elf.so.1 -v | sed -n -e '/^Default lib path /s///p' | tr : ' ') to only edit the relevant line.
(In reply to Konstantin Belousov from comment #5) > I do not understand what it has to do with rc.conf. It was I who did not understand when you mentioned ldconfig32_paths. I see now that the section of rc.d/ldconfig that handles 32-bit compatibility re-initializes _LDC="", and that is where the system paths should be set. > Also, I would write the calculation somewhat differently: > _LDC=$(/libexec/ld-elf.so.1 -v | sed -n -e '/^Default lib path /s///p' | tr : ' ') > to only edit the relevant line. I will incorporate that into revised patches.
Created attachment 246263 [details] stable/12: Initialize ldconfig baseline paths from rtld standard library paths
Created attachment 246264 [details] stable/13: Initialize ldconfig baseline paths from rtld standard library paths
(In reply to John W. O'Brien from comment #8) Do you have account on reviews.freebsd.org? Please put your stable/13' patch there.
(In reply to Konstantin Belousov from comment #9) Certainly. In light of this, more general approach, I realize this change should be applied to main and subsequently back-ported to stable/14, stable/13, and (if still relevant) stable/12. I will prepare the Phabricator revision accordingly.
See review D42557.
(In reply to Konstantin Belousov from comment #5) This is for (life expectancy less than 2 months) stable/12 or earlier :) I see that you are now modifying the default values to get them from the command... Is there a problem with leaving /usr/src/libexec/rc/rc.conf side empty and only using the command if it is empty? But, I don't see what the point is in specifying it on the rc.conf side, though :)
(In reply to Tatsuki Makino from comment #12) Sorry, comment #12 is a terrible misdirection. The value in /etc/default/rc.conf was only appended. It was to match the default values hard-coded in /usr/src/libexec/rc/rc.d/ldconfig with the default values hard-coded in /usr/src/libexec/rtld-elf/*path*.h. How about pioneering an option on libexec/rtld-elf side that allows output per value? Something about the pipes seems too redundant.
Created attachment 246272 [details] rc.d/ldconfig: Prepend rtld stdlib paths to ldconfig(32)_paths
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=99132daf6f70cb0cc969c555d3612547fa3cf1db commit 99132daf6f70cb0cc969c555d3612547fa3cf1db Author: John W. O'Brien <john@saltant.com> AuthorDate: 2023-11-12 22:45:27 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2023-11-13 23:39:17 +0000 rc.d/ldconfig: Prepend rtld stdlib paths to ldconfig(32)_paths Ensure that ldconfig-managed elf and elf32 hints always include the standard library paths that are known independently to rtld. PR: 275031 Reviewed by: kib MFC after: 2 weeks Sponsored by: Saltant Solutions LLC Differential Revision: https://reviews.freebsd.org/D42557 libexec/rc/rc.d/ldconfig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
(In reply to commit-hook from comment #15) It seems that using the results of ld-elf*.so.1 run as is may result in setting up a directory that does not exist. Shortcut to its reporting https://lists.freebsd.org/archives/freebsd-ports/2023-November/004910.html
(In reply to Tatsuki Makino from comment #16) This is innocent. Anyway, I put the fix at https://reviews.freebsd.org/D42626
(In reply to Konstantin Belousov from comment #17) I think that should be a check added to the 64-bit side as well. Here, all data is picked up automatically, and deficiencies are avoided automatically. Then, only the rtld side would have to check to see if the directory is actually there, won't it?
A commit in branch stable/14 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=5dba91f557f0fb295977a07b2837b0351723b9c8 commit 5dba91f557f0fb295977a07b2837b0351723b9c8 Author: John W. O'Brien <john@saltant.com> AuthorDate: 2023-11-12 22:45:27 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2023-11-28 11:39:39 +0000 rc.d/ldconfig: Prepend rtld stdlib paths to ldconfig(32)_paths PR: 275031 (cherry picked from commit 99132daf6f70cb0cc969c555d3612547fa3cf1db) libexec/rc/rc.d/ldconfig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=481273492bbbab5ee1978a24e55b13c1f39bc560 commit 481273492bbbab5ee1978a24e55b13c1f39bc560 Author: John W. O'Brien <john@saltant.com> AuthorDate: 2023-11-12 22:45:27 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2023-11-28 11:42:22 +0000 rc.d/ldconfig: Prepend rtld stdlib paths to ldconfig(32)_paths PR: 275031 (cherry picked from commit 99132daf6f70cb0cc969c555d3612547fa3cf1db) libexec/rc/rc.d/ldconfig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
^Triage: assign to committer that resolved. Already mfced to 13.