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

Dan Nicholson dbn.lists@gmail.com
Sun Apr 1 16:09:00 GMT 2012


On Sat, Mar 31, 2012 at 02:07:56PM -0700, Roland McGrath wrote:
> > Add a -P|--print-dirs option to ldconfig for printing the linker
> > search directories. 
> 
> Seems like a reasonable feature.  But call it --print-search-dirs,
> consistent with the analogous gcc option.
> 
> > +2012-03-28  Dan Nicholson  <dbn.lists@gmail.com>
> > +
> > +	* elf/ldconfig.c: Add option to print linker path.
> 
> This log entry needs to be specific about the variables and functions
> touched.
> 
> > +  if (opt_print_dirs)
> > +    {
> > +      struct dir_entry *entry;
> > +
> > +      for (entry = dir_entries; entry != NULL; entry = entry->next)
> 
> You can (and should) always use C99 syntax in glibc code.
> So write:
> 
>     if (...)
>       for (struct dir_entry *entry = dir_entries; entry != NULL; entry = entry->next)

OK, updated patch attached. Hopefully it addresses both comments, but
I don't have a ton of experience with GNU ChangeLog format. Let me
know if there's any further changes you'd like to see.

--
Dan
-------------- next part --------------
>From a39ecacf40b687162fdebe74c7bf1622fab69825 Mon Sep 17 00:00:00 2001
From: Dan Nicholson <dbn.lists@gmail.com>
Date: Wed, 28 Mar 2012 09:48:32 -0700
Subject: [PATCH v2] 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 -P
/usr/lib64/llvm
/usr/lib64/tracker-0.12
/usr/lib64/xulrunner-2
/lib
/lib64
/usr/lib
/usr/lib64
---
 ChangeLog      |    6 ++++++
 elf/ldconfig.c |   15 +++++++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ba7b2cd..b5dfbda 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2012-03-28  Dan Nicholson  <dbn.lists@gmail.com>
+
+	* elf/ldconfig.c (opt_print_dirs): New option enabled with -P or
+	--print-search-dirs.
+	(main): Use it to print the linker search path.
+
 2012-02-22  Siddhesh Poyarekar  <siddhesh@redhat.com>
 
 	[BZ #13760]
diff --git a/elf/ldconfig.c b/elf/ldconfig.c
index aa97213..acde834 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_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_dirs = 1;
+      break;
     case 'r':
       opt_chroot = arg;
       break;
@@ -1359,6 +1366,14 @@ main (int argc, char **argv)
 	add_system_dir (LIBDIR);
     }
 
+  if (opt_print_dirs)
+    {
+      for (struct dir_entry *entry = dir_entries; entry != NULL;
+	   entry = entry->next)
+	puts (entry->path);
+      exit (0);
+    }
+
   const char *aux_cache_file = _PATH_LDCONFIG_AUX_CACHE;
   if (opt_chroot)
     aux_cache_file = chroot_canon (opt_chroot, aux_cache_file);
-- 
1.7.7.6



More information about the Libc-alpha mailing list