Add support such that if LD_TRACE_LOADED_OBJECTS_ALL is defined to a

non-empty string in the environment; we indicate which objects caused
each object to be loaded.

PR:		30908
Submitted-by:	Mike Meyer <mwm@mired.org>
This commit is contained in:
David E. O'Brien 2002-02-17 07:04:32 +00:00
parent b894188248
commit 2024994319
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=90755
4 changed files with 30 additions and 7 deletions

View File

@ -107,6 +107,11 @@ When set to a nonempty string, causes
.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_ALL
When set to a nonempty string, causes
.Nm
to expand the summary to indicate which objects caused each object to
be loaded.
.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

View File

@ -2010,7 +2010,7 @@ symlook_obj(const char *name, unsigned long hash, const Obj_Entry *obj,
static void
trace_loaded_objects(Obj_Entry *obj)
{
char *fmt1, *fmt2, *fmt, *main_local;
char *fmt1, *fmt2, *fmt, *main_local, *list_containers;
int c;
if ((main_local = getenv("LD_TRACE_LOADED_OBJECTS_PROGNAME")) == NULL)
@ -2022,14 +2022,18 @@ trace_loaded_objects(Obj_Entry *obj)
if ((fmt2 = getenv("LD_TRACE_LOADED_OBJECTS_FMT2")) == NULL)
fmt2 = "\t%o (%x)\n";
list_containers = getenv("LD_TRACE_LOADED_OBJECTS_ALL");
for (; obj; obj = obj->next) {
Needed_Entry *needed;
char *name, *path;
bool is_lib;
if (list_containers && obj->needed != NULL)
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 && !list_containers)
continue;
needed->obj->traced = true;
path = needed->obj->path;

View File

@ -8,6 +8,7 @@
.Nd list dynamic object dependencies
.Sh SYNOPSIS
.Nm
.Op Fl a
.Op Fl v
.Op Fl f Ar format
.Ar program ...
@ -35,6 +36,13 @@ See
for a list of recognized conversion characters.
.Pp
The
.Fl a
option displays the list of all objects that are needed by each loaded
object. This option does not work with
.Xr a.out 5
binaries.
.Pp
The
.Fl v
option displays an verbose listing of the dynamic linking headers
encoded in the executable. See the source code and include

View File

@ -49,7 +49,7 @@ extern int error_count;
void
usage()
{
fprintf(stderr, "usage: ldd [-v] [-f format] program ...\n");
fprintf(stderr, "usage: ldd [-a] [-v] [-f format] program ...\n");
exit(1);
}
@ -61,10 +61,15 @@ char *argv[];
char *fmt1 = NULL, *fmt2 = NULL;
int rval;
int c;
int vflag = 0;
int aflag, vflag;
while ((c = getopt(argc, argv, "vf:")) != -1) {
aflag = vflag = 0;
while ((c = getopt(argc, argv, "avf:")) != -1) {
switch (c) {
case 'a':
aflag++;
break;
case 'v':
vflag++;
break;
@ -101,7 +106,7 @@ char *argv[];
#endif
/* ld.so magic */
setenv("LD_TRACE_LOADED_OBJECTS", "1", 1);
setenv("LD_TRACE_LOADED_OBJECTS", "yes", 1);
if (fmt1)
setenv("LD_TRACE_LOADED_OBJECTS_FMT1", fmt1, 1);
if (fmt2)
@ -190,7 +195,8 @@ char *argv[];
}
setenv("LD_TRACE_LOADED_OBJECTS_PROGNAME", *argv, 1);
if (fmt1 == NULL && fmt2 == NULL)
if (aflag) setenv("LD_TRACE_LOADED_OBJECTS_ALL", "1", 1);
else if (fmt1 == NULL && fmt2 == NULL)
/* Default formats */
printf("%s:\n", *argv);