summaryrefslogtreecommitdiffstats
path: root/sbin/ldconfig/ldconfig.c
diff options
context:
space:
mode:
authorjdp <jdp@FreeBSD.org>1998-09-05 03:31:00 +0000
committerjdp <jdp@FreeBSD.org>1998-09-05 03:31:00 +0000
commit6c76bd6d548ca5eba7c437f4e56c952e1e9381c2 (patch)
treedab184fa80fe4435136d04ef1e0a049ea999352d /sbin/ldconfig/ldconfig.c
parentbd08049a9520d9d91e43c864ebbb2e4788219331 (diff)
downloadFreeBSD-src-6c76bd6d548ca5eba7c437f4e56c952e1e9381c2.zip
FreeBSD-src-6c76bd6d548ca5eba7c437f4e56c952e1e9381c2.tar.gz
Implement ldconfig functionality for ELF. The hints are stored in
a different file than the a.out hints, namely, "/var/run/ld-elf.so.hints". These hints consist only of the directory search path. There is no hash table as in the a.out hints, because ELF doesn't have to search for the file with the highest minor version number. (It doesn't have minor version numbers at all.) A single run of ldconfig updates either the a.out hints or the ELF hints, but not both. The set of hints to process is selected in the usual way, via /etc/objformat, or ${OBJFORMAT}, or the "-aout" or "-elf" command line option. The rationale is that you probably want to search different directories for ELF than for a.out. "ldconfig -r" is faked up to produce output like we are used to, except that for ELF there are no minor version numbers. This should enable "ldconfig -r" to be used for checking LIB_DEPENDS in ports even for ELF. I implemented the ELF functionality in a new source file, with an eye toward eliminating the a.out code entirely at some point in the future.
Diffstat (limited to 'sbin/ldconfig/ldconfig.c')
-rw-r--r--sbin/ldconfig/ldconfig.c101
1 files changed, 92 insertions, 9 deletions
diff --git a/sbin/ldconfig/ldconfig.c b/sbin/ldconfig/ldconfig.c
index 197cf78..64d4001 100644
--- a/sbin/ldconfig/ldconfig.c
+++ b/sbin/ldconfig/ldconfig.c
@@ -30,7 +30,7 @@
#ifndef lint
static const char rcsid[] =
- "$Id: ldconfig.c,v 1.23 1998/07/06 07:02:26 charnier Exp $";
+ "$Id: ldconfig.c,v 1.24 1998/08/02 16:06:33 bde Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -40,6 +40,7 @@ static const char rcsid[] =
#include <a.out.h>
#include <ctype.h>
#include <dirent.h>
+#include <elf.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
@@ -49,6 +50,7 @@ static const char rcsid[] =
#include <string.h>
#include <unistd.h>
+#include "ldconfig.h"
#include "shlib.h"
#include "support.h"
@@ -56,17 +58,29 @@ static const char rcsid[] =
/* test */
#undef _PATH_LD_HINTS
#define _PATH_LD_HINTS "./ld.so.hints"
+#undef _PATH_ELF_HINTS
+#define _PATH_ELF_HINTS "./ld-elf.so.hints"
#endif
#undef major
#undef minor
+enum obj_format { Unknown, Aout, Elf };
+
+#ifndef DEFAULT_FORMAT
+#ifdef __ELF__
+#define DEFAULT_FORMAT Elf
+#else
+#define DEFAULT_FORMAT Aout
+#endif
+#endif
+
static int verbose;
static int nostd;
static int justread;
static int merge;
static int rescan;
-static char *hints_file = _PATH_LD_HINTS;
+static char *hints_file;
struct shlib_list {
/* Internal list of shared libraries found */
@@ -82,13 +96,14 @@ struct shlib_list {
static struct shlib_list *shlib_head = NULL, **shlib_tail = &shlib_head;
static char *dir_list;
-static void enter __P((char *, char *, char *, int *, int));
-static int dodir __P((char *, int));
-int dofile __P((char *, int));
-static int buildhints __P((void));
-static int readhints __P((void));
-static void listhints __P((void));
-static void usage __P((void));
+static int buildhints __P((void));
+static int dodir __P((char *, int));
+int dofile __P((char *, int));
+static void enter __P((char *, char *, char *, int *, int));
+static enum obj_format getobjfmt __P((int *, char **));
+static void listhints __P((void));
+static int readhints __P((void));
+static void usage __P((void));
int
main(argc, argv)
@@ -97,7 +112,10 @@ char *argv[];
{
int i, c;
int rval = 0;
+ enum obj_format fmt;
+ fmt = getobjfmt(&argc, argv);
+ hints_file = fmt == Aout ? _PATH_LD_HINTS : _PATH_ELF_HINTS;
while ((c = getopt(argc, argv, "Rf:mrsv")) != -1) {
switch (c) {
case 'R':
@@ -124,6 +142,15 @@ char *argv[];
}
}
+ if (fmt == Elf) {
+ if (justread)
+ list_elf_hints(hints_file);
+ else
+ update_elf_hints(hints_file, argc - optind,
+ argv + optind, merge || rescan);
+ return 0;
+ }
+
dir_list = strdup("");
if (justread || merge || rescan) {
@@ -179,6 +206,62 @@ char *argv[];
return rval;
}
+static enum obj_format
+getobjfmt(argcp, argv)
+ int *argcp;
+ char **argv;
+{
+ enum obj_format fmt;
+ char **src, **dst;
+ const char *env;
+ FILE *fp;
+
+ fmt = Unknown;
+
+ /* Scan for "-aout" or "-elf" arguments, deleting them as we go. */
+ for (dst = src = argv + 1; *src != NULL; src++) {
+ if (strcmp(*src, "-aout") == 0)
+ fmt = Aout;
+ else if (strcmp(*src, "-elf") == 0)
+ fmt = Elf;
+ else
+ *dst++ = *src;
+ }
+ *dst = NULL;
+ *argcp -= src - dst;
+ if (fmt != Unknown)
+ return fmt;
+
+ /* Check the OBJFORMAT environment variable. */
+ if ((env = getenv("OBJFORMAT")) != NULL) {
+ if (strcmp(env, "aout") == 0)
+ return Aout;
+ else if (strcmp(env, "elf") == 0)
+ return Elf;
+ }
+
+ /* Take a look at "/etc/objformat". */
+ if ((fp = fopen("/etc/objformat", "r")) != NULL) {
+ char buf[1024];
+
+ while (fgets(buf, sizeof buf, fp) != NULL) {
+ if (strcmp(buf, "OBJFORMAT=aout\n") == 0)
+ fmt = Aout;
+ else if (strcmp(buf, "OBJFORMAT=elf\n") == 0)
+ fmt = Elf;
+ else
+ warnx("Unrecognized line in /etc/objformat: %s",
+ buf);
+ }
+ fclose(fp);
+ }
+ if (fmt != Unknown)
+ return fmt;
+
+ /* As a last resort, use the compiled in default. */
+ return DEFAULT_FORMAT;
+}
+
static void
usage()
{
OpenPOWER on IntegriCloud