Bug 259069 - ldd -f format not applied to libraries
Summary: ldd -f format not applied to libraries
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 13.0-STABLE
Hardware: amd64 Any
: --- Affects Some People
Assignee: freebsd-toolchain (Nobody)
URL:
Keywords:
Depends on:
Blocks: 258972
  Show dependency treegraph
 
Reported: 2021-10-11 12:25 UTC by Dominic Fandrey
Modified: 2021-11-22 08:19 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dominic Fandrey freebsd_committer 2021-10-11 12:25:46 UTC
E.g.:
# ldd -f '%A|%o|%p\n' /bin/sh /lib/libuutil.so.2                                                                                        
/bin/sh|libedit.so.8|/lib/libedit.so.8                                                                                                                                                                                           
/bin/sh|libc.so.7|/lib/libc.so.7                                                                                                                                                                                                 
/bin/sh|libncursesw.so.9|/lib/libncursesw.so.9                                                                                                                                                                                   
        libavl.so.2 => /lib/libavl.so.2 (0x80068e000)                                                                                                                                                                            
        libspl.so.2 => /lib/libspl.so.2 (0x800693000)                                                                                                                                                                            
        libc.so.7 => /lib/libc.so.7 (0x800266000)
Comment 1 Li-Wen Hsu freebsd_committer 2021-10-11 18:37:54 UTC
This is a regression, it works on 13.0-R

ldd -f '%A|%o|%p\n' /bin/sh /lib/libuutil.so.2
/bin/sh|libedit.so.8|/lib/libedit.so.8
/bin/sh|libc.so.7|/lib/libc.so.7
/bin/sh|libncursesw.so.9|/lib/libncursesw.so.9
/lib/libuutil.so.2|libavl.so.2|/lib/libavl.so.2
/lib/libuutil.so.2|libspl.so.2|/lib/libspl.so.2
/lib/libuutil.so.2|libc.so.7|/lib/libc.so.7

It doesn't work on FreeBSD 14.0-CURRENT main-n249945-67bceb38f463
Comment 2 Konstantin Belousov freebsd_committer 2021-10-12 10:38:47 UTC
Apparently this is an old issue, rtld in principle cannot reliably query
environment of the running process.  It happens to work in somewhat limited
setting of ldd before bfd4c875a10560aaa2f4, but that revision formalized the
fact that rtld should not try to dig into/nor it should trust the runtime
changes.

I have something prototyped to fix lld with custom format, but productizing
it would take time.
Comment 3 Konstantin Belousov freebsd_committer 2021-10-12 11:53:08 UTC
https://reviews.freebsd.org/D32464
Comment 4 commit-hook freebsd_committer 2021-10-21 00:11:43 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=2c7a6dad4de17c357eb91c723bad860c6512a598

commit 2c7a6dad4de17c357eb91c723bad860c6512a598
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2021-10-11 22:35:56 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2021-10-21 00:09:14 +0000

    ldd: do not use dlopen(RTLD_TRACE) for dso when format is specified

    Problem is that rtld cannot reliably access updated environment.
    This was made more obvious by bfd4c875a10560aaa2.  The application
    environment can be in arbitrary state and place, system components
    can observe it only during execve(2), or in case of rtld, right after
    execve, when environment is still at know location and format.

    Instead spawn ld-elf.so.1 in direct exec mode which can correctly read
    all inherited updates to the environment.

    PR:     259069
    Reviewed by:    arichardson, jhb
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D32464

 usr.bin/ldd/Makefile |  1 +
 usr.bin/ldd/ldd.c    | 12 +++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)
Comment 5 commit-hook freebsd_committer 2021-10-28 00:36:52 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=7a3d7b9efc3373e439bccf234fd4fadd2af9a75f

commit 7a3d7b9efc3373e439bccf234fd4fadd2af9a75f
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2021-10-11 22:35:56 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2021-10-28 00:35:54 +0000

    ldd: do not use dlopen(RTLD_TRACE) for dso when format is specified

    PR:     259069

    (cherry picked from commit 2c7a6dad4de17c357eb91c723bad860c6512a598)

 usr.bin/ldd/Makefile |  1 +
 usr.bin/ldd/ldd.c    | 12 +++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)
Comment 6 Yuri Victorovich freebsd_committer 2021-11-15 20:03:17 UTC
I have stable/13-n248012-b6b91760300 that includes 7a3d7b9efc3373e439bccf234fd4fadd2af9a75f 'but ldd -a' still doesn't show sections for shared libraries:
$ ldd -a /usr/local/lib/libraqm.so
	libfreetype.so.6 => /usr/local/lib/libfreetype.so.6 (0x80067c000)
	libharfbuzz.so.0 => /usr/local/lib/libharfbuzz.so.0 (0x801000000)
	libfribidi.so.0 => /usr/local/lib/libfribidi.so.0 (0x800746000)
	libc.so.7 => /lib/libc.so.7 (0x800263000)
	libz.so.6 => /lib/libz.so.6 (0x800767000)
	libbz2.so.4 => /usr/lib/libbz2.so.4 (0x800783000)
	libpng16.so.16 => /usr/local/lib/libpng16.so.16 (0x800799000)
	libm.so.5 => /lib/libm.so.5 (0x8010f2000)
	libgraphite2.so.3 => /usr/local/lib/libgraphite2.so.3 (0x80112c000)
	libglib-2.0.so.0 => /usr/local/lib/libglib-2.0.so.0 (0x801158000)
	libthr.so.3 => /lib/libthr.so.3 (0x801293000)
	libc++.so.1 => /usr/lib/libc++.so.1 (0x8012c0000)
	libcxxrt.so.1 => /lib/libcxxrt.so.1 (0x8007d8000)
	libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x801398000)
	libpcre.so.1 => /usr/local/lib/libpcre.so.1 (0x8013b3000)
	libintl.so.8 => /usr/local/lib/libintl.so.8 (0x801457000)
	libiconv.so.2 => /usr/local/lib/libiconv.so.2 (0x801466000)
	libutil.so.9 => /lib/libutil.so.9 (0x801586000)
Comment 7 commit-hook freebsd_committer 2021-11-15 20:50:02 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=7d20a08076b4c9d4513585a01fc57c39be654edf

commit 7d20a08076b4c9d4513585a01fc57c39be654edf
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2021-11-15 20:45:51 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2021-11-15 20:49:33 +0000

    ldd: also use exec mode for -a

    The -a option also requires passing specific environment variables to
    instance of rtld doing tracing.

    PR:     259069
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week

 usr.bin/ldd/ldd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 8 commit-hook freebsd_committer 2021-11-19 04:37:46 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=e8b954f136a7af19c44e16c11335abb9fb5fa7d1

commit e8b954f136a7af19c44e16c11335abb9fb5fa7d1
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2021-11-15 20:45:51 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2021-11-19 04:25:28 +0000

    ldd: also use exec mode for -a

    PR:     259069

    (cherry picked from commit 7d20a08076b4c9d4513585a01fc57c39be654edf)

 usr.bin/ldd/ldd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)