git: 2f72ee987d49 - main - ldd: remove '[preloaded]' marker for the preloaded objects

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Thu, 22 Sep 2022 11:20:55 UTC
The branch main has been updated by kib:

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

commit 2f72ee987d492b3dc9116c5cf49777edd2474b11
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-09-18 00:49:30 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-09-22 11:20:13 +0000

    ldd: remove '[preloaded]' marker for the preloaded objects
    
    for the default output.  For '-a' (per-object needed printout) the
    [preloaded] banner is kept.
    
    Instead, use special format2 for printing the preloaded objects (and
    vdso), which does not include DT_NEEDED, since there is no object
    needing the printed one.
    
    In this way, the output is more compatible with glibc.
    
    Example:
    LD_PRELOAD=/lib/libthr.so.3 LD_TRACE_LOADED_OBJECTS=1 /libexec/ld-elf.so.1 /bin/ls
            libutil.so.9 => /lib/libutil.so.9 (0x801099000)
            libncursesw.so.9 => /lib/libncursesw.so.9 (0x8010b0000)
            libc.so.7 => /lib/libc.so.7 (0x801123000)
            [vdso] (0x7ffffffff000)
            /lib/libthr.so.3 (0x80106c000)
    Note the absense of the part before and including '=>' for preloaded
    libthr.so.3, and for vdso.
    
    PR:     265750
    Reviewed by:    jhb
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D36616
---
 libexec/rtld-elf/rtld.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index 86515ef416d3..d40cd9f90f0b 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -4956,7 +4956,12 @@ trace_print_obj(Obj_Entry *obj, const char *name, const char *path,
 	const char *fmt;
 	int c;
 
-	fmt = strncmp(name, "lib", 3) == 0 ? fmt1 : fmt2;	/* XXX bogus */
+	if (fmt1 == NULL)
+		fmt = fmt2;
+	else
+		/* XXX bogus */
+		fmt = strncmp(name, "lib", 3) == 0 ? fmt1 : fmt2;
+
 	while ((c = *fmt++) != '\0') {
 		switch (c) {
 		default:
@@ -5038,19 +5043,23 @@ trace_loaded_objects(Obj_Entry *obj, bool show_preload)
 	}
 
 	if (show_preload) {
+		if (ld_get_env_var(LD_TRACE_LOADED_OBJECTS_FMT2) == NULL)
+			fmt2 = "\t%p (%x)\n";
 		first_spurious = true;
+
 		TAILQ_FOREACH(obj, &obj_list, next) {
 			if (obj->marker || obj == obj_main || obj->traced)
 				continue;
 
-			if (first_spurious) {
+			if (list_containers && first_spurious) {
 				rtld_printf("[preloaded]\n");
 				first_spurious = false;
 			}
+
 			Name_Entry *fname = STAILQ_FIRST(&obj->names);
 			name = fname == NULL ? "<unknown>" : fname->name;
 			trace_print_obj(obj, name, obj->path, main_local,
-			    fmt1, fmt2);
+			    NULL, fmt2);
 		}
 	}
 }