1 /* Copyright (C) 1999-2004, 2005, 2006, 2007 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Andreas Jaeger <aj@suse.de>, 1999.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License version 2 as
7 published by the Free Software Foundation.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 #define PROCINFO_CLASS static
30 #include <stdio_ext.h>
34 #include <sys/fcntl.h>
37 #include <sys/types.h>
44 #include <dl-procinfo.h>
46 #ifdef _DL_FIRST_PLATFORM
47 # define _DL_FIRST_EXTRA (_DL_FIRST_PLATFORM + _DL_PLATFORMS_COUNT)
49 # define _DL_FIRST_EXTRA _DL_HWCAP_COUNT
53 # define LD_SO_CONF SYSCONFDIR "/ld.so.conf"
56 /* Get libc version number. */
59 #define PACKAGE _libc_intl_domainname
67 {"libc4", FLAG_LIBC4
},
68 {"libc5", FLAG_ELF_LIBC5
},
69 {"libc6", FLAG_ELF_LIBC6
},
70 {"glibc2", FLAG_ELF_LIBC6
}
74 /* List of directories to handle. */
81 struct dir_entry
*next
;
84 /* The list is unsorted, contains no duplicates. Entries are added at
86 static struct dir_entry
*dir_entries
;
88 /* Flags for different options. */
90 static int opt_print_cache
;
95 /* Format to support. */
96 /* 0: only libc5/glibc2; 1: both; 2: only glibc 2.2. */
100 static int opt_build_cache
= 1;
102 /* Generate links. */
103 static int opt_link
= 1;
105 /* Only process directories specified on the command line. */
106 static int opt_only_cline
;
108 /* Path to root for chroot. */
109 static char *opt_chroot
;
111 /* Manually link given shared libraries. */
112 static int opt_manual_link
;
114 /* Cache file to use. */
115 static char *cache_file
;
117 /* Configuration file. */
118 static const char *config_file
;
120 /* Mask to use for important hardware capabilities. */
121 static unsigned long int hwcap_mask
= HWCAP_IMPORTANT
;
123 /* Configuration-defined capabilities defined in kernel vDSOs. */
124 static const char *hwcap_extra
[64 - _DL_FIRST_EXTRA
];
126 /* Name and version of program. */
127 static void print_version (FILE *stream
, struct argp_state
*state
);
128 void (*argp_program_version_hook
) (FILE *, struct argp_state
*)
131 /* Definitions of arguments for argp functions. */
132 static const struct argp_option options
[] =
134 { "print-cache", 'p', NULL
, 0, N_("Print cache"), 0},
135 { "verbose", 'v', NULL
, 0, N_("Generate verbose messages"), 0},
136 { NULL
, 'N', NULL
, 0, N_("Don't build cache"), 0},
137 { NULL
, 'X', NULL
, 0, N_("Don't generate links"), 0},
138 { NULL
, 'r', N_("ROOT"), 0, N_("Change to and use ROOT as root directory"), 0},
139 { NULL
, 'C', N_("CACHE"), 0, N_("Use CACHE as cache file"), 0},
140 { NULL
, 'f', N_("CONF"), 0, N_("Use CONF as configuration file"), 0},
141 { NULL
, 'n', NULL
, 0, N_("Only process directories specified on the command line. Don't build cache."), 0},
142 { NULL
, 'l', NULL
, 0, N_("Manually link individual libraries."), 0},
143 { "format", 'c', N_("FORMAT"), 0, N_("Format to use: new, old or compat (default)"), 0},
144 { NULL
, 0, NULL
, 0, NULL
, 0 }
147 #define PROCINFO_CLASS static
148 #include <dl-procinfo.c>
150 /* Short description of program. */
151 static const char doc
[] = N_("Configure Dynamic Linker Run Time Bindings.");
153 /* Prototype for option handler. */
154 static error_t
parse_opt (int key
, char *arg
, struct argp_state
*state
);
156 /* Data structure to communicate with argp functions. */
157 static struct argp argp
=
159 options
, parse_opt
, NULL
, doc
, NULL
, NULL
, NULL
162 /* Check if string corresponds to an important hardware capability or
165 is_hwcap_platform (const char *name
)
167 int hwcap_idx
= _dl_string_hwcap (name
);
169 if (hwcap_idx
!= -1 && ((1 << hwcap_idx
) & hwcap_mask
))
172 hwcap_idx
= _dl_string_platform (name
);
176 for (hwcap_idx
= _DL_FIRST_EXTRA
; hwcap_idx
< 64; ++hwcap_idx
)
177 if (hwcap_extra
[hwcap_idx
- _DL_FIRST_EXTRA
] != NULL
178 && !strcmp (name
, hwcap_extra
[hwcap_idx
- _DL_FIRST_EXTRA
]))
184 /* Get hwcap (including platform) encoding of path. */
186 path_hwcap (const char *path
)
188 char *str
= xstrdup (path
);
199 /* Search pathname from the end and check for hwcap strings. */
202 ptr
= strrchr (str
, '/');
207 h
= _dl_string_hwcap (ptr
+ 1);
209 if (h
== (uint64_t) -1)
211 h
= _dl_string_platform (ptr
+ 1);
212 if (h
== (uint64_t) -1)
214 for (h
= _DL_FIRST_EXTRA
; h
< 64; ++h
)
215 if (hwcap_extra
[h
- _DL_FIRST_EXTRA
] != NULL
216 && !strcmp (ptr
+ 1, hwcap_extra
[h
- _DL_FIRST_EXTRA
]))
224 /* Search the next part of the path. */
232 /* Handle program arguments. */
234 parse_opt (int key
, char *arg
, struct argp_state
*state
)
267 if (strcmp (arg
, "old") == 0)
269 else if (strcmp (arg
, "compat") == 0)
271 else if (strcmp (arg
, "new") == 0)
275 return ARGP_ERR_UNKNOWN
;
281 /* Print the version information. */
283 print_version (FILE *stream
, struct argp_state
*state
)
285 fprintf (stream
, "ldconfig (GNU %s) %s\n", PACKAGE
, VERSION
);
286 fprintf (stream
, gettext ("\
287 Copyright (C) %s Free Software Foundation, Inc.\n\
288 This is free software; see the source for copying conditions. There is NO\n\
289 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
291 fprintf (stream
, gettext ("Written by %s.\n"),
295 /* Add a single directory entry. */
297 add_single_dir (struct dir_entry
*entry
, int verbose
)
299 struct dir_entry
*ptr
, *prev
;
305 /* Check for duplicates. */
306 if (ptr
->ino
== entry
->ino
&& ptr
->dev
== entry
->dev
)
308 if (opt_verbose
&& verbose
)
309 error (0, 0, _("Path `%s' given more than once"), entry
->path
);
310 /* Use the newer information. */
311 ptr
->flag
= entry
->flag
;
319 /* Is this the first entry? */
320 if (ptr
== NULL
&& dir_entries
== NULL
)
322 else if (ptr
== NULL
)
326 /* Add one directory to the list of directories to process. */
328 add_dir (const char *line
)
331 struct dir_entry
*entry
= xmalloc (sizeof (struct dir_entry
));
334 /* Search for an '=' sign. */
335 entry
->path
= xstrdup (line
);
336 char *equal_sign
= strchr (entry
->path
, '=');
341 entry
->flag
= FLAG_ANY
;
342 for (i
= 0; i
< sizeof (lib_types
) / sizeof (lib_types
[0]); ++i
)
343 if (strcmp (equal_sign
, lib_types
[i
].name
) == 0)
345 entry
->flag
= lib_types
[i
].flag
;
348 if (entry
->flag
== FLAG_ANY
)
349 error (0, 0, _("%s is not a known library type"), equal_sign
);
353 entry
->flag
= FLAG_ANY
;
356 /* Canonify path: for now only remove leading and trailing
357 whitespace and the trailing slashes slashes. */
358 i
= strlen (entry
->path
) - 1;
360 while (isspace (entry
->path
[i
]) && i
> 0)
361 entry
->path
[i
--] = '\0';
363 while (entry
->path
[i
] == '/' && i
> 0)
364 entry
->path
[i
--] = '\0';
366 char *path
= entry
->path
;
368 path
= chroot_canon (opt_chroot
, path
);
370 struct stat64 stat_buf
;
371 if (path
== NULL
|| stat64 (path
, &stat_buf
))
374 error (0, errno
, _("Can't stat %s"), entry
->path
);
380 entry
->ino
= stat_buf
.st_ino
;
381 entry
->dev
= stat_buf
.st_dev
;
383 add_single_dir (entry
, 1);
392 chroot_stat (const char *real_path
, const char *path
, struct stat64
*st
)
398 return stat64 (real_path
, st
);
400 ret
= lstat64 (real_path
, st
);
401 if (ret
|| !S_ISLNK (st
->st_mode
))
404 canon_path
= chroot_canon (opt_chroot
, path
);
405 if (canon_path
== NULL
)
408 ret
= stat64 (canon_path
, st
);
413 /* Create a symbolic link from soname to libname in directory path. */
415 create_links (const char *real_path
, const char *path
, const char *libname
,
418 char *full_libname
, *full_soname
;
419 char *real_full_libname
, *real_full_soname
;
420 struct stat64 stat_lib
, stat_so
, lstat_so
;
423 /* XXX: The logics in this function should be simplified. */
425 /* Get complete path. */
426 full_libname
= alloca (strlen (path
) + strlen (libname
) + 2);
427 full_soname
= alloca (strlen (path
) + strlen (soname
) + 2);
428 sprintf (full_libname
, "%s/%s", path
, libname
);
429 sprintf (full_soname
, "%s/%s", path
, soname
);
432 real_full_libname
= alloca (strlen (real_path
) + strlen (libname
) + 2);
433 real_full_soname
= alloca (strlen (real_path
) + strlen (soname
) + 2);
434 sprintf (real_full_libname
, "%s/%s", real_path
, libname
);
435 sprintf (real_full_soname
, "%s/%s", real_path
, soname
);
439 real_full_libname
= full_libname
;
440 real_full_soname
= full_soname
;
443 /* Does soname already exist and point to the right library? */
444 if (chroot_stat (real_full_soname
, full_soname
, &stat_so
) == 0)
446 if (chroot_stat (real_full_libname
, full_libname
, &stat_lib
))
448 error (0, 0, _("Can't stat %s\n"), full_libname
);
451 if (stat_lib
.st_dev
== stat_so
.st_dev
452 && stat_lib
.st_ino
== stat_so
.st_ino
)
453 /* Link is already correct. */
455 else if (lstat64 (full_soname
, &lstat_so
) == 0
456 && !S_ISLNK (lstat_so
.st_mode
))
458 error (0, 0, _("%s is not a symbolic link\n"), full_soname
);
463 else if (lstat64 (real_full_soname
, &lstat_so
) != 0
464 || !S_ISLNK (lstat_so
.st_mode
))
465 /* Unless it is a stale symlink, there is no need to remove. */
469 printf ("\t%s -> %s", soname
, libname
);
471 if (do_link
&& opt_link
)
473 /* Remove old link. */
475 if (unlink (real_full_soname
))
477 error (0, 0, _("Can't unlink %s"), full_soname
);
480 /* Create symbolic link. */
481 if (do_link
&& symlink (libname
, real_full_soname
))
483 error (0, 0, _("Can't link %s to %s"), full_soname
, libname
);
489 fputs (_(" (changed)\n"), stdout
);
491 fputs (_(" (SKIPPED)\n"), stdout
);
494 else if (opt_verbose
)
495 fputs ("\n", stdout
);
498 /* Manually link the given library. */
500 manual_link (char *library
)
507 struct stat64 stat_buf
;
509 unsigned int osversion
;
511 /* Prepare arguments for create_links call. Split library name in
512 directory and filename first. Since path is allocated, we've got
513 to be careful to free at the end. */
514 path
= xstrdup (library
);
515 libname
= strrchr (path
, '/');
519 /* Successfully split names. Check if path is just "/" to avoid
523 libname
= library
+ 1;
524 path
= xrealloc (path
, 2);
535 /* There's no path, construct one. */
537 path
= xrealloc (path
, 2);
543 real_path
= chroot_canon (opt_chroot
, path
);
544 if (real_path
== NULL
)
546 error (0, errno
, _("Can't find %s"), path
);
550 real_library
= alloca (strlen (real_path
) + strlen (libname
) + 2);
551 sprintf (real_library
, "%s/%s", real_path
, libname
);
556 real_library
= library
;
559 /* Do some sanity checks first. */
560 if (lstat64 (real_library
, &stat_buf
))
562 error (0, errno
, _("Cannot lstat %s"), library
);
566 /* We don't want links here! */
567 else if (!S_ISREG (stat_buf
.st_mode
))
569 error (0, 0, _("Ignored file %s since it is not a regular file."),
574 if (process_file (real_library
, library
, libname
, &flag
, &osversion
,
577 error (0, 0, _("No link created since soname could not be found for %s"),
582 create_links (real_path
, path
, libname
, soname
);
588 /* Read a whole directory and search for libraries.
589 The purpose is two-fold:
590 - search for libraries which will be added to the cache
591 - create symbolic links to the soname for each library
593 This has to be done separatly for each directory.
595 To keep track of which libraries to add to the cache and which
596 links to create, we save a list of all libraries.
598 The algorithm is basically:
599 for all libraries in the directory do
600 get soname of library
601 if soname is already in list
602 if new library is newer, replace entry
603 otherwise ignore this library
604 otherwise add library to list
606 For example, if the two libraries libxy.so.1.1 and libxy.so.1.2
607 exist and both have the same soname, e.g. libxy.so, a symbolic link
608 is created from libxy.so.1.2 (the newer one) to libxy.so.
609 libxy.so.1.2 and libxy.so are added to the cache - but not
612 /* Information for one library. */
619 unsigned int osversion
;
620 struct dlib_entry
*next
;
625 search_dir (const struct dir_entry
*entry
)
628 struct dirent64
*direntry
;
629 char *file_name
, *dir_name
, *real_file_name
, *real_name
;
630 int file_name_len
, real_file_name_len
, len
;
632 struct dlib_entry
*dlibs
;
633 struct dlib_entry
*dlib_ptr
;
634 struct stat64 lstat_buf
, stat_buf
;
636 uint64_t hwcap
= path_hwcap (entry
->path
);
637 unsigned int osversion
;
639 file_name_len
= PATH_MAX
;
640 file_name
= alloca (file_name_len
);
647 printf ("%s: (hwcap: %#.16" PRIx64
")\n", entry
->path
, hwcap
);
649 printf ("%s:\n", entry
->path
);
654 dir_name
= chroot_canon (opt_chroot
, entry
->path
);
655 real_file_name_len
= PATH_MAX
;
656 real_file_name
= alloca (real_file_name_len
);
660 dir_name
= entry
->path
;
661 real_file_name_len
= 0;
662 real_file_name
= file_name
;
665 if (dir_name
== NULL
|| (dir
= opendir (dir_name
)) == NULL
)
668 error (0, errno
, _("Can't open directory %s"), entry
->path
);
669 if (opt_chroot
&& dir_name
)
674 while ((direntry
= readdir64 (dir
)) != NULL
)
677 #ifdef _DIRENT_HAVE_D_TYPE
678 /* We only look at links and regular files. */
679 if (direntry
->d_type
!= DT_UNKNOWN
680 && direntry
->d_type
!= DT_LNK
681 && direntry
->d_type
!= DT_REG
682 && direntry
->d_type
!= DT_DIR
)
684 #endif /* _DIRENT_HAVE_D_TYPE */
685 /* Does this file look like a shared library or is it a hwcap
686 subdirectory? The dynamic linker is also considered as
688 if (((strncmp (direntry
->d_name
, "lib", 3) != 0
689 && strncmp (direntry
->d_name
, "ld-", 3) != 0)
690 || strstr (direntry
->d_name
, ".so") == NULL
)
692 #ifdef _DIRENT_HAVE_D_TYPE
693 direntry
->d_type
== DT_REG
||
695 !is_hwcap_platform (direntry
->d_name
)))
697 len
= strlen (direntry
->d_name
);
698 /* Skip temporary files created by the prelink program. Files with
699 names like these are never really DSOs we want to look at. */
700 if (len
>= sizeof (".#prelink#") - 1)
702 if (strcmp (direntry
->d_name
+ len
- sizeof (".#prelink#") + 1,
705 if (len
>= sizeof (".#prelink#.XXXXXX") - 1
706 && memcmp (direntry
->d_name
+ len
- sizeof (".#prelink#.XXXXXX")
707 + 1, ".#prelink#.", sizeof (".#prelink#.") - 1) == 0)
710 len
+= strlen (entry
->path
);
711 if (len
> file_name_len
)
713 file_name_len
= len
+ 1;
714 file_name
= alloca (file_name_len
);
716 real_file_name
= file_name
;
718 sprintf (file_name
, "%s/%s", entry
->path
, direntry
->d_name
);
721 len
= strlen (dir_name
) + strlen (direntry
->d_name
);
722 if (len
> real_file_name_len
)
724 real_file_name_len
= len
+ 1;
725 real_file_name
= alloca (real_file_name_len
);
727 sprintf (real_file_name
, "%s/%s", dir_name
, direntry
->d_name
);
729 #ifdef _DIRENT_HAVE_D_TYPE
730 if (direntry
->d_type
!= DT_UNKNOWN
)
731 lstat_buf
.st_mode
= DTTOIF (direntry
->d_type
);
734 if (__builtin_expect (lstat64 (real_file_name
, &lstat_buf
), 0))
736 error (0, errno
, _("Cannot lstat %s"), file_name
);
740 is_link
= S_ISLNK (lstat_buf
.st_mode
);
743 /* In case of symlink, we check if the symlink refers to
745 if (__builtin_expect (stat64 (real_file_name
, &stat_buf
), 0))
748 error (0, errno
, _("Cannot stat %s"), file_name
);
750 /* Remove stale symlinks. */
751 if (strstr (direntry
->d_name
, ".so."))
752 unlink (real_file_name
);
755 is_dir
= S_ISDIR (stat_buf
.st_mode
);
758 is_dir
= S_ISDIR (lstat_buf
.st_mode
);
760 if (is_dir
&& is_hwcap_platform (direntry
->d_name
))
762 /* Handle subdirectory later. */
763 struct dir_entry
*new_entry
;
765 new_entry
= xmalloc (sizeof (struct dir_entry
));
766 new_entry
->path
= xstrdup (file_name
);
767 new_entry
->flag
= entry
->flag
;
768 new_entry
->next
= NULL
;
771 new_entry
->ino
= stat_buf
.st_ino
;
772 new_entry
->dev
= stat_buf
.st_dev
;
776 #ifdef _DIRENT_HAVE_D_TYPE
777 /* We have filled in lstat only #ifndef
778 _DIRENT_HAVE_D_TYPE. Fill it in if needed. */
779 if (direntry
->d_type
!= DT_UNKNOWN
780 && __builtin_expect (lstat64 (real_file_name
, &lstat_buf
),
783 error (0, errno
, _("Cannot lstat %s"), file_name
);
784 free (new_entry
->path
);
790 new_entry
->ino
= lstat_buf
.st_ino
;
791 new_entry
->dev
= lstat_buf
.st_dev
;
793 add_single_dir (new_entry
, 0);
796 else if (!S_ISREG (lstat_buf
.st_mode
) && !is_link
)
799 if (opt_chroot
&& is_link
)
801 real_name
= chroot_canon (opt_chroot
, file_name
);
802 if (real_name
== NULL
)
804 if (strstr (file_name
, ".so") == NULL
)
805 error (0, 0, _("Input file %s not found.\n"), file_name
);
810 real_name
= real_file_name
;
812 if (process_file (real_name
, file_name
, direntry
->d_name
, &flag
,
813 &osversion
, &soname
, is_link
))
815 if (real_name
!= real_file_name
)
821 /* A link may just point to itself. */
824 /* If the path the link points to isn't its soname and it is not
825 .so symlink for ld(1) only, we treat it as a normal file. */
826 const char *real_base_name
= basename (real_file_name
);
828 if (strcmp (real_base_name
, soname
) != 0)
830 len
= strlen (real_base_name
);
831 if (len
< strlen (".so")
832 || strcmp (real_base_name
+ len
- strlen (".so"), ".so") != 0
833 || strncmp (real_base_name
, soname
, len
) != 0)
838 if (real_name
!= real_file_name
)
844 soname
= xstrdup (direntry
->d_name
);
848 && (entry
->flag
== FLAG_ELF_LIBC5
849 || entry
->flag
== FLAG_ELF_LIBC6
))
851 /* Some sanity checks to print warnings. */
854 if (flag
== FLAG_ELF_LIBC5
&& entry
->flag
!= FLAG_ELF_LIBC5
855 && entry
->flag
!= FLAG_ANY
)
856 error (0, 0, _("libc5 library %s in wrong directory"), file_name
);
857 if (flag
== FLAG_ELF_LIBC6
&& entry
->flag
!= FLAG_ELF_LIBC6
858 && entry
->flag
!= FLAG_ANY
)
859 error (0, 0, _("libc6 library %s in wrong directory"), file_name
);
860 if (flag
== FLAG_LIBC4
&& entry
->flag
!= FLAG_LIBC4
861 && entry
->flag
!= FLAG_ANY
)
862 error (0, 0, _("libc4 library %s in wrong directory"), file_name
);
865 /* Add library to list. */
866 for (dlib_ptr
= dlibs
; dlib_ptr
!= NULL
; dlib_ptr
= dlib_ptr
->next
)
868 /* Is soname already in list? */
869 if (strcmp (dlib_ptr
->soname
, soname
) == 0)
871 /* Prefer a file to a link, otherwise check which one
873 if ((!is_link
&& dlib_ptr
->is_link
)
874 || (is_link
== dlib_ptr
->is_link
875 && _dl_cache_libcmp (dlib_ptr
->name
, direntry
->d_name
) < 0))
877 /* It's newer - add it. */
878 /* Flag should be the same - sanity check. */
879 if (dlib_ptr
->flag
!= flag
)
881 if (dlib_ptr
->flag
== FLAG_ELF
882 && (flag
== FLAG_ELF_LIBC5
|| flag
== FLAG_ELF_LIBC6
))
883 dlib_ptr
->flag
= flag
;
884 else if ((dlib_ptr
->flag
== FLAG_ELF_LIBC5
885 || dlib_ptr
->flag
== FLAG_ELF_LIBC6
)
887 dlib_ptr
->flag
= flag
;
889 error (0, 0, _("libraries %s and %s in directory %s have same soname but different type."),
890 dlib_ptr
->name
, direntry
->d_name
, entry
->path
);
892 free (dlib_ptr
->name
);
893 dlib_ptr
->osversion
= osversion
;
894 dlib_ptr
->name
= xstrdup (direntry
->d_name
);
895 dlib_ptr
->is_link
= is_link
;
897 /* Don't add this library, abort loop. */
898 /* Also free soname, since it's dynamically allocated. */
903 /* Add the library if it's not already in. */
904 if (dlib_ptr
== NULL
)
906 dlib_ptr
= (struct dlib_entry
*)xmalloc (sizeof (struct dlib_entry
));
907 dlib_ptr
->name
= xstrdup (direntry
->d_name
);
908 dlib_ptr
->flag
= flag
;
909 dlib_ptr
->osversion
= osversion
;
910 dlib_ptr
->soname
= soname
;
911 dlib_ptr
->is_link
= is_link
;
912 /* Add at head of list. */
913 dlib_ptr
->next
= dlibs
;
920 /* Now dlibs contains a list of all libs - add those to the cache
921 and created all symbolic links. */
922 for (dlib_ptr
= dlibs
; dlib_ptr
!= NULL
; dlib_ptr
= dlib_ptr
->next
)
924 /* Don't create links to links. */
925 if (dlib_ptr
->is_link
== 0)
926 create_links (dir_name
, entry
->path
, dlib_ptr
->name
,
929 add_to_cache (entry
->path
, dlib_ptr
->soname
, dlib_ptr
->flag
,
930 dlib_ptr
->osversion
, hwcap
);
933 /* Free all resources. */
937 free (dlib_ptr
->soname
);
938 free (dlib_ptr
->name
);
943 if (opt_chroot
&& dir_name
)
947 /* Search through all libraries. */
951 struct dir_entry
*entry
;
953 for (entry
= dir_entries
; entry
!= NULL
; entry
= entry
->next
)
956 /* Free all allocated memory. */
960 dir_entries
= dir_entries
->next
;
967 static void parse_conf_include (const char *config_file
, unsigned int lineno
,
968 bool do_chroot
, const char *pattern
);
970 /* Parse configuration file. */
972 parse_conf (const char *filename
, bool do_chroot
)
980 if (do_chroot
&& opt_chroot
)
982 canon
= chroot_canon (opt_chroot
, filename
);
984 file
= fopen (canon
, "r");
991 file
= fopen (filename
, "r");
996 error (0, errno
, _("Can't open configuration file %s"), canon
);
997 if (canon
!= filename
)
998 free ((char *) canon
);
1002 /* No threads use this stream. */
1003 __fsetlocking (file
, FSETLOCKING_BYCALLER
);
1005 if (canon
!= filename
)
1006 free ((char *) canon
);
1011 ssize_t n
= getline (&line
, &len
, file
);
1016 if (line
[n
- 1] == '\n')
1019 /* Because the file format does not know any form of quoting we
1020 can search forward for the next '#' character and if found
1021 make it terminating the line. */
1022 *strchrnul (line
, '#') = '\0';
1024 /* Remove leading whitespace. NUL is no whitespace character. */
1026 while (isspace (*cp
))
1029 /* If the line is blank it is ignored. */
1033 if (!strncmp (cp
, "include", 7) && isblank (cp
[7]))
1037 while ((dir
= strsep (&cp
, " \t")) != NULL
)
1039 parse_conf_include (filename
, lineno
, do_chroot
, dir
);
1041 else if (!strncasecmp (cp
, "hwcap", 5) && isblank (cp
[5]))
1044 char *p
, *name
= NULL
;
1045 unsigned long int n
= strtoul (cp
, &cp
, 0);
1046 if (cp
!= NULL
&& isblank (*cp
))
1047 while ((p
= strsep (&cp
, " \t")) != NULL
)
1060 error (EXIT_FAILURE
, 0, _("%s:%u: bad syntax in hwcap line"),
1064 if (n
>= (64 - _DL_FIRST_EXTRA
))
1065 error (EXIT_FAILURE
, 0,
1066 _("%s:%u: hwcap index %lu above maximum %u"),
1067 filename
, lineno
, n
, 64 - _DL_FIRST_EXTRA
- 1);
1068 if (hwcap_extra
[n
] == NULL
)
1070 for (unsigned long int h
= 0; h
< (64 - _DL_FIRST_EXTRA
); ++h
)
1071 if (hwcap_extra
[h
] != NULL
&& !strcmp (name
, hwcap_extra
[h
]))
1072 error (EXIT_FAILURE
, 0,
1073 _("%s:%u: hwcap index %lu already defined as %s"),
1074 filename
, lineno
, h
, name
);
1075 hwcap_extra
[n
] = xstrdup (name
);
1079 if (strcmp (name
, hwcap_extra
[n
]))
1080 error (EXIT_FAILURE
, 0,
1081 _("%s:%u: hwcap index %lu already defined as %s"),
1082 filename
, lineno
, n
, hwcap_extra
[n
]);
1084 error (0, 0, _("%s:%u: duplicate hwcap %lu %s"),
1085 filename
, lineno
, n
, name
);
1091 while (!feof_unlocked (file
));
1093 /* Free buffer and close file. */
1098 /* Handle one word in an `include' line, a glob pattern of additional
1099 config files to read. */
1101 parse_conf_include (const char *config_file
, unsigned int lineno
,
1102 bool do_chroot
, const char *pattern
)
1104 if (opt_chroot
&& pattern
[0] != '/')
1105 error (EXIT_FAILURE
, 0,
1106 _("need absolute file name for configuration file when using -r"));
1109 if (pattern
[0] != '/' && strchr (config_file
, '/') != NULL
)
1111 if (asprintf (©
, "%s/%s", dirname (strdupa (config_file
)),
1113 error (EXIT_FAILURE
, 0, _("memory exhausted"));
1119 if (do_chroot
&& opt_chroot
)
1121 char *canon
= chroot_canon (opt_chroot
, pattern
);
1122 result
= glob64 (canon
?: pattern
, 0, NULL
, &gl
);
1126 result
= glob64 (pattern
, 0, NULL
, &gl
);
1131 for (size_t i
= 0; i
< gl
.gl_pathc
; ++i
)
1132 parse_conf (gl
.gl_pathv
[i
], false);
1143 error (0, errno
, _("%s:%u: cannot read directory %s"),
1144 config_file
, lineno
, pattern
);
1156 /* Honour LD_HWCAP_MASK. */
1160 char *mask
= getenv ("LD_HWCAP_MASK");
1163 hwcap_mask
= strtoul (mask
, NULL
, 0);
1168 main (int argc
, char **argv
)
1170 /* Set locale via LC_ALL. */
1171 setlocale (LC_ALL
, "");
1173 /* Set the text message domain. */
1174 textdomain (_libc_intl_domainname
);
1176 /* Parse and process arguments. */
1178 argp_parse (&argp
, argc
, argv
, 0, &remaining
, NULL
);
1180 /* Remaining arguments are additional directories if opt_manual_link
1182 if (remaining
!= argc
&& !opt_manual_link
)
1185 for (i
= remaining
; i
< argc
; ++i
)
1186 if (opt_build_cache
&& argv
[i
][0] != '/')
1187 error (EXIT_FAILURE
, 0,
1188 _("relative path `%s' used to build cache"),
1194 hwcap_extra
[63 - _DL_FIRST_EXTRA
] = "tls";
1200 /* Normalize the path a bit, we might need it for printing later. */
1201 char *endp
= rawmemchr (opt_chroot
, '\0');
1202 while (endp
> opt_chroot
&& endp
[-1] == '/')
1205 if (endp
== opt_chroot
)
1210 /* It is faster to use chroot if we can. */
1211 if (!chroot (opt_chroot
))
1214 error (EXIT_FAILURE
, errno
, _("Can't chdir to /"));
1220 if (cache_file
== NULL
)
1222 cache_file
= alloca (strlen (LD_SO_CACHE
) + 1);
1223 strcpy (cache_file
, LD_SO_CACHE
);
1226 if (config_file
== NULL
)
1227 config_file
= LD_SO_CONF
;
1229 if (opt_print_cache
)
1233 char *p
= chroot_canon (opt_chroot
, cache_file
);
1235 error (EXIT_FAILURE
, errno
, _("Can't open cache file %s\n"),
1239 print_cache (cache_file
);
1247 /* Canonicalize the directory name of cache_file, not cache_file,
1248 because we'll rename a temporary cache file to it. */
1249 char *p
= strrchr (cache_file
, '/');
1250 char *canon
= chroot_canon (opt_chroot
,
1251 p
? (*p
= '\0', cache_file
) : "/");
1255 error (EXIT_FAILURE
, errno
,
1256 _("Can't open cache file directory %s\n"),
1257 p
? cache_file
: "/");
1265 cache_file
= alloca (strlen (canon
) + strlen (p
) + 2);
1266 sprintf (cache_file
, "%s/%s", canon
, p
);
1270 if (opt_manual_link
)
1272 /* Link all given libraries manually. */
1275 for (i
= remaining
; i
< argc
; ++i
)
1276 manual_link (argv
[i
]);
1282 if (opt_build_cache
)
1285 if (!opt_only_cline
)
1287 parse_conf (config_file
, true);
1289 /* Always add the standard search paths. */
1290 add_system_dir (SLIBDIR
);
1291 if (strcmp (SLIBDIR
, LIBDIR
))
1292 add_system_dir (LIBDIR
);
1297 if (opt_build_cache
)
1298 save_cache (cache_file
);