From edwin@mavetju.org  Thu Apr 25 01:16:17 2002
Return-Path: <edwin@mavetju.org>
Received: from topaz.mdcc.cx (topaz.mdcc.cx [212.204.230.141])
	by hub.freebsd.org (Postfix) with ESMTP id D304937B417
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 25 Apr 2002 01:16:09 -0700 (PDT)
Received: from k7.mavetju.org (topaz.mdcc.cx [212.204.230.141])
	by topaz.mdcc.cx (Postfix) with ESMTP id A4E192B840
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 25 Apr 2002 10:16:04 +0200 (CEST)
Received: by k7.mavetju.org (Postfix, from userid 1001)
	id 926F5397; Thu, 25 Apr 2002 18:17:09 +1000 (EST)
Message-Id: <20020425081709.926F5397@k7.mavetju.org>
Date: Thu, 25 Apr 2002 18:17:09 +1000 (EST)
From: Edwin Groothuis <edwin@mavetju.org>
Reply-To: Edwin Groothuis <edwin@mavetju.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] ldd/rtld support for more information of linked libraries
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         37448
>Category:       kern
>Synopsis:       [PATCH] ldd/rtld support for more information of linked libraries
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    obrien
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Apr 25 01:20:01 PDT 2002
>Closed-Date:    Sat May 12 22:52:13 GMT 2007
>Last-Modified:  Sat May 12 22:52:13 GMT 2007
>Originator:     Edwin Groothuis
>Release:        FreeBSD 4.5-RELEASE i386
>Organization:
-
>Environment:
System: FreeBSD k7.mavetju.org 4.5-RELEASE FreeBSD 4.5-RELEASE #3: Mon Mar 11 13:32:05 EST 2002 edwin@k7.mavetju.org:/usr/src/sys/compile/k7 i386

>Description:

Last night, I couldn't start glade anymore (I use it once in a
while). After checking for missing libraries, I found out that I
had to recompile it due to a change from libfreetype.so.6 ->
libfreetype.so.9. Even after the recompile it didn't start, still
complaining about libfreetype.so.6. After half a night and recompiling
all dependencies of glade and their depencies, it worked again.

I knew with ldd that it was libfreetype.so.6 which was somewhere
still needed. But I couldn't find out where it was, ldd doesn't
give information regarding the libraries itself.

This patch does two things:
- In ldd.c, it checks for the -s option (I've heard that SunOS uses
  that one for this kind of feature). If so, it sets the
  LD_TRACE_LOADED_OBJECTS_OPTS environment variable.

- In rtld.c, it checks for LD_TRACE_LOADED_OBJECTS_OPTS and then
  prints the name of the object and doesn't skip already traced
  objects. So the output will be more, but more complete.

>How-To-Repeat:

ldd `which glade`. Do you know which part needs libfreetype.so.6 ?

>Fix:

This is a patch against 4.5-RELEASE. I'm not able to do this stuff
under -current. Apologies for this.


