This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Add --print-dirs option for ldconfig
- From: Dan Nicholson <dbn dot lists at gmail dot com>
- To: Roland McGrath <roland at hack dot frob dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Fri, 11 May 2012 07:51:01 -0700
- Subject: Re: [PATCH] Add --print-dirs option for ldconfig
- References: <1333225410-20724-1-git-send-email-dbn.lists@gmail.com><20120331210756.AD8972C0C5@topped-with-meat.com><20120401160854.GA10330@buster.dwcab.com><20120402164541.066C92C081@topped-with-meat.com><20120402172807.GA11723@buster.dwcab.com><20120402181419.6D81C2C07E@topped-with-meat.com><20120403003507.GA25174@buster.dwcab.com><20120511125709.GA16870@buster.dwcab.com>
On Fri, May 11, 2012 at 05:57:09AM -0700, Dan Nicholson wrote:
> On Mon, Apr 02, 2012 at 05:35:07PM -0700, Dan Nicholson wrote:
> > 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.
>
> OK, that patch sucked. After spending more time looking at this
> (especially the hwcap paths), I think it's important to decide what this
> feature should do.
>
> 1. Print just the base directories or the hwcap subdirectories, too? The
> latter can additionally confusing because ldconfig will recursively
> join hwcap entries as it finds them. From what I can tell, ld.so does
> not perform that feature.
>
> 2. Print the directories that are requested to be searched or just the
> ones that actually exist?
>
> On this iteration, I've decided to optionally add the hwcap subdirs (not
> recursively) and print the directories as requested. Here is sample
> output from a Fedora 16 x86_64 system:
>
> $ ./elf/ldconfig -P
> /usr/lib64/atlas
> /usr/lib64/llvm
> /usr/lib64/tracker-0.12
> /usr/lib64/xulrunner-2
> /lib
> /lib64
> /libx32
> /usr/lib
> /usr/lib64
> /usr/libx32
>
> When -v|--verbose is added, the hwcap entries will be appended as
> subdirs.
>
> $ ./elf/ldconfig -Pv
> /usr/lib64/atlas/sse2
> /usr/lib64/atlas/i386
> /usr/lib64/atlas/i486
> /usr/lib64/atlas/i586
> /usr/lib64/atlas/i686
> /usr/lib64/atlas/tls
> /usr/lib64/atlas
> ...
>
> I had to more or less duplicate some code to do this without entering a
> major refactoring. The difference here is that I'm iterating over all
> known hwcap entries, but the cache building code looks at each entry and
> checks if it's a hwcap. Roland, what do you think?
Sorry, scratch that one. I still had some asprintfs in there from when I
was actually filling in the dir_entry for each hwcap path.
2012-05-11 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_dir): Print directories when set. Print hwcap subdirs when
opt_verbose set.
(main): Exit after adding directories when option set.
---
elf/ldconfig.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/elf/ldconfig.c b/elf/ldconfig.c
index aa97213..cdffcf5 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;
@@ -395,6 +402,37 @@ add_dir (const char *line)
if (i == 0)
return;
+ /* Don't bother stating if we're just printing the search path */
+ if (opt_print_search_dirs)
+ {
+ /* Append the hwcap entries when verbose. */
+ if (opt_verbose)
+ {
+ /* Find all the hwcap subdirectories. */
+ for (int hwcap_idx = 0; hwcap_idx < _DL_HWCAP_COUNT; ++hwcap_idx)
+ if ((1ULL << hwcap_idx) & hwcap_mask)
+ printf ("%s/%s\n", entry->path, _dl_hwcap_string (hwcap_idx));
+
+#ifdef _DL_FIRST_PLATFORM
+ /* Find all the platform subdirectories. */
+ for (int plat_idx = _DL_FIRST_PLATFORM; plat_idx < _DL_FIRST_EXTRA;
+ ++plat_idx)
+ printf ("%s/%s\n", entry->path, _dl_platform_string (plat_idx));
+#endif /* _DL_FIRST_PLATFORM */
+
+ /* Extra hwcap directories */
+ for (int hwcap_idx = _DL_FIRST_EXTRA; hwcap_idx < 64; ++hwcap_idx)
+ if (hwcap_extra[hwcap_idx - _DL_FIRST_EXTRA] != NULL)
+ printf ("%s/%s\n", entry->path,
+ hwcap_extra[hwcap_idx - _DL_FIRST_EXTRA]);
+ }
+
+ puts (entry->path);
+ free (entry->path);
+ free (entry);
+ return;
+ }
+
char *path = entry->path;
if (opt_chroot)
path = chroot_canon (opt_chroot, path);
@@ -1359,6 +1397,10 @@ main (int argc, char **argv)
add_system_dir (LIBDIR);
}
+ /* Search path printed in add_dir () */
+ if (opt_print_search_dirs)
+ 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