aboutsummaryrefslogtreecommitdiff
path: root/elf/rtld.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2004-09-18 06:46:52 +0000
committerUlrich Drepper <drepper@redhat.com>2004-09-18 06:46:52 +0000
commit7a11603dc6bde67066ce6f8d4c5f6b86bebaf3c1 (patch)
tree310fc0913c5e35b0a6e05bfab4423e38012e6ecf /elf/rtld.c
parentf04b1e1f0f86cce932ede5b5a088c0ec4712ce34 (diff)
downloadglibc-7a11603dc6bde67066ce6f8d4c5f6b86bebaf3c1.zip
glibc-7a11603dc6bde67066ce6f8d4c5f6b86bebaf3c1.tar.gz
glibc-7a11603dc6bde67066ce6f8d4c5f6b86bebaf3c1.tar.bz2
Update.
2004-09-17 Ulrich Drepper <drepper@redhat.com> * include/link.h (struct link_map): Add l_used element. * sysdeps/generic/ldsodefs.h: Define DL_DEBUG_UNUSED. * elf/rtld.c (process_dl_debug): Recognize unused. (dl_main): When unused debug flag is set check for unused direct dependencies. When printing dependencies and SONAME starts with /, omit the SONAME => part. * elf/dl-lookup.c (_dl_lookup_symbol_x): Mark object in which the symbol has been found as used. * elf/ldd.bash.in: Add -u option.
Diffstat (limited to 'elf/rtld.c')
-rw-r--r--elf/rtld.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/elf/rtld.c b/elf/rtld.c
index e015477..93c4531 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1526,6 +1526,44 @@ cannot allocate TLS data structures for initial thread");
_dl_printf ("\n");
}
}
+ else if (GLRO(dl_debug_mask) & DL_DEBUG_UNUSED)
+ {
+ /* Look through the dependencies of the main executable
+ and determine which of them is not actually
+ required. */
+ struct link_map *l = GL(dl_loaded);
+
+ /* Relocate the main executable. */
+ struct relocate_args args = { .l = l, .lazy = GLRO(dl_lazy) };
+ _dl_receive_error (print_unresolved, relocate_doit, &args);
+
+ /* This loop depends on the dependencies of the executable to
+ correspond in number and order to the DT_NEEDED entries. */
+ ElfW(Dyn) *dyn = GL(dl_loaded)->l_ld;
+ bool first = true;
+ while (dyn->d_tag != DT_NULL)
+ {
+ if (dyn->d_tag == DT_NEEDED)
+ {
+ l = l->l_next;
+
+ if (!l->l_used)
+ {
+ if (first)
+ {
+ _dl_printf ("Unused direct dependencies:\n");
+ first = false;
+ }
+
+ _dl_printf ("\t%s\n", l->l_name);
+ }
+ }
+
+ ++dyn;
+ }
+
+ _exit (first != true);
+ }
else if (! GL(dl_loaded)->l_info[DT_NEEDED])
_dl_printf ("\tstatically linked\n");
else
@@ -1534,6 +1572,10 @@ cannot allocate TLS data structures for initial thread");
if (l->l_faked)
/* The library was not found. */
_dl_printf ("\t%s => not found\n", l->l_libname->name);
+ else if (l->l_libname->name[0] == '/')
+ _dl_printf ("\t%s (0x%0*Zx)\n", l->l_libname->name,
+ (int) sizeof l->l_map_start * 2,
+ (size_t) l->l_map_start);
else
_dl_printf ("\t%s => %s (0x%0*Zx)\n", l->l_libname->name,
l->l_name, (int) sizeof l->l_map_start * 2,
@@ -1962,6 +2004,8 @@ process_dl_debug (const char *dl_debug)
| DL_DEBUG_BINDINGS | DL_DEBUG_VERSIONS | DL_DEBUG_IMPCALLS },
{ LEN_AND_STR ("statistics"), "display relocation statistics",
DL_DEBUG_STATISTICS },
+ { LEN_AND_STR ("unused"), "determined unused DSOs",
+ DL_DEBUG_UNUSED },
{ LEN_AND_STR ("help"), "display this help message and exit",
DL_DEBUG_HELP },
};