Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 25 Apr 2002 18:17:09 +1000 (EST)
From:      Edwin Groothuis <edwin@mavetju.org>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/37448: [PATCH] ldd/rtld support for more information of linked libraries
Message-ID:  <20020425081709.926F5397@k7.mavetju.org>

next in thread | raw e-mail | index | archive | help

>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:

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:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020425081709.926F5397>