--- /usr/src/libexec/rtld-elf/rtld.c-4.5	Thu Apr 25 18:00:23 2002
+++ /usr/src/libexec/rtld-elf/rtld.c	Thu Apr 25 17:30:07 2002
@@ -1957,7 +1957,7 @@
 trace_loaded_objects(Obj_Entry *obj)
 {
     char	*fmt1, *fmt2, *fmt, *main_local;
-    int		c;
+    int		c,opts;
 
     if ((main_local = getenv("LD_TRACE_LOADED_OBJECTS_PROGNAME")) == NULL)
 	main_local = "";
@@ -1968,14 +1968,21 @@
     if ((fmt2 = getenv("LD_TRACE_LOADED_OBJECTS_FMT2")) == NULL)
 	fmt2 = "\t%o (%x)\n";
 
+    opts = 0;
+    if (getenv("LD_TRACE_LOADED_OBJECTS_OPTS") != NULL)
+	opts = 1;
+
     for (; obj; obj = obj->next) {
 	Needed_Entry		*needed;
 	char			*name, *path;
 	bool			is_lib;
 
+	if (opts)
+	    printf("  %s\n",obj->path);
+
 	for (needed = obj->needed; needed; needed = needed->next) {
 	    if (needed->obj != NULL) {
-		if (needed->obj->traced)
+		if (needed->obj->traced && opts == 0)
 		    continue;
 		needed->obj->traced = true;
 		path = needed->obj->path;


--- /usr/src/libexec/rtld-elf/rtld.1-4.5	Thu Apr 25 17:49:29 2002
+++ /usr/src/libexec/rtld-elf/rtld.1	Thu Apr 25 17:58:33 2002
@@ -107,6 +107,9 @@
 .Nm
 to exit after loading the shared objects and printing a summary which includes
 the absolute pathnames of all objects, to standard output.
+.It Ev LD_TRACE_LOADED_OBJECTS_OPTS
+When set to a nonempty string, causes the summary printed with
+LD_TRACE_LOADED_OBJECTS to show all shared objects and their objects.
 .It Ev LD_TRACE_LOADED_OBJECTS_FMT1
 .It Ev LD_TRACE_LOADED_OBJECTS_FMT2
 When set, these variables are interpreted as format strings a la


--- /usr/src/usr.bin/ldd/ldd.c-4.5	Thu Apr 25 18:01:13 2002
+++ /usr/src/usr.bin/ldd/ldd.c	Thu Apr 25 18:05:00 2002
@@ -48,7 +48,7 @@
 void
 usage()
 {
-	fprintf(stderr, "usage: ldd [-v] [-f format] program ...\n");
+	fprintf(stderr, "usage: ldd [-v] [-s] [-f format] program ...\n");
 	exit(1);
 }
 
@@ -61,9 +61,13 @@
 	int		rval;
 	int		c;
 	int		vflag = 0;
+	int		sflag = 0;
 
-	while ((c = getopt(argc, argv, "vf:")) != -1) {
+	while ((c = getopt(argc, argv, "vsf:")) != -1) {
 		switch (c) {
+		case 's':
+			sflag++;
+			break;
 		case 'v':
 			vflag++;
 			break;
@@ -101,6 +105,8 @@
 
 	/* ld.so magic */
 	setenv("LD_TRACE_LOADED_OBJECTS", "1", 1);
+	if (sflag)
+		setenv("LD_TRACE_LOADED_OBJECTS_OPTS", "1", 1);
 	if (fmt1)
 		setenv("LD_TRACE_LOADED_OBJECTS_FMT1", fmt1, 1);
 	if (fmt2)

--- /usr/src/usr.bin/ldd/ldd.1-4.5	Thu Apr 25 18:01:09 2002
+++ /usr/src/usr.bin/ldd/ldd.1	Thu Apr 25 18:03:24 2002
@@ -9,6 +9,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl v
+.Op Fl s
 .Op Fl f Ar format
 .Ar program ...
 .Sh DESCRIPTION
@@ -38,6 +39,11 @@
 option displays an verbose listing of the dynamic linking headers
 encoded in the executable.  See the source code and include
 files for the definitive meaning of all the fields.
+.Pp
+The
+.Fl s
+option displays all shared objects and also the shared objects they
+are depending on.
 .Sh SEE ALSO
 .Xr ld 1 ,
 .Xr nm 1 ,
>Release-Note:
>Audit-Trail:

From: Edwin Groothuis <edwin@mavetju.org>
To: bugs-followup@FreeBSD.org
Cc:  
Subject: Re: bin/37448: [PATCH] ldd/rtld support for more information of linked libraries
Date: Fri, 26 Apr 2002 07:29:37 +1000

 On Thu, Apr 25, 2002 at 06:17:09PM +1000, Edwin Groothuis wrote:
 > 
 > >Number:         37448
 > >Category:       bin
 > >Synopsis:       [PATCH] ldd/rtld support for more information of linked libraries
 > >Confidential:   no
 > >Severity:       non-critical
 > >Priority:       medium
 > >Responsible:    freebsd-bugs
 > >State:          open
 > >Quarter:        
 > >Keywords:       
 > >Date-Required:
 > >Class:          change-request
 > >Submitter-Id:   current-users
 > >Arrival-Date:   Thu Apr 25 01:20:01 PDT 2002
 > >Closed-Date:
 > >Last-Modified:
 > >Originator:     Edwin Groothuis
 > >Release:        FreeBSD 4.5-RELEASE i386
 > >Organization:
 > -
 > >Environment:
 > System: FreeBSD k7.mavetju.org 4.5-RELEASE FreeBSD 4.5-RELEASE #3: Mon Mar 11 13:32:05 EST 2002 edwin@k7.mavetju.org:/usr/src/sys/compile/k7 i386
 > 
 > >Description:
 
 A patch for this was already made by Mike Meyer <mwm@mired.org> as
 bin/30908 ([PATCH] Tweak ldd to provide more information if requested).
 It is already commited to -current, but not MFC'ed.
 
 Please close this PR after bin/30908 has been MFC'ed.
 
 Edwin
 
 -- 
 Edwin Groothuis      |           Personal website: http://www.MavEtJu.org
 edwin@mavetju.org    |        Interested in MUDs? Visit Fatal Dimensions:
 bash$ :(){ :|:&};:   |                    http://www.FatalDimensions.org/

From: Dag-Erling Smorgrav <des@ofug.org>
To: Edwin Groothuis <edwin@mavetju.org>
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: bin/37448: [PATCH] ldd/rtld support for more information of linked libraries
Date: 27 Apr 2002 16:59:22 +0200

 Edwin Groothuis <edwin@mavetju.org> writes:
 > - In ldd.c, it checks for the -s option (I've heard that SunOS uses
 >   that one for this kind of feature). If so, it sets the
 >   LD_TRACE_LOADED_OBJECTS_OPTS environment variable.
 
 Solaris uses -v for this; -s is for debugging the search algorithm.
 
 % ldd =ls
         libc.so.1 =>     /usr/lib/libc.so.1
         libdl.so.1 =>    /usr/lib/libdl.so.1
         /usr/platform/SUNW,Ultra-5_10/lib/libc_psr.so.1
 % ldd -v =ls
 
    find object=libc.so.1; required by /local/gnu/bin/ls
         libc.so.1 =>     /usr/lib/libc.so.1
 
    find object=libdl.so.1; required by /usr/lib/libc.so.1
         libdl.so.1 =>    /usr/lib/libdl.so.1
    find version=libdl.so.1
         libdl.so.1 (SISCD_2.3) =>        /usr/lib/libdl.so.1
         libdl.so.1 (SUNWprivate_1.1) =>  /usr/lib/libdl.so.1
 
    find object=/usr/platform/SUNW,Ultra-5_10/lib/libc_psr.so.1; required by /usr/lib/libc.so.1
         /usr/platform/SUNW,Ultra-5_10/lib/libc_psr.so.1
 % ldd -s =ls
 
    find object=libc.so.1; required by /local/gnu/bin/ls
     search path=/usr/lib  (default)
     trying path=/usr/lib/libc.so.1
         libc.so.1 =>     /usr/lib/libc.so.1
 
    find object=libdl.so.1; required by /usr/lib/libc.so.1
     search path=/usr/lib  (default)
     trying path=/usr/lib/libdl.so.1
         libdl.so.1 =>    /usr/lib/libdl.so.1
 
    find object=/usr/platform/SUNW,Ultra-5_10/lib/libc_psr.so.1; required by /usr/lib/libc.so.1
         /usr/platform/SUNW,Ultra-5_10/lib/libc_psr.so.1
 
 DES
 -- 
 Dag-Erling Smorgrav - des@ofug.org
State-Changed-From-To: open->patched 
State-Changed-By: johan 
State-Changed-When: Thu May 2 18:32:11 PDT 2002 
State-Changed-Why:  
The fix in PR 30908 was commited in Feb. 


Responsible-Changed-From-To: freebsd-bugs->obrien 
Responsible-Changed-By: johan 
Responsible-Changed-When: Thu May 2 18:32:11 PDT 2002 
Responsible-Changed-Why:  
David can you MFC your commit and close this PR, please. 
1.28      +5 -0      src/libexec/rtld-elf/rtld.1 
1.60      +6 -2      src/libexec/rtld-elf/rtld.c 

1.20      +8 -0      src/usr.bin/ldd/ldd.1 
1.28      +11 -5     src/usr.bin/ldd/ldd.c 



http://www.freebsd.org/cgi/query-pr.cgi?pr=37448 
State-Changed-From-To: patched->closed 
State-Changed-By: pav 
State-Changed-When: Sat May 12 22:47:10 UTC 2007 
State-Changed-Why:  
This is now in all supported releases (5.0 and up, in fact) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=37448 
>Unformatted:
