[PATCH] Add --print-dirs option for ldconfig

Dan Nicholson dbn.lists@gmail.com
Tue Apr 3 00:35:00 GMT 2012


On Mon, Apr 02, 2012 at 11:14:19AM -0700, Roland McGrath wrote:
> Exactly what uses is this intended for?  

Figuring out where the linker is looking for libraries since it's not
really documented anywhere.

> It shows all the directories listed in configuration files.  It
> doesn't show all the directories that ldconfig searches.  That's
> because the hwcap-named subdirectories don't get added until inside
> the same loop that finds the individual libraries.  So if the intent
> is to list all the directories where ldconfig might find libraries,
> then it needs more work.

Right, I'd forgotten about those since they don't really get used on
Fedora. I took another look and did the print at the time the
directory is added to the list. It seems to work correctly now, but
it's not as clean since you actually have to let it build up the cache
to find all the directories. Untangling that seemed way too intrusive,
though.

Doing this change did highlight a couple things to me, though.

* The non-existent directories won't be shown. It could be nice to
  know all the possible directories, but didn't seem ncessary.

* The path built up by ldconfig puts the hwcap directories at the end.
  I would have expected them to come at the beginning like
  LD_DEBUG=libs shows. It does seem that things work out correctly in
  the cache, though.

Anyway, updated patch attached.

--
Dan
-------------- next part --------------
>From 4262e60bbc24c3f13fb2a1588f3c96add195a601 Mon Sep 17 00:00:00 2001
From: Dan Nicholson <dbn.lists@gmail.com>
Date: Mon, 2 Apr 2012 17:06:24 -0700
Subject: [PATCH v4] Add --print-search-dirs option for ldconfig

In order to debug linking issues, it's often beneficial to know the
current linker path. This can be difficult since the platform's trusted
directories may not be known, and parsing the ld.so.conf entries is
error prone. Fortunately, ldconfig already does this.

Add a -P|--print-search-dirs option to ldconfig for printing the linker
search directories. Here is sample output from a Fedora 16 x86_64
system:

$ ./elf/ldconfig --print-search-dirs
/usr/lib64/llvm
/usr/lib64/tracker-0.12
/usr/lib64/xulrunner-2
/lib
/lib64
/usr/lib
/usr/lib64
/lib/i686
/lib64/tls
/usr/lib/sse2
/usr/lib64/sse2
/usr/lib64/tls

2012-04-02  Dan Nicholson  <dbn.lists@gmail.com>

	* elf/ldconfig.c (opt_print_search_dirs): New variable.
	(options, parse_opt): Add -P|--print-search-dirs to set it.
	(add_single_dir): When set, print the linker search path.
	(main): When set, don't generate the cache files.
---
 elf/ldconfig.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/elf/ldconfig.c b/elf/ldconfig.c
index aa97213..3250275 100644
--- a/elf/ldconfig.c
+++ b/elf/ldconfig.c
@@ -89,6 +89,9 @@ static struct dir_entry *dir_entries;
 /* Print Cache.  */
 static int opt_print_cache;
 
+/* Print search directories.  */
+static int opt_print_search_dirs;
+
 /* Be verbose.  */
 int opt_verbose;
 
@@ -138,6 +141,7 @@ static char *more_help (int key, const char *text, void *input);
 static const struct argp_option options[] =
 {
   { "print-cache", 'p', NULL, 0, N_("Print cache"), 0},
+  { "print-search-dirs", 'P', NULL, 0, N_("Print search directories"), 0},
   { "verbose", 'v', NULL, 0, N_("Generate verbose messages"), 0},
   { NULL, 'N', NULL, 0, N_("Don't build cache"), 0},
   { NULL, 'X', NULL, 0, N_("Don't generate links"), 0},
@@ -266,6 +270,9 @@ parse_opt (int key, char *arg, struct argp_state *state)
     case 'p':
       opt_print_cache = 1;
       break;
+    case 'P':
+      opt_print_search_dirs = 1;
+      break;
     case 'r':
       opt_chroot = arg;
       break;
@@ -350,6 +357,8 @@ add_single_dir (struct dir_entry *entry, int verbose)
     dir_entries = entry;
   else if (ptr == NULL)
     prev->next = entry;
+  if (opt_print_search_dirs)
+    puts (entry->path);
 }
 
 /* Add one directory to the list of directories to process.  */
@@ -1370,7 +1379,7 @@ main (int argc, char **argv)
 
   search_dirs ();
 
-  if (opt_build_cache)
+  if (opt_build_cache && !opt_print_search_dirs)
     {
       save_cache (cache_file);
       if (aux_cache_file)
-- 
1.7.7.6



More information about the Libc-alpha mailing